I’ve spent three weeks fighting the quaternion digicam!
Now I’ve two Implementations. One has some form of gimbal lock concern or one thing like that. One other one is completely anti-human ( I really feel like I’m utilizing a ZBrush digicam to play a sport).
the defective one:
the zbrush and anti-human one:
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 Replace() {
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 Replace() {
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 Every thing
yaw = 0;
pitch = 0;
roll = 0;
}
The view matrix features 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 aroundOnePoint = glm::translate(glm::mat4(1.0f), aroundPoint);
glm::mat4 rotate = glm::mat4_cast(orientation);
return glm::inverse(aroundOnePoint * rotate * translate);
}
The primary one is tousled once I look immediately from as much as down or all the way down to up.
The second, I can by no means return to the identical place once I simply drag/draw a circle with my mouse…
I really want some assist to make a human-friendly, “strong”, and elegantly quaternion digicam(some issues just like the digicam within the Ace Fight 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…