簡體   English   中英

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]

這是向右移動之前和之后的示例。 任何澄清將大有幫助!

移動相機的位置和它所看的位置:

void world_view:: MoveRight(float units) {

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

}

編輯:同樣-如果只想向右移動,則可能要檢查負單位。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM