- Cal3D 0.11 API Reference -

vector.h

00001 //****************************************************************************//
00002 // vector.h                                                                   //
00003 // Copyright (C) 2001, 2002 Bruno 'Beosil' Heidelberger                       //
00004 //****************************************************************************//
00005 // This library is free software; you can redistribute it and/or modify it    //
00006 // under the terms of the GNU Lesser General Public License as published by   //
00007 // the Free Software Foundation; either version 2.1 of the License, or (at    //
00008 // your option) any later version.                                            //
00009 //****************************************************************************//
00010 
00011 #ifndef CAL_VECTOR_H
00012 #define CAL_VECTOR_H
00013 
00014 //****************************************************************************//
00015 // Includes                                                                   //
00016 //****************************************************************************//
00017 
00018 #include "cal3d/global.h"
00019 #include "cal3d/matrix.h"
00020 
00021 //****************************************************************************//
00022 // Forward declarations                                                       //
00023 //****************************************************************************//
00024 
00025 class CalQuaternion;
00026 //class CalMatrix;
00027 
00028 //****************************************************************************//
00029 // Class declaration                                                          //
00030 //****************************************************************************//
00031 
00032  /*****************************************************************************/
00036 class CAL3D_API CalVector
00037 {
00038 // member variables
00039 public:
00040   float x ,y ,z;
00041 
00042 // constructors/destructor
00043 public:
00044   inline CalVector(): x(0.0f), y(0.0f), z(0.0f) {};
00045   inline CalVector(const CalVector& v) : x(v.x), y(v.y), z(v.z) {};
00046   inline CalVector(float vx, float vy, float vz): x(vx), y(vy), z(vz) {};
00047   inline ~CalVector() {};
00048 
00049 // member functions
00050 public:
00051   inline float& operator[](unsigned int i) 
00052   {
00053       return (&x)[i];
00054   }
00055 
00056   inline const float& operator[](unsigned int i) const
00057   {
00058       return (&x)[i];
00059   }
00060 
00061   inline void operator=(const CalVector& v)
00062   {
00063       x = v.x;
00064       y = v.y;
00065       z = v.z;
00066   }
00067 
00068   inline void operator+=(const CalVector& v)
00069   {
00070       x += v.x;
00071       y += v.y;
00072       z += v.z;
00073   }
00074   
00075   
00076   inline void operator-=(const CalVector& v)
00077   {
00078       x -= v.x;
00079       y -= v.y;
00080       z -= v.z;
00081   }
00082 
00083   inline void operator*=(const float d)
00084   {
00085       x *= d;
00086       y *= d;
00087       z *= d;
00088   }
00089 
00090   void operator*=(const CalQuaternion& q);
00091 
00092   inline void operator*=(const CalMatrix &m)
00093   {
00094       float ox = x;
00095       float oy = y;
00096       float oz = z;
00097       x = m.dxdx*ox + m.dxdy*oy + m.dxdz*oz;
00098       y = m.dydx*ox + m.dydy*oy + m.dydz*oz;
00099       z = m.dzdx*ox + m.dzdy*oy + m.dzdz*oz;
00100   }  
00101 
00102   inline void operator/=(const float d)
00103   {
00104       x /= d;
00105       y /= d;
00106       z /= d;
00107   }
00108 
00109   inline bool operator==(const CalVector& v) const
00110   {
00111       return ((x == v.x) && (y == v.y) && (z == v.z));
00112   }
00113 
00114   inline bool operator!=(const CalVector& v) const
00115   {
00116     return !operator==(v);
00117   }
00118 
00119   inline void blend(float d, const CalVector& v)
00120   {
00121       x += d * (v.x - x);
00122       y += d * (v.y - y);
00123       z += d * (v.z - z);
00124   }
00125 
00126   inline void clear() 
00127   {
00128       x=0.0f;
00129       y=0.0f;
00130       z=0.0f;         
00131   }
00132 
00133   inline float length() const
00134   {
00135       return (float)sqrt(x * x + y * y + z * z);
00136   }
00137   inline float normalize()
00138   {
00139       // calculate the length of the vector
00140       float length;
00141       length = (float) sqrt(x * x + y * y + z * z);
00142       
00143       // normalize the vector
00144       x /= length;
00145       y /= length;
00146       z /= length;
00147       
00148       return length;
00149   }
00150   
00151   void set(float vx, float vy, float vz)
00152   {
00153       x = vx;
00154       y = vy;
00155       z = vz;
00156   }
00157 
00158 };
00159 
00160 static inline CalVector operator+(const CalVector& v, const CalVector& u)
00161 {
00162   return CalVector(v.x + u.x, v.y + u.y, v.z + u.z);
00163 }
00164 
00165 static inline CalVector operator-(const CalVector& v, const CalVector& u)
00166 {
00167     return CalVector(v.x - u.x, v.y - u.y, v.z - u.z);
00168 }
00169 
00170 static inline CalVector operator*(const CalVector& v, const float d)
00171 {
00172     return CalVector(v.x * d, v.y * d, v.z * d);
00173 }
00174 
00175 static inline CalVector operator*(const float d, const CalVector& v)
00176 {
00177     return CalVector(v.x * d, v.y * d, v.z * d);
00178 }
00179 
00180 static inline CalVector operator/(const CalVector& v, const float d)
00181 {
00182     return CalVector(v.x / d, v.y / d, v.z / d);
00183 }
00184 
00185 static inline float operator*(const CalVector& v, const CalVector& u)
00186 {
00187     return v.x * u.x + v.y * u.y + v.z * u.z;
00188 }  
00189 
00190 static inline CalVector operator%(const CalVector& v, const CalVector& u)
00191 {
00192     return CalVector(v.y * u.z - v.z * u.y, v.z * u.x - v.x * u.z, v.x * u.y - v.y * u.x);
00193 }
00194 
00195 
00196  /*****************************************************************************/
00201 class CAL3D_API CalPlane
00202 {
00203    public:
00204       float a,b,c,d;
00205       
00206       // These methods are made only to calculate the bounding boxes,
00207       // don't use them in you program
00208       
00209       float eval(CalVector &p);
00210       float dist(CalVector &p);
00211       void setPosition(CalVector &p);
00212       void setNormal(CalVector &p);
00213 };
00214 
00215  /*****************************************************************************/
00220 class CAL3D_API CalBoundingBox
00221 {
00222    public:
00223      CalPlane plane[6];
00224      
00225      void computePoints(CalVector *p);
00226    
00227 };
00228 
00229 
00230 
00231 #endif
00232 
00233 //****************************************************************************//

Generated at Thu Jun 29 19:03:59 2006 by The Cal3D Team with Doxygen 1.4.6