Game Development Community

Turnshape.cs rotation (chapter 3)

by Matthew W · in Torque Game Engine · 03/10/2008 (8:49 pm) · 2 replies

This code makes an error that i cant understand and i cant find an answer in the past threads.
function TurnShape(%shape, %angle) {

  echo ("TurnShape: shape id: ", %shape);
  echo ("TurnShape: angle: ", %angle);
  %xfrm = %shape.getTransform();
  %lx = getword(%xfrm, 0);
  %ly = getword(%xfrm, 1);
  %lz = getWord(%xfrm, 2);
  %rx = getword(%xfrm, 3);
  %ry = getword(%xfrm, 4);
  %rz = getword(%xfrm, 5);
  %rd = getword(%xfrm, 6);  //i added this line..


  echo ("TurnShape: current angle: ", %rd);  //..and this line

  %rd += %angle;  // ..and changed this line.


  %shape.setTransform(%lx SPC %ly SPC %lz SPC %rx SPC %ry SPC %rz SPC %rd);
  echo ("TurnShape: done.");
}


and, after a while, this happens:

img.photobucket.com/albums/v311/fluttering/turnshape_console.jpg
As that command keeps being entered it gets to 2.02 and then jumps back and forth between 4.16319 and 2.02. Well, i just wanted to see the building rotate all the way around; and it did rotate in the same direction for a while before it messes up. What do you think is wrong?

#1
03/10/2008 (10:11 pm)
Well it look sto me like you're messing with the angle portion of a transform matrix.
If you're trying to rotate an object, why not add onto the heading,bank, or pitch rotation 3,4,5?

But anyhow, the angle affects all the rotation direction. it's sorta a multiplier of sorts. I don't really understand it, but i know that's not the way to rotate things.
#2
03/10/2008 (10:36 pm)
Transform elements 3,4,5 and 6 form an axis angle specification of rotation.
They have nothing to do with heading, bank, pitch (that is: elements 3,4,5 aren't Euler angles.)

If the object is always upright, you can use an "axis" part of 0 0 1 (rotating "angle" about the up axis.)

%rx = 0
%ry = 0
%rz = 1

Another issue may be that the angle may be expressed in radians.