Tag Info

Hot answers tagged matrix

11

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 ...

7

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 ...

7

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....

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

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 * ...

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 ...

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

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 \\ ... 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 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 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 Object Space → World Space → Eye Space → Clip Space → Normalized Device Space → Window Space You get from Object Space to World Space by multiplying by the "World Matrix" (This may actually be multiple matrices depending on the parent-child object hierarchy of the scene. Compose them all together to get a single "World Matrix" for a given object.) You get ... 4 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 ... 4 The second matrix translates the eye [...] You don't do that in a projection matrix. You do that with your view matrix: Model (/Object) Matrix transforms an object into World Space View Matrix transforms all objects from world space to Eye (/Camera) Space (no projection so far!) Projection Matrix transforms from Eye Space to Clip Space Therefore you don't ... 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 ... 4 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 ... 4 So, A lot of folks would tell you that a 4x4 matrix is used so you can get a translation component rolled into your linear transformation. Meaning that with a 3x3 matrix you can only compute rotations, scales, and shears. (and some would argue that a shear is really another type of rotation) This same person might also go into great detail about affine ... 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 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

By lighting in object space, sure, you could avoid transforming the normals into world space. However, you'd have to transform the light positions/vectors into the object's space. Also, if you want any view-dependent shading such as specular, you would have to transform the camera position into object space as well, to calculate view vectors. Now, all of ...

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 ...

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