Skip to main content
gamedev.net
🔒 Locked

D3DMATRIX?

Started by Azteroth 10 replies 3.1k views
Original Post
Azteroth
Azteroth
Hi Everyone I was wondering how do I implement the D3DXMATRIX for displaying models I know that its a 4x4 matrix but I'm trying to do the same thing that is done in NeHe's tutorial 37 but have no idea how to go about doing this. Thank you, Azteroth
Evil Steve
Evil Steve
What are you trying to do? Are you trying to creat your own matrix that can be interchanged with D3DXMATRIX? Are you trying to build a certain type of matrix (E.g. rotational)? Are you trying to set up the transform state to view something?
Azteroth
Azteroth
Well I know on the Nehe tutorial it speaks of openGL using float array of 16 floats to create the matrix and I actually am just trying to render a simple model to the screen and to view but I am under the assumption that I need to use the matrix for putting each vertex on the screen and positioning their normals. Is this the case?

Azteroth
Evil Steve
Evil Steve
D3DX has a bunch of functions for setting up matrices for you, like D3DXMatrixRotationX, D3DXMatrixMultiply, D3DXMatrixTranslation, etc. I wouldn't work with the raw matrix data unless you absolutely have to.
Azteroth
Azteroth
Ok but how do I use those for say an individual vertex, the translation one would be for the positioning right? and the rotation one could be used for calculating the normal position? what is the multiply one used for?

Thank you Steve,
Azteroth
Evil Steve
Evil Steve
I'd recommend reading up on some matrix maths before going any further. A matrix (in this context) is a way to transform a geometric point in some way (A normal is just a point with a distance from the origin of 1). A rotation matrix will rotate a point around another point (the origin), around an axis, a translation will move that point towards from or away from another point (the origin, again), a skew matrix will skew the points, and so on.
When you want to say, rotate and move a point, you multiply the matrices together. Matrix multiplication is not communicative; A * B is not the same as B * A. If C = A * B, then transforming a point by C has the same effect as transforming a point by A, then by B.

OpenGL matrices are the same as Direct3D matrices, except that OpenGL matrices are the transpose of D3D matrices I belive (I've never used OpenGL myself), meaning the order of the elements when you refer to them as a float array is different.
don
don
Quote:
Original post by Evil Steve
...

Matrix multiplication is not communicative; A * B is not the same as B * A. If C = A * B, then transforming a point by C has the same effect as transforming a point by A, then by B.

...


You probably meant to say "commutative".



Azteroth
Azteroth
You are right I do need to read up on this but the best way I have learned in this whole process is to learn by doing so I am going to look around to find some examples of model loaders in directx and looks around for the math and see how they work together. Thank you so much for your help.

Azteroth
Sc4Freak
Sc4Freak
Quote:
Original post by Azteroth
You are right I do need to read up on this but the best way I have learned in this whole process is to learn by doing so I am going to look around to find some examples of model loaders in directx and looks around for the math and see how they work together. Thank you so much for your help.

Azteroth


The problem with that is often you'll know how to use it, but not how it works.

I, too, suggest you do some reading on matrix maths, specifically as they apply to 3D graphics.
Evil Steve
Evil Steve
Quote:
Original post by don
Quote:
Original post by Evil Steve
...

Matrix multiplication is not communicative; A * B is not the same as B * A. If C = A * B, then transforming a point by C has the same effect as transforming a point by A, then by B.

...


You probably meant to say "commutative".
Oddly, I thought that was the word, but the link I got on Google to check said communicative [smile]
TheAdmiral
TheAdmiral
Understand that in the sense of linear algebra, a position is represented by a vector, a direction is also represented by a vector, and a transformation is represented by matrix. In order to apply the transformation to a point, you simply multiply the corresponding matrix and vector, to get a new vector, which represents the new, transformed point.

There's a lot to learn, but a good starting place would be the maths subsection section of GameDev's Articles. Start with vectors, then, when you're comfortable, move on to matrices. Don't worry about quaternions until you have the basics down.

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Azteroth
Azteroth
Thanks a lot for your guys help and to Sc4Freak I do understand what you are saying and in my post I did not mean to imply that I would "just" look at the examples in my learning process in getting to this point I have made sure that I do understand the underlying factors that make the stuff work. I actually was looking into the stuff when I decided to come back here and look now theres a link :).

Thank you for the link TheAdmiral.

Azteroth

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.