directx problem with camera , nothing happens

This is a discussion on directx problem with camera , nothing happens within the Game Programming forums, part of the General Programming Boards category; i seem to have come to a stop my directx book this function is in a case WM_KEYDOWN , then ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    319

    directx problem with camera , nothing happens

    i seem to have come to a stop my directx book
    this function is in a case WM_KEYDOWN , then in another switch with case VK_UP:
    nothing happens to the screen camera at all
    infact i am totally stuck on the transformation section part of directx
    moving vertices to a new axis etc


    Code:
    void Camera()
    {
    D3DXVECTOR3 vEyePt(0.0f , 0.0f , -0.5);
    D3DXVECTOR3 vLookPt(0.0f , 0.0f , 0.5);
    D3DXVECTOR3 vUpVec(0.0f, 1.0f ,0.0f);
    D3DXMATRIXA16 matView;
    D3DXMatrixLookAtLH(&matView , &vEyePt , &vLookPt , &vUpVec);
    g_pDirect3DDevice->SetTransform(D3DTS_VIEW, &matView);
    }
    Last edited by Anddos; 04-09-2006 at 11:18 PM.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Start with this:

    Code:
    class CCamera
    {
      D3DXVECTOR3 Look;
      D3DXVECTOR3 Right;
      D3DXVECTOR3 Up;
      D3DXVECTOR3 Pos;
    
      float m_fPitch,m_fRoll,m_fYaw;
      ....
    
      public:
        void Init();
        void GetViewMatrix(D3DXMATRIX *outMatrix);
        
        void Strafe(float units);
        void Fly(float units);
        void Walk(float units);
        ...
    
    };
    
    void CCamera::Init(void)
    {
       Pos=D3DXVECTOR3(0.0f,0.0f,0.0f);
       Right=D3DXVECTOR3(1.0f,0.0f,0.0f);
       Up=D3DXVECTOR3(0.0f,1.0f,0.0f);
       Look=D3DXVECTOR3(0.0f,0.0f,1.0f);
       m_fPitch=m_fRoll=m_fYaw=0.0f;
    }
    
    void CCamera::GetViewMatrix(D3DXMATRIX *outMatrix)
    {
      D3DXVec3Normalize(&Look,&Look);
      
      D3DXVec3Cross(&Up,&Look,&Right);
      D3DXVec3Normalize(&Right,&Right);
    
      D3DXVec3Cross(&Right,&Up,&Look);
      D3DXVec3Normalize(&Look,&Look);
    
      float x=-D3DXVec3Dot(&Right,&Pos);
      float y=-D3DXVec3Dot(&Up,&Pos);
      float z=-D3DXVec3Dot(&Look,&Pos);
    
      (*outMatrix)(0,0)=Right.x;
      (*outMatrix)(0,1)=Up.x;
      (*outMatrix)(0,2)=Look.x;
      (*outMatrix)(0,3)=0.0f;
    
      (*outMatrix)(1,0)=Right.y;
      (*outMatrix)(1,1)=Up.y;
      (*outMatrix)(1,2)=Look.y;
      (*outMatrix)(1,3)=0.0f;
    
      (*outMatrix)(2,0)=Right.z;
      (*outMatrix)(2,1)=Up.z;
      (*outMatrix)(2,2)=Look.z;
      (*outMatrix)(2,3)=0.0f;
    
      (*outMatrix)(3,0)=x;
      (*outMatrix)(3,1)=y;
      (*outMatrix)(3,2)=z;
      (*outMatrix)(3,3)=1.0f;
    }
    
    void CCamera::Pitch(float angle)
    {
      m_fPitch+=angle;
      if (m_fPitch>=(D3DX_PI*2)) m_fPitch=0.0f;
    
      D3DXMATRIX T;
      D3DXMatrixRotationAxis(&T,&Right,angle);
    
      D3DXVec3TransformCoord(&Up,&Up,&T);
      D3DXVec3TransformCoord(&Look,&Look,&T);
    
    }
    
    void CCamera::Yaw(float angle)
    {
      m_fYaw+=angle;
      if (m_fYaw>=(D3DX_PI*2.0f)) m_fYaw-=(D3DX_PI*2.0f);
    
      D3DXMATRIX T;
    
      if (CameraType==LANDOBJECT) D3DXMatrixRotationY(&T,angle);
    
      if (CameraType==AIRCRAFT) D3DXMatrixRotationAxis(&T,&Up,angle);
    
      D3DXVec3TransformCoord(&Right,&Right,&T);
      D3DXVec3TransformCoord(&Look,&Look,&T);
    }
    
    void CCamera::Roll(float angle)
    {
      m_fRoll+=angle;
      if (m_fRoll>=(D3DX_PI*2)) m_fRoll=0.0f;
    
      if (CameraType==AIRCRAFT)
      {
        D3DXMATRIX T;
        D3DXMatrixRotationAxis(&T,&Look,angle);
    
        D3DXVec3TransformCoord(&Right,&Right,&T);
        D3DXVec3TransformCoord(&Up,&Up,&T);
      }
    }
    That should give you enough to complete the class.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. camera rotation matrix
    By Vick jr in forum Game Programming
    Replies: 5
    Last Post: 05-26-2009, 08:16 AM
  2. Physics Engine Problem
    By Muphin in forum Game Programming
    Replies: 4
    Last Post: 07-26-2005, 09:04 PM
  3. DirectX DirectInput problem
    By Muphin in forum C++ Programming
    Replies: 1
    Last Post: 07-10-2005, 04:35 PM
  4. Replies: 0
    Last Post: 05-21-2005, 09:42 PM
  5. DirectX (Camera Distance)
    By Epo in forum C++ Programming
    Replies: 3
    Last Post: 12-22-2003, 06:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21