Hot answers tagged

9 votes
Accepted

Why is the size of glm's vec3 struct 12 bytes?

The "union" there says that these are three different ways of viewing the same memory. So the x component of the first struct ...
DMGregory's user avatar
  • 132k
6 votes
Accepted

Direction vector to quaternion

From http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/ ...
Bram's user avatar
  • 3,729
5 votes
Accepted

Rotate an object to face a point with glm::lookAt

Because the lookAt function is to position the camera to look at an object (not for an object to look at another object) and the way 3D cameras work is that ...
Stephane Hockenhull's user avatar
5 votes
Accepted

Euler angle and Quaternion conversion become weird when yaw is bigger than 90 degrees

Your current code assumes it's always going to get Euler angles where x is between ±90° and z is close to 0. Meanwhile, glm wants to return Euler angles that are standardized so that y is between ±90°,...
DMGregory's user avatar
  • 132k
4 votes
Accepted

OpenGL 3.3+ Problem with ortho projection for UI/HUD

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 ...
cozmic's user avatar
  • 477
4 votes

Storing component vectors to avoid matrix and quaternion inaccuracies?

Short answer: To store position, use a single vec3. To store rotation, use a quaternion and normalize it after every multiplication or after every ...
HolyBlackCat's user avatar
  • 1,998
4 votes
Accepted

Convert a direction vector (normalized) to rotation?

Making a model always face a point is trickier in 3d than it is in 2d: the added dimension makes one wonder "what about the UP?". This here assumes that you want your model to stay vertical as much ...
Vaillancourt's user avatar
  • 16.3k
4 votes
Accepted

Storing transformations in game objects. (GLM, C++)

My general recommendation is to keep both the source components of your transformation for ease of manipulation: local translation vector local orientation quaternion local axis-aligned scale triplet,...
DMGregory's user avatar
  • 132k
4 votes

GLM conversion from euler angles to quaternion and back does not hold

The results are not what you expect, but they are not wrong. It’s just that for a given orientation there are at least two “paths” through Euler angles that lead there. For instance, the identity ...
sam hocevar's user avatar
  • 23.8k
3 votes

Why does GLM only have a translate function that returns a 4x4 matrix, and not a 3x3 matrix?

