   need help Directx9 FPS camera!!
  I wanted to do a FPS camera using directx9. But the screen only show the FPS hand(it's a sprite) but the environment is not there. Can anybody show me what I did wrong? And the keyboard input has not been set yet. Just wanted to get the environmt appear 1st. ThanksNow i've got the environment but theres no movement.Anybody?Winmain.cpp/**************************************************winmain.cppCreate a window with black color backgroundTGP2711 Game Programming II by DCKu (Feb 2010)**************************************************/// Include the  header files needed for all Windows and DirectX applications#include <windows.h>#include <stdio.h>#include "d3d9.h"#include "d3dx9.h"#define DIRECTINPUT_VERSION 0x0800#include "dinput.h"#pragma comment (lib, "dinput8.lib")#pragma comment (lib, "dxguid.lib")// Linking to the library files#pragma comment (lib, "d3d9.lib")// the Direct3D library #pragma comment (lib, "d3dx9.lib")#include "FPCamera.h"HWND wndHandle = NULL;// global variable to hold the window handleLPDIRECT3D9 pD3D = NULL; // the Direct3D objectLPD3DXSPRITE pd3dSprite = NULL;LPDIRECT3DDEVICE9 pd3dDevice = NULL; // the Direct3D deviceLPDIRECT3DTEXTURE9 pd3dTexture = NULL;IDirectInput8 *pdInput = NULL;IDirectInputDevice8 *pdidKeyboard = NULL;IDirectInputDevice8 *pdidMouse = NULL;IDirect3DVertexBuffer9 *pd3dVB = NULL;IDirect3DTexture9 **pTextureList;IDirect3DTexture9 *pd3dTexture1 = NULL;float transZ = -19;float transX = -2.6;float rot = 0;int XPos = 0;int YPos = 0;float transY = 0.5;// Our camera classCFPCamera *gCamera=NULL;// Some program constantsconst float kCameraMovementSpeed=0.4f;const float kCameraRotationSpeed=0.01f;static char windowClass[]   = "TGP2271Assignment2";// name of the window class static char windowCaption[] = "Shah-Qays 1051105626 AS2"; // title of the windowint windowWidth  = 800;int windowHeight = 800;ID3DXMesh *pd3dMeshSpaceship;D3DMATERIAL9 *pd3dMaterial;DWORD numMaterials;typedef struct {FLOAT x, y, z; // 3D coordinatesFLOAT u, v; // Texture coordinates} sVertex;#define VERTEX_FVF (D3DFVF_XYZ | D3DFVF_TEX1)// forward declarationsbool initWindow( HINSTANCE hInstance );bool initDirectInput (HINSTANCE hInstance);bool KeyboardInput (void);bool MouseInput (void);void initXfile(void);void initlight(void);LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);bool initDirect3D(void);void render(void);void cleanUp (void);int ToDegrees(float rads);int ToDegrees(float rads){return (int)(180.0f/D3DX_PI*rads);}// This is winmain, the main entry point for Windows applicationsint WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,   LPSTR lpCmdLine, int nCmdShow ){// Initialize the windowif ( !initWindow( hInstance ) )return false;// called after creating the windowif ( !initDirect3D( ) )return false;if( FAILED( initDirectInput (hInstance) )){return false;}RECT rect;GetWindowRect(wndHandle, &rect);SetCursorPos( 0,0 );// main message loop:MSG msg;ZeroMemory( &msg, sizeof( msg ) );while( msg.message!=WM_QUIT ){// Check the message queueif(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {TranslateMessage( &msg );// translate keystroke messages into the right formatDispatchMessage( &msg );// send the message to the WindowProc function}else{if( FAILED( KeyboardInput( ) ) ){return false;}if( FAILED(MouseInput( ) ) ){return false;}gCamera=new CFPCamera(D3DXVECTOR3(0,0,-12.0f));render( );}}cleanUp();UnregisterClass(windowClass, hInstance);return msg.wParam;}/******************************************************************************* bool initWindow( HINSTANCE hInstance )* initWindow registers the window class for the application, creates the window******************************************************************************/bool initWindow( HINSTANCE hInstance ){WNDCLASSEX wcex;// Fill in the WNDCLASSEX structure. This describes how the window// will look to the systemwcex.cbSize = sizeof(WNDCLASSEX); // the size of the structurewcex.style = CS_HREDRAW | CS_VREDRAW; // the class stylewcex.lpfnWndProc = (WNDPROC)WndProc; // the window procedure callbackwcex.cbClsExtra = 0; // extra bytes to allocate for this classwcex.cbWndExtra = 0; // extra bytes to allocate for this instancewcex.hInstance = hInstance; // handle to the application instancewcex.hIcon = 0; // icon to associate with the applicationwcex.hCursor = LoadCursor(NULL, IDC_ARROW);// the default cursorwcex.hbrBackground = (HBRUSH)(CreateSolidBrush(RGB(0,0,0)) ); // the background colorwcex.lpszMenuName  = NULL; // the resource name for the menuwcex.lpszClassName = windowClass; // the class name being createdwcex.hIconSm = 0; // the handle to the small iconif( !RegisterClassEx(&wcex) )return false;// Create the window and use the result as the handlewndHandle = CreateWindow(windowClass,// name of the window class windowCaption,// title of the windowWS_OVERLAPPEDWINDOW,// window styleCW_USEDEFAULT, // the starting x coordinateCW_USEDEFAULT, // the starting y coordinatewindowWidth, // the pixel width of the windowwindowHeight, // the pixel height of the windowNULL, // the parent window; NULL for desktopNULL, // the menu for the application; NULL for nonehInstance, // the handle to the application instanceNULL); // no values passed to the window// Make sure that the window handle that is created is validif (!wndHandle)return false;// Display the window on the screenShowWindow(wndHandle, SW_SHOW);UpdateWindow(wndHandle);return true;}/******************************************************************************* bool initDirectInput(HINSTANCE hInstance);* The Xfile******************************************************************************/bool initDirectInput(HINSTANCE hInstance){if FAILED( DirectInput8Create (hInstance,DIRECTINPUT_VERSION,IID_IDirectInput8,(void**)&pdInput, // the DirectInput objectNULL) ){return false;}if FAILED( pdInput->CreateDevice(GUID_SysKeyboard, &pdidKeyboard, NULL) ){return false;}if FAILED( pdidKeyboard->SetDataFormat (&c_dfDIKeyboard) ){return false;}if (FAILED( pdidKeyboard->SetCooperativeLevel (wndHandle,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE) )){return false;}if (FAILED(pdidKeyboard->Acquire() ) ){return false;}if(FAILED(pdInput->CreateDevice(GUID_SysMouse,&pdidMouse, NULL))) {return false;}if(FAILED(pdidMouse->SetDataFormat(&c_dfDIMouse))) {return false;}if(FAILED(pdidMouse->SetCooperativeLevel(wndHandle,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE))) {return false;}if(FAILED(pdidMouse->Acquire())) {return false;}}/******************************************************************************* bool KeyboardInput (void);* The inputkeyboard******************************************************************************/bool KeyboardInput (void){unsigned char keystate[256];#define KEYDOWN(name, key) (name[key] & 0x80)#define KEYUP(name, key) ((name[key] & 0x80) ? 0:1)if( FAILED( pdidKeyboard->Poll() )){return false;}if( FAILED( pdidKeyboard->GetDeviceState (sizeof(keystate),(LPVOID)&keystate) ) ) {pdidKeyboard->Acquire(); // re-acquire if failreturn false;}if (KEYDOWN(keystate, DIK_D)) {transX -= 1.0f;}else if(KEYDOWN(keystate, DIK_A)) {transX += 1.0f;}else if(KEYDOWN(keystate, DIK_W)) {transZ -= 1.0f;}else if(KEYDOWN(keystate, DIK_S)) {transZ += 1.0f;}else if(KEYDOWN(keystate, DIK_LEFT)) {rot -= 0.5f;}else if(KEYDOWN(keystate, DIK_RIGHT)) {rot += 0.5f;}else if(KEYDOWN(keystate, DIK_UP)) {transY += 0.5f;}else if(KEYDOWN(keystate, DIK_DOWN)) {transY -= 0.5f;}}/******************************************************************************* bool MouseInput (void);* The inputmouse******************************************************************************/bool MouseInput (void){DIMOUSESTATE MouseState;if( FAILED( pdidMouse->Poll() )) {return false;}if(FAILED(pdidMouse->GetDeviceState( sizeof(DIMOUSESTATE),(LPVOID)&MouseState ))) {return false;}if(FAILED(pdidMouse->Acquire())) {return false;}XPos += 0.3*MouseState.lX;YPos -= 0.3*MouseState.lY;}/******************************************************************************* bool initXfile(HINSTANCE hInstance);* The Xfile******************************************************************************/void initXfile(void){LPD3DXBUFFER bufShipMaterial;D3DXLoadMeshFromX("plane2.x",D3DXMESH_SYSTEMMEM,pd3dDevice,NULL,&bufShipMaterial,NULL,&numMaterials,&pd3dMeshSpaceship);pTextureList = new LPDIRECT3DTEXTURE9 [numMaterials];D3DXMATERIAL *tempMaterials =(D3DXMATERIAL*) bufShipMaterial->GetBufferPointer();pd3dMaterial = new D3DMATERIAL9[numMaterials];for (DWORD i = 0; i < numMaterials; i++){pd3dMaterial = tempMaterials.MatD3D;pd3dMaterial.Ambient = pd3dMaterial.Diffuse;if ( tempMaterials.pTextureFilename ){D3DXCreateTextureFromFile (pd3dDevice,tempMaterials.pTextureFilename,&pTextureList );}}}/******************************************************************************* bool initlight;* The Xfile******************************************************************************/void initlight(void){D3DLIGHT9 light;ZeroMemory(&light, sizeof(light));light.Type = D3DLIGHT_DIRECTIONAL;light.Diffuse = light.Ambient = D3DXCOLOR(0.3f, 0.5f, 0.3f, 1.0f);light.Range = 800.0f;light.Attenuation0 = 0.5f;light.Position.x = 200.0f;light.Position.y = -100.0f;light.Position.z = -200.0f;light.Direction = D3DXVECTOR3(-1.0f, 0.5f, 1.0f);pd3dDevice->SetLight(1, &light);pd3dDevice->LightEnable(1, TRUE);}/******************************************************************************* LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,* LPARAM lParam)* The window procedure******************************************************************************/LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){// Check any available messages from the queueswitch (message){case WM_DESTROY:PostQuitMessage(0);break;}// Always return the message to the default window// procedure for further processingreturn DefWindowProc(hWnd, message, wParam, lParam);}/********************************************************************** initDirect3D*********************************************************************/bool initDirect3D(void){// Create the DirectX objectif( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ){return false;}D3DDISPLAYMODE d3ddm;if(FAILED(pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))){return FALSE;}// Fill the presentation parameters structureD3DPRESENT_PARAMETERS d3dpp;ZeroMemory( &d3dpp, sizeof( d3dpp ) );d3dpp.Windowed = TRUE;d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;d3dpp.BackBufferCount = 1;d3dpp.BackBufferWidth = windowWidth;d3dpp.BackBufferHeight = windowHeight;d3dpp.hDeviceWindow = wndHandle;d3dpp.EnableAutoDepthStencil = TRUE;d3dpp.AutoDepthStencilFormat = D3DFMT_D16;d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;// Create a default DirectX deviceif( FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,wndHandle,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pd3dDevice ) ) ){return false;}D3DXCreateTextureFromFile(pd3dDevice,"hand.png",&pd3dTexture);initXfile( );initlight();BYTE *Ptr;sVertex Verts[4] = {// x y z u v{ -200.0f, 100.0f, 0.0f, 0.0f, 0.0f },{ 200.0f, 100.0f, 0.0f, 1.0f, 0.0f },{ -200.0f, -100.0f, 0.0f, 0.0f, 1.0f },{ 200.0f, -100.0f, 0.0f, 1.0f, 1.0f }};if( FAILED( pd3dDevice->CreateVertexBuffer( sizeof(Verts), 0, VERTEX_FVF, D3DPOOL_DEFAULT, &pd3dVB, NULL) ) ) {return false;}if( FAILED( pd3dVB->Lock(0, sizeof(Verts), (void**)&Ptr, 0) ) ) {return false;}memcpy(Ptr, Verts, sizeof(Verts)); // copy info into the vertex bufferpd3dVB->Unlock(); //unlock vertex buffer after finished copyingif( FAILED(D3DXCreateSprite(pd3dDevice,&pd3dSprite))){return false;}if( FAILED( D3DXCreateTextureFromFile (pd3dDevice,"NightSky.jpg", &pd3dTexture1) )){return false;}return true;}/********************************************************************** render*********************************************************************/void render(void){// Check to make sure you have a valid Direct3D deviceif( NULL == pd3dDevice )return;// Clear the back buffer to a blue colorpd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,D3DCOLOR_RGBA(0,0,100,255), 1.0f, 0 );pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);pd3dDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));if( FAILED(pd3dDevice->BeginScene()) )    // begins the scene{return;}// Set the vertex stream for the modelpd3dDevice->SetStreamSource( 0, pd3dVB, 0, sizeof(sVertex) );// Set the vertex formatpd3dDevice->SetFVF( VERTEX_FVF );// Create and set the view mat    D3DXMATRIX matProj;D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.3333f, 1.0f, 100.0f );pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );// Get and set the view matrixD3DXMATRIX viewMatrix;gCamera->CalculateViewMatrix(&viewMatrix);pd3dDevice->SetTransform( D3DTS_VIEW, &viewMatrix );//D3DXMATRIX matView;//D3DXMatrixLookAtLH (&matView,//&D3DXVECTOR3(0.0, transY, -20), // the camera position//&D3DXVECTOR3(XPos*0.1, YPos*0.1, 0.0f), // the look-at position//&D3DXVECTOR3(0.0f, 1.0f, 0.0f)); // the up direction//pd3dDevice->SetTransform(D3DTS_VIEW, &matView);//D3DXMATRIX matProj;//D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4.0f, 1.33333f, 1.0f, 1000.0f);//pd3dDevice->SetTransform (D3DTS_PROJECTION, &matProj);D3DXMATRIX matWorld;D3DXMatrixIdentity(&matWorld);D3DXMATRIX matTrans;D3DXMATRIX matRot;D3DXMatrixRotationY(&matRot, rot);D3DXMatrixMultiply( &matWorld, &matWorld, &matRot );//D3DXMatrixTranslation( &matTrans, transX, -0.2,transZ );//D3DXMatrixMultiply( &matWorld, &matWorld, &matTrans );pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);pd3dSprite->Begin(D3DXSPRITE_ALPHABLEND);D3DXVECTOR2 pos=D3DXVECTOR2(320,600); //set positionD3DXVECTOR2 scaling(0.5f,0.8f); //set scalingD3DXMATRIX mat; // the transformation matrixD3DXMatrixTransformation2D(&mat,NULL,0.0,&scaling,NULL,0,&pos);// Tell the sprite about the matrixpd3dSprite->SetTransform(&mat);pd3dSprite->Draw(pd3dTexture,NULL,NULL,NULL,0xFFFFFFFF);pd3dSprite->End(); // end sprite drawingfor (DWORD i = 0; i < numMaterials; i++){pd3dDevice->SetMaterial (&pd3dMaterial);pd3dDevice->SetTexture (0, pTextureList);pd3dMeshSpaceship->DrawSubset(i);}D3DXMATRIX matScale;D3DXMatrixTranslation( &matTrans, 0.0f, 4,0.0f );D3DXMatrixMultiply( &matWorld, &matWorld, &matTrans );D3DXMatrixScaling( &matScale, 3.0f, 3.5f, 3.0f );D3DXMatrixMultiply( &matWorld, &matWorld, &matScale );pd3dDevice->SetTexture(0, pd3dTexture1);pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);pd3dDevice->EndScene();    // ends the 3D scene// Present the back buffer contents to the displaypd3dDevice->Present( NULL, NULL, NULL, NULL );}void cleanUp (void){// Release the device and the Direct3D objectif( pd3dDevice != NULL )pd3dDevice->Release( );if( pD3D != NULL )pD3D->Release( );if( pd3dMeshSpaceship != NULL )pd3dMeshSpaceship->Release( );if( pd3dVB != NULL )pd3dVB->Release();if( pd3dTexture != NULL ) pd3dTexture->Release();if( pd3dSprite!= NULL ) pd3dSprite->Release();if( pd3dTexture1 != NULL ) pd3dTexture1->Release();delete gCamera;}FPCamera.h#pragma once#include <d3dx9.h>/*A first person camera implementationSee acompanying notesKeith Ditchburn May 2007*/class CFPCamera{private:D3DXVECTOR3 m_position; // camera positionfloat m_yaw;  // rotation around the y axisfloat m_pitch; // rotation around the x axisfloat m_roll; // rotation around the z axisD3DXVECTOR3 m_up,m_look,m_right; // camera axisfloat RestrictAngleTo360Range(float angle) const;public:CFPCamera(D3DXVECTOR3 startPos);~CFPCamera(void);void CalculateViewMatrix(D3DXMATRIX *viewMatrix);// Getsfloat GetYaw() const {return m_yaw;}float GetPitch() const {return m_pitch;}float GetRoll() const {return m_roll;}D3DXVECTOR3 GetPosition() const {return m_position;}// Move operationsvoid MoveForward(float amount) {m_position+=m_look*amount;}void MoveRight(float amount) {m_position+=m_right*amount;}void MoveUp(float amount) {m_position+=m_up*amount;}// Rotationsvoid Yaw(float amount); // rotate around x axisvoid Pitch(float amount); // rotate around x axisvoid Roll(float amount); // rotate around z axis};FPcamera.cpp#include "FPCamera.h"CFPCamera::CFPCamera(D3DXVECTOR3 startPos) : m_position(startPos),m_yaw(0),m_pitch(0),m_roll(0){// Start with an orthagonal camera axism_up=D3DXVECTOR3(0.0f,1.0f,0.0f);m_look=D3DXVECTOR3(0.0f,0.0f,1.0f);m_right=D3DXVECTOR3(1.0f,0.0f,0.0f);}CFPCamera::~CFPCamera(void){}void CFPCamera::CalculateViewMatrix(D3DXMATRIX *viewMatrix){/* Start with our camera axis pointing down z An alternative method is to just keep adjusting our axis but if we do that the axis can start to lose its orthogonal shape (due to floating point innacuracies). This could be solved by rebuilding the orthogonal shape each time with the following: 1. normalising the look vector 2. creating the up vector from the cross product of the look and the right 3. normalising up 4. creating the right vector from the cross product of the look and the up 5. normalising right*/m_up=D3DXVECTOR3(0.0f,1.0f,0.0f);m_look=D3DXVECTOR3(0.0f,0.0f,1.0f);m_right=D3DXVECTOR3(1.0f,0.0f,0.0f);// Yaw is rotation around the y axis (m_up)// Create a matrix that can carry out this rotationD3DXMATRIX yawMatrix;D3DXMatrixRotationAxis(&yawMatrix, &m_up, m_yaw);// To apply yaw we rotate the m_look & m_right vectors about the m_up vector (using our yaw matrix)D3DXVec3TransformCoord(&m_look, &m_look, &yawMatrix); D3DXVec3TransformCoord(&m_right, &m_right, &yawMatrix); // Pitch is rotation around the x axis (m_right)// Create a matrix that can carry out this rotationD3DXMATRIX pitchMatrix;D3DXMatrixRotationAxis(&pitchMatrix, &m_right, m_pitch);// To apply pitch we rotate the m_look and m_up vectors about the m_right vector (using our pitch matrix)D3DXVec3TransformCoord(&m_look, &m_look, &pitchMatrix); D3DXVec3TransformCoord(&m_up, &m_up, &pitchMatrix); // Roll is rotation around the z axis (m_look)// Create a matrix that can carry out this rotationD3DXMATRIX rollMatrix;D3DXMatrixRotationAxis(&rollMatrix, &m_look, m_roll);// To apply roll we rotate up and right about the look vector (using our roll matrix)// Note: roll only really applies for things like aircraft unless you are implementing leanD3DXVec3TransformCoord(&m_right, &m_right, &rollMatrix); D3DXVec3TransformCoord(&m_up, &m_up, &rollMatrix); // Build the view matrix from the transformed camera axisD3DXMatrixIdentity(viewMatrix);viewMatrix->_11 = m_right.x; viewMatrix->_12 = m_up.x; viewMatrix->_13 = m_look.x;viewMatrix->_21 = m_right.y; viewMatrix->_22 = m_up.y; viewMatrix->_23 = m_look.y;viewMatrix->_31 = m_right.z; viewMatrix->_32 = m_up.z; viewMatrix->_33 = m_look.z;viewMatrix->_41 = - D3DXVec3Dot( &m_position,&m_right); viewMatrix->_42 = - D3DXVec3Dot( &m_position,&m_up);viewMatrix->_43 = - D3DXVec3Dot( &m_position,&m_look);}// Yaw - rotation around y axisvoid CFPCamera::Yaw(float amount) {m_yaw+=amount;m_yaw=RestrictAngleTo360Range(m_yaw);}// Pitch - rotation around x axisvoid CFPCamera::Pitch(float amount){m_pitch+=amount;m_pitch=RestrictAngleTo360Range(m_pitch);}// Roll - rotation around z axis// Note: normally only used for aircraft type cameras rather than land based onesvoid CFPCamera::Roll(float amount) {m_roll+=amount;m_roll=RestrictAngleTo360Range(m_roll);}// Keep the angle in the range 0 to 360 (2*PI)float CFPCamera::RestrictAngleTo360Range(float angle) const{while(angle>2*D3DX_PI)angle-=2*D3DX_PI;while(angle<0)angle+=2*D3DX_PI;return angle;}[Edited by - klipnov on April 21, 2010 2:58:46 AM]
  It looks like you are re-creating the FPCamera class every time the scene is rendered, instead just re-calculate the view matrix for every frame. We both used the same first-person camera tutorial for reference so I may be able to help :)What I've done is modified my CalculateViewMatrix code to create a matrix based on the position of my character mesh. So instead of storing x,y,z,pitch,yaw,roll in the Camera class they are stored in my DynamicModel class. This way I can make the camera first-person, third-person or even a birds-eye view and it will follow the movement of any mesh I choose:D3DXMATRIX Camera::CalculateViewMatrix(DynamicModel *dynamicModel){D3DXMATRIX matRot, matView;D3DXVECTOR3 eye, at;D3DXVECTOR3 up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);D3DXVECTOR3 look = D3DXVECTOR3(0.0f, 0.0f, 1.0f);D3DXVECTOR3 right = D3DXVECTOR3(1.0f, 0.0f, 0.0f);D3DXVECTOR3 position = dynamicModel->GetPosition();D3DXVECTOR3 rotation = dynamicModel->GetRotation();// Rotate yaw/pitch/rollD3DXMatrixRotationYawPitchRoll(&matRot, rotation.y, rotation.x, rotation.z);// Transform vectorsD3DXVec3TransformNormal(&look, &look, &matRot); // Look same direction as modelD3DXVec3TransformNormal(&up, &up, &matRot); // Up same orientation as modelif (Orientation == ORIENTATION_FIRSTPERSON){position.y = 15.0f;eye = position;at = position + 1.0f * look;}else{eye = position - 100.0f * look;at = eye + look;}D3DXMatrixLookAtLH(&matView, &eye, &at, &up);return matView;}Then when I process keyboard/mouse input I just move/rotate my mesh as needed:if (gKeyboard->KeyDown(KEY_W)) gMouseModel->MoveForward(0.5f); // Move Forwardif (gKeyboard->KeyDown(KEY_S)) gMouseModel->MoveForward(-0.5f); // Move Backif (gKeyboard->KeyDown(KEY_A)) gMouseModel->MoveRight(-0.5f); // Move Leftif (gKeyboard->KeyDown(KEY_D)) gMouseModel->MoveRight(0.5f); // Move RightgMouseModel->RotatePitch(DegreesToRadians(gMouse->GetY() / sensitivity)); // Rotate Up/DowngMouseModel->RotateYaw(DegreesToRadians(gMouse->GetX() / sensitivity)); // Rotate Left/RightIn my render code I calculate the view matrix and render the mesh, the camera will follow the direction/roation of the mesh, in this case my mouse model:gD3D->BeginRender(gCamera->CalculateViewMatrix(gMouseModel));gTerrain->Render();gMouseModel->Render();gD3D->EndRender();Here's my BeginRender() code also, hope this helps :)void Direct3D::BeginRender(D3DXMATRIX matView){// Setup camerapDevice->SetTransform(D3DTS_VIEW, &matView);// Clear the backbuffer and the zbufferpDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);// Begin the scenepDevice->BeginScene();}