Jump to content
  • Advertisement

Archived

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

Mister Stewart

How many matrices do I actually need?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not sure if this is the right forum for this, but here goes. I have 2 3d objects on screen. Now, I know you need: - a view matrix - a projection matrix - a world matrix Now I've been looking through some of the tutorials and I'm a little bit confused regarding how many matrices you need regarding the movement of each object. I know you need - 3 rotation matrices (1 for each axis (some people use 1 rotation matrix for all 3 axis, but I read 3 separate ones was simpler)) - 1 translation matrix for moving around - 1 scaling matrix What I would like to know is can all the objects use the same rotational/translate/scale matrices, or does each object need its own set of matrices? I think I saw in one piece of code that an object can use a matrix, call SetTransform(world), render that object, then move onto the next object and repeat with the same matrices. Can anyone help please? "Sweetie! Get Mommy's bazooka!" [edited by - Mister Stewart on April 20, 2002 8:43:02 AM]

Share this post


Link to post
Share on other sites
Advertisement
There are many schools of thought on this subject, here''s mine...
You''re going to need independant information (pos,rot,scale) for each object that you want to draw independantly. The SetTransform(world) call that you mentioned most likely took a 4x4 matrix to set the pos,rot,scale as world coordinates ~ this means that the world coordinates are being kept in a 4x4 matrix for each object.
If you are simply going to draw the objects based on external information (input from a device/user/animation path) and you do not need to use the information for editing (e.g. in a modeling package), I would just keep all of the information in one matrix. You can create (or download) a matrix class where you can apply dPos/dRot/dScale and the class applies all of the deltas to the internal matrix. Then, you just have to supply your stored matrix to the SetTransform(world) method.
If you want more feedback (without trying to extract the information from a 4x4 matrix ~which is not entirely possible for there can me multiple solutions to the description of the rotations), then keep the information in a Vector for the position, in a Vector for scale and a Quaternion for the rotation (search for quaternion on this site ~ there are *plenty* of discussion on it). Then, when you make a call to SetTransform(world), you would have to create the 4x4 matrix with the data that is kept in those 3 data sets. Better yet, encapsulate the SetTransform(world) to take those three inputs and calculate the result internally.

Share this post


Link to post
Share on other sites
Thanks for replying.

quote:

There are many schools of thought on this subject, here's mine...
You're going to need independant information (pos,rot,scale) for each object that you want to draw independantly. The SetTransform(world) call that you mentioned most likely took a 4x4 matrix to set the pos,rot,scale as world coordinates ~ this means that the world coordinates are being kept in a 4x4 matrix for each object. [\quote]

So just to clarify, all the info for ALL objects is in this matrix?

[quote]
If you are simply going to draw the objects based on external information (input from a device/user/animation path) and you do not need to use the information for editing (e.g. in a modeling package), I would just keep all of the information in one matrix. You can create (or download) a matrix class where you can apply dPos/dRot/dScale and the class applies all of the deltas to the internal matrix. Then, you just have to supply your stored matrix to the SetTransform(world) method.
[\quote]

So you're saying, each object has its own world matrix, which I use for all the rotation, translation etc
for that object, then call the SetTransform(object matrix)?






"Sweetie! Get Mommy's bazooka!"

[edited by - Mister Stewart on April 20, 2002 12:18:36 PM]

[edited by - Mister Stewart on April 20, 2002 12:19:41 PM]

Share this post


Link to post
Share on other sites
quote:

So just to clarify, all the info for ALL objects is in this matrix?


Not quite.
Each object has a "unique" pos/rot/scale in 3D space. For simplicity, by "unique" I mean that the object''s pos/rot/scale belongs only to the object. The pos/rot/scale/scew[don''t worry about scew right now] set is often collectivley referred to as a Transform.
quote:

So you''re saying, each object has its own world matrix, which I use for all the rotation, translation etc for that object, then call the SetTransform(object matrix)?


For purpose of this discussion... Yes, you are correct.
As an illustration, think of the objects on your desk. Each object (keyboard, mouse, coffee cup, etc...) has a unique transform (it''s position in the world). If you rotate your coffee cup, you change its Transform. To draw all of the objects on your desk as you see them, you would apply the object''s Transform and then draw it. You would do this for every object ~ apply keyboard transform, draw keyboard, apply mouse transform, draw mouse, etc... The fact that each object has a unique Transform requires you to store data for each object (objects are often in a class that encapsulates the object mesh, transform and other things appropriate for the object).
I''m not sure which rendering engine that you are using, but [in OpenGL] it''s important to note that between the drawing of an object and the application of the next object, you generally need to apply an Identity transform (in OpenGL via a push and pop of the matrix) so that the coffee cup''s Transform does not influence the keyboard''s Transform. This is where a discussion on World and Local Transforms would take place... (do understand World and Local?)
Does that make sense?

Share this post


Link to post
Share on other sites
quote:

Each object has a "unique" pos/rot/scale in 3D space. For simplicity, by "unique" I mean that the object''s pos/rot/scale belongs only to the object. The pos/rot/scale/scew[don''t worry about scew right now] set is often collectivley referred to as a Transform.



Gotcha.

quote:

For purpose of this discussion... Yes, you are correct.
As an illustration, think of the objects on your desk. Each object (keyboard, mouse, coffee cup, etc...) has a unique transform (it''s position in the world). If you rotate your coffee cup, you change its Transform. To draw all of the objects on your desk as you see them, you would apply the object''s Transform and then draw it. You would do this for every object ~ apply keyboard transform, draw keyboard, apply mouse transform, draw mouse, etc... The fact that each object has a unique Transform requires you to store data for each object (objects are often in a class that encapsulates the object mesh, transform and other things appropriate for the object).



Gotcha.

quote:

I''m not sure which rendering engine that you are using, but [in OpenGL] it''s important to note that between the drawing of an object and the application of the next object, you generally need to apply an Identity transform (in OpenGL via a push and pop of the matrix) so that the coffee cup''s Transform does not influence the keyboard''s Transform. This is where a discussion on World and Local Transforms would take place... (do understand World and Local?)
Does that make sense?



I''m using DX - I haven''t seen any mention of an identity matrix - would still I need one?

In any case, a struct for a 3d object could be something like
- x,y,z pos
- x,y,z rotation angles
- x,y,z scale factors
- world matrix (for rotating/translating and all that)



"Sweetie! Get Mommy''s bazooka!

Share this post


Link to post
Share on other sites
quote:

In any case, a struct for a 3d object could be something like
- x,y,z pos
- x,y,z rotation angles
- x,y,z scale factors
- world matrix (for rotating/translating and all that)


Yes, you could do it like that. As a note, the world matrix would only be in your structure so that you didn''t have to allocate/deallocate memory every frame. The world matrix should be updated every time you have to draw the object. The value would be based on pos/rot/scale.

Share this post


Link to post
Share on other sites
Identity matrix.
given a matrix 3x3, the id matrix is...
|1 0 0|
|0 1 0| = I
|0 0 1|

I*M = M, where M is any matrix.

Like 1. 1 is the identity for multiplication in Reals.

In opengl, setting the id matrix sets all current matrices to default.


Bugle4d

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!