Home Game Development opengl – How to make a concisely, elegantly, and human-friendly Quaternion digicam?

opengl – How to make a concisely, elegantly, and human-friendly Quaternion digicam?

0
opengl – How to make a concisely, elegantly, and human-friendly Quaternion digicam?

[ad_1]

I’ve spent three weeks scuffling with the quaternion digicam!

Now I’ve two Implementations. One has some type of gimbal lock subject or one thing like that. Another one is completely anti-human ( I really feel like I’m utilizing a ZBrush digicam to play a recreation).

the defective one:

enter image description here

the zbrush and anti-human one:
enter image description here

key codes of that two cameras:

the defective one:

void MouseInput(GLfloat xOffset, GLfloat yOffset, bool constrainPitch = 0) {
        xOffset *= turnSpeed;
        yOffset *= turnSpeed;

        if (glm::abs(glm::fmod(pitch, 360.0f)) < 90.0f || glm::abs(glm::fmod(pitch, 360.0f)) > 270.0f)
            yaw += xOffset;
        else
            yaw -= xOffset;

        pitch += yOffset;

        if (constrainPitch) 
        {
            ...
        }
    }
void Update() {

        glm::quat qPitch = glm::angleAxis(glm::radians(-pitch), glm::vec3(1.0f, 0, 0));
        glm::quat qYaw = glm::angleAxis(glm::radians(-yaw), glm::vec3(0, 1.0f, 0));
        glm::quat qRoll = glm::angleAxis(glm::radians(roll), glm::vec3(0, 0, -1.0f));

        orientation = glm::normalize(qYaw * qPitch * qRoll);

        entrance = glm::normalize(orientation * glm::vec3(0, 0, -1.0f));
        up = glm::normalize(orientation * glm::vec3(0, 1.0f, 0));
        proper = glm::normalize(orientation * glm::vec3(1.0f, 0, 0));

        fps = ViewMatrix();
        tps = ViewMatrixOrbital();
    }

the zbrush and anti-human one:

void MouseInput(GLfloat xOffset, GLfloat yOffset) {
        xOffset *= turnSpeed;
        yOffset *= turnSpeed;
        
        yaw = xOffset;
        pitch = yOffset;
    }
void Update() {
        glm::quat qYaw = glm::angleAxis(glm::radians(-yaw), up);
        glm::quat qPitch = glm::angleAxis(glm::radians(-pitch), proper);
        glm::quat qRoll = glm::angleAxis(glm::radians(roll), entrance);

        orientation = glm::normalize(qRoll * qPitch * qYaw * orientation);

        entrance = glm::normalize(orientation * glm::vec3(0, 0, -1.0f));
        up = glm::normalize(orientation * glm::vec3(0, 1.0f, 0));
        proper = glm::normalize(orientation * glm::vec3(1.0f, 0, 0));

        fps = ViewMatrix();
        tps = ViewMatrixOrbital();

                //Clear Everything
        yaw = 0;
        pitch = 0;
        roll = 0;
    }

The view matrix capabilities of each of them are the identical:

    glm::mat4 ViewMatrix() {
        glm::mat4 translate = glm::translate(glm::mat4(1.0f), place);
        glm::mat4 rotate = glm::mat4_cast(orientation);
        return glm::inverse(translate * rotate);
    }

    glm::mat4 ViewMatrixOrbital() {
        glm::mat4 translate = glm::translate(glm::mat4(1.0f), localPosition);
        glm::mat4 roundOneLevel = glm::translate(glm::mat4(1.0f), aroundPoint);
        glm::mat4 rotate = glm::mat4_cast(orientation);
        return glm::inverse(roundOneLevel * rotate * translate);
    }

The first one is tousled after I look straight from as much as down or all the way down to up.

The second one, I can by no means return to the similar place after I simply drag/draw a circle with my mouse…

I actually need some assist to make a human-friendly, “strong”, and elegantly quaternion digicam(some issues just like the digicam within the Ace Combat or EVERSPACE)…

The assets I’ve used:

https://stackoverflow.com/questions/49609654/quaternion-based-first-person-view-camera

http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/

https://www.3dgep.com/understanding-the-view-matrix/

and naturally…

https://www.youtube.com/watch?v=d4EgbgTm0Bg&ab_channel=3Blue1Brown

Sorry for my English…

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here