Skip to main content
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 ...
DMGregory's user avatar
  • 135k
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 ...
Dan's user avatar
  • 501
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 ...
Jimmy's user avatar
  • 9,029
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 ...
GettingShwifty's user avatar
7 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 ...
Theraot's user avatar
  • 27.3k
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 ...
DMGregory's user avatar
  • 135k
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 ...
Bálint's user avatar
  • 14.9k
6 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, ...
DMGregory's user avatar
  • 135k
5 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 ...
Pikalek's user avatar
  • 12.4k
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 ...
lyinch's user avatar
  • 361
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: ...
Callum Ferguson's user avatar
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 ...
HolyBlackCat's user avatar
  • 2,035
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. ...
Stephane Hockenhull's user avatar
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 ...
Bálint's user avatar
  • 14.9k
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 ...
Bryan Robertson's user avatar
4 votes
Accepted

Normal Matrix in plain English

You need to use a different matrix to transform your normal vectors when your model's transformation might include non-uniform scale. When we stretch a shape along, say, just the y axis, the y ...
DMGregory's user avatar
  • 135k
4 votes

How does glm::lookAt produce a View Matrix?

Alright so upon looking into it further, here's how glm::lookAt produces a View Matrix: Make a row-major ordered 4x4 Translation Matrix by negating the camera position, c: ...
Ian's user avatar
  • 61
4 votes
Accepted

Difference between World matrix and Model matrix?

The names "world matrix" and "model matrix" are just terminology, and are not 100% standardised, so depending which source you read you may see them being used to refer to a number ...
Maximus Minimus's user avatar
4 votes
Accepted

How do I create a localtoworldmatrix and worldtolocalmatrix in Godot?

In Godot a Transform3D has no concept of local or world. They are transformations between spaces, and what those spaces are depend on how you use them. For a ...
Theraot's user avatar
  • 27.3k
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 ...
DMGregory's user avatar
  • 135k
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 ...
Honeybunch's user avatar
  • 1,383
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 ...
Ilmari Karonen's user avatar
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 and when do the model to world, world to view, et cetera multiplications happen?

Please allow me to elaborate what the responsibility of the GPU should be in the most common scenarios as well as the responsibilities of the CPU, game-engine, and OpenGL. Basics to the OpenGL ...
Nicholas Miller's user avatar
3 votes
Accepted

Why do these DirectXMath functions seem like they return column-major matrics?

You posted a column-major version of the translation matrix for (1,1,-1): 1.0 0.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 0.0 1.0 -1.0 0.0 0.0 0.0 1.0 ...
Chuck Walbourn's user avatar
3 votes
Accepted

3d isometric projection matrix?

You should try having a separate camera and projection matrix, since isometric projection is just ortographic with a very specific camera placement. If you are using a modern matrix library (you ...
Bálint's user avatar
  • 14.9k
3 votes
Accepted

Should 3D transformations be represented by a 4x4 matrix or a 3x4 matrix?

Since 3D transformations are represented by 4x4 homogeneous matrices Correction: Might be represented by 4x4 matrices ;) Now I can see how this would be a great optimization at first as it ...
wychmaster's user avatar
3 votes
Accepted

Invert parent transform (doesn't work for combination of rotation and scale)

A 4x4 homogeneous matrix can represent any affine transformation. That is, any combination of: Translation by any offset Rotation around any axis by any angle Scale along multiple arbitrary axes by ...
DMGregory's user avatar
  • 135k

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