D3d Camera position type question

Started by
14 comments, last by ThaUnknownProgga 23 years, 9 months ago
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
Advertisement
Thanks, but i''d still like to know how to calculate the World Matrix with a position and a matrix describing orientation
Just multiply the orientation matrix with the translation matrix, and you have the world matrix

To build the view matrix you multiply the inverted translation matrix with the transposed orientation matrix

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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?
Look at the d3d framework source code, I believe it has a look at function, with source. Look in the d3dutil files.
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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement