Camera rotation problem
by Russell Tracey · in Torque Game Engine · 09/23/2004 (2:40 pm) · 0 replies
Firstly hold back your sniggers as you look at this picture:

What i want to do is have a camera point directly down and then be able to rotate it round. This is all via settransform calls in script. At the moment i can point the camera down but when i try to rotate it round the rotation is off (should be 90 but seems random).
After further looking at the camera code (camera.cc) i noticed the comment that rotations are converted to rotations round the z and x axis. So im wondering if this is the problem.
I'm quite lost, and I've been breaking code for the past couple of days trying to get this seemingly simple thing to work.
Oh yes, my programmer diagram art services are available for a nominal amount :)
code wise this is what i'm doing in script:

What i want to do is have a camera point directly down and then be able to rotate it round. This is all via settransform calls in script. At the moment i can point the camera down but when i try to rotate it round the rotation is off (should be 90 but seems random).
After further looking at the camera code (camera.cc) i noticed the comment that rotations are converted to rotations round the z and x axis. So im wondering if this is the problem.
I'm quite lost, and I've been breaking code for the past couple of days trying to get this seemingly simple thing to work.
Oh yes, my programmer diagram art services are available for a nominal amount :)
code wise this is what i'm doing in script:
// When camera is created:
%newtransform = %this.editorCamera.getPosition() SPC eulerToQuat("-90 0 0",false);
%this.editorCamera.setTransform(%newtransform);
// When the rotate key is pressed:
commandToServer('SetEditCameraRotation',eulerToQuat("0 0 -90",false));
// server-side handler
function serverCmdSetEditCameraRotation(%client, %newrot)
{
%camtransform = %client.editorcamera.getTransform();
// get rotation quaternion
%camrotation = GetWords(%camtransform,3,6);
%v1 = "0 0 0" SPC %camrotation;
%v2 = "0 0 0" SPC %newrot;
%v3 = MatrixMultiply(%v1,%v2);
// build new transform with modified rotation
%newtrans = getWords(%camtransform,0,2) SPC GetWords(%v3,3,6);
%client.editorcamera.setTransform(%newtrans);
}About the author