#### Archived

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

# Pre-Transformations

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

## Recommended Posts

Is there a way of using a D3DMATRIX to transform an object without projecting it on to the screen? I got scaling and translating, but not rotations. Yes, I did transform the verticies myself.

##### Share on other sites
If you put your object in a vertex buffer you can use ProcessVertices on it. Look in the docs for more info on it.

Josh

##### Share on other sites
ewww, vertex buffers! Sorry Josh, no-can-do. I have to pre-rotate my object because I am loading my map files as objects and not as triangles.

##### Share on other sites
You can create a transformation matrix and then multiply each vector with the matrix. Just remember that the normals in the object should be transformed with the transpose of the inverse of the matrix.

V'' = V*M;
N'' = N*(M-1)T

- WitchLord

##### Share on other sites
Spell...er uh...witchlord: I did make a transformation matrix. I used a simple D3DMatrix variable and multiplied it with the vertex. I used the transformation that is used for projecting though.

x = m11 * x + m21 * y + m31 * z + m41
...
...

So should I do this:
V'' = V * m11 + m21 + m31 + m41?

##### Share on other sites

You transform a vector with a matrix like this

void TransformVector(D3DVECTOR &VNew, D3DVECTOR &V, D3DMATRIX &M)
{
float x,y,z,w;
x = V.x * M._11 + V.y * M._21 + V.z * M._31 + M._41;
y = V.x * M._12 + V.y * M._22 + V.z * M._32 + M._42;
z = V.x * M._13 + V.y * M._23 + V.z * M._33 + M._43;
w = V.x * M._14 + V.y * M._24 + V.z * M._34 + M._44;

if( fabs(w) < 1e-5f )
w = 1; // Avoid divide by zero

VNew.x = x/w;
VNew.y = y/w;
VNew.z = z/w;
}

- WitchLord

##### Share on other sites
I know that but I am trying to just rotate an object so I can just copy all of the verticies of that object into one object. Basically the rotation matrix is to be used for just rotating and not projecting. The thing that you did is only for projecting right? At least when I first did that it looked like it was 2d in 3d space.

##### Share on other sites
What I do _can_ be used for projecting the vertices, but it doesn''t have to do that. The calculation that I do can do all the transformations you need, translation, rotation, scaling etc.

In fact this is exactly how it is done inside Direct3D. Just build the transformation matrix like you would build the world matrix in Direct3D, and then use it to transform your vertices with the above function.

Optimization: If your transform matrix doesn''t have any divisions in it (projections) you can safely omit the calculations of w and instead set it to 1.

Technical (you don''t need to understand this): In order to transform a vector with a matrix the vector must be in homogenous format, i.e. (x,y,z,w). This conversion is usually done by setting w to 1 and then multiply it with the matrix. Then the vector must be converted back to normal 3D format and so you divide all by w, and then remove it to get (x/w, y/w, z/w).

- WitchLord

##### Share on other sites
You can hit each vertex with the tx matrix and use the D3DMath method:

D3DMath_VertexMatrixMultiply(D3DVERTEX& vDest, D3DVERTEX& vSrc, D3DMATRIX& mat );

just include d3dmath.h

##### Share on other sites
quote:
Original post by WitchLord

What I do _can_ be used for projecting the vertices, but it doesn't have to do that. The calculation that I do can do all the transformations you need, translation, rotation, scaling etc.

In fact this is exactly how it is done inside Direct3D. Just build the transformation matrix like you would build the world matrix in Direct3D, and then use it to transform your vertices with the above function.

Optimization: If your transform matrix doesn't have any divisions in it (projections) you can safely omit the calculations of w and instead set it to 1.

Technical (you don't need to understand this): In order to transform a vector with a matrix the vector must be in homogenous format, i.e. (x,y,z,w). This conversion is usually done by setting w to 1 and then multiply it with the matrix. Then the vector must be converted back to normal 3D format and so you divide all by w, and then remove it to get (x/w, y/w, z/w).

- WitchLord

I understand 100%, but when I transform my verticies they are projected and not transformed. They are not projected on to the screen, but they are projecting in 3d as a 2d object. If you still cannot understand what I mean, I'll make a screenshot and/or give you a copy of the code.(Visual Basic!)

Basically I just did the v*m type thing and did NOT divide by w and multiply by half the screen dimensions. I forgot to tell you that I am trying to transform the verts and then pass them as a normal D3DVERTEX struct and not a D3DTLVERTEX struct. That is why I called a PRE-transformation. Thanks.

Edited by - Anonymous Poster on May 10, 2000 4:21:52 PM

Edited by - nes8bit on May 10, 2000 4:50:28 PM

• 12
• 33
• 12
• 15
• 15