Hot answers tagged glm
user1118321's answer will provide you the correct answer, though it is more general than necessary. Since we're dealing with a right triangle, the easiest solution is to use the definition of the tangent function: tan(α) = A / B Substituting half the height of the screen, the z coordinate of the camera, and half the vertical field of view gets us: ...
Check out the Law of Cosines. It allows you to calculate any side or angle in a triangle if you have the opposite 2 angles or sides. Or alternately, use the law of sines (described at the bottom of the above link). In your case, you know that vertical field of view is 45 degrees and that the base side you want is the height of the screen. You can think of ...
One way is to disable GL_DEPTH_TEST for rendering 2D stuff. So draw everything of the 3D world like normal, then disable depth testing and then draw your UI at last. Another approach would make use of the depth test by setting the z-component of the vertices for the 2D stuff to 0 (and the near plane in the prohection matrix to something greater than 0) to ...
Short answer: To store position, use a single vec3. To store rotation, use a quaternion and normalize it after every multiplication or after every n (1-1000) multiplications. You shall only use mat4s when it comes to drawing or transforming lots of vertices: Convert vec3+quaternion pair to mat4 and pass it to your shader or use it to transform vertices ...
If you have v-sync enabled ( SDL_GL_SetSwapInterval(1) ), SDL_GL_SwapWindow will wait until your monitor refreshes.
When you rotate your camera you should apply the same rotation matrix to your up vector. That should result in an up vector in the same direction as your view matrix's up direction.
You should probably use glm::angleAxis() (documentation here): glm::quat &rot = glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f));
the glm::quat(float, float, float, float); constructor doesn't do what you think it does. It sets the values directly. The values of the quaternion (w, x, y, z) are in order: the cosine of half the angle, the sine of half the angle times the x coordinate of the normalized rotation axis, and the same for the y ans z components. So instead you want to use ...
Only top voted, non community-wiki answers of a minimum length are eligible