4 ms·
This is obvious for anyone who does game development. Matrices are use to convert between 3d game coords -> screen coords. Also almost all movements/rotations/s
by stevemk14ebr 9y ago
This is obvious for anyone who does game development. Matrices are use to convert between 3d game coords -> screen coords. Also almost all movements/rotations/scaling of objects in game is done via matrix multiplications.
I used matrices once to draw 3d spheres efficiently! It's very computationally expensive to calculate the points of many sphere's of varying radii every frame. What i instead did was pre-compute a few small sized spheres located at the origin. I then matrix multiplied the pre-computed vertices to position spheres at the desired location and size in the 3d world. This was so much faster my fps went from ~5 to a smooth 60!
Very useful knowledge!
- deleted 9y ago[deleted]
- Scea91 9y ago> Also almost all movements/rotations/scaling of objects in game is done via matrix multiplications. Not necessarily true. Quaternions are used a lot because they have some desirable properties over matrices. As far as I remember, they are smaller and more suitable for interpolation.
- andrewflnr 9y agoI could have sworn that quaternion transforms were still 4x4 matrices, but I think that's just because quaternions themselves are representable as 4x4 real matrices, which are computationally convenient. https://en.wikipedia.org/wiki/Quaternion#Matrix_representations https://en.wikipedia.org/wiki/Quaternion#Matrix_representati...
- deleted 9y ago[deleted]
- jacobolus 9y agoQuaternions are a 4-parameter representation of a rotation + scaling operator, the analog of using a complex number to represent rotation + scaling in the plane. You can convert a (4 parameter) quaternion to a (9 parameter) 3x3 matrix in a similar way that you can convert a (2 parameter) complex number to a (4 parameter) 2x2 matrix. In either case you aren't using the full parameter space of the matrices. In general in programs quaternions are used for storing and manipulating rotation operators (e.g. composing them together, etc.) because it saves work and improves numerical stability, but then final application of the rotation to a gigantic list of vectors is done using a matrix, because matrix-vector multiplication is very efficient (only need 9 multiplications and 6 additions to multiply a 3x3 matrix by a 3-element vector).
- theoh 9y agoQuaternions represent 3D rotations in a way which avoids the drawbacks of Euler angles. See "gimbal lock".
- cma 9y agoYes, but he's comparing them against Rotation Matrices (which don't suffer from gimbal lock), not Euler angles: http://work.thaslwanter.at/Kinematics/html/04_Quaternions.html http://work.thaslwanter.at/Kinematics/html/04_Quaternions.ht... In practice, game engines use all three methods.
- theoh 9y agoEuler angles (or an equivalent) are implicit in the the way rotation matrices work.
- jacobolus 9y agoThis is not correct (or at any rate is oversimplified). A rotation matrix can represent any arbitrary path through the space of possible rotations (SO(3)) by smoothly varying parameters. There is no inherent “gimbal lock” or the like. In general I would recommend avoiding Euler angles as a formal representation of rotations. There are several choices of better representations, some of which are described at https://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions https://en.wikipedia.org/wiki/Rotation_formalisms_in_three_d...
- theoh 9y agoYou're right, I should have said "usually inherent". But it's a major reason for using quaternions. While you stress the case of gimbal lock occuring within a single rotation, which is typically due to the use of Euler angles, there is also the problem of gimbal lock emerging through the composition of two or more rotations in matrix form. I'm vague on this point but AFAIK this problem can arise with rotation matrices whether or not Euler angles are used. Choose three successive unlucky rotation axes and you've got the problem. This seems to get so complicated. See e.g. https://en.m.wikipedia.org/wiki/Davenport_chained_rotations https://en.m.wikipedia.org/wiki/Davenport_chained_rotations
- dahart 9y agoIt's not either-or, quaternions do not replace matrices. Matrices are (almost) always used, regardless of the use of quaternions (also regardless of use of any other types of transforms including geometric algebra). Quats are typically used for interpolating orientations. Once you have an interpolated orientation, you still have to turn it into a matrix to interact with other transforms, and to send to the GPU. The vast majority (if not all) game engines, libaries, and GPU/console hardware operate on matrices at the lower levels.