Hot answers tagged

72

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


37

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


28

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


28

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


23

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 (hitTest[...


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


19

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


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


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


14

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

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

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; }; float[...


12

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


11

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


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

Short Answer First invert the view matrix. Then fetch the translation from the last row/column. Long Answer One way to deduce the contents of a view matrix is to start by considering the camera as any other object in the world, and calculating a world matrix for it: RightX RightY RightZ 0 UpX UpY UpZ 0 LookX LookY LookZ 0 PosX ...


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


8

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


8

A matrix is used to convert a vector from one coordinate system to another (say, from coordinate system 'A' to coordinate system 'B'). The inverse of a matrix is a matrix which converts the other direction (say, from 'B' back into 'A') In games, we commonly have a matrix which will transform positions from world-space into homogenous eye-space, since ...


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

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


8

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


7

First off I would HIGHLY recommend just storing the position as a vector separately, it'll make things much easier computationally. Anyways... [x (dot) right, y (dot) up, z (dot) look] is not the actual view matrix. The matrix itself is of the form: 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 where the top left 3x3 matrix represents rotations, scale, ...


7

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


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