CFirstPersonCamera 的使用方法
先声明相机:
CFirstPersonCamera g_Camera;
//建立并设置投影矩阵
float fAspectRatio = pBackBufferSurfaceDesc->Width / (FLOAT)pBackBufferSurfaceDesc->Height;
g_Camera.SetProjParams( D3DX_PI/4, fAspectRatio, 0.1f, 10000.0f );
//pd3dDevice->SetTransform( D3DTS_PROJECTION,g_Camera.GetProjMatrix());
在每一帧的动作里面设置观察矩阵:
g_Camera.FrameMove( fElapsedTime );//更新相机的信息
pd3dDevice->SetTransform(D3DTS_VIEW,g_Camera.GetViewMatrix());//设置观察矩阵
然后在消息响应函数里添加相机的消息响应:
g_Camera.HandleMessages( hWnd, uMsg, wParam, lParam ); //在MsgProc函数中添加
需要注意的是在CFirstPersonCamera中已经有了g_pd3dDevice->Present( NULL, NULL, NULL, NULL );这个将后台提交到前台的操作,在自己写渲染函数的时候一定不要再写这个了,不然会出现模型闪动的情况.
//摄像机初始位置
//Set the application initial viewpoint
D3DXVECTOR3 vecEye( 0.0f, 2.0f, -5.0f );
D3DXVECTOR3 vecAt ( 0.0f, 1.0f, 0.0f );
g_Camera.SetViewParams( &vecEye, &vecAt );
// Set the camera speed
g_Camera.SetScalers( 0.01f, 10.0f ); //设置鼠标和键盘移动的快慢
// Constrain the camera to movement within the horizontal plane
g_Camera.SetEnableYAxisMovement( false );//不移动Y轴
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/luoya263547560/archive/2009/05/03/4144623.aspx
posted on 2011-06-09 16:56 DoubleSnake 阅读(666) 评论(0) 编辑 收藏 举报