Skip to main content
Share Your Experience: Take the 2024 Developer Survey
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
  • 135k
6 votes
Accepted

Direction vector to quaternion

From http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/ ...
Bram's user avatar
  • 3,719
6 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
  • 135k
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
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
  • 135k
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.9k
4 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
  • 485
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

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 ...
DMGregory's user avatar
  • 135k
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
  • 711
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.9k
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,649
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
  • 2,035
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
  • 2,035
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

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,178
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,719
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
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.9k
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
  • 135k
2 votes

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: ...
DMGregory's user avatar
  • 135k
2 votes

Matrix math in cascade shadow mapping

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 ...
shybovycha's user avatar
2 votes
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: ...
DMGregory's user avatar
  • 135k
2 votes
Accepted

How to make a concisely, elegantly, and human-friendly Quaternion camera?

OK, thanks for the links from DMGregory and the ideal form HolyBlackCat. I think that I find a temporary solution. Of course, it is not very elegant and not perfect... Any suggestions or comments are ...
potter john's user avatar

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