- Cal3D 0.9 API Reference -

Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

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)
00110   {
00111       return ((x == v.x) && (y == v.y) && (z == v.z));
00112   }
00113 
00114   inline void blend(float d, const CalVector& v)
00115   {
00116       x += d * (v.x - x);
00117       y += d * (v.y - y);
00118       z += d * (v.z - z);
00119   }
00120 
00121   inline void clear() 
00122   {
00123       x=0.0f;
00124       y=0.0f;
00125       z=0.0f;         
00126   }
00127 
00128   inline float length()
00129   {
00130       return (float)sqrt(x * x + y * y + z * z);
00131   }
00132   inline float normalize()
00133   {
00134       // calculate the length of the vector
00135       float length;
00136       length = (float) sqrt(x * x + y * y + z * z);
00137       
00138       // normalize the vector
00139       x /= length;
00140       y /= length;
00141       z /= length;
00142       
00143       return length;
00144   }
00145   
00146   void set(float vx, float vy, float vz)
00147   {
00148       x = vx;
00149       y = vy;
00150       z = vz;
00151   }
00152 
00153 };
00154 
00155 static inline CalVector operator+(const CalVector& v, const CalVector& u)
00156 {
00157   return CalVector(v.x + u.x, v.y + u.y, v.z + u.z);
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 float d)
00166 {
00167     return CalVector(v.x * d, v.y * d, v.z * d);
00168 }
00169 
00170 static inline CalVector operator*(const float d, const CalVector& v)
00171 {
00172     return CalVector(v.x * d, v.y * d, v.z * d);
00173 }
00174 
00175 static inline CalVector operator/(const CalVector& v, const float d)
00176 {
00177     return CalVector(v.x / d, v.y / d, v.z / d);
00178 }
00179 
00180 static inline float operator*(const CalVector& v, const CalVector& u)
00181 {
00182     return v.x * u.x + v.y * u.y + v.z * u.z;
00183 }  
00184 
00185 static inline CalVector operator%(const CalVector& v, const CalVector& u)
00186 {
00187     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);
00188 }
00189 
00190 
00191  /*****************************************************************************/
00196 class CAL3D_API CalPlane
00197 {
00198    public:
00199       float a,b,c,d;
00200       
00201       // These methods are made only to calculate the bounding boxes,
00202       // don't use them in you program
00203       
00204       float eval(CalVector &p);
00205       void setPosition(CalVector &p);
00206       void setNormal(CalVector &p);
00207 };
00208 
00209  /*****************************************************************************/
00214 class CAL3D_API CalBoundingBox
00215 {
00216    public:
00217      CalPlane plane[6];
00218      
00219      void computePoints(CalVector *p);
00220    
00221 };
00222 
00223 
00224 
00225 #endif
00226 
00227 //****************************************************************************//

Generated at Thu Dec 2 20:30:18 2004 by The Cal3D Team with doxygen 1.3.9.1 © 1997-2001 Dimitri van Heesch