Author Topic: [SOLVED] Vector to Euler or Axis  (Read 682 times)

I need to convert a 3D normal vector (i.e. getEyeVector()) into a Euler angle set or an axis (For orientating objects). I've found no valuable information so far and a large amount of google searching has been no help. A full function to convert a vector to a set of Euler angles or an axis would be great, but tips are also appreciated.
« Last Edit: November 17, 2014, 07:03:25 PM by redoctober2009 »

Code: [Select]
function eulerToVector(%ang) {
if(getWordCount(%ang) == 2) //Support for giving pitch and yaw, but not roll.
%ang = getWord(%ang, 0) SPC 0 SPC getWord(%ang, 1);

%yaw = mDegToRad(getWord(%ang, 2));
%pitch = mDegToRad(getWord(%ang, 0));
%x = mSin(%yaw) * mCos(%pitch) * 1;
%y = mCos(%yaw) * mCos(%pitch);
%z = mSin(%pitch);

return %x SPC %y SPC %z;
}

function axisToVector(%ang) {
return eulerToVector(axisToEuler(%ang));
}

function vectorToEuler(%vec) {
%vec = vectorNormalize(%vec);
%yaw   = mRadToDeg(mATan(getWord(%vec, 0), getWord(%vec, 1)));
%pitch = mRadToDeg(mASin(getWord(%vec, 2)));
return %pitch SPC 0 SPC %yaw;
}

function vectorToAxis(%vec) {
return eulerToAxis(vectorToEuler(%vec));
}

You'll need the stickied euler/axis conversion functions for the axis parts.

I really need to post all my advanced vector math functions in a resource somewhere..
Its worth noting that these are not optimized at all. I'm sure port or trinick or somebody is gonna come in and point out all the horrible things I did. But they work.
« Last Edit: November 17, 2014, 07:05:48 PM by boodals 2 »

-helpful as forget snip

This is exactly what I needed. Please do post those functions somewhere.