Game Development Community

How to Rotate DTS Models in TorqueX

by Charles Speer · in Torque X 2D · 05/06/2008 (9:02 pm) · 2 replies

I have a sphere model loaded in the game and I have the velocity change with the thumbstick accordingly. However, the sphere does not rotate. I need it to rotate along only 1 axis, but I'm not sure how to achieve this. I've messed with the RotationScale variable in the Rigid component, but it still didn't work right. I've read up on the rotation matrix and how this can help rotate your object, but I don't know how to apply this correctly. Can anyone give any sample code or a simple example of how this can be done? Any help is greatly appreciated.

#1
05/07/2008 (5:48 am)
I'm sure there is an easier way of handling rotations but this is how I am handling rotations within my models since I am manipulating individual bones. Essentially I name my object in the xml declaration and then use that to find the object in code. Then I access the render component to get at its render transform and locate a bone. I believe that all models have at least one bone so you can use that root node to manipulate the entire object.

Once you have the objects transform it is pretty easy to manipulate the object in any axis using:
Matrix.CreateRotationX(rad);
Matrix.CreateRotationY(rad);
Matrix.CreateRotationZ(rad);
....

_dtsObj = TorqueObjectDatabase.Instance.FindObject(_dtsName);
_dtsRender = _dtsObj.Components.FindComponent();
_nodeID = _dtsRender.Shape.FindNode("boneName");
_dtsRender.ShapeInstance.NodeTransforms[_nodeID] = Matrix .Identity * Matrix.CreateRotationZ(MathHelper.PiOver2);

Hopefully someone else can come up with an easier way of accomplishing this since I am still very early in my learning of the TorqueX engine.

John
#2
05/07/2008 (8:08 am)
That looks great! Thanks JT. I'll try it out later today, and hopefully that will work for me.