Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


How to move object in Directx?


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
6 replies to this topic

#1 Dannyli   Members   -  Reputation: 135

Like
0Likes
Like

Posted 26 August 2013 - 12:43 PM

in opengl, if I want move an object ,a box, I can type:

glPushMatrix();
glTranslatef(x,y,z);
drawBox();
glPopMatrix();

Can someone tell me how to do the same effect in Directx?



Sponsor:

#2 Migi0027   Crossbones+   -  Reputation: 2131

Like
1Likes
Like

Posted 26 August 2013 - 01:09 PM

Well you can create a world matrix, which defines the modal space transformations. And then apply it the all the vertices on the current mesh being rendered.

 

Example:

C++:

D3DXMATRIX worldC, worldT, worldR, worldS;

// Translate Scale Rotate it
D3DXMatrixTranslation(&worldT, tx, ty, tz);
D3DXMatrixRotationYawPitchRoll(&worldR, rx, ry, rz);
D3DXMatrixScaling(&worldS, sx, sy, sz);

worldC = worldR * worldS * worldT;

// Send the matrix to our shader
bff_perObject.worldC = worldC;
.. Send it

VS:
{
    ..
    OUT.position = mul(input.position, worldC);
    OUT.position = mul(input.position, viewMatrix);
    OUT.position = mul(input.position, projMatrix);
}

Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!

#3 Dannyli   Members   -  Reputation: 135

Like
0Likes
Like

Posted 26 August 2013 - 01:42 PM

can I use   g_pd3dDevice->SetViewport() ?



#4 Dave Hunt   Crossbones+   -  Reputation: 2479

Like
1Likes
Like

Posted 26 August 2013 - 02:00 PM

No. You need to use a model transformation. SetViewport is for defining which portion of the display to draw to.


Edited by Dave Hunt, 26 August 2013 - 02:03 PM.


#5 GuardianX   Crossbones+   -  Reputation: 1527

Like
0Likes
Like

Posted 26 August 2013 - 11:47 PM

Either use world matrix approach as described by Migi0027, or use dynamic vertex buffers. I believe that the first one is faster anyway. First method is similar to OpenGL's shader approach if you are familiar with something different from fixed function pipeline.



#6 unbird   Crossbones+   -  Reputation: 6018

Like
0Likes
Like

Posted 27 August 2013 - 01:56 PM

If you're happier with the stack approach you could use the D3DX library : Matrix Stacks.

#7 Medo3337   Members   -  Reputation: 680

Like
0Likes
Like

Posted 27 August 2013 - 03:01 PM

If you are using D3D9, you can set your world matrix using:

g_pd3dDevice->SetTransform(D3DTS_WORLD, &mWorld);

However, you will also need to set projection and view matrix.






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