Game Development Reference
In-Depth Information
public Vector GetScale()
{
Vector result = new Vector();
result.X = (new Vector(_m11, _m12, _m13)).Length();
result.Y = (new Vector(_m21, _m22, _m23)).Length();
result.Z = (new Vector(_m31, _m32, _m33)).Length();
return result;
}
The scale can also be non-uniform. It can be scaled more along one axis than the
others. To find out the scale along a particular axis, just get the row and convert
it to a vector; then apply the vector length operation, and this will give you the
scaling amount.
Rotation
The math for rotating around an arbitrary axis is a lot more complicated than the
previous matrices. It's not important to know exactly how this works; it's more
important to know the result. The rotation matrix is made from an axis u which
is defined as a normalized vector and a scalar value (
) that describes the amount
of rotation in radians. If the model you wanted to rotate was a wine cork then the
normalized vector u could be represented by a needle pushed through the cork.
The angle ( y ) represents the amount the needle is rotated which in turn rotates
the cork.
y
2
3
1þð1cosÞðu x 1Þ 1cosÞu x u y u z sin ð1cosÞu x u z þu y sin 0
ð1cosÞu x u y þu z sin 1þð1cosÞðu y 1Þ 1cosÞu y u z u x sin 0
ð1cosÞu x u z u y sin ð1cosÞu y u z þu x sin
4
5
1þð1cosÞðu z
0
0
0
0
1
public void SetRotate(Vector axis, double angle)
{
double angleSin = Math.Sin(angle);
double angleCos = Math.Cos(angle);
double a = 1.0 - angleCos;
double ax = a * axis.X;
double ay = a * axis.Y;
double az = a * axis.Z;
 
Search WWH ::




Custom Search