#### Archived

This topic is now archived and is closed to further replies.

# Converting coordinate systems

This topic is 5715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, this may be a big beginnerish sounding, but I haven''t been able to get any conclusive answers yet, so here it goes: The question: How do I transform Object coordinates to World coordinates? The books I have, say to do a rotation and such, but it doesn''t how much to rotate, or how to tell when you''ve rotated enough. The situation: I have a basic terrain engine, and have a .3DS model loader. The .3DS models all have a bounding box around them, and Min/Max vectors accessible. I''m looking to convert these boxes (vectors) to world coordintates, for a rudimentary collision detection system. I''m looking for some kind of explanation of what steps are necessary (and, if it involves rotations like the 1 paragraph in a book that "covers" this topic, more info on how to tell how much of a rotation is needed. The book is "3D Math Primer...") I''m using OpenGL if that helps. Thanks in advance!

##### Share on other sites
Transform the coordinates by the object-to-world transform.

You probably associate a position and an orientation with your 3ds models. WHen they walk around, you change the position. When they look around, you change the orientation/rotation.

Your render code probably looks like this:
for each model
PushMatrix();
Translate(position);
Rotate(angle,axis);
DrawModel();
PopMatrix();

So, the transformation is described by the translation and the rotation. Specifically, if T is your translation matrix, and R is your rotation matrix, you want T*R. Transform the bounding box vertices by this matrix, and you''ll get its coordinates in world space. Don''t forget to transform back to object space(by (T*R)^-1) when you apply collision response.

##### Share on other sites
You''re pretty much right on with the render code that I have (minus the rotate), but I''m still not quite clear -- Is the rotation matrix something that I should be specifying? And the same question for the translation matrix... What exactly is a "transform," when you say "Transform the bounding box vertices by this matrix." For my world-movement, I have created a custom "ViewMatrix" matrix, which is multiplied by the OpenGL matrix for all movement -- Does this count as my translation and rotation matrix? Sorry for all the Q''s, but I''m new to the space conversions and such...

Thanks again...

##### Share on other sites
quote:
Is the rotation matrix something that I should be specifying?

You can specify it with a glRotate. If your object doesn''t have a rotation, then don''t worry about it.

A transformation is a operation to go from one coordinate space to another. For our purposes, it is a matrix that is composed of translation and rotation matrices. Your view matrix is a transformation that goes from world space to eye space.

When I say transform the bounding box, you can multiply each corner vertex by the transformation matrix that goes from object space to world space.

##### Share on other sites
Hey, thanks a lot -- I think I understand what I need to do to get it done -- With a few lingering questions. With the Objects, let''s say I translate one of them to (10, 20, 30). When you say "the transformation is described by the translation and the rotation," then (since I have no rotation on the objects) what needs to be done to the Min/Max object vectors is:

(Min.x * 10) (Max.x * 10)
(Min.y * 20) (Max.y * 20)
(Min.z * 30) (Max.z * 30)

Is this correct? I''ve implemented that basic math -- And the collisions still do not register, so I am not sure if the problem lies within my collision function or the Object/World coordinates still.

Thanks again for all your help!

##### Share on other sites
Well, if all you have is a translation, then you can just add vectors:
world.x = object.x + translation.x
world.y = object.y + translation.y
world.z = object.z + translation.z

If you want to construct a translation matrix, it will look like this:
1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1
Where x,y,z is your translation. Then you can do a matrix vector multiply(translation matrix * object position vector).

So for now you can just take the bounding box min and max, and add the translation from object to world space. So if your object is at (10,20,30), just add (10,20,30) to the bounding box min and max. If you add rotations to your objects later on it will get more complicated though.

Hope that helps =)

##### Share on other sites
Well, I''m glad you said that about just adding the object translations to the min/max vectors... That''s actually what I had been doing first, but it wasn''t working so I figured I needed to do something else. Guess I''ll go check out my actual collision function...thanks for all the help! =)

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633324
• Total Posts
3011366
• ### Who's Online (See full list)

There are no registered users currently online

×