21
votes
Why do we use 4x4 matrices to transform things in 3D?
3x3 matrices cannot represent 3D translations, but 4x4 matrices can
A simple argument why 3D translations are not possible with 3x3 matrices is that translation can take the origin vector:
...
18
votes
How does a 4x4 matrix represent an object in space and matrix lore?
How is Matrix Multiplication a Transformation?
A matrix is just a big grid of numbers with rules that define how we can multiply it with other grids or lists of numbers.
In games, we usually want to ...
15
votes
Accepted
Why do we need a fourth coordinate to divide by z?
Because if you only divide [x, y, z] by z you get [x/z, y/z, 1] and you lost the actual ...
11
votes
How and when do the model to world, world to view, et cetera multiplications happen?
Think about it logically:
What is your goal when you render something?
To display it on the screen!
What are the constraints?
The model must be visible to the camera (i.e. in the view frustum, not ...
9
votes
Accepted
Do matrix manipulations for 3D graphics ever produce singular matrices?
The simplest way this can happen is if you shrink an object until its local scale in one or more axes is 0 (flattening it to a plane, line, or point). You can avoid this by disallowing scales below a ...
9
votes
Accepted
lookAt with orthographic camera (gl-matrix)
When I use the identity view matrix, I can see my model, but when I use LookAt, it is not visible. How can I see my model using ...
8
votes
Confused About My Code Suggesting The Normal Matrix Is Equivalent To The ModelView Matrix
When a matrix is orthogonal, inverse and transpose are equivalent making an inverse transpose equal to the original matrix. So if your model view matrix is orthogonal, the normal matrix will be equal ...
7
votes
Accepted
Finding islands from array
This is a standard computer science problem called connected component search.
You can solve it in time linear in the number of cells using iterated depth-first / breadth-first search or a flood fill ...
6
votes
How do you make a camera look at a box and ensure all of it is visible?
Take every point (vertex), project them into screen space (basically multiply them with the projection * view * model matrix).
After you got this, take every point ...
5
votes
Accepted
Extract a rotation matrix given a camera direction (vector) and a up vector for the camera?
NOTE: Edited because it was likely too verbose (source).
A rotation matrix actually always defines an orthonormal basis. What this means is each column defines one of your original axes in its ...
5
votes
Accepted
How much matrices should I use for OpenGL transformation?
Your object is transformed in multiple steps, and for each step, you usually use a matrix.
You can rotate, scale and translate every model. This can be done with three separate matrices, but usually ...
5
votes
Accepted
How to mirror/reflect/flip a 4D transformation matrix
To get a transformation matrix equivalent to the one you have, but reflected across a major axis you can compose it (multiply it by) a reflection matrix.
That is, if you have your input matrix M and ...
4
votes
From 3d rotation, snap to nearest 90 directions
For anyone in the future looking for a solution to this using Unity/C#, here is an implementation I made based on Steve's answer:
...
4
votes
Fastest way to neutralize scale in the transform matrix?
Assuming your matrix multiplication follows the convention...
M * v = (T * R * S) * v
(where M is your composed matrix, ...
4
votes
Accepted
How to convert -1 to 1 coordinate back to screen coordinates?
For this problem specifically:
screenX = ((glX + 1) / 2.0) * maxScreenX;
screenY = ((glY + 1) / 2.0) * maxScreenY;
In general, the solution for going from ...
4
votes
How do I create a view matrix that does not contain the camera translation?
In fact you don't need to create a second matrix separately. To remove any translation you just need to cast the matrix to mat3 and back to ...
4
votes
Accepted
Issues with OpenGL rotation matricies and shaders
You're off by 1 in your matrix initialization.
The matrix rows are 4 entries wide (4x4 matrix) but you're initializing them like they're 3 entries wide.
...
4
votes
Accepted
multiply matrix4x4 with vec4
Matrix-vector multiplication works the same as matrix-matrix multiplication, because a 4d vector is basically matrix with one of the dimensions equal to 1.
If we have a vector ...
4
votes
How much matrices should I use for OpenGL transformation?
In professional games every object in the world will have its own world matrix. This is usually stored in some structure that represents your entity in the world, or some component hanging off that ...
4
votes
Accepted
How to convert a 4x4 matrix transformation to another coordinate system?
This is as easy as writing your old coordinates in terms of the new ones.
We want +x to map to +x (1, 0, 0)
We want +y to map to +z (0, 0, 1)
We want +z to map to -y (0, -1, 0)
We want the fourth, ...
3
votes
Accepted
Tetris: 2D Rotation Matrix?
At 90 degrees, you can work out rotations in both directions just by swapping and reversing positions. Begin with the following shape:
Ahead, we rotate it manually clockwise, and look at the ...
3
votes
Accepted
Cumulative transformation matrices for hierarchical object transformations
So firstly, I'd like to apologize if my question was poorly worded or if it was just confusing in general. I think I've figured out the proper solution now. It took a while because I had passed it off ...
3
votes
Accepted
Change value of uniform for each VAO
You can make a uniform for as many things as you want, including per object. If you want object A) to have a different uniform then object B), then create one for each item and bind it to the shader ...
3
votes
Accepted
Projection Matrix Breaks My Rectangle
First of all, there's something fishy about your vertices. If we write them out properly:
...
3
votes
Accepted
Get the difference between 2 matrices
Your problem is that you're trying to compare floating-point numbers for equality. The matrix inversion and multiplication, however, will inevitable introduce slight rounding errors that will make ...
3
votes
Accepted
How would you design a transformation matrix to project absolute coordinates to any orthographic projection desired?
I'm going to make some assumptions...
Your 3D world coordinate system is left-handed, with the y axis
pointing up in the world.
You want to convert to camera space, where y is up on the screen, x
is ...
3
votes
Accepted
Passing Matrix to shader
Yes, there is no way to pass a float4x4 to an input description. By doing that you'd be passing a matrix for every vertex to your vertex shader. This is bad practice unless you need to bind a ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
matrix × 592opengl × 135
mathematics × 130
transformation × 107
rotation × 86
3d × 82
xna × 65
camera × 63
c# × 49
projection × 44
vector × 41
c++ × 37
linear-algebra × 33
coordinates × 27
2d × 26
unity × 24
quaternion × 24
directx × 23
shaders × 22
glm × 20
skeletal-animation × 18
java × 17
directx11 × 17
projection-matrix × 17
glsl × 16