Sign in to follow this  
pdugan

Help with DirectX Transforms

Recommended Posts

pdugan    122
I need some help with my DirectX transforms. I have a function that displays the axis, like so.
  Vertex verts[] = {
    Vertex(0,0,0,0,0,0xffff0000),
    Vertex(3,0,0,0,0,0xffff0000),
    Vertex(0,0,0,0,0,0xff00ff00),
    Vertex(0,3,0,0,0,0xff00ff00),
    Vertex(0,0,0,0,0,0xff00ffff),
    Vertex(0,0,3,0,0,0xff00ffff)
  };
  vertexBuffer.Write(verts, 6);
  vertexBuffer.SetAsSource();
  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
Armadon    1091
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
Source    272
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
dalep    331
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this