首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >DirectX9左右移动摄影机

DirectX9左右移动摄影机
EN

Stack Overflow用户
提问于 2013-02-18 13:34:17
回答 1查看 893关注 0票数 0

根据这个网站:http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-5

代码语言:javascript
运行
复制
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加/减来左右移动。然而,当我这样做的时候,奇怪的事情就发生了。我有什么地方做错了吗?下面是我的代码!

代码语言:javascript
运行
复制
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);

}

这是向右移动之前和之后的示例。任何澄清都会有很大帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-18 13:51:01

同时移动摄影机的位置和所看的位置:

代码语言:javascript
运行
复制
void world_view:: MoveRight(float units) {

struct_world_view.vLookAt.x += units;
struct_world_view.vPosition.x += units;

}

编辑:另外-如果你只想要向右移动,你可能想要检查负单位。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14930117

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档