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 ...
6
votes
Accepted
Direction vector to quaternion
From http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/
...
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 ...
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°,...
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 ...
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 ...
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 ...
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,...
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 ...
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 ...
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...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
2
votes
Convert a direction vector (normalized) to rotation?
You just need the standard lookat function.
...
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 ...
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 ...
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 ...
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 ...
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
...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
glm × 150opengl × 90
c++ × 69
mathematics × 27
quaternion × 23
rotation × 20
matrix × 20
camera × 18
3d × 15
transformation × 13
glsl × 7
vector × 6
glfw × 5
euler-angles × 5
skeletal-animation × 4
linear-algebra × 4
frustum × 4
projection-matrix × 4
vulkan × 4
collision-detection × 3
graphics × 3
graphics-programming × 3
coordinates × 3
aabb × 3
assimp × 3