Archived

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

D3d Camera position type question

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

I have my engine currently utilizing the view world and perspective matrices after a long time of static renderings. The matrix code i''m using is basically the same as on this page: http://www.ziron.com/links/directx/drawprim.htm This implemention is alright except I can''t seem to get the location of the camera. This is because it''s just a view matrix, not an actual camera implementation, but i''ve had a lot of trouble implementing a camera system. i was wondering how then to get the current position of the view matrix, or help on creating a good camera system. thanks in advance

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I have just posted a camera routine in the thread "How do I re-align orientation". It uses LookFrom -> LookAt system, with a RollAngle. Check that thread, and ask any questions about it.

Share this post


Link to post
Share on other sites
Ok then could you help me with a few questions I have?

first of all, how should my camera class be organized? Should it contain a vector (the position of the camera) and a matrix (the orientation of the camera)? If so, how do i maintain the position of the camera after applying things like rotations and transformations to the matrix? And finally, should I just create a new view matrix every time i update my camera using the origin/lookat/up direction vectors?

thanks for the help so far, and thanks in advance

Share this post


Link to post
Share on other sites
Create a new view matrix from scratch every time it needs to be changed. This can be done with the help of position, lookat, and up vectors, but there is also other ways. For example with, position vector and yaw, pitch, and roll angles. You can go one step further and always keep three vectors describing the orientation of the camera, namely the front, right and up vectors of the camera. And then there is the buzz word quaternions .

Choose which ever model is most fitting to what type of camera your class is going to represent. The important thing to remember is that it is most efficient to rebuild the matrix every time it changes, otherwise you''ll have to deal with recalibration of the matrix and other stuff to avoid numerical errors.

- WitchLord

Share this post


Link to post
Share on other sites
Ok, I created a class that contains a D3DVECTOR Position and a D3DMATRIX Axis. However, every time i call my functions to rotate a matrix the function begins by setting the matrix to an identity matrix. Thus I have no clue how to properly keep track of my position vector.
Is this how i should be doing this? or should i just keep track of 4 vectors, position, lookat, up, and right? If so, how would i calculate how to rotate these vectors properly and translate correctly?

Share this post


Link to post
Share on other sites
Hmm, that tutorial was a help, but i refuse to use the D3DX stuff. The one thing i need to know how to do was done through the function D3DXVec3TransformCoord, so i still can''t figure out how to do this!


How do I translate a point through a matrix?

Share this post


Link to post
Share on other sites
Witchlord helped me out with this a while back, but anyway here is a rough example of how it works with mine.

        

vEyePt = MakeVector(vx, vy, vz);
vLookatPt = MakeVector(vx + (float)cos(XAxisRotate * g_DEGTORAD) * (float)sin(YAxisRotate * g_DEGTORAD), vy + (float)sin(XAxisRotate * g_DEGTORAD), vz + (float)cos(XAxisRotate * g_DEGTORAD) * (float)cos(YAxisRotate * g_DEGTORAD));
vUpVec = MakeVector(0,1,0);
D3DUtil_SetViewMatrix( matView, Camera->vEyePt, Camera->vLookatPt, Camera->vUpVec);
g_pd3dDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &matView);

//I just keep track of my camers X/Y/Z position, and it's
//rotation around the X and Y axis (this is a simple
//implementation of an fps camera movement).

//Then to move forwards/backwards etc just do something like


vx +=(float)cos(XAxisRotate * g_DEGTORAD) * (float)sin(YAxisRotate * g_DEGTORAD) * distance;
vy +=(float)sin(XAxisRotate * g_DEGTORAD) * distance;
vz +=(float)cos(XAxisRotate * g_DEGTORAD) * (float)cos(YAxisRotate * g_DEGTORAD) * distance;



This will move in the direction the camera is facing. Just drop the line which updates the VY coord if you want to ignore movement up or down.

(This is some old code I had lying around, and is by no means guarenteed working anymore =)

HTH


Adam "Nutz" Hoult
VB Gaming Central

Edited by - daedalusd on July 13, 2000 6:36:24 PM

Share this post


Link to post
Share on other sites
Well, i scrapped my old code and followed your tutorial witchlord, and it worked great. i was wondering thought, using this type of camera setup, how would I set my camera to have a lookat position which it looks at?

Share this post


Link to post
Share on other sites
If you want to use a look at position with the way I''m doing the camera, you will have to rotate the camera your self. Find the yaw angle that the camera needs to be in to look in the direction of the look at vector. Then find the pitch angle so that the camera is looking at the right height as well. Then use these two angles when setting up the view matrix.

- WitchLord

Share this post


Link to post
Share on other sites