Converting normal rotation to transform rotation
by A F · in Torque 3D Professional · 10/23/2012 (1:17 am) · 3 replies
I am trying to create a new object and rotate that to line up with the angle of the surface of the object that the player is facing.
I cast a ray infront with:
The setTransform function needs 7 numbers to be given to it, the XYZ position and the XYZW rotation.
How do you convert the 3 number rotation to the correct 4 number rotation?
I cast a ray infront with:
%res = containerRayCast(%start, %end, %mask, %player);and this gives 7 numbers. The ID, The XYZ position and the XYZ rotation of the face that the ray hit.
The setTransform function needs 7 numbers to be given to it, the XYZ position and the XYZW rotation.
How do you convert the 3 number rotation to the correct 4 number rotation?
#2
I found my problem, I had it working originally, in theory.
I made this:
which seemed to me like it should work but wasn't really doing anything.
I was creating a static shape and running this function on it was scaling it. The numbers that were being used from the raycast were fairly similar so I didn't notice the scaling and thought it just wasn't rotating.
When I use a player object instead it rotates correctly to match teh face of the model that the ray cast hits.
10/23/2012 (6:43 pm)
Thanks Steve. There are lots of useful functions in there, somehow not the one for doing this though.I found my problem, I had it working originally, in theory.
I made this:
DefineEngineMethod( SceneObject, setRot, void, ( VectorF rot ),,
"Set the object's rotation.\n"
"@param rot objects new VectorF rotation\n" )
{
MatrixF mat;
mat = object->getTransform();
mat.setColumn(1, rot);
object->setTransform(mat);
}which seemed to me like it should work but wasn't really doing anything.
I was creating a static shape and running this function on it was scaling it. The numbers that were being used from the raycast were fairly similar so I didn't notice the scaling and thought it just wasn't rotating.
When I use a player object instead it rotates correctly to match teh face of the model that the ray cast hits.
#3
Get player rotation or transform and do rotation +-180 degrees.
Torque script step in radians, you can have a value between 0 and 2PI.
Conversion help: (equivalence decimal)
0 radians = -2PI radians.
PI radians = -3PI/2 radians.
example: (z 180 degree rotation)
%objTransform = %object.getTransform();
%tryRotation = "0 0 0 0 0 1 " @ mDegToRad(180);
%newTransform = matrixMultiply(%objTransform, %tryRotation);
%object.setTransform(%newTransform);
10/24/2012 (12:38 am)
A simple way to do this is the player transform.Get player rotation or transform and do rotation +-180 degrees.
Torque script step in radians, you can have a value between 0 and 2PI.
Conversion help: (equivalence decimal)
0 radians = -2PI radians.
PI radians = -3PI/2 radians.
example: (z 180 degree rotation)
%objTransform = %object.getTransform();
%tryRotation = "0 0 0 0 0 1 " @ mDegToRad(180);
%newTransform = matrixMultiply(%objTransform, %tryRotation);
%object.setTransform(%newTransform);
Associate Steve Acaster
[YorkshireRifles.com]
[edit]
library_functions_Torque.zip
Not sure if useful or not.