Share Your Experience: Take the 2024 Developer Survey

# Tag Info

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 ...
• 135k
Accepted

### Direction vector to quaternion

From http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/ ...
• 3,719
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°,...
• 135k
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 ...
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 ...
• 16.3k
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,...
• 135k

### 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 ...
• 23.9k
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 ...
• 485

### 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 ...
• 20.2k

### 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...
• 131
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 ...
• 56
Accepted

### Rotating an object to face the same direction as another object

You can do this without the back-and-forth to matrix steps by computing your new quaternion directly. Here we use the fact that the axis to rotate around must be perpendicular to the start and ending ...
• 135k
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 ...
• 711
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 ...
• 151

### Convert a direction vector (normalized) to rotation?

You just need the standard lookat function. ...
• 23.9k

### 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 ...
• 2,649
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 ...
• 36
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 ...
• 2,035

### 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 ...
• 2,035
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 ...
• 14.8k
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 ...
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 ...
• 1,178

### 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 ...
• 3,719
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 ...
• 3,577
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 ...
• 14.9k
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 ...
• 135k

### how to use glm::rotate with a eulerangle?

in my code i just want to be able to do rotation.x += 5.0f; in the update method of an obj A quaternion representing a rotation of angle radians in the x axis is: ...
• 135k

I have figured a hacky (at least from my lack of understanding) way to fix the issue - construct a new light view matrix every time. This is also what is happening in Vulkan example of cascade shadow ...
• 191
Accepted

### Rotation matrix for a model where the forward axis is not +X

You still handle it in the usual way. Make 3 perpendicular unit vectors (an orthonormal basis), expressing the directions your object's local axes should point after rotation: ...
• 135k