Hot answers tagged

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: ...
Ciro Santilli OurBigBook.com's user avatar
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
  • 130k
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 ...
sam hocevar's user avatar
  • 23.7k
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

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 ...
DMGregory's user avatar
  • 130k
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,019
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

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
  • 130k
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.8k
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 ...
WafflesTasty's user avatar
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
  • 351
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 ...
Theraot's user avatar
  • 24.4k
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

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, ...
DMGregory's user avatar
  • 130k
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 ...
Pikalek's user avatar
  • 10.8k
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
  • 1,963
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.8k
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

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
  • 130k
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 ...
Kroltan's user avatar
  • 397
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 ...
nicholaschiasson's user avatar
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 ...
Yattabyte's user avatar
  • 1,013
3 votes
Accepted

Projection Matrix Breaks My Rectangle

First of all, there's something fishy about your vertices. If we write them out properly: ...
Nasser Al-Shawwa's user avatar
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
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
  • 130k
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,373

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