OpenGL / GLSL / GLM - Skybox rotates as if a third party

I just started implementing skyboxes and am doing this with OpenGL / GLSL and GLM as my math library. I assume the problem is with the matrix, and I could not find an implementation that uses the GLM library:

The skybox model loads just fine, the camera, however, twists it, as if it rotated around it in a third-party 3d camera.

For my skybox matrix, I update it every time my camera updates. Since I use glm :: lookAt, it is essentially created in the same way as my view matrix, except that I use 0, 0, 0 for direction.

Here is my view matrix creation. It works great when rendering objects and geometry:

direction = glm::vec3(cos(anglePitch) * sin(angleYaw), sin(anglePitch), cos(anglePitch) * cos(angleYaw)); right = glm::vec3(sin(angleYaw - 3.14f/2.0f), 0, cos(angleYaw - 3.14f/2.0f)); up = glm::cross(right, direction); glm::mat4 viewMatrix = glm::lookAt(position, position+direction, up); 

Similarly, my sky matrix is โ€‹โ€‹created in the same way with just one change:

 glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f); glm::mat4 skyView = glm::lookAt(position, position + direction, up); 

I know that skybox does not apply translation and only considers rotations, so I'm not sure what the problem is. Is there an easier way to do this?

Visual aids:

Straight without moving Straight on when I first start the program

When I rotate the camera: enter image description here

My question is this: how to set up the correct matrix for rendering skybox using glm: lookAt?

+4
source share
1 answer

Esthete is right skybox / skydome is only an object, which means that you do not change the projection matrix !!!

your render should look something like this:

  • clear screen / buffers
  • install camera
  • give a model representation of the identity and then translate it to the camera position, you can get the position directly from the projection matrix (if my memory serves the array positions 12,13,14) to get the matrix, see this fooobar.com/questions/1355127/ ...
  • draw skybox / skydome (do not cross your z_far plane or turn off the depth test)
  • optional cleaning Z-buffer or re-entering the depth test
  • draw your stuf scene .... (don't forget to set the view matrix for each of your models)

Of course, you can temporarily set the camera position (projection matrix) to (0,0,0) and leave the modelโ€™s viewing matrix with a personality, sometimes this is a more accurate approach, but do not forget to set the camera position back after drawing the skybox.

hope this helps.

+2
source

All Articles