# Tag Info

## Hot answers tagged matrix

10

Because $x_{proj}$ doesn't vary from $0 \to width$, it varies from $-\tfrac{width}{2} \to \tfrac{width}{2}$. What's important is not the width, but the minimum and maximum values of $x_{proj}$. Because $(0, 0)$ is in the centre of the viewport, not the corner, the min and max values are plus and minus half of the width. BTW, the Red Book is not a great ...

8

The notation $\delta_{i,j}$ is the Kronecker delta, a notation commonly used in physics. It's defined as: $$\delta_{i,j} \equiv \begin{cases}1,&i=j\\0,&i\neq j\end{cases}$$ So, as you suspected, it's essentially a shorthand for the identity matrix. The notation $\mathbf{S}_i \in \mathrm{R}^s$ means that each $\mathbf{S}_i$ is an $s$-dimensional ...

6

I (believe) I've solved this (even if it has taken 2 days). My problem was essentially I wanted to take the dot product of the face normal, and line-of-sight vector like below And determine the angle to see if the face was looking towards or away from the view point. My erroneous step was that I was doing this AFTER transforming from world-space to view-...

6

As a general rule, you cannot interpolate transformation matrices. In stead, you decompose them into their individual values, then interpolate those and recompose. The Möbius transformation as suggested in the comments sounds interesting, but tradionally I'd just extract scale and rotation and interpolate those. Assuming a transformation matrix | a ...

6

No, he's talking about subtracting the position of the cube from the vertex positions, so that your cube is positioned at the origin. If you positioned the cube at (10, 30, 15), you subtract that value from every vertex. Next, you rotate the vertices. Lastly, you add the position to the vertices again so the box goes back to where it was, but the vertices ...

6

There is no 100% consensus on what order matrix multiplication should model things, worse the industry is split along this. Some sources use row major and some sources use column major matrices. Great care should be taken to verify which is being used in your source and what is being used by your API! Some API's go as far as allowing one to multiply vectors ...

6

When you scale along the X-axis, the X-coordinate (parallel to the axis) gets stretched, while the Y-coordinate (perpendicular to the axis) remains the same. You can think of scaling along an arbitrary axis as stretching along some diagonal. Here's a pic of a square being scaled along the main diagonal (the axis pointing to <1, 1> ) by factors of 2 and 0....

5

