Jump to content
  • Advertisement

Archived

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

kevlur

camera with direct3d9

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

Hi, i have a question about camera with direct3d9,with these lines...
D3DXVECTOR3 eye_vector;
D3DXVECTOR3 lookat_vector;
D3DXVECTOR3 up_vector;
D3DXMATRIX view_matrix;

eye_vector=D3DXVECTOR3(0.0f,10.0f,0.0f);

lookat_vector=D3DXVECTOR3(0.0f,0.0f,0.0f);

up_vector=D3DXVECTOR3(0.0f,1.0f,0.0f);

D3DXMatrixLookAtLH(&view_matrix,&eye_vector,
                                &lookat_vector,
                                &up_vector);

d3d_device->SetTransform(D3DTS_VIEW,&view_matrix);
...i build a view matrix so to have a camera positioned at (0,10,0) in world coordinates looking at origin(0,0,0) and with Y up axis...but...how have i to build a view matrix so that the camera haven''t to looking at a fixed point? is there a way to do it? (eg. how can i have a camera positioned at (o,10,0) that look straigh without looking at a fixed point lock?) Thanks Kev

Share this post


Link to post
Share on other sites
Advertisement
Your camera has to look SOMEwhere. You say straight, so straight obviously is somewhere. That''s the whole point of having a camera. When you move or strafe the camera it''s still looking in a direction, maybe the old lookat point, maybe not.

Share this post


Link to post
Share on other sites
look at the dx9 docs to check what the lookat functions really do. then throw it away, because unless its 3rd person you want to look in a direction not at a point.

Share this post


Link to post
Share on other sites
That''s what i want, look in a direction and not a point, i would build a matrix to look in a direction to pass to d3d_device->SetTransform(D3DTS_VIEW,&matrix);

how can i build this up?

Share this post


Link to post
Share on other sites
what you want is look somewhere and still move in the same direction like any FPS HL where you use the mouse to look around and you still move in the same direction unlike if you make the camera point up when you move youll fly off the ground...ive been lookin on how to do this too but havent figured it out

Share this post


Link to post
Share on other sites
what about taking the camera direction and assigning the Up Component 0 (Z component in my book... Y in alot of other peoples) and then normalizing it... that gives you a vector pointing in the direction you want to move on the movement plane, This is also why some FPS's don't allow you to look directy up or down but just enough... then add gravity etc to your player...

Most fps programs just store 2 angles.. the Facing angle and the Look up/down angle.. then it's mearly something like the vector(cos(playerangle), sin(playerangle), 0) for the movement and the camera vector is similar except you have to add the up down vector to that. I have code for that buried somewhere in my old machine but it's currently dead.. but it'd just be easier to make 2 rotation matricies, concatinate them and multiply a point by it to get your camera lookat direction.

some pseudo code
RotationMatrix.Identity()
RotationMatrix.RotateZ(Player.Angle)
RotationMatrix.RotateY(Player.LookUpDown)

Camera.Up = Vector(0, 0, 1);
Camera.From = Player.Pos;
Camera.To = PlayerPos + Vector(1, 0, 0) * RotationMatrix;

Edit: typo

[edited by - Ximmer on February 8, 2004 2:59:33 AM]

Share this post


Link to post
Share on other sites
I always think view matrix as inverse of camera position. So, just update player postion, and put inverse of that matrix as view matrix. However, you`ll have to modify angles of camera position a bit if player wish to look up/down.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!