Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

D3DXMatrix functions do nothing


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Lyev   Members   -  Reputation: 118

Like
0Likes
Like

Posted 05 June 2012 - 05:58 AM

When I call these functions the matrix, v_mat_world, remains unchanged, please help :S

    float origin[3] = {1, 0, 0}, angles[3] = {D3DXToRadian(180), 0, 0}, scale[3] = {1, 1, 1};

	D3DXMatrixIdentity (&v_mat_world);
	D3DXMatrixTranslation (&v_mat_world, origin[0], origin[1], origin[2]);
	D3DXMatrixRotationX (&v_mat_world, angles[0]);
	D3DXMatrixRotationY (&v_mat_world, angles[1]);
	D3DXMatrixRotationZ (&v_mat_world, angles[2]);
	D3DXMatrixScaling (&v_mat_world, scale[0], scale[1], scale[2]);

Edited by Lyev, 05 June 2012 - 05:59 AM.


Sponsor:

#2 Nik02   Members   -  Reputation: 1994

Like
0Likes
Like

Posted 05 June 2012 - 06:29 AM

You overwrite the matrix with each function call. The last operation sets the matrix to identity since the scaling factors happen to be 1.

In order to combine the effects of the transformations, you have to multiply the matrices together by your own code.

Edited by Nik02, 05 June 2012 - 06:30 AM.

Niko Suni
Software developer

#3 Lyev   Members   -  Reputation: 118

Like
0Likes
Like

Posted 05 June 2012 - 06:38 AM

So something like this?
    D3DXMATRIX trans, rotx, roty, rotz, scaling;
    D3DXMatrixIdentity (&v_mat_world);
    D3DXMatrixTranslation (&trans, origin[0], origin[1], origin[2]);
    D3DXMatrixRotationX (&rotx, angles[0]);
    D3DXMatrixRotationY (&roty, angles[1]);
    D3DXMatrixRotationZ (&rotz, angles[2]);
    D3DXMatrixScaling (&scaling, scale[0], scale[1], scale[2]);

    D3DXMatrixMultiply (&v_mat_world, &v_mat_world, &rotx);
    D3DXMatrixMultiply (&v_mat_world, &v_mat_world, &roty);
    D3DXMatrixMultiply (&v_mat_world, &v_mat_world, &rotz);
    D3DXMatrixMultiply (&v_mat_world, &v_mat_world, &scaling);
    D3DXMatrixMultiply (&v_mat_world, &v_mat_world, &trans);


#4 Nik02   Members   -  Reputation: 1994

Like
0Likes
Like

Posted 05 June 2012 - 07:11 AM

Yea, but you don't need the first identity step. You can use the translation as the baseline.
Niko Suni
Software developer

#5 Nik02   Members   -  Reputation: 1994

Like
0Likes
Like

Posted 05 June 2012 - 07:13 AM

In addition, if you are using C++, the * operator of D3DXMATRIX is overloaded to multiply matrices, so you don't need to explicitly use D3DXMatrixMultiply.
Niko Suni
Software developer

#6 Lyev   Members   -  Reputation: 118

Like
0Likes
Like

Posted 05 June 2012 - 07:15 AM

Okay, thanks for your help! :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS