#### Archived

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

# SetTransform() Method

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

## Recommended Posts

I have a few questions about the SetTransform() method of the IDirect3DDevice9 class. First, does it apply the transformation to the world, object (I don't think it could), or the camera? Second, I was looking in the Direct X SDK files, and I found the declaration (or definition, I'm having problems which is the one where the function has no body, has a colon, and is defined elsewhere) of the function in the D3D9.h file, but couldn't find where the body was (and therefore couldn't try to answer the first question myself), does anyone have an idea where it would be? Edit: Oh yeah, I'm using Visual C++ 6.0. [edited by - jtmerchant on September 2, 2003 12:26:09 AM]

##### Share on other sites
quote:
Original post by jtmerchant
I have a few questions about the SetTransform() method of the IDirect3DDevice9 class. First, does it apply the transformation to the world, object (I don''t think it could), or the camera? Second, I was looking in the Direct X SDK files, and I found the declaration (or definition, I''m having problems which is the one where the function has no body, has a colon, and is defined elsewhere) of the function in the D3D9.h file, but couldn''t find where the body was (and therefore couldn''t try to answer the first question myself), does anyone have an idea where it would be?

Edit: Oh yeah, I''m using Visual C++ 6.0.

[edited by - jtmerchant on September 2, 2003 12:26:09 AM]

You won''t find the actual code for SetTransform. Internally, it tells the driver to update a bunch of stuff and D3D itself updates all kinds of things. But you really don''t need to worry about all that. Look at the documentation that came with the SDK and lookup the function. Here is what the docs say:
IDirect3DDevice9::SetTransform Method--------------------------------------------------------------------------------Sets a single device transformation-related state.SyntaxHRESULT SetTransform(          D3DTRANSFORMSTATETYPE State,    CONST D3DMATRIX *pMatrix);ParametersState[in] Device-state variable that is being modified. This parameter can be any member of the D3DTRANSFORMSTATETYPE enumerated type, or the D3DTS_WORLDMATRIX macro. pMatrix[in] Pointer to a D3DMATRIX structure that modifies the current transformation. Return ValueIf the method succeeds, the return value is D3D_OK.D3DERR_INVALIDCALL is returned if one of the arguments is invalid.

What this tells you is that the function takes two parameters as input. The first one is an enumeration that tells D3D which particular transform you''re setting. The common ones are the world, view, and projection transforms. The second parameter is the actual matrix you want to use.

The matrices are applied to the geometry you render with any of the DrawPrimitive methods in this order:
1. World
2. View
3. Projection

Hope this helps,
neneboricua

##### Share on other sites
Hmm... thanks, but maybe I should be more specific. What my question is if I have the code:

D3DXMATRIX T;
D3DXMatrixTranslation(&T, 2, 0, 0);
Device->SetTransform(D3DTS_WORLD, &T);

Will that actually change the world coordinates, for example, would (0,0,0) the world before I used SetTransform now be (2,0,0) or (-2,0,0) or what?

##### Share on other sites
quote:
Original post by jtmerchant
Hmm... thanks, but maybe I should be more specific. What my question is if I have the code:

D3DXMATRIX T;
D3DXMatrixTranslation(&T, 2, 0, 0);
Device->SetTransform(D3DTS_WORLD, &T);

Will that actually change the world coordinates, for example, would (0,0,0) the world before I used SetTransform now be (2,0,0) or (-2,0,0) or what?

Ok. I see what you mean. In your example, coordinate (0,0,0) would be transformed to (2,0,0). You can see this if you work out the matrix multiplication by hand.

This gets into the whole idea of different "spaces" in 3D graphics. You can think of the World Matrix as the matrix that allows you to position all of the objects in your scene. Usually, an artist will model some object (an airplane, house, etc...) in some 3D modeling package and they will set their model to be at the origin. This is called "model space". All the vertices in the model are relative to the origin.

Say you have a whole bunch of these models that you want to use in your game. Each one is modeled so that all of it''s geometry is around the origin. But you want to position each model at a different location in your world. One thing you could do is access each vertex in the model and change their values so that the model is at the location you want it to be. The problem is that it is really slow to change the vertices of a model every frame. Instead, you use the world transform matrix. D3D will transform all of the vertices in your model by the matrix you''ve set using SetTransform.

So say you have two models. The author of each model has designed their model so that it sits at the origin. But you want to place each model in a different location in your world (i.e. world space). Here''s some pseudo-code for what you do.

beginscene
D3DXMATRIX t;
D3DXMatrixTranslation(&t, model1->p.x, model1->p.y, model1->p.z);
SetTransform(D3DTS_WORLD, &t);
model1->Render();

D3DXMatrixTranslation(&t, model2->p.x, model2->p.y, model2->p.z);
SetTransform(D3DTS_WORLD, &t);
model2->Render();
endscene

By using the world transform, you can position your geometry anywhere in "world space" you want.

neneboricua

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631431
• Total Posts
3000039
×