Sign in to follow this  
DevTuts

Reset states of the matrix

Recommended Posts

DevTuts    100
hi!

I am studying DirectX 9, and I have a doubt:

I apply some transformations in a box, exactly those transformations
	// Setup world matrix
D3DXMATRIXA16 matWorld,matWorld2;

// set the rotation matrix
D3DXMatrixRotationYawPitchRoll(&matWorld2,rotation.x,rotation.y,rotation.z);

D3DXMatrixScaling(&matWorld,scale,scale,scale);

D3DXMatrixMultiply(&matWorld,&matWorld,&matWorld2);

D3DXMatrixTranslation( &matWorld2, vPos.x, vPos.y,vPos.z );

D3DXMatrixMultiply(&matWorld,&matWorld,&matWorld2);

m_pDevice->SetTransform( D3DTS_WORLD, &matWorld );


But the next box receives those changes too, would like to know how to "disable" those changes at the next object, leaving only one object


thanks

Share this post


Link to post
Share on other sites
Kazuo5000    177
if you are rendering objects seperately (without data encapsulation) you would do

(Psuedocode)

// object one
RotateMatrix
ScaleMatrix
Transform
Multiply
SetWorldMatrix (SetTransform)
RenderObject
// end of object one rendering
LoadMatrixIdentity(worldMat) => DirectX it's D3DXMatrixIdentity(&matWorld)
// object two
RotateMatrix
ScaleMatrix
Transform
Multiply
SetWorldMatrix (SetTransform)
RenderObject
// end of object two render
.. and so on...

Hope that helps

Share this post


Link to post
Share on other sites
DevTuts    100
Quote:
Original post by Kazuo5000
if you are rendering objects seperately (without data encapsulation) you would do

(Psuedocode)

// object one
RotateMatrix
ScaleMatrix
Transform
Multiply
SetWorldMatrix (SetTransform)
RenderObject
// end of object one rendering
LoadMatrixIdentity(worldMat) => DirectX it's D3DXMatrixIdentity(&matWorld)
// object two
RotateMatrix
ScaleMatrix
Transform
Multiply
SetWorldMatrix (SetTransform)
RenderObject
// end of object two render
.. and so on...

Hope that helps


I have to use the atrixIdentity?
What does it do exactly?

D3DXMATRIX worldMatrix;
D3DXMatrixIdentity( &worldMatrix );
m_pDevice->SetTransform(D3DTS_WORLD,&world_matrix);


so?

Share this post


Link to post
Share on other sites
Kazuo5000    177
The matrix identity for a 4x4 matrix is
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

so, if matrix a is the identity matrix and matrix b is a translation matrix
a * b = b

The when multiplied with the identity it does nothing.

So the identity will 'reset' the world matrix and when used in with the next object it will not be affected by the previous transformations (rotation, scaling etc.)

Use:

// object 1 transformation and rendering here
D3DXMatrixIdentity(&matWorld) // set the world matrix to its identity
m_pDevice->SetTransform(D3DTS_WORLD, &matWorld);
// render 2nd object.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this