Game Development Reference
In-Depth Information
Figure 8.17
Calculating the forward normal of a train.
Finishing Touches to the Vector Structure
By now, quite an impressive, fully functional vector structure has been made, but
there are a few final touches that will make it easier to work with. First, the
ToString method can be overridden so it outputs something useful. The To-
String method is automatically called when using the debugger in Visual Stu-
dio. Overriding this method will allow a vector to be understood at a glance,
without needing to dig down into the definition and look at the individual
values.
public override string ToString()
{
return string.Format("X:{0}, Y:{1}, Z:{2}", X, Y, Z);
}
The zero vector is a special type of vector; it has no unit vector. It is a vector that
represents no direction and has no magnitude. It is a little like the null of vec-
tors. For that reason it is useful to have as a constant.
[StructLayout(LayoutKind.Sequential)]
public struct Vector
{
public static Vector Zero = new Vector(0, 0, 0);
 
Search WWH ::




Custom Search