Hot answers tagged

63

Why ? Because, A camera represents a projection view. But in case of 3D Camera (Virtual Camera), camera moves instead of the world. I have made a detailed explanation later of this answer. Understanding Mathematically Projection View moves around space and change its orientation. The first thing to notice is that the desired projection on the ...


44

Usually it is scale * rotation * translation. However, if you want to rotate an object around a certain point, then it is scale * point_translation * rotation * object_translation. Why: First you want to scale the object so that the translations work properly. Then you rotate the axes so the translation takes place on the adjusted axes. Finally you ...


25

Mahbubar R Aaman's answer is quite correct and the links he provides explain the math accurately, but in the event you want a less technical/mathy answer, I'll try a different approach. Positions of objects in the real world and the game world are defined with some coordinate system. A coordinate system gives meaning to position values. If I tell you that ...


25

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


22

transform, or transformation http://en.wikipedia.org/wiki/Transformation_matrix


21

First, here is the code. An explanation will follow: /* * tw, th contain the tile width and height. * * hitTest contains a single channel taken from a tile-shaped hit-test * image. Data was extracted with getImageData() */ worldToTilePos = function(x, y) { var eventilex = Math.floor(x%tw); var eventiley = Math.floor(y%th); if ...


19

Any combination of the order S*R*T gives a valid transformation matrix. However, it is pretty common to first scale the object, then rotate it, then translate it: L = T * R * S If you do not do it in that order, then a non-uniform scaling will be affected by the previous rotation, making your object look skewed. And the rotation will be affected by the ...


16

In short You only need to change T in your SQT form. Replace the translation vector v with v' = v-invscale(p-invrotate(p)) where v is the initial translation vector, p is the point around which you want the rotation to occur, and invrotate and invscale are the inverses of your rotation and scale. Quick demonstration Let p be the point around which you ...


16

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


15

So long as the matrix M is invertible (which it generally will be, unless you're doing something very unusual), then computing the matrix inverse of M will give you a matrix that does what you want. That is, if M performs some transformation, inverse(M) performs the "opposite" transformation. Most matrix/vector libraries provide a means for computing the ...


14

Short Answer Yes, it can. You should simply calculate a View Matrix and Projection Matrix separately (which are both 4x4 matrices), multiply them together in that order and pass the result (which is still a 4x4 matrix) to your 3D engine. Long Answer Do you know the difference between a View Matrix, a Projection Matrix, and Perspective? You seem to be ...


13

All of the canonical rotational formulas used to derive your rotation matrices are for rotation about the origin. If you would like instead to apply that rotation around a specific point, you must first offset the origin -- or, equivalently, move the object so the point you want to rotate about is at the origin. Consider the 2D case first, because it is ...


12

Put zeros in the last column and row, except for the lower-left value which should be 1. Like this: V V V 0 V V V 0 V V V 0 0 0 0 1 Where V are the actual values you use.


12

The graphics pipeline (typically) involves transformation from model space to world space, from world space to view space, and from view space to clip space. There is a transformation matrix associated with each of these (the world, view and projection transformations, respectively). There are of course stages of the pipeline after geometry reaches clip ...


12

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


11

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


10

Why choose? You can have both. (Without any added complexity to logic and without any additional memory requirement thanks to unions.) struct Mat4 { union { struct { float m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44; }; ...


10

Linear Algebra is the foremost discipline for 3d graphics programming simply because it's the mathematical language for describing spatial geometry. Your other three topics are really just subsets of linear algebra: Vectors are a way of thinking about points in space Matrices are ways of thinking about transformations of space and objects: translating ...


9

If you add shear to your list (although rarely used in games), it is generally known in mathematics as an affine transformation. The general term 'transformation' has been mentioned already, is a usually considered a superset and includes projection transformations as well (which are not affine).


9

Just adding to the other two (excellent) answers some further elaboration on a point that Mahbubur R Aaman touched on: "there is no camera". This is quite true and represents a failing of the common "camera" analogy, because the "camera" does not actually exist. It's important to realise that the camera analogy is just exactly that - an analogy. It ...


9

From a mathematical point of view, it depends on in which order you are multiplying the vectors with the matrix. Using a row-vector (v) and multiplying it with a matrix (A) as v∙A, then the rows will act as the axes. Using a column-vector (v) and multiplying a matrix (A) with it as A∙v, then the columns will act as the axes.


9

In openGl matrices are transposed in memory. So transpose the matrix is OK. But your code doesn't look correct. So you are in OpenGl. OpenGl uses right handed coordinate system. And for RH is lookat function defined like this: zaxis = normal(cameraPosition - cameraTarget) xaxis = normal(cross(cameraUpVector, zaxis)) yaxis = cross(zaxis, xaxis) xaxis.x ...


9

In computer graphics, we use matrices to encode transformations. Matrices that contain only translation, rotation or scaling transforms have a commonly-exploited interpretation: the upper-left 3x3 of the matrix contains only rotation or scale data, the bottom row or right column contains translation data. This is not a generality, but holds true often ...


8

Well, if you want to use it for 2D games (assuming from the tags), you only need a Transform matrix to apply to the SpriteBatch, you don't need World and Projection matrices. So, when you're drawing an object that should be drawn inside your game world (e.g. the main player), you use the following Begin method from SpriteBatch (XNA 4.0, replace the other ...


8

if I look at a populated matrix in my program I see the translation components occupying the 4th, 8th and 12th elements. Before I begin, it's important to understand: this means your matrices are row major. Therefore, you answer to this question: my column major WVP matrix is used successfully to transform vertices with the HLSL call: ...


8

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


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

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


7

It's best you read nVidia's pages containing some GPU Gems articles. There's the key formula which I will briefly explain to you in the following pseud-answer: This is where you'll find the complete article, and it's a classic resource by now. I will only assume you want an explanation of that process, done in a simplistic manner (as much as I can). The ...


7

No. At no time should you ever have an explicit world matrix in your shader. A detailed explanation for why can be found here, but the short version is really very simple: you never need it and it can kill your floating-point precision. If your world space is too big, then a camera that is far from the origin can cause floating point precision problems. ...



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