CVector3D.h
00001 00007 #ifndef __CVECTOR3D_H__ 00008 #define __CVECTOR3D_H__ 00009 00010 #include "math.h" 00011 #include "stdio.h" 00012 00013 class CVector3D 00014 { 00015 public: 00016 float x, y, z; 00017 00018 // constructeurs et destructeur 00019 CVector3D() : x(0.0f), y(0.0f), z(0.0f) {} 00020 CVector3D(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {} 00021 virtual ~CVector3D() {} 00022 00023 // operateurs 00024 __forceinline friend CVector3D operator+ (const CVector3D& v1, const CVector3D& v2) // addition 00025 { return CVector3D(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z); } 00026 00027 __forceinline friend void operator+= (CVector3D& v1, const CVector3D& v2) // addition 00028 { v1.x += v2.x; v1.y += v2.y; v1.z += v2.z; } 00029 00030 __forceinline friend CVector3D operator- (const CVector3D& v1, const CVector3D& v2) // soustraction 00031 { return CVector3D(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z); } 00032 00033 __forceinline friend CVector3D operator* (const CVector3D& v1, const CVector3D& v2) // produit en croix 00034 { return CVector3D( ( v1.y * v2.z ) - ( v1.z * v2.y ), ( v1.z * v2.x ) - ( v1.x * v2.z ), ( v1.x * v2.y ) - ( v1.y * v2.x ) ); }; 00035 00036 __forceinline friend CVector3D operator* (const CVector3D& v1, const float multiple) // scaling 00037 { return CVector3D(v1.x*multiple, v1.y*multiple, v1.z*multiple); } 00038 00039 __forceinline friend CVector3D operator/ (const CVector3D& v1, const float multiple) // scaling 00040 { return CVector3D(v1.x/multiple, v1.y/multiple, v1.z/multiple); } 00041 00042 __forceinline friend void operator/= (CVector3D& v1, float multiple) // scaling 00043 { v1.x /= multiple; v1.y /= multiple; v1.z /= multiple; } 00044 00045 __forceinline friend CVector3D operator- (const CVector3D& v) // opposé 00046 { return CVector3D(-v.x, -v.y, -v.z); } 00047 00048 // methodes 00049 __forceinline float DotProduct(const CVector3D& v) { return (x*v.x + y*v.y + z*v.z); } 00050 __forceinline float GetMagnitude() const { return (float)sqrt(x*x+y*y+z*z); } 00051 __forceinline void Normalize() { float mag = GetMagnitude(); x /= mag; y /= mag; z /= mag; } 00052 __forceinline float GetSquareLength() const { return (x*x+y*y+z*z); } 00053 __forceinline CVector3D Reflect(const CVector3D& n) { float fac=2.0f*(n.x*x+n.y*y+n.z*z); return CVector3D(fac*n.x-x,fac*n.y-y,fac*n.z-z); } 00054 }; 00055 00056 00057 #endif /* #ifndef __CVECTOR3D_H__ */
Generated on Fri Apr 19 16:19:34 2002 by 1.2.15