VChuckShunA
VChuckShunA

Reputation: 25

Confused about how Rotation works in vulkan

I set up a Vulkan Pipeline using Branden Gela's tutorials and started putting together my own system using it. I derived a class from his gameobject class.

The gameobject has some transform matrices like this.

glm::mat4 TransformComponent::mat4()
    {
        {
            const float c3 = glm::cos(rotation.z);
            const float s3 = glm::sin(rotation.z);
            const float c2 = glm::cos(rotation.x);
            const float s2 = glm::sin(rotation.x);
            const float c1 = glm::cos(rotation.y);
            const float s1 = glm::sin(rotation.y);
            return glm::mat4{
                {
                    scale.x * (c1 * c3 + s1 * s2 * s3),
                    scale.x * (c2 * s3),
                    scale.x * (c1 * s2 * s3 - c3 * s1),
                    0.0f,
                },
                {
                    scale.y * (c3 * s1 * s2 - c1 * s3),
                    scale.y * (c2 * c3),
                    scale.y * (c1 * c3 * s2 + s1 * s3),
                    0.0f,
                },
                {
                    scale.z * (c2 * s1),
                    scale.z * (-s2),
                    scale.z * (c1 * c2),
                    0.0f,
                },
                {translation.x, translation.y, translation.z, 1.0f} };
        }
    }
    glm::mat3 TransformComponent::normalMatrix()
    {
            const float c3 = glm::cos(rotation.z);
            const float s3 = glm::sin(rotation.z);
            const float c2 = glm::cos(rotation.x);
            const float s2 = glm::sin(rotation.x);
            const float c1 = glm::cos(rotation.y);
            const float s1 = glm::sin(rotation.y);
            const glm::vec3 invScale = 1.0f/scale;
            return glm::mat3{
                {
                    invScale.x * (c1 * c3 + s1 * s2 * s3),
                    invScale.x * (c2 * s3),
                    invScale.x * (c1 * s2 * s3 - c3 * s1),
                },
                {
                    invScale.y * (c3 * s1 * s2 - c1 * s3),
                    invScale.y * (c2 * c3),
                    invScale.y * (c1 * c3 * s2 + s1 * s3),
                },
                {
                    invScale.z * (c2 * s1),
                    invScale.z * (-s2),
                    invScale.z * (c1 * c2),
                },
            };
    }

Now I want to set up a quad and have it face the camera. But the problem is I can't seem to get it to properly face the camera AT ALL!

Right now my code sets it up like this:

 player.transform.rotation = { 190.f,0.f,0.f };

And this is the result(SIDE VIEW): Note: My player IS derived from gameobject

enter image description here

It's not completely 180. Nor 190 imo. I don't know if it's a something to do with my camera, but I am NOT setting any default rotations for the camera. Does this have to do with the way Vulkan handles Rotation or am I missing something?

Upvotes: 0

Views: 136

Answers (0)

Related Questions