Game Development Community

using arrow keys to rotate an object?

by Jeff Yaskus · in Torque 3D Beginner · 09/19/2015 (6:42 pm) · 0 replies

I've been experimenting with rotating an object in T3D.

At first, I setup the camera to orbit around the object.
But that didn't have the desired affect.

Instead, I'd like to rotate the object itself -
Leaving the camera in a fixed position.

So, far I've only been able to get it to rotate on the Z axis ... not X or Y.

Not sure if I'm trying the wrong approach or what --

echo(" object starting transform=" @ %object.getTransform() );

  %txfm = %object.getTransform();

  // change the rotation based on number keys //
   switch$(%direction)
   {
      case "LEFT":   %rotMod = "0 0 0.1";
      case "RIGHT":  %rotMod = "0 0 -0.1";

      case "DOWN":   %rotMod = "0 1 0";
      case "UP":     %rotMod = "0 -1 0";
   }

   // create rotation matrix from radian angles  
   %rotTrans = MatrixCreateFromEuler(%rotMod); 
   
   // multiply against objects original transform
   %newTransform = MatrixMultiply(%txfm, %rotTrans);

   // set the transform   
   %object.setTransform( %newTransform );

This seems to rotate it correctly on the horizontal axis (Z?)
But not the other axis's (guessing it X and Y not rotating)

Is this the correct approach -- Using a matrix multiply ?

Any ideas or examples of how to get it rotating in all directions?
in other words ... +/- X or Y or Z ... based on input.

I get the key mapping, etc ... just need a working example of the matrix math to use.