DirectX9左右移动相机
DirectX9 moving a camera left and right
根据本网站:http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-5
3DXMATRIX* D3DXMATRIXLookAtLH(D3DXMATRIX* pOut,
CONST D3DXVECTOR3* pEye,
CONST D3DXVECTOR3* pAt,
CONST D3DXVECTOR3* pUp);
D3DXMATRIX* pOut,
// We know this one. It is the pointer to the matrix we are going to fill.
CONST D3DXVECTOR3* pEye,
// This parameter is a pointer to a vector which contains the exact position
// of the camera. Considering our example above, we want to fill this struct
// with (100, 100, 100).
CONST D3DXVECTOR3* pAt,
// This vector contains the exact location the camera should look at.
// Our example is looking at (0, 0, 0), so we will fill this struct
// with those values.
CONST D3DXVECTOR3* pUp,
// This vector contains the direction of "up" for the camera. In other
// words, what direction will the top of the screen be. Usually, game
// programmers use the y-axis as the "up" direction. To set the camera
// this way, you simply need to fill this struct with (0, 1, 0), or
// 1.0f on the y-axis and 0.0f on the other two.
我想我所要做的就是改变pEye的x坐标,以及pAt的正负值来向左和向右移动。然而,当我这样做的时候,奇怪的事情就会发生。我做错了什么吗?下面是我的代码!
void world_view::start_cam() {
vPosition = D3DXVECTOR3 ( console_editor.window_w/2 , console_editor.window_h/2 , console_editor.window_h/2 );
vLookAt = D3DXVECTOR3 ( console_editor.window_w/2 , console_editor.window_h/2 , 0.0f );
vUp = D3DXVECTOR3 ( 0.0f , -1.0f , 0.0f );
fov = D3DXToRadian(90); // the horizontal field of view
aspectRatio = (FLOAT)console_editor.window_w / (FLOAT)console_editor.window_h; // aspect ratio
zNear = 1.0f;
zFar = console_editor.window_h/2+10;
}
void world_view:: MoveLeft(float units) {
}
void world_view:: MoveRight(float units) {
D3DXVECTOR3 vTemp = struct_world_view.vPosition;
vTemp.x = vTemp.x + units;
//vTemp.y = vTemp.y + units;
//vTemp.z = vTemp.z + units;
struct_world_view.vPosition = vTemp;
D3DXVECTOR3 vlTemp = struct_world_view.vLookAt;
vlTemp.x + units;
//vlTemp.y + units;
//vlTemp.z + units;
struct_world_view.vLookAt = vlTemp;
}
void world_view::UpdateCamera(){
D3DXMatrixLookAtLH(&struct_world_view.cam,
&struct_world_view.vPosition,
&struct_world_view.vLookAt,
&struct_world_view.vUp);
D3DXMatrixPerspectiveFovLH(&struct_world_view.cam_lens,
struct_world_view.fov,
struct_world_view.aspectRatio,
struct_world_view.zNear,
struct_world_view.zFar);
}
[之前][1]![2]之后
这是Before和After向右移动的示例。任何澄清都将大有帮助!
移动相机的位置和它要看的地方:
void world_view:: MoveRight(float units) {
struct_world_view.vLookAt.x += units;
struct_world_view.vPosition.x += units;
}
编辑:如果你只想向右移动,你可能需要检查负单位。
相关文章:
- OpenGL 相机移动程序顶点着色器问题
- 如何将相机移动并将其粘贴在玩家身上
- OpenGL - 让相机移动
- OpenCV中移动相机的深度/视差图
- 将网格与VTK相机对齐(相机的视觉表示,随之移动和旋转的网格)
- 检测OpenCV C (移动相机)上的运动
- 如何在 3D 空间中正确移动相机
- OpenGL3SFML2.0rc FPS风格的相机-抖动的鼠标移动
- 如何在 directx11 中将相机移动到窗口的 1 个像素单位,而不是世界空间中的 1 个单位
- 当相机移动DirectX时,模型会消失
- 如何在OpenGL中使用鼠标在相机周围移动
- 如何将鼠标移动转换为相机平移
- OpenGL程序/w着色器,相机移动不正确
- 需要帮助在OpenGL中移动相机
- OpenGL-向前移动相机
- glulookat()-使用键盘移动相机(OpenGL)
- 更新相机移动与键不工作
- GLSL灯光/高光随相机移动
- OpenGL——随着相机移动的文本和纹理也以专家建议的方式表现
- 如何使一个形状静态,而相机移动c++ OpenGL