ps2vector4.h

00001 /*
00002 * "PS2" Application Framework
00003 *
00004 * University of Abertay Dundee
00005 * May be used for educational purposed only
00006 *
00007 * Author - Dr Henry S Fortuna
00008 *
00009 * $Revision: 1.4 $
00010 * $Date: 2007/08/27 20:22:34 $
00011 *
00012 */
00013 
00014 #ifndef __PS2VECTOR4_H__
00015 #define __PS2VECTOR4_H__
00016 
00017 #include <stdio.h>
00018 #include "ps2maths.h"
00019 
00020 class Vector4
00021 {
00022 public:
00023         // Constructors
00024         Vector4(void);
00025         Vector4(const float _x, const float _y, const float _z, const float _w);
00026         // Copy constructor - use as Vector4 V1 = V;
00027         Vector4(const Vector4 & rhs); 
00028 
00029         ~Vector4(void);
00030 
00031         // Operations with other vectors
00032         Vector4 & operator+=(const Vector4 & rhs);
00033         Vector4 & operator-=(const Vector4 & rhs);
00034 
00035         // Special arithmetic
00036         float Dot3(const Vector4 & rhs) const;
00037         float Dot4(const Vector4 & rhs) const;
00038         Vector4 Cross(const Vector4 & rhs) const;
00039 
00040         Vector4 & operator*=(const float s);
00041         Vector4 & operator/=(const float s);
00042 
00043         bool operator==(const Vector4 & rhs) const;
00044 
00045         // Miscellaneous
00046         float Length(void) const;
00047         float LengthSqr(void) const;
00048         Vector4 Normalise(void);
00049         void NormaliseSelf(void);
00050         void DumpVector4(char * s = NULL);
00051         int IsZeroVector(void);
00052         
00053         // Member data
00054         float x,y,z,w; 
00055 };
00056 
00057 inline Vector4 operator + (const Vector4 &v1,
00058                                                    const Vector4 &v2)
00059 {
00060         return Vector4(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, 1.0f);
00061 }
00062 
00063 inline Vector4 operator - (const Vector4 &v1,
00064                                                    const Vector4 &v2)
00065 {
00066         return Vector4(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, 1.0f);
00067 }
00068 
00069 inline Vector4 operator - (const Vector4 &v1)
00070 {
00071         return Vector4(-v1.x, -v1.y, -v1.z, 1.0f);
00072 }
00073 
00074 inline Vector4 operator * (const Vector4 &v,
00075                                                    const float &s)
00076 {
00077         return Vector4(v.x * s, v.y * s, v.z * s, 1.0f);
00078 }
00079 
00080 inline Vector4 operator * (const float & s,
00081                                                    const Vector4 &v)
00082 {
00083         return Vector4(v.x * s, v.y * s, v.z * s, 1.0f);
00084 }
00085 
00086 inline Vector4 operator / (const Vector4 &v,
00087                                                    const float & s)
00088 {
00089         return Vector4(v.x / s, v.y / s, v.z / s, 1.0f);
00090 }
00091 
00092 inline Vector4 CrossProduct (const Vector4 &v1,
00093                                                          const Vector4 &v2)
00094 {
00095         return Vector4(v1.y * v2.z - v1.z * v2.y,
00096                                    v1.z * v2.x - v1.x * v2.z,
00097                                    v1.x * v2.y - v1.y * v2.x,
00098                                    1.0f);
00099 }
00100 
00101 inline float DotProduct4(const Vector4 &v1,
00102                                                  const Vector4 &v2)
00103 {
00104         return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w);
00105 }
00106 
00107 inline float DotProduct3(const Vector4 &v1,
00108                                                  const Vector4 &v2)
00109 {
00110         return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);
00111 }
00112 
00113 // Return the ZeroVector if the lenth of the vector is very small
00114 inline Vector4 Normalise (const Vector4 &v)
00115 {
00116         float tmp_Length;
00117         Vector4 ZeroVector = Vector4(0.0f, 0.0f, 0.0f, 0.0f);
00118         
00119         tmp_Length = v.Length();
00120         
00121         if(tmp_Length < 0.0001f)
00122                 return ZeroVector;
00123         else
00124                 return (v / tmp_Length);
00125 }
00126 
00127 #endif

Generated on Sun May 18 21:45:09 2008 for PS2X by  doxygen 1.5.4