People who code: we want your input. Take the Survey

# Tag Info

## Hot answers tagged matrix

32

Yes, you can add a vector in the case of translation. The reason to use a matrix boils down to having a uniform way to handle different combined transformations. For example, rotation is usually done using a matrix (check @MickLH comment for other ways to deal with rotations), so in order to deal with multiple transformations (rotation/translation/scaling/...

20

Matrices in computer graphics are the transformations given to each coordinate in the model. Each Matrix is a combination of multiple transformations to apply to a coordinate (a point in 3-space). Building a transformation is based from one of three transform types: Translate, Rotate and Scale. A translation matrix is something like: And a scale matrix:...

19

Within a 3D rendered scene, there are typically three main matrices used to transform an object from its own local space (object/model space) to a homogeneous space known as screen space. World The World matrix being the first, is unique for every object within your world, and is responsible for transforming the vertices of an object from its own local ...

15

The problem with rotations, is that, most people think of it in terms of Euler angles, since they are easy to understand. Yet most people forget the point that Euler angles are three sequential angles. Meaning that rotation around the first axis, will make next rotation be relative to the first original rotation, hence you cannot independently rotate a ...

15

Because if you only divide [x, y, z] by z you get [x/z, y/z, 1] and you lost the actual value of z, which is actually useful if you want to do near/far plane clipping or fill a Z-buffer. The best way to keep some information about z, at least on the GPU, is therefore to use 4 components instead of 3. In practice, what is actually in the last two vector ...

13

TL; DR: If you multiply stuff together, you need to start with a 1 Forget about matrices for a second, let's talk about numbers. Suppose to rotate by 90, you multiply by 90. So P' = 90*P Now you do other transforms - a rotation R, a translation T, a scale S and so on. So P' = T*R*S*P Since you will apply all these transforms to a lot of points, you want ...

12

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 construct a matrix so that, when multiplied with a list of numbers representing a source position (say, the position of a vertex in a mesh) we get a list of ...

11

As long as you're doing only uniform scaling, this is easy; you can simply extract each row (or column; it doesn't matter), of the 3x3 matrix. The scale factor will be the length of the row vector. If you normalize each row vector and construct a new matrix from the normalized rows, that will be the rotation part. (If you have a 4x4 matrix, you just do ...

11

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 occluded by other objects, etc.) What are the inputs? A collection of vertices in a coordinate system local to the model's origin. A transformation matrix that ...

10

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: 0 0 0 away from the origin, say to x = 1: 1 0 0 But that would require a matrix such that: | a b c | |0| |1| | d e f | * |0| = |0| | g h i | |0| |0| But that is ...

9

I still think you need to understand basic trigonometry. But here is a simple introduction of how to use sin and cos to simulate a wave. The basic wave formula is: f(t) = A * sin( 2 * pi * f * t + phase ) Where: f is the frequency, which controls the number of times the waves repeats per unit time, f = 1/P where P is the number of periods. A ...

9

What is a matrix? A matrix with m columns and n rows represents a function which consumes a vector* with m elements (or coordinates) and produces a vector with n elements. From this you can observe that if and only if a matrix is square, will the dimensionality of the vector not change. Eg. you get a 3D vector from transforming a 3D vector, a 2D from a 2D, ...

9

Transforming the ray position and direction by the inverse model transformation is correct. However, many ray-intersection routines assume that the ray direction is a unit vector. If the model transformation involves scaling, the ray direction won't be a unit vector afterward, and should likely be renormalized. However, the distance along the ray returned ...

9

Some of the things I typically try when nothing appears to be drawing on the screen: Disable backface culling (in case your geometry winding is wrong) Change the glClearColor() to something other than black (texturing problems can cause your geometry to be drawn solid black, in which case you won't see it) Change your fragment shader to output a specific ...

8

In practice, even when a scene is built to minimise problems, a 360-degree-FOV camera tends to introduce so much distortion in some directions that its results are useless for most purposes. If you want to avoid the expense of rendering a full texture cube, you can get a similar effect by using dual paraboloid environment maps, in which you render two ...

8

You are correct that a combined axis-angle representation like the one you describe has a stronger expressive power than many other systems because it can more conveniently store a rotation speed. However, in practice, people actually use quaternions and 3×3 matrices to manipulate rotations a lot more than just represent them. One typical operation is the ...

8

To succinctly answer the "why" question, it's because a 4x4 matrix can describe rotation, translation, and scaling operations all at once. Being able to describe any of these in a consistent manner simplifies a lot of things. Different kinds of transformations can be more simply represented with a different mathematical operations. As you note, ...

8

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 algorithm. Walk over the cells of your grid systematically. If the cell is 0, skip ahead to the next cell. Otherwise, check if you've already visited this ...

7

If your matrix and quaternion classes are functioning properly, then a sequence of rotations should not ever give you a reflection (inverting or flipping a sprite). You should not just sweep the problem under the rug by writing code to flip something if it comes out with a reflection; you should try to figure out the actual problem. That being said, based ...

7

Rotation/scaling is around the origin. To both scale/rotate around a pivot, you apply a negative translation to move the pivot point to the origin, apply your scale and rotate, and then move your pivot point back. mat4 result = glm::translate(-pivot) * glm::scale(..) * glm::rotate(..) * glm::translate(pivot) * ...

7

If all you are ever going to do is move along a single axis and never apply any other transformation then what you are suggesting is fine. The real power of using a matrix is that you can easily concatenate a series of complex operations together, and apply the same series of operations to multiple objects. Most cases aren't that simple and if you rotate ...

7

For a cavalier projection, it looks like you would want to start with an orthographic projection and then apply a shear to the z-axis. In other words, for OpenGL you would want to multiply the projection matrix on the left by a matrix of the form: \begin{matrix} 1 & 0 & a & 0 \\ 0 & 1 & a & 0 \\ 0 & 0 & 1 & 0 ...

7

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 to it. As user41442 pointed out, in most cases modelview matrices are actually orthogonal so this can be a bit of a short hand. There's still cases where it's ...

7

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 certain magnitude on any axis. (If your system allows hierarchical nesting of transforms, you'll also have to watch out that no chain of parented matrices ...

7

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 LookAt? The LookAt function takes three parameters: eye, which is where your camera is. in the identity matrix, your camera is at 0, 0, 0 target, which is where your camera is pointed at. you can think of the camera's direction ...

6

I would expect your matrix multiplication code to look like $$\begin{bmatrix} x & y & 1 \\ \end{bmatrix} * \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 50 & 0 & 1 \end{bmatrix} = \begin{bmatrix} x+50 & y & 1 \\ \end{bmatrix}$$ This is because matrix multiplication is defined so that you go by row in the first ...

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