Library updated to remove a wee buglet.
For those who may be interested here is the code that displays the 'jets' from the nozzles in my little moonlander demo
function Show_Jets (q, x, y, z, xr, yr, zr)
for k,_ in pairs(g_nozzles_list) do
local noz = g_nozzles_list[k]
local NX, NY, NZ = Rotate3D (noz.xo, noz.yo, noz.zo, xr, yr, zr)
local qj = QuatMul(q, noz.q)
local jxr, jyr, jzr = QuatToEuler(qj)
ResetPosition(noz.e1, x - NX, y - NY, z - NZ)
ResetRotation(noz.e1, math.deg(jxr), math.deg(jyr), math.deg(jzr))
jxr, jyr, jzr = QuatToEuler(QuatMul(qj, q90))
ResetPosition(noz.e2, x - NX, y - NY, z - NZ)
ResetRotation(noz.e2, math.deg(jxr), math.deg(jyr), math.deg(jzr))
end
end
Go on admit it, you thought it would be a lot longer than that didn't you?
Here is the code for the Rotate3D function:
function RotatePoint2D (x, y, Ang) -- Ang in radians
local Sa, Ca = math.sin(Ang), math.cos(Ang)
return x*Ca - y*Sa, x*Sa + y*Ca
end
function Rotate3D (x, y, z, xrot, yrot, zrot)
local NX, NY, NZ = x, y, z
-- X
NZ, NY = RotatePoint2D (NZ, NY, -xrot)
-- Y
NX, NZ = RotatePoint2D (NX, NZ, -yrot)
-- Z
NY, NX = RotatePoint2D (NY, NX, -zrot)
return NX, NY, NZ
end
Someone might find it useful, the angles are in radians btw, pass in the x, y, z values (for example the offsets from centre of an entity to the entities rotation point) and the Euler angles (i.e math.rad(Entity,anglex) etc) and it will return back the rotated offsets, simply subtract them from the Entities x, y, z values to find the centre of the entity.
Been there, done that, got all the T-Shirts!