Archived

This topic is now archived and is closed to further replies.

D3D Matrix operations - how to bind objects together...

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

This is a problem I''ve been having. I''m sure its elementary to those more experienced. I have a camera, its orientation is described by the matrice returned by the D3DXMatrixLookAtLH() function. This is passed to the below function - which sets the matrice for a "D3DGui object". VOID D3DGui::setMatrix(LPDIRECT3DDEVICE8 &lpD3DDevice, D3DXMATRIX &cameraView) { D3DXMATRIX matTrans, matObject; D3DXMatrixTranslation( &matTrans, windowPosition.x, windowPosition.y, windowPosition.z ); D3DXMatrixMultiply( &matObject, &matTrans, &cameraView ); lpD3DDevice->SetTransform( D3DTS_WORLD, &matObject); } The Gui object is essentially the same as any other object except its going to have a special setMatrix function. The end result is for the object to have its position relative to the camera ("D3DXVector3 windowPosition" describes this). I was hoping the above code would take the object and position it in the exact same spot (and direction) as the camera and windowPosition would be the position relative to the camera. I was hoping that I would end up with an object which would sit in front of the camera in the same position no matter where the camera looked (ie a building block for creating a GUI). The end result seems to be as though the multiply operation had absolutely no effect and the object is positioned according to the absolute coordinate system. If the camera moves the object doesn''t move with it. Hence the title really, in 3d matrix operations whats the best way to set an objects position relative to another objects position?

Share this post


Link to post
Share on other sites
If I understand your question, I think you are doing this the really hard way!

The question as I understand it: "I have a 3D game - how do I draw a window like a status window, compass, HUD, whatever?"

The easy way - when drawing the GUI stuff, ignore the 3D world.

Read this article:
http://www.gamedev.net/reference/programming/features/2ddx8/

Now, in your game, draw all the 3D stuff and then setup your matrices for 2D drawing and draw the GUI stuff (remember to reset the matrices for 3d).

Share this post


Link to post
Share on other sites
Ok, if I understand the question correctly, you''re trying to keep an object in a fixed position in front of the camera, no matter which way the player is looking.

The mistake you have made is believing that camera matrices are the same as all the other transformation matrices that you are using for your objects. Before you can use the camera matrix that way, you''ll need to invert it;

  
// the matrices..

D3DMATRIX mInvView, mView, mobject, mFinal;

// get the current view matrix

lpDevice->GetTransform( D3DTRANSFORMSTATE_VIEW, &mView );

// invert it

D3DMath_MatrixInvert( mInvView, mView );

// position the object straight down the z axis

D3DUtil_SetIdentityMatrix( object );
object(3,2) = 200.0f;

// now calculate the world transformation matrix

D3DMath_MatrixMultiply( mFinal, mInvView, object );


mFinal is the matrix you need to position the object.

Remember to move the object down the Z axis (not leaving it at Z0) or it''ll get clipped by the near clipping plane.

- Matt



Share this post


Link to post
Share on other sites
Cheers guys, yep you''ve both understood the problem, I''ll be giving these approaches and shot. I do tend to do things the hard way, but its only because I''m learning - I''ve yet to reach that meca where I can envisualise the use matrices properly. Again, thanks for the help.

Share this post


Link to post
Share on other sites