Sign in to follow this  
BlueJester

A lil' help please :)

Recommended Posts

Hey guys, I've been watching these forums for a little while now and I hope this is in the right forum (maybe a directx issue, but i think its more general).. anyway, I'm having a weird issue regarding player(camera) position and actual world position of objects. I have 2 cubes(width,height,depth = 10) setup, the first has an its center position at (0, 10, 0) the second has its center position at (10, 10, 10). Here is the issue, when the player(camera) moves over to the second cube the position of the player reads (-10, y, -10), this position is used to calc the camera matrix and nothing is tampered with: D3DXMatrixTranslation( &camera, position.x, position.y, position.z); the lookat is setup like so, and then multiplied with the camera matrix: D3DXMatrixLookAtLH( &tempMat2, &D3DXVECTOR3( 0.0f, 0.0f, -0.1f ), &D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), &D3DXVECTOR3( 0.0f, 1.0f, 0.0f )); D3DXMatrixMultiply(&camera, &camera, &tempMat2); Also, inerestingly enough, when you add a value to the player position, the player camera moves down, and subtract a value, the player camear moves up :confused: wouldn't the way the look at matrix is setup dictate that up is +?? i am using a standard world matrix(identity), nothing fancy. Why does it seem that the player is using a flipped(rotated 180, upside-down, etc.. ) system as opposed to everything else?? Any help/ideas/suggestions would be greatly appreciated!! Thanks, Chris P.S. this is using directx 8

Share this post


Link to post
Share on other sites
D3DXMatrixLookAtLH creates a world-to-view matrix (or just view matrix), which happens to be the inverse of the camera matrix.

The simple solution to your problem is to just set the Eye parameter of D3DXMatrixLookAtLH to the camera's position, rather than using [0,0,-.1] and trying to combine a translation.

Share this post


Link to post
Share on other sites
thats a good point, i could save myself a translation by changing the Eye and LookAt point. But i still would be left in the same situation. I figured it out though (usually do right after i ask for help, figures lol...), the positions that need to be translated in have to be negated to work correctly in the camera matrix. So when i do the translation, instead of using (position.x, position.y, position.z) i need to use (-position.x, -position.y, -position.z).
Thanks again!
Chris

Share this post


Link to post
Share on other sites
Quote:
Original post by BlueJester
... i could save myself a translation by changing the Eye and LookAt point ...


My intent was not to optimize your code. My intent was to help fix your problem, which is this -- you are trying to orient the camera by transforming the view matrix. That is going to become a never-ending source of confusion and problems for you.

Share this post


Link to post
Share on other sites
If you have a "camera", then you should move the camera around the world as you would do with any other object. Then, you get the view matrix by inverting the camera's orientation/position matrix. You can move and orient the camera by transforming the view matrix directly, but then it gets confusing (as you have seen).

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