XNA Geometry Utility classes

XNA provides a number of useful Utility classes for geometry and other applications

Vector

There are 3 vector classes Vector2, Vector3, Vector4. These classes encapsulate functionality for 2,3& 4 dimensional vectors.

Common vector functions are provided;

	
			  Vector3 a = new Vector3(1, 0, 0);
            Vector3 b = new Vector3(0, 1, 0);
            Vector3 c = new Vector3(1, 0, 1);
            Vector3 d;


            Matrix M=Matrix.Identity;

            float f;


            d = a.Add(b); // add a & b
            d = a.Multiply(2.0);
            f = Vector3.Dot(b, c);
            d = Vector3.Cross(b, c);
            f = c.Length();
            f = c.Lengthsq();
            d = Vector3.Lerp(a, b, 0.25);

            a.X = 5;
            a.Y = 6.7;
            a.Z = 2;

            f = Vector3.Distance(a, b);
            c = Vector3.Normalize(a);
            c = Vector3.Transform(a, M);

 

Matrix

There is a Matrix class (representing a 4x4 matrix). This encapsulates key matrix functionality;

Plane

The Plane class contains fuctionality to work with geometric planes in 3D.

Geometry Classes

There are a number of Geometry Classes to help compute common geometry tasks