Jump to content
  • Advertisement
Sign in to follow this  

Help with DirectX Transforms

This topic is 4595 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

I need some help with my DirectX transforms. I have a function that displays the axis, like so.
  Vertex verts[] = {
  vertexBuffer.Write(verts, 6);
  pd3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, 6 );

So far so good, displays the axis looking down the z axis. Now, when I apply my transforms, I see absolutely nothing. Nada. Zip.
  D3DXMATRIXA16 matWorld;
  D3DXMatrixRotationY( &matWorld, timeGetTime()/1000.0f );
  pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

  D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f );
  D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
  D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
  D3DXMATRIXA16 matView;
  D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
  pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

  D3DXMATRIXA16 matProj;
  D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
  pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

Any idea what I'm doing wrong?

Share this post

Link to post
Share on other sites
There are a few things you will need to check.
Is your camera (view) pointing in the right direction.
Your view you can think of as being a camera. If your object is outside of the camera's view you won't be able to see it.

Try changing the D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f ) to D3DXVECTOR3 vEyePt( 0.0f, 0.0f, -5.0f ).

With that said make sure that your object isn't outside of the clipping planes. In your case it's probably not out of the clipping planes at all but it's nice to note. Change D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f ) to D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 1000.0f ) as it will help you in the long run.

Also when doing this type of setup it's generally good practise to setup the Projection and View transformation matrices and setting them in the init function of your engine/renderer as they don't usually change very often if not at all. Then when you render objects try and associate objects with a world transformation matrix as this locates the object in the world.

Some simple steps to follow.
1) Update world transformation matrix for your axis
2) Set the world transformation matrix for your axis
3) Render your axis.

I hope this helps.
Take care.

Share this post

Link to post
Share on other sites
I haven't had a chance to test this yet, but something that did pop out at me was you are calling DrawPrimitive() with 6 as the primitive count - this should be 3, as you only want 3 lines, not 6 - which is the vertex count.

This can have really odd consequences, though i'm not sure that it is having the effects of which you speak.

Share this post

Link to post
Share on other sites
How about lighting? Is that on or off when you render these line segments? And where is the device getting its colors from? Material? Vertex?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!