You still need 4x4 for the projection matrix, even in 2D. Typically you will use a combined MVP matrix in your shaders rather than separate matrices, so the calculations are easier (and faster - 4x4 ...
Maximus Minimus's user avatar
3 votes

How to use GLM Simd using GLM version 0.9.8.2?

It also depends on your OS and compiler. I'm testing GLM-0.99, and this is the behavior I observe. Note that I have the following macros defined before including glm...
Samuel Li's user avatar
  • 131
3 votes
Accepted

Find angle (slope) of collision plane?

If you have the normal of the collision triangle, then you can do a dot product with a normal pointing up (0, 1, 0), the result will be related to the angle of the surface (0 when is completety ...
jucarave's user avatar
3 votes
Accepted

Orthographic projection not showing a triangle

The triangle appears very small because the ortho projection is quite big. Try this projection = glm::ortho(0.0f, 4.0f, 0.0f, 3.0f, 0.1f, 100.0f) And if you want ...
tuket's user avatar
  • 475
3 votes
Accepted

How do I increment a quaternion rotation in update()?

Applying the rotation that a quaternion represents is done via multiplication. This is really neat, because it works on vectors, like so: v2 = q * v1 but also on ...
PepeOjeda's user avatar
  • 656
2 votes
Accepted

How should I rotate vertices around the origin on the CPU?

It's unclear where your issue lies. To rotate a vector about the origin, you create a rotation matrix, and then you multiply the vertex by the matrix. In order to create the rotation matrix, you ...
Vaillancourt's user avatar
  • 16.3k
2 votes
Accepted

C++ Opengl transforming a glm::vec4 with a glm::mat4

You get the error because there is no operator*= for vec4 that takes a matrix as a parameter. It then tries to convert the ...
Vaillancourt's user avatar
  • 16.3k
2 votes

How do you build a rotation matrix from a normalized vector?

Turns out the manual matrix creation method was on the right track, I just wasn't building it in the correct order. This appears to do what I want (though oriented on the -Z axis rather than the +X ...
Nairou's user avatar
  • 584
2 votes
Accepted

How to use GLM Simd using GLM version 0.9.8.2?

The good news is that simd support is now part of the standard GLM types (GLM\GTX\simd_mat4.hpp is deprecated), the bad news is that its activation looks broken. Here is how I managed to enable the ...
Yvain's user avatar
  • 36
2 votes
Accepted

Should I use the X-Y-plane when using an orthographic projection in OpenGL?

Yes, you can choose any coordinate system for your world. Choose one you like the most. No, you don't need to rotate each object, you can just modify your projection matrix accordingly. How to do that ...
HolyBlackCat's user avatar
  • 1,998
2 votes

Quaternion based camera pitch freaking out, and Z-axis drift

Firstly, I would recommend working in radians, not degrees. Whilst the GLM library can work with degrees, it was designed with radians in minds(this is a very minor issue though, so work with what you ...
Ian Young's user avatar
  • 2,629
2 votes
Accepted

Drawn frustum does not match with glm::perspective

Looks like that by luck I found the solution to the problem. I really don't like the glm documentation, was my understanding that glm doc was intentionally skinny since it matches corresponding glsl ...
user1777995's user avatar
2 votes

Convert a direction vector (normalized) to rotation?

You just need the standard lookat function. ...
sam hocevar's user avatar
  • 23.8k
2 votes
Accepted

Aligning a weapon model with a first-person camera

One old trick for FPS games is that the player's weapon is rendered separately. What that means in practice is that you render your scene in (at least) two parts: first the world, then the player ...
congusbongus's user avatar
  • 14.8k
2 votes
Accepted

How to get the center position for AABB of rotated mesh right?

According to this tutorial, the vector you are transforming should be the right-hand operand in the matrix multiplication expression, when using glm. Having it on the left will cause your vector to be ...
Colin Wade's user avatar
2 votes
Accepted

Getting Vector at 90 Degrees from provided vector

Edit: So the question was for 3D and It isn't very clear whether you're drawing 2 vectors or 3. Use colors for each axis! To get the perpendicular of a plane you ...
Sidar's user avatar
  • 3,577
2 votes

Why does GLM only have a translate function that returns a 4x4 matrix, and not a 3x3 matrix?

Because GLM (as well as OpenGL) is designed to work for 3D graphics in the first place, and you need mat4 to perform translations in 3D. You could write a 2D ...
HolyBlackCat's user avatar
  • 1,998
2 votes

How to 'point' an arrow in the direction that it's going?

The problem of creating a matrix to point somewhere becomes easy to solve once you understand the make-up of a matrix. Fundamentally, the 4x4 matrix is just a collection of four vectors: The X-Axis ...
Bram's user avatar
  • 3,729
2 votes
Accepted

Problem with FPS camera in Software Renderer

Perspective projection as you have probably implemented it is a pure mathematical transformation. It warps your world space by making all of the lines orthogonal to your viewing plane cross at the ...
Quentin's user avatar
  • 1,168
2 votes
Accepted

OpenGL calculate circle rotation around a given point

You first need to translate the objects, so that the center point falls on (0,0,0), this basically make everything centered around that. Then you can just rotate the object and then translate ...
Bálint's user avatar
  • 14.8k
2 votes
Accepted

Camera Pitch, Yaw from View Matrix

First, let's look at y because it's simplest. to encode pitch into your direction vector's y, you convert the pitch value to radians, then take its sine. to decode ...
DMGregory's user avatar
  • 132k

Only top scored, non community-wiki answers of a minimum length are eligible