1

모든 3D 객체에 대한 일반 행렬 클래스를 작성했지만 변환은 실제로 꺼져있는 것 같습니다.DirectX 11.1 행렬 곱셈 문제

class GenericMatrix 
{ 
public: 
    GenericMatrix(); 

    virtual void Identity(); 

    virtual void Scale(float x, float y, float z); 
    virtual void Scale(const DirectX::XMFLOAT3& s); 
    virtual DirectX::XMFLOAT3 Scaling(void); 

    virtual void Translate(float x, float y, float z); 
    virtual void Translate(const DirectX::XMFLOAT3& t); 
    virtual DirectX::XMFLOAT3 Translations(void); 

    virtual void Rotate(float x, float y, float z); 
    virtual void Rotate(const DirectX::XMFLOAT3& r); 
    virtual DirectX::XMVECTOR Rotations(void); 
    virtual DirectX::XMFLOAT3 RotationsPYR(void); 

    virtual DirectX::XMMATRIX Matrix(bool process = true); 

    virtual operator DirectX::XMMATRIX() 
    { 
     return this->Matrix(); 
    } 

    virtual void UpdateMatrix(void); 

    DirectX::XMMATRIX matrix; 
    DirectX::XMFLOAT3 scale; 
    DirectX::XMFLOAT3 translation; 
    DirectX::XMVECTOR rotation; 
    bool    matrixNeedsUpdate; 

protected: 
    float    yaw, pitch, roll; 
}; 

그리고 소스 : 여기

내 클래스 내가 신원()를 수행 한 후, 모델 매트릭스로 사용하는 경우

#include "pch.h" 
#include "GenericMatrix.h" 

GenericMatrix::GenericMatrix() 
    : matrixNeedsUpdate(true) 
{ 
    this->Identity(); 
    this->pitch = 90.0f; 
    this->yaw = 0.0f; 
    this->roll = 0.0f; 
} 

void GenericMatrix::Identity() 
{ 
    this->scale = DirectX::XMFLOAT3(1.0f, 1.0f, 1.0f); 
    this->translation = DirectX::XMFLOAT3(0.0f, 0.0f, 0.0f); 
    this->rotation = DirectX::XMQuaternionIdentity(); 
    this->pitch = 90.0f; 
    this->yaw = 0.0f; 
    this->roll = 0.0f; 
    matrixNeedsUpdate = true; 
} 

void GenericMatrix::Scale(float x, float y, float z) 
{ 
    this->scale.x += x; 
    this->scale.y += y; 
    this->scale.z += z; 
    this->matrixNeedsUpdate = true; 
} 

void GenericMatrix::Scale(const DirectX::XMFLOAT3& s) 
{ Scale(s.x, s.y, s.z); } 

DirectX::XMFLOAT3 GenericMatrix::Scaling(void) 
{ return this->scale; } 

void GenericMatrix::Translate(float x, float y, float z) 
{ 
    this->translation.x += x; 
    this->translation.y += y; 
    this->translation.z += z; 
    this->matrixNeedsUpdate = true; 
} 

void GenericMatrix::Translate(const DirectX::XMFLOAT3& t) 
{ Translate(t.x, t.y, t.z); } 

DirectX::XMFLOAT3 GenericMatrix::Translations(void) 
{ return this->translation; } 

void GenericMatrix::Rotate(float x, float y, float z) 
{ 
    pitch = x; 
    yaw = y; 
    roll = z; 
    this->rotation = DirectX::XMQuaternionRotationRollPitchYaw(pitch, yaw, roll); 
    this->matrixNeedsUpdate = true; 
} 

void GenericMatrix::Rotate(const DirectX::XMFLOAT3& r) 
{ Rotate(r.x, r.y, r.z); } 

DirectX::XMVECTOR GenericMatrix::Rotations(void) 
{ return this->rotation; } 

DirectX::XMFLOAT3 GenericMatrix::RotationsPYR(void) 
{ 
    return DirectX::XMFLOAT3(pitch, yaw, roll); 
} 

DirectX::XMMATRIX GenericMatrix::Matrix(bool process) 
{ 
    if (process && this->matrixNeedsUpdate) 
    { 
     UpdateMatrix(); 
     this->matrixNeedsUpdate = false; 
    } 
    return this->matrix; 
} 

void GenericMatrix::UpdateMatrix(void) 
{ 
    DirectX::XMVECTOR scaleVec, translateVec; 
    scaleVec = DirectX::XMLoadFloat3(&this->scale); 
    translateVec = DirectX::XMLoadFloat3(&this->translation); 
    this->matrix = DirectX::XMMatrixScalingFromVector(scaleVec) * DirectX::XMMatrixRotationQuaternion(this->rotation) * DirectX::XMMatrixTranslationFromVector(translateVec); 
} 

, 다음 (0.0f로, 0.0f로 번역 , 5.0f), 나의 모델은 [0,0,5]에 카메라를 위치 시켰을 때만 보이고, 심지어 깜박 거린다. 내가했던 3D 프로그래밍의 마지막 비트는 OpenGL 1.x에서였습니다. 그래서 행렬에 뭔가 이상한 행동을하고 있지만 그렇지 않은 방법을 알려주지는 못했습니다. 누구에게나 필요한 정보가 더 있으면 그냥 물어보십시오. 갱신

: 일부 자세한 내용은 - 내가 신원 (에 행렬을 설정)하고두면, 내가 카메라를 이동하고 난 아무데도 이동 한편 경우에, 어떤 위치에서 아무 문제없이 모델을 참조, 그것은 놨어요 시야를 확보하십시오.

답변

0

몇 가지 테스트를 통해 문제를 발견했습니다. 카메라에 왼손잡이 좌표계를 사용하고있는 것 같지만 내 관점에서는 오른손 잡 이용입니다. z 0.9에서 -0.9 사이에서 좌우측 시스템 모두 모델을 볼 수 있어야한다는 점에 동의 할 수 있었지만 카메라를 그 공간 밖으로 옮겼을 때 카메라가 정확히 같은 좌표.

이야기의 도덕 - 코드 전체에서 일관되게 같은 좌표계를 사용하는 것을 잊지 마십시오.