Archived

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

Camera again

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

Hello all! I tried many way to implement a quake-style player movement in direct3d. Whatever i try, i get stuck. I tried to do the rotation of the camera by hand, so rotate and translate matrices and multiply them to get the view matrix: Then i tried to abbrevate it using
	D3DXMatrixTranslation(&ViewMatrix,fCamTransX,fCamTransY,fCamTransZ);
	D3DXMatrixRotationYawPitchRoll( &ViewRotMatrix, D3DXToRadian(fCamRotX), D3DXToRadian(fCamRotY), D3DXToRadian(fCamRotZ));
	D3DXMatrixMultiply(&ViewMatrix, &ViewMatrix,&ViewRotMatrix);
 
Well... Rotating around the Y-Axis works properly, but when i move the camera and look down the x-axis, the whole world seems to rotate around the x-axis. Now i wanted to use the MatrixLookAtLH method to set up my camera. I know how to move in space relative to where im looking, but i dont know how to calculate the point to look at. I want to implement a quake-like movement and looking, so i will move and rotate the camera. But how can i get a point im looking at from the rotation angles? Is there a tutorial out there that explains how to do it in DirectX 8? All tutorials i could get hold of were about having the look- up and right- vectors of the camera rotated and built their own view matrix. Is there any simple method to do it? Im quite new to d3d programming and want to keep it as simple as possible. Im stuck on this problem for 2 weeks now and i hope you can help me! Thank you! Gerd Brost

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i am no expert in D3D cameras (the damn things annoy me to no end)... but what you can do is make a unit vector that stores where you are looking at...
read this webpage
you can use spherical coordinates to determine where you are looking, and then make it into a D3D vector usint the equations on that website... then just plug the vetor into the function for aiming the camera (LookAt argument, or something, i don''t recall exactly)...
for example, if you are looking 30 degrees east of north, and 25 degrees up, theta=30 and phi=25, plug them in to get (x,y,z), and use that vector.

--- krez (krezisback@aol.com)

Share this post


Link to post
Share on other sites
Have u ever try this :

D3DXMATRIX mat;

D3DXMatrixTranslation(&ViewMatrix,fCamTransX,fCamTransY,fCamTransZ);

D3DXMatrixRotationYawPitchRoll( &ViewRotMatrix, D3DXToRadian(fCamRotX), D3DXToRadian(fCamRotY), D3DXToRadian(fCamRotZ));

D3DXMatrixMultiply(&mat, &ViewMatrix,&ViewRotMatrix);

then finally transform mat to world.

Share this post


Link to post
Share on other sites
Thank you both!
Im going to try to use a third matrix.
I changed my camera system,
im trying to do it this way now:
      
//r is a factor of 100, k is a factor to convert sperical coordinates to carthesian coordinates, can use d3d..toradians


fLookX=fCamTransX + r * sinf(fCamRotY * k);
fLookY=fCamTransY + r * sinf(fCamRotX * k);
fLookZ=fCamTransZ + r * cosf(fCamRotY * k);

D3DXMatrixLookAtLH(&d3dInit.ViewMatrix, &D3DXVECTOR3(fCamTransX,fCamTransY,fCamTransZ), //eye

//&D3DXVECTOR3(fLookX,fLookY,fLookZ), //lookat

&D3DXVECTOR3(0.0f,1.0f,0.0f)); //up

d3dInit.device->SetTransform(D3DTS_VIEW,&d3dInit.ViewMatrix);

Is this a suitable way to do it?
I seems to work so far

Edited by - gerbrost on October 22, 2001 7:30:50 PM

Edited by - gerbrost on October 22, 2001 7:40:35 PM

Share this post


Link to post
Share on other sites
Now i got movement problems *sigh*
I am handling my movement that way:
  
// if "up" key is pressed

fCamTransX += fFwdSpeed * sinf(fCamRotY);
fCamTransZ -= fFwdSpeed * cosf(fCamRotY);

When im looking down the z-axis, its fine, but if i start to rotate, the movement reacts really strange.
Can you help me?
Thanks!

Share this post


Link to post
Share on other sites
I''m not sure, but it sounds like you have one or both of these problems.

1. Matrix order matters. translate-then-rotate is very different than rotate-then-translate. You might have the order wrong?

2. Hard to tell from your initial post, but you may be having problems with gimbal lock. Euler angles (Yaw, pitch, roll) have a problem where angles start to get funky in certain situations. (Look it up for a better explanation).

Personally, I think LookAt is a bad way to go. You always have to compute two points...

Try this:
Code just the translation. Make sure it works. If so, move on...
Add in rotation about Y (yaw) - Make sure it works. If not, it''s probably order...
Add in rotation about X (pitch). Check it, check the order if it doesn''t work
Add in rotation about Z (roll). check it, check the order.

Once you''re comfortable, you might go back to euler angles or maybe not, either way this should let you see what''s going on and understand it better.

Share this post


Link to post
Share on other sites
i wonder why its fCamTransZ -= fFwdSpeed * cosf(fCamRotY); instead of
fCamTransZ += fFwdSpeed * cosf(fCamRotY);

are u using left hand coordinate system?

Share this post


Link to post
Share on other sites
Yes, its left-handed. You are right, of course, it has to be += in the Z-case.
Now i got a working movement and camera system, thanks to all of you helping me!
Im still not sure why the matrix calculations did not work, since they are not made up by me but by people that tested them already...
I tried to redo my matrix system just to see if it works, but it didnt help. So for now im sticking with my lookat-camera system.
The fact that only the up- and down-looking (sorry for my english) didnt work makes me also think its a cause of glimbal lock...
I read about it in the excellent tutorial by mrrgamemaker, which is offline now

Once again, thank you all!

Share this post


Link to post
Share on other sites