Yes, you can use an off-axis projection matrix. This is what I use in my code (note: I shift the centre upwards, not left as you do in your example.) void camera_setAspectRatio(float aspect, float zNear, float zFar, bool offaxis) { // create a projection matrix const float f = 1.0f / tanf(fovy_radians/2.0f); fovx_radians = 2.0f * ...

5

If you have a 3x3 matrix representing some transformation, you will actually have the X,Y,Z vectors of that transformation in the rows or columns (depending on if it's a row major or column major matrix). In other words, if you have a 3x3, you can look at it and immediately get the up, right(*), forward vectors (asterisk due to handedness, it could be the ...

5

Let me try to make my comment into a complete answer. The general idea is to build a linear system using those 6 point pairs and solve for the desired 12 unknowns. You may find this paper[1] useful if you want to learn the theoretical background, and you can find some more details in my blog post[2]. Here is my solution using Mathematica. In the first ...

5

OpenGL uses column-major matrices. For example, the translation values will be in the last row rather than the last column of the matrix. For example when loading matrices into uniforms in glsl, the glUniformMatrix4fv() function takes its matrix parameters in column-major order: Each matrix is assumed to be supplied in column major order. In glm, the ...

4

I've done some small changes to how I usually construct my view matrix, here is what I've modified: // put it after N = ... U = cross(N, Vspec); U = U / sqrt(dot(U,U)); % normalize V = cross(U, N); Then I also set N vector as -N to R matrix, like this: R= [U(1),U(2),U(3),0; % U is direction of camera space X axis V(1),V(2),V(3),0; % V is direction of ...

4

It is not necessarily affine. An affine matrix in homogeneous coordinates has a form like: $$\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ 0 & 0 & 1 \end{bmatrix}$$ (assuming you use a column vector convention). Here, the upper-left 2×2 submatrix is the linear part, and $(a_{13}, a_{23})$ is the ...

4

Yes, you do need to transform the fetch direction into the space of the cubemap. If you could somehow figure out the fetch direction in the vertex shader, then you could do the transformation there instead, but that would produce worse lighting. It also may be worth optimizing for a smaller number of interpolants between the vertex and pixel shaders (rather ...

4

You have to step outside the world of mathematics for a while and look at what we are trying to achieve. Mathematics in its purest form only tells us what kinds of properties certain constructs have, it does not tell us why and how that would be useful. The modeler's perspective on things So we have to look at the problem from modeling perspective. In this ...

4

That quote is a very strange way to phrase things. We definitely use 3x3 matrices in computer graphics. They tend to be most useful for doing affine transformations of 2D objects. It allows you to have scale, rotation, shearing, and translation (in 2D), but not perspective transformations. I believe that's what the quote is trying to say. To get a ...

4

Yes. If you're compounding operations to make a matrix, then the inverse matrix will be the compound of the inverse operations, in the reverse order. So if $C = AB$ then $C^{-1} = B^{-1}A^{-1}$ Think of it geometrically. Taking a 2D example, if you have an object at the origin, and you want to move it +2 units in X then rotate around the origin by +45 ...

3

A matrix can be used to transform a coordinate system into a new one. More specifically, it can be used to transform the basis vectors of a coordinate system. That's how it defines a new coordinate system. It is of course always in relation to another coordinate system but that is often implicit. local coordinate system usually means a coordinate system ...

3

You can detect a matrix that can't be decomposed in TRS form by taking its 3×3 upper-left submatrix, interpreting its columns as vectors, and dotting them together in all combinations (1 with 2, 2 with 3, and 1 with 3). For a TRS matrix, the three dot products should all be zero, i.e. the column vectors should be orthogonal to each other. If any of the dot ...

3

glUniformMatrix4fv(transformLocation, sizeof(transform), GL_FALSE, &transform.m[0][0]); The second parameter to glUniformMatrix is not the number of bytes in the data. OpenGL can figure that out from the 4fv part of the command (a 4x4 matrix of GLfloats). The second parameter is the number of matrices you're sending to that uniform, in case it is an ...

3

You can't perform this transformation by applying constant transformation matrix to the ladder model since it's not linear transformation like joojaa said in the comments. What you would have to do instead is to define the transformation as a function of height as you have done in both of your proposals. So both of your proposals are kind of correct, except ...

3

Your triangle's coordinates: (-0.1f,0.7f) (0.0f,0.8f) (0.1f,0.7f) are defined with the origin at the center of the screen. Multiplying a rotation matrix by a vertex position will rotate around the point (0,0,0). In your case, that is the center of the screen. Possible solution: Define the vertices as: (-0.1f,-0.5f) (0.0f,0.5f,) and (0.1f,-0.5f) Rotate ...

3

There is a direct formula for the rotation matrix for an arbitrary axis and angle. Given a unit vector $a = (a_x, a_y, a_z)$ and angle $\theta$, the matrix can be constructed as follows (derivation from Wikipedia): First build a matrix $C$ from the components of $a$ according to the following formula: $$C = \begin{bmatrix} 0 & -a_z & a_y \\ ... 3 Edit: This answer is only helpful in 3D If you want to do it geometrically... The inverse of the view-projection matrix, K^{-1} is the matrix you want. Where K = View * Projection If \vec{v} is a point in homogeneous screen coordinates, [x, y, 1] where x and y are whatever coordinates your K matrix projects onto.$$\vec{d} = K^{-1} * \vec{...

3

In a linear transformation system, your origin is always a fixed point, since 0*anything = 0. So imagine you have a cinema screen, and the origin is at the centre of the screen. Using linear transformations, you can rotate, scale or shear the image, what you can't do is move it, since you have a fixed point in the middle. Now add a dimension, and move your ...

3

The bottom row allows you to create perspective foreshortening. That is, it makes lines that are getting further away appear to converge. When arranged this way, we call this a perspective projection matrix. There are other ways to arrange a projection matrix where that foreshortening doesn't happen. For example in an orthographic projection. This graphic ...

2

Your transform looks correct. To transform from world to eye coordinates, I I always use a "lookat" transform, defined by 3 vectors: $\bf{e}$, $\bf{a}$ and $\bf{u}$; in english, the eye position, the point it's looking at, and an up vector, which must not be in the same direction as $\bf{a} - \bf{e}$ (more specifically, not a multiple of it). The space is ...

2

The values will only form a cube after performing the perspective divide, which I don't see happening in your code. That is, you take a vector $[x, y, z, 1]$ and transform it by the projection matrix, resulting in a new vector $[x', y', z', w']$. Then divide out the fourth component to get a 3D vector, $[x'/w', y'/w', z'/w']$. This last is the one that ...

2

I would like to address an issue in your naming. This issue makes the question a bit odd, but not impossible, as I will try to show. There is an, often unspoken, implied relationship between the matrices. For a matrix to be meaningful there has to be a common ancestor of the matrix that all matrices relate to. See a transformation chain works like a disk ...

2

I'm assuming you mean $A$ is object$\rightarrow$world matrix and $B$ is your camera$\rightarrow$world matrix? If that's the case, to calculate object object$\rightarrow$camera matrix you calculate: $$C=B^{-1}*A$$ In general your math is correct, i.e. the order of matrix multiplication is reversed for the inverse calculation. It's just that normally these ...

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