Jump to content

Barebone scripting - AOA?


Sickdog

Recommended Posts

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...

Link to comment
Share on other sites

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.

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.

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.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

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.

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.

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.


Edited by Sickdog

TM Warthog, Oculus Rift, Win10...

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...