Barebone scripting - AOA? - ED Forums
 


Notices

Reply
 
Thread Tools Display Modes
Old 12-09-2018, 03:20 AM   #1
Sickdog
Member
 
Sickdog's Avatar
 
Join Date: Jun 2010
Location: Los Angeles, Ca.
Posts: 147
Default Barebone scripting - AOA?

Anyone know how to get the AOA from position vectors with barebone scripting? I realize I can use MIST or MOOSE, but I’d like to figure out how to do it without any scripting tools. I’ve managed to find some equations with the assistance of Google but haven’t had much success despite a lot of trial and error. I’ve gotten Roll, Pitch, Heading, V/S, and Altitude equations working thus far.

While we’re at it, anyone know if it’s possible to get thrust setting from barebone scripting?

Thanks!
__________________
TM Warthog, Oculus Rift, Win10...
Sickdog is offline   Reply With Quote
Old 12-09-2018, 04:01 AM   #2
Grimes
ED Testers Team
 
Grimes's Avatar
 
Join Date: Jan 2006
Location: Black Mesa
Posts: 7,658
Default

You can still look at the code of mist to figure out what is going on. All mist, moose, etc do is to repackage the scripting engine functions to collectively be useful. So if one does something you want to do but on your own, you should feel free to take a look under the hood.

These two functions get called multiple times, so it is good to know them.
Code:
	function mist.vec.dp (vec1, vec2)
		return vec1.x*vec2.x + vec1.y*vec2.y + vec1.z*vec2.z
	end
	function mist.vec.mag(vec)
		return (vec.x^2 + vec.y^2 + vec.z^2)^0.5
	end
Then the actual code to return a given units AoA.
Code:
	function mist.getAoA(unit)
		local unitpos = unit:getPosition()
		if unitpos then
			local unitvel = unit:getVelocity()
			if mist.vec.mag(unitvel) ~= 0 then --must have non-zero velocity!
				local AxialVel = {}	--unit velocity transformed into aircraft axes directions

				--transform velocity components in direction of aircraft axes.
				AxialVel.x = mist.vec.dp(unitpos.x, unitvel)
				AxialVel.y = mist.vec.dp(unitpos.y, unitvel)
				AxialVel.z = mist.vec.dp(unitpos.z, unitvel)

				-- AoA is angle between unitpos.x and the x and y velocities
				local AoA = math.acos(mist.vec.dp({x = 1, y = 0, z = 0}, {x = AxialVel.x, y = AxialVel.y, z = 0})/mist.vec.mag({x = AxialVel.x, y = AxialVel.y, z = 0}))

				--now set correct direction:
				if AxialVel.y > 0 then
					AoA = -AoA
				end
				return AoA
			end
		end
	end
With the scripting engine, the thrust value is not accessible. Probably is within export, but that environment isn't accessible at the mission level. Plus it only works on your own aircraft.
__________________
You can only tie the world record for lowest flight.
Current Projects: Scripting Wiki, Something...
Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD for DCS 1.5/2.0, IADScript, Mission Editing Wiki!, Mission Building Forum
Grimes is offline   Reply With Quote
Old 12-09-2018, 05:14 AM   #3
Sickdog
Member
 
Sickdog's Avatar
 
Join Date: Jun 2010
Location: Los Angeles, Ca.
Posts: 147
Default

Quote:
Originally Posted by Grimes View Post
You can still look at the code of mist to figure out what is going on. All mist, moose, etc do is to repackage the scripting engine functions to collectively be useful. So if one does something you want to do but on your own, you should feel free to take a look under the hood.

These two functions get called multiple times, so it is good to know them.
Code:
	function mist.vec.dp (vec1, vec2)
		return vec1.x*vec2.x + vec1.y*vec2.y + vec1.z*vec2.z
	end
	function mist.vec.mag(vec)
		return (vec.x^2 + vec.y^2 + vec.z^2)^0.5
	end
Then the actual code to return a given units AoA.
Code:
	function mist.getAoA(unit)
		local unitpos = unit:getPosition()
		if unitpos then
			local unitvel = unit:getVelocity()
			if mist.vec.mag(unitvel) ~= 0 then --must have non-zero velocity!
				local AxialVel = {}	--unit velocity transformed into aircraft axes directions

				--transform velocity components in direction of aircraft axes.
				AxialVel.x = mist.vec.dp(unitpos.x, unitvel)
				AxialVel.y = mist.vec.dp(unitpos.y, unitvel)
				AxialVel.z = mist.vec.dp(unitpos.z, unitvel)

				-- AoA is angle between unitpos.x and the x and y velocities
				local AoA = math.acos(mist.vec.dp({x = 1, y = 0, z = 0}, {x = AxialVel.x, y = AxialVel.y, z = 0})/mist.vec.mag({x = AxialVel.x, y = AxialVel.y, z = 0}))

				--now set correct direction:
				if AxialVel.y > 0 then
					AoA = -AoA
				end
				return AoA
			end
		end
	end
With the scripting engine, the thrust value is not accessible. Probably is within export, but that environment isn't accessible at the mission level. Plus it only works on your own aircraft.
Grimes- Has anyone ever told you that you are a gentleman and a scholar? Seriously, THANK YOU, and thank you for the quick reply.

Bummer that the thrust value isn't accessible within the mission scripting... not the end of the world tho.
__________________
TM Warthog, Oculus Rift, Win10...

Last edited by Sickdog; 12-09-2018 at 05:23 AM.
Sickdog is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 04:56 AM. vBulletin Skin by ForumMonkeys. Powered by vBulletin®.
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.