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/...
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:...
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 ...
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 ...
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 ...
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:
away from the origin, say to x = 1:
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 ...
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 ...
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 ...
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 ...
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 )
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.
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, ...
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 ...
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 ...
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 ...
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 ...
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, ...
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 ...
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) *
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 ...
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:
1 & 0 & a & 0 \\
0 & 1 & a & 0 \\
0 & 0 & 1 & 0 ...
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 ...
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 ...
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 ...
I would expect your matrix multiplication code to look like
x & y & 1 \\
1 & 0 & 0 \\
0 & 1 & 0 \\
50 & 0 & 1
x+50 & y & 1 \\
This is because matrix multiplication is defined so that you go by row in the first ...
From what I read from the shaders the light is in world-space and the light calculation is done on the object in part in untransformed object-space.
You need to compute your lighting with both light & model in world-space or both in camera space.
Whenever moving the camera messes up the lighting it means some of the data is calculated in a different ...
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 you multiply by a matrix N that has the reflection.
To create the reflection matrix based on the major axis, you take the identity matrix and flip signs ...