0

I'm trying to render water with reflection and refraction and I am new on OpenGL and I have stumbled upon a simple problem. I want for the reflection texture to move the camera down and invert it to capture the image. I have a Camera with quaternions and Yaw and Pitch. I thought to add roll also and rotate roll by 180 degrees to get the inversion but I can not manage to combine the 3 quaternions. Here is the update function of the camera :

void UpdateCameraVectors()
{
    // Yaw
    glm::quat aroundY = glm::angleAxis(glm::radians(-RightAngle), glm::vec3(0, 1, 0));

    // Pitch
    glm::quat aroundX = glm::angleAxis(glm::radians(UpAngle), glm::vec3(1, 0, 0));

    // Roll
    glm::quat aroundZ = glm::angleAxis(glm::radians(RollAngle), glm::vec3(0, 0, 1));

    Orientation = aroundY * aroundX;

    glm::quat qF = Orientation * glm::quat(0, 0, 0, -1) * glm::conjugate(Orientation);
    Front = { qF.x, qF.y, qF.z };
    Right = glm::normalize(glm::cross(Front, glm::vec3(0, 1, 0)));
}

Any suggestions on how to invert the view or how to combine the quaternions? I already tried all possible multiplications between them.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Mike F
  • 316
  • 3
  • 14
  • You simply can not mirror ("invert") coordinate system just by rotation ... if you use [transform matrices](https://stackoverflow.com/a/28084380/2521214) in there you just scale one of the axises by `-1.0` ... not familiar with quaternions but my guts are telling me its not possible with them as from what I know they represent just rotation... – Spektre Nov 13 '20 at 08:34
  • @Spetre Thank you for the reply. scaling the view matrix by vec3(1, -1, 1) seems to rotate the Y axis but now the objects are facing in the opposite direction on Z axis. tried also vec3(1, -1, -1) but did not get the correct result. – Mike F Nov 13 '20 at 10:05
  • mirroring is not rotating! also these operations are sensitive to order ... you need to scale the matrix at the right place in your code (otherwise it will affect also other nested transforms) ... where depends on your notations and if you have direct or inverse matrices ... so either before rotations or after ... more on this topic in here [Understanding 4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) – Spektre Nov 13 '20 at 10:12

0 Answers0