Question

I have a camera class that uses the DirectXMath API:

__declspec(align(16)) class Camera
{
    public:
        XMVECTOR Translation;
        XMMATRIX Rotation;
        XMVECTOR Scale;
        XMMATRIX Transform;

        XMFLOAT3 RotAngles;

        XMMATRIX ProjectionMatrix;

        float Width;
        float Height;

        float NearZ;
        float FarZ;
        float AspectRatio;
        float FieldOfView;

        Camera()
        {
            Translation = XMVectorZero();
            Rotation = XMMatrixIdentity();
            Scale = XMVectorSplatOne();

            Transform = XMMatrixIdentity();

            Width = 800;
            Height = 600;

            NearZ = 0.1f;
            FarZ = 100.0f;
            AspectRatio = 800 / 600;
            FieldOfView = (XM_PIDIV4);

            ProjectionMatrix = XMMatrixPerspectiveFovLH(FieldOfView, AspectRatio, NearZ, FarZ);
        }

        void Update()
        {
            Rotation = XMMatrixRotationRollPitchYaw(RotAngles.x, RotAngles.y, RotAngles.z);
            XMMATRIX scaleM = XMMatrixScalingFromVector(Scale);
            XMMATRIX translationM = XMMatrixTranslationFromVector(Translation);

            Transform = scaleM * Rotation * translationM;
        }

        XMMATRIX GetViewMatrix()
        {
            XMVECTOR Eye;
            XMVECTOR At;
            XMVECTOR Up;

            Eye = Translation;
            At = Translation + Transform.r[2];
            Up = Transform.r[1];

            return(XMMatrixLookAtLH(Eye, At, Up));
        }

        XMMATRIX GetViewProjectionMatrix()
        {
            return(XMMatrixTranspose(GetViewMatrix() * ProjectionMatrix));
        }
};

When I store the result of GetViewProjectionMatrix() in a XMFLOAT4X4 and update it to the constant buffer, the geometry gets torn apart or doesn't show up at all when I move/rotate the camera with the keyboard.I have isolated the camera to be issue with the deforming/disappearing geometry, but I have no idea what the problem is.I mean the projection matrix can't be wrong, it's just 1 function call, so it's most likely the view matrix.Could someone tell me where the issue is?I tried different combinations of multiplication orders/transposing both/transposing only one/anything.It never works properly.

Was it helpful?

Solution

In case anyone sees this question again:

It seems that OP did not transpose to ViewProjection matrix they generated. Note that DirectXMath works in row-major order while HLSL defaults to column-major. As per the documentation at - https://msdn.microsoft.com/en-us/library/windows/desktop/bb509634(v=vs.85).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top