Jump to content
  • Advertisement
Sign in to follow this  
Dannyli

OpenGL How to move object in Directx?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement

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);
}

Share this post


Link to post
Share on other sites

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

Edited by Dave Hunt

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!