• Advertisement

Archived

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

camera with direct3d9

This topic is 5123 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
Yes, ok, but how can i look up or down without modify the direction the camera is moving?

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
my problem is that when i make an Y rotation on the object and so on the camera that is locked on the object both rotate around the origin and not around themself, so in order to go farther from the origin they rotate in circle always lookin at the origin


Share this post


Link to post
Share on other sites
Not sure why but my earlier email seemed to get lost. If it did not apologies for posting again.

I have written a little web page on creating a 1st person camera in DirectX that should address your issues, you can see it here:

http://www.petra.demon.co.uk/Games/camera.html

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by kevlur
my problem is that when i make an Y rotation on the object and so on the camera that is locked on the object both rotate around the origin and not around themself, so in order to go farther from the origin they rotate in circle always lookin at the origin



Sounds like you are just applying the translation and rotation matrices in the wrong order. Rotating then translating rather than translating then rotating.

Share this post


Link to post
Share on other sites
I had a hard time with setting up a camera so..... I found an example of how to do it and learned from it, it can kinda be hard if you don't read up on the math about it. Basically a good link with an example of how to set it up can be found at here, its the second camera example on that page

However you will probably have to make it a bit better, its not really very fast, mainly because there is to much mouse padding if you ask me. So, you kinda have to fix it up a bit but it will get you where you want to go. Its probably a good idea to change the angle movement with the mouse to direct input instead, mainly because thats a lot faster.

[edited by - DevLiquidKnight on February 9, 2004 3:42:23 PM]

Share this post


Link to post
Share on other sites

  • Advertisement