Object Coordinates 101
by Gordon Marsh · in Torque Game Engine · 09/01/2006 (7:48 am) · 4 replies
Hi,
Can anyone explain to me how the coordinates system works in Torque for positioning objects or point me towards a resource for this?
I was expecting to see a grid something like (for the 2D plane):
(0,1000) -- (1000, 1000)
| |
| |
(0,0) ------- (1000,0)
But I now realise I am way off the mark as when I call
Point3F Pos = this->getRotation();
Point3F Rot = this->getPosition();
(where 'this' is my player object) and print out the x,y,z values of each I get something like the following:
0.000000 0.000000 5.117071 -45.696762 450.231781 202.960510
I really have no idea what these numbers relate to, and am therefore at a bit of a loss when I try to do the dynamic repositioning work I am currently involved in.
Thanks, Gords
Can anyone explain to me how the coordinates system works in Torque for positioning objects or point me towards a resource for this?
I was expecting to see a grid something like (for the 2D plane):
(0,1000) -- (1000, 1000)
| |
| |
(0,0) ------- (1000,0)
But I now realise I am way off the mark as when I call
Point3F Pos = this->getRotation();
Point3F Rot = this->getPosition();
(where 'this' is my player object) and print out the x,y,z values of each I get something like the following:
0.000000 0.000000 5.117071 -45.696762 450.231781 202.960510
I really have no idea what these numbers relate to, and am therefore at a bit of a loss when I try to do the dynamic repositioning work I am currently involved in.
Thanks, Gords
#2
The first three are X Y Z coordinates in world space. The last three are rotation values for the object. There's alot more stuff going on with Object Boxes, World Boxes and relational vectors, but that is the basic idea.
09/01/2006 (8:52 am)
Quote:
0.000000 0.000000 5.117071 -45.696762 450.231781 202.960510
I really have no idea what these numbers relate to, and am therefore at a bit of a loss when I try to do the dynamic repositioning work I am currently involved in.
The first three are X Y Z coordinates in world space. The last three are rotation values for the object. There's alot more stuff going on with Object Boxes, World Boxes and relational vectors, but that is the basic idea.
#3
i'm sure you've realized, but you've got Rotation and Position swapped:
Point3F Pos = this->getRotation();
Point3F Rot = this->getPosition();
also note that player objects are special in that they only rotate around Z (the vertical), never around X or Y.
i believe that *only* player objects have the simple "getRotation()" method.
so yr numbers are telling you the player is located at x = -45 y = 450 z = 202, and is rotated 5.12 radians about Z, aka 293 degrees.
For objects besides Player objects,
the "TGE way" to get/set position and rotation involve the transformation matrix directly.
eg
Setting the position and orientation are similar but reversed.
in general your coding will go better if you use quaternions instead of eulers,
i try to use eulers only when there's a specific reason to.
also note that "quaternion" is unfortunately a somewhat imprecisely defined term across various 3D systems, so beware that what mathworld.wolfram.com has to say about them may not be obviously relevant to TGE. ;)
09/01/2006 (9:33 am)
Gord -i'm sure you've realized, but you've got Rotation and Position swapped:
Point3F Pos = this->getRotation();
Point3F Rot = this->getPosition();
also note that player objects are special in that they only rotate around Z (the vertical), never around X or Y.
i believe that *only* player objects have the simple "getRotation()" method.
so yr numbers are telling you the player is located at x = -45 y = 450 z = 202, and is rotated 5.12 radians about Z, aka 293 degrees.
For objects besides Player objects,
the "TGE way" to get/set position and rotation involve the transformation matrix directly.
eg
// get position Point3F pos; shape->GetTransform().getColumn(3, &pos); // get orientation as quaternion QuatF rotQuat; rotQ.set(shape->GetTransform()); // or get orientation as euler rotations EulerF rotEuler; rotEuler = shape->GetTransform().extractEuler();
Setting the position and orientation are similar but reversed.
MatrixF mat; // set orientation from quaternion rotQuat.setMatrix(&mat); // or set orientation from eulers mat.set(rotEuler); // set position mat.setColumn(3, pos); // and apply the transform shape->setTransform(mat); // also you can do things more directly: shape->getTransform().setColumn(3, Point3F(100.0f, 200.0f, 300.0f));
in general your coding will go better if you use quaternions instead of eulers,
i try to use eulers only when there's a specific reason to.
also note that "quaternion" is unfortunately a somewhat imprecisely defined term across various 3D systems, so beware that what mathworld.wolfram.com has to say about them may not be obviously relevant to TGE. ;)
#4
en.wikipedia.org/wiki/Cartesian_coordinate_system#Three-dimensional_coordinate_s...
And no Orion, I hadn't noticed my mix up, so you probably saved me a few hours of hair-tearing there!
Thanks,
Gords
09/06/2006 (12:01 pm)
OK, thanks very much Orion and Stefan. For anyone else interested, or those who need a reminder as to which way x, y, z actually go... look here:en.wikipedia.org/wiki/Cartesian_coordinate_system#Three-dimensional_coordinate_s...
And no Orion, I hadn't noticed my mix up, so you probably saved me a few hours of hair-tearing there!
Thanks,
Gords
Torque Owner Gordon Marsh
www.garagegames.com/mg/forums/result.thread.php?qt=33800
but if anyone could give me a laymans overview that would be great!