Jump to content

  • Log In with Google      Sign In   
  • Create Account

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   Members   

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?



#2   Members   

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

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/cuboidzone.wordpress.com/


#3   Members   

135
Like
0Likes
Like

Posted 26 August 2013 - 01:42 PM

can I use   g_pd3dDevice->SetViewport() ?



#4   Members   

4841
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   Members   

1590
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   Members   

8297
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   Members   

891
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.