// Common Support Function Library R7 // Created by Keen - http://radiantage.com // The functions below were created by the following: // Founder // ZOD // z0dd // Code rights (c) the aforementioned, if used, credit for function usage is required // Calculate Quaternion rotation from Euler rotation given Radians function calcThisRot(%thisRot) { %Mrot = MatrixCreateFromEuler(%thisRot); %rot = getWord(%Mrot, 3) SPC getWord(%Mrot, 4) SPC getWord(%Mrot, 5) SPC mCeil(mRadtoDeg(getWord(%Mrot, 6))); return %rot; } // Same as above, but using Degrees function calcThisRotD(%this) { %rx = mDegToRad(getWord(%this, 0)); %ry = mDegToRad(getWord(%this, 1)); %rz = mDegToRad(getWord(%this, 2)); %thisRot = %rx SPC %ry SPC %rz; %Mrot = MatrixCreateFromEuler(%thisRot); %rot = getWord(%Mrot, 3) SPC getWord(%Mrot, 4) SPC getWord(%Mrot, 5) SPC mCeil(mRadtoDeg(getWord(%Mrot, 6))); return %rot; } // Same as above, but using a Vector function calcThisRotV(%this) { %rx = mDegToRad(getWord(%this, 0)); %ry = mDegToRad(getWord(%this, 1)); %rz = mDegToRad(getWord(%this, 2)); %thisRot = %rx SPC %ry SPC %rz; %Mrot = MatrixCreateFromEuler(%thisRot); %rot = getWord(%Mrot, 3) SPC getWord(%Mrot, 4) SPC getWord(%Mrot, 5) SPC mCeil(mRadtoDeg(getWord(%Mrot, 6))); return %rot; } // Converts decimal numbers to hexidecimal function DecToHex(%num) { %w[1] = mFloor(%num / 16); %w[2] = %num - (%w[1] * 16); for (%i=1;%i<3;%i++) { if (%w[%i] == 10) %w[%i] = "A"; if (%w[%i] == 11) %w[%i] = "B"; if (%w[%i] == 12) %w[%i] = "C"; if (%w[%i] == 13) %w[%i] = "D"; if (%w[%i] == 14) %w[%i] = "E"; if (%w[%i] == 15) %w[%i] = "F"; } return %w[1] @ %w[2]; } // returns the rotation from position one pointing to position two, quaternion function getRotationFromPoints(%posOne, %posTwo) { %vec = VectorSub(%posTwo, %posOne); // pull the values out of the vector %x = firstWord(%vec); %y = getWord(%vec, 1); %z = getWord(%vec, 2); //this finds the distance from origin to our point %len = vectorLen(%vec); //---------XY----------------- //given the rise and length of our vector this will give us the angle in radians %rotAngleXY = mATan( %z, %len ); //---------Z----------------- //get the angle for the z axis %rotAngleZ = mATan( %x, %y ); //create 2 matrices, one for the z rotation, the other for the x rotation %matrix = MatrixCreateFromEuler("0 0" SPC %rotAngleZ * -1); %matrix2 = MatrixCreateFromEuler(%rotAngleXY SPC "0 0"); //now multiply them together so we end up with the rotation we want %finalMat = MatrixMultiply(%matrix, %matrix2); //we're done, send the proper numbers back return getWords(%finalMat, 3, 6); }