To vector translate or not to vector translate...
Hello all, do any of you brainy folk have a code snippet that translates a vector without the use of matrices, or is that a bad idea??
When you say "translate a vector" I assume you have a vector that represents a coordinate location. I don''t know why you''d want to translate a pure vector, such as a normal vector.
Ultimately, even using a matrix, a translation leads to something
like:
vector.x = vector.x + translation.x;
vector.y = vector.y + translation.y;
vector.z = vector.z + translation.z;
I see no harm in doing that directly.
(If you need to "transform" the vector----which can mean scale or rotate----then you can do that in a closed form manner as well, and it can be cheaper when you know you''re rotating about a given axis for example.)
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Ultimately, even using a matrix, a translation leads to something
like:
vector.x = vector.x + translation.x;
vector.y = vector.y + translation.y;
vector.z = vector.z + translation.z;
I see no harm in doing that directly.
(If you need to "transform" the vector----which can mean scale or rotate----then you can do that in a closed form manner as well, and it can be cheaper when you know you''re rotating about a given axis for example.)
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
September 25, 2001 05:54 AM
Thanks for the reply Graham, I''ll clarify my exact problem.
I am using opengl''s tranlation function to posistion a model at a certain location. I am calculating a bounding box for this model before I translate it and I obviously want the bounding box to move to the same location. So I''m after a similar function that will actualy update a vectors posisiton.
I am using opengl''s tranlation function to posistion a model at a certain location. I am calculating a bounding box for this model before I translate it and I obviously want the bounding box to move to the same location. So I''m after a similar function that will actualy update a vectors posisiton.
OK, your clarification helps me to ask these new questions. Hopefully we''ll get to the bottom of the solution!
So the vector you want to translate is actually the position of the bounding box? And, since the bounding box is used for collisions or culling or something and not merely a graphic to be drawn, you''d like to know how to translate the vector *independent* of the glTranslate() methods? (Because if the bounding box was merely to be rendered, why not just draw it with the object once you''ve caleld glTranslate()?)
If the answer to both questions is yes, then here is a new question. How do you represent the vector? Is it a property of the bounding box object? What does the vector object itself look like?
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
So the vector you want to translate is actually the position of the bounding box? And, since the bounding box is used for collisions or culling or something and not merely a graphic to be drawn, you''d like to know how to translate the vector *independent* of the glTranslate() methods? (Because if the bounding box was merely to be rendered, why not just draw it with the object once you''ve caleld glTranslate()?)
If the answer to both questions is yes, then here is a new question. How do you represent the vector? Is it a property of the bounding box object? What does the vector object itself look like?
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Well Graham, the answer to the first 2 questions are indeed yes.
The bounding box is represented by 2 3d co-ordinates, minimum and max values. I can translate the box using gl_translate() and display it correctly. I''m using the box for collision perposes and what I want to do is to translate the actual pair of co-ordinates. For example:
--read model;
--calculate bounds;
--translate model;
--display model;
--translate bounds;
--check collisions;
Theres nothing fancy going on at all as regards to the bounding box. I hope I''ve made the problem clearer.
The bounding box is represented by 2 3d co-ordinates, minimum and max values. I can translate the box using gl_translate() and display it correctly. I''m using the box for collision perposes and what I want to do is to translate the actual pair of co-ordinates. For example:
--read model;
--calculate bounds;
--translate model;
--display model;
--translate bounds;
--check collisions;
Theres nothing fancy going on at all as regards to the bounding box. I hope I''ve made the problem clearer.
I''ve come to the conclusion that this is really a programming question and not a math or physics question. I''ll give my thoughts, but if they don''t really give you the guidance you''re looking for I''ll move the thread to the graphics programming and theory forum.
You have *two* coordinates that need to be translated, the minimum and maximum 3d points of the bounding box. I see this as straightforward. I''ll write *one* approach in terms of your list of steps:
So, really all I did was explicitly increment the 2 bounding box points using the *same* values that were passed into the glTranslate() call.
This approach is simple as long as you are only doing a translate. If you''re doing a rotate as well, then you may be better off constructing a 4x4 transformation matrix and then applying that matrix to each of the two box points, for example:
bbox->min = transformation_matrix * bbox->min;
bbox->max = transformation_matrix * bbox->max;
where transformation_matrix is your 4x4 matrix that contains both translation and rotations, and * is overloaded to multiply a 4 x 4 matrix times a vector of length 4. NOTE: For arbitrary transformations, vectors are represented as either (x, y, z, 1) or (x, y, z, 0). The former case is a coordinate in space----which your bounding box points are. The latter case is a vector direction that doesn''t represent a physical point in space.
If you do need to do rotations, but are not familiar with transformation matrices, let me know here. That is something that you can get an answer to in the graphics programming and theory forum, and I''ll move the thread there if you need some assistance learning about this.
If you''re only doing translation, then you can save a bit of work by representing your bounding box as one minimum point, and then the vector representing the width, height, and depth. This way, you only have to update the minimum point in the translate bounds step. But this does make your collision checks a bit more expensive. If you have very few collisions it might be a good idea.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
You have *two* coordinates that need to be translated, the minimum and maximum 3d points of the bounding box. I see this as straightforward. I''ll write *one* approach in terms of your list of steps:
|
So, really all I did was explicitly increment the 2 bounding box points using the *same* values that were passed into the glTranslate() call.
This approach is simple as long as you are only doing a translate. If you''re doing a rotate as well, then you may be better off constructing a 4x4 transformation matrix and then applying that matrix to each of the two box points, for example:
bbox->min = transformation_matrix * bbox->min;
bbox->max = transformation_matrix * bbox->max;
where transformation_matrix is your 4x4 matrix that contains both translation and rotations, and * is overloaded to multiply a 4 x 4 matrix times a vector of length 4. NOTE: For arbitrary transformations, vectors are represented as either (x, y, z, 1) or (x, y, z, 0). The former case is a coordinate in space----which your bounding box points are. The latter case is a vector direction that doesn''t represent a physical point in space.
If you do need to do rotations, but are not familiar with transformation matrices, let me know here. That is something that you can get an answer to in the graphics programming and theory forum, and I''ll move the thread there if you need some assistance learning about this.
If you''re only doing translation, then you can save a bit of work by representing your bounding box as one minimum point, and then the vector representing the width, height, and depth. This way, you only have to update the minimum point in the translate bounds step. But this does make your collision checks a bit more expensive. If you have very few collisions it might be a good idea.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Thankyou Graham, the problem has finally been resolved!
Your example did not not work as expected as the bounding values were constantly iterated every frame, due to the fact that the code is in the main rendering loop. So once I moved it, the box was translated correctly. Before posting my prob I remember trying your method at one stage, and since getting the undesired results I got a bit confused, thinking that there must be more to translation than I thought.
Thanks for your advice on matrices, I''m trying to steer clear of them for now until I really know why I need to use them.(It''s working so far!).
Your example did not not work as expected as the bounding values were constantly iterated every frame, due to the fact that the code is in the main rendering loop. So once I moved it, the box was translated correctly. Before posting my prob I remember trying your method at one stage, and since getting the undesired results I got a bit confused, thinking that there must be more to translation than I thought.
Thanks for your advice on matrices, I''m trying to steer clear of them for now until I really know why I need to use them.(It''s working so far!).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement