Game Development Reference
In-Depth Information
coordinate system is right-handed, the Z-axis will point to your right. A left-handed
coordinate system will have a positive Z-axis pointed to the left.
Why is handedness important? For one thing, when you move objects around your
world, you
ll want to know where your positive Z-axis is and how it relates to the
other two, or you might have things zig instead of zag. The tougher answer is that
it affects the formulas for calculating important 3D equations, such as a cross prod-
uct. I
'
'
m extremely glad I don
'
t have to explain a 4D coordinate system. I don
'
t think
I have it in me.
Converting Handedness
Since some art packages have different handedness than 3D rendering
engines, you have to know how to convert the handedness of objects from
one coordinate system to another. If you don
t do this, all of your objects
will draw incorrectly, with the polygons facing the opposite way that they
should, giving objects an
'
inside out
appearance. Here is how you do the
conversion:
1. Reverse the order of the vertices on each triangle. If a triangle started
with vertices v0, v1, and v2, they need to be flipped to v2, v1, and v0.
2. Multiply each Z coordinate in the model by
1.
Here
s an example:
Original:
V0 = (2.3, 5.6, 1.2)
'
V1 = (1.0, 2.0, 3.0)
V2 = (30.0, 20.0, 10.0)
Becomes:
V0 = (30.0, 20.0,
10.0)
V1 = (1.0, 2.0,
3.0)
V2 = (2.3, 5.6,
1.2)
Vector Mathematics
Vector and matrix math was always the sleepiest part of linear algebra for me. Rather
than just show you the guts of the dot product or cross product for the umpteenth
time, I ' ll also tell you what they do. That ' s more important anyway. I ' ll also show you
some safety rules regarding matrix mathematics, because they don
'
t act like regular
numbers.
Before we go any further, you need to know what a unit vector is because it is some-
thing you ' ll use all the time in 3D graphics programming. A unit vector is any vector
that has a length of 1.0. If you have a vector of arbitrary length, you can create a unit
vector that points in the same direction by dividing the vector by its length. This is
also known as normalizing a vector:
Vec3 v(3, 4, 0);
float length = sqrt ( v.x * v.x + v.y * v.y + v.z * v.z);
 
 
Search WWH ::




Custom Search