Hot answers tagged

73

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


30

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


29

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


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

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

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


12

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


9

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


9

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


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


9

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


8

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


8

gluLookAt will rotate and translate the world in a way, that the camera will be located at {0, 0, 0} and looks towards the negative z-axis. This is the camera setup used in OpenGL. The camera actually never moves, the world does. Sound confusing? Hell yeah, let me try to explain :) Lets take this example: eye : {300, 0, 0} lookat : { 0, 0, 0} up :...


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

3D translations cannot be represented by 3x3 matrices, but 4x4 matrices can A simple argument why 3D translations are not possible with 3x3 matrices is that translation can take the origin vector: 0 0 0 away from the origin, say to x = 1: 1 0 0 But that would require a matrix such that: | a b c | |0| |1| | d e f | * |0| = |0| | g h i | |0| |0| But ...


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

Moving the camera or moving the world are two equally valid choices which both amount to the same thing. At the end of the day you are changing from one coordinate system to the other. The above answers are correct but which way you visualise it are two sides of the same coin. Transformations can go either way - they are just the inverse of each other. Part ...


7

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) * glm::scale(..) * glm::rotate(..) * glm::translate(pivot) * ...


7

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


7

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: \begin{matrix} 1 & 0 & a & 0 \\ 0 & 1 & a & 0 \\ 0 & 0 & 1 & 0 ...


7

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


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