Home | Gaming | Programming | Play Online | Contact | Keyword Query
Games++ Games & Game Programming

GAMES++
Games++ Home
Games++ Gaming
Games++ Programming
Beta Testing Games
Free Online Games
Hints & Cheats

BROWSER UTILITIES
E-mail This Page
Add to Favorites

SITE SEARCH

Web Games++

AFFILIATES
Cheat Codes
Trickster Wiki
Game Ratings
Gameboy Cheats
PlayStation Cheats
BlackBerry Games
Photoshop Tutorials
Illustrator Tutorials
ImageReady Tutorials

ADVERTISEMENT

ADVERTISEMENT

Transforming a Vector by a Matrix Part 4: Matrix Transformation Tutorial

Table of Contents

  1. Introduction
  2. Math Prerequisites

  3. Importance of Correct Transformations
  4. What a Matrix Represents
  5. Matrix Multiplication
  6. Transforming a Vector by a Matrix
  7. Object Space Transformations
  8. Camera Transformations
  9. Inverse Transformations
  10. Hierarchical Transformations

  11. Precision
  12. Conclusion

Transforming a Vector by a Matrix

This is the second operation which is required for our matrix transformations. It involves projecting a stationary vector onto transformed axis vectors using the dot product. One dot product is performed for each coordinate axis.

        x = x0 * matrix[0][0] + y0 * matrix[1][0] + z0 * matrix[2][0] +
            w0 * matrix[3][0];

        y = x0 * matrix[0][1] + y0 * matrix[1][1] + z0 * matrix[2][1] +
            w0 * matrix[3][1];

        z = x0 * matrix[0][2] + y0 * matrix[1][2] + z0 * matrix[2][2] +
            w0 * matrix[3][2];

The x0, y0, etc. coordinates are the original object space coordinates for the vector. That is, they never change due to transformation.

"Alright," you say. "Where did all the w coordinates come from???" Good question :) The w coordinates come from what is known as a homogenous coordinate system, which is basically a way to represent 3d space in terms of a 4d matrix. Because we are limiting ourselves to 3d, we pick a constant, nonzero value for w (1.0 is a good choice, since anything * 1.0 = itself). If we use this identity axiom, we can eliminate a multiply from each of the dot products:

        x = x0 * matrix[0][0] + y0 * matrix[1][0] + z0 * matrix[2][0] +
            matrix[3][0];

        y = x0 * matrix[0][1] + y0 * matrix[1][1] + z0 * matrix[2][1] +
            matrix[3][1];

        z = x0 * matrix[0][2] + y0 * matrix[1][2] + z0 * matrix[2][2] +
            matrix[3][2];

These are the formulas you should use to transform a vector by a matrix.

Copyright © 1998-2007, Games++ All rights reserved. | Privacy Policy