Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

vector3d.h

Go to the documentation of this file.
00001 /*
00002   svas_server -- virtual World Server of Svas
00003   Copyright (c) 2001, 2002 David Moreno Montero
00004  
00005  
00006   This program is free software; you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License as published by
00008   the Free Software Foundation; either version 2 of the License, or
00009   (at your option) any later version.
00010  
00011   This program is distributed in the hope that it will be useful, but
00012   WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   General Public License for more details.
00015  
00016   You should have received a copy of the GNU General Public License
00017   along with this program; if not, write to the Free Software
00018   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00019   02111-1307, USA.  
00020 
00021 */
00022 
00023 #ifndef __VECTOR3D__
00024 #define __VECTOR3D__
00025 
00026 #include <math.h>
00027 #include <string>
00028 
00029 #define Point3d Vector3d
00030 
00031 class BoundingBox;
00032 class Matrix3x3;
00033 class Quaternion; 
00034 
00035 /** 
00036  * A Vector in a 3d coordinate system, with the product and dividion
00037  * with doubles, product, sum, difference of vectors, assignation
00038  * to string, and conversion to polar systems.
00039  *
00040  * Point3d is an alias of Vector3d.
00041  */
00042 class Vector3d{
00043  protected:
00044   /** The coordinate of the vector (or point) */
00045   double x,y,z;
00046  public:
00047   Vector3d(double _x,double _y, double _z);
00048   /** A convenience contructor, content is unknown */
00049   Vector3d(){};
00050 
00051 
00052   Vector3d operator=(const Vector3d &v);
00053   Vector3d operator-=(const Vector3d &v);
00054   Vector3d operator+=(const Vector3d &v);
00055   Vector3d operator*=(const Vector3d &v);
00056   Vector3d operator/=(const Vector3d &v);
00057   Vector3d operator*=(double);
00058   Vector3d operator/=(double);
00059   Vector3d operator=(const Quaternion &q);
00060 
00061   /// Rotate in any given axis
00062   Vector3d rotate(const Vector3d &v, double ang);
00063   double module(void);
00064   /// Distance to a given plane
00065   double distToPlane(const Point3d &p, const Vector3d &n);
00066   /// Distance to a given line
00067   double distToLine(const Point3d &p, const Vector3d &d);
00068   /// Returns the current vector, normalized
00069   Vector3d normalized(void);
00070   /// Normalize current vector
00071   void normalize(void);
00072 
00073   /// Converts the Vector3d to a string
00074   string toString(void);
00075 
00076   /** 
00077    * @name Get components
00078    * @{
00079    */
00080   double X();
00081   double Y();
00082   double Z();
00083   /** @} */
00084 
00085   friend class BoundingBox;
00086 
00087   friend bool operator==(const Vector3d &a,const Vector3d &b);
00088   friend Vector3d operator^(const Vector3d &a,const Vector3d &b);
00089   friend double operator*(const Vector3d &a,const Vector3d &b);
00090   friend Vector3d operator-(const Vector3d &a,const Vector3d &b);
00091   friend Vector3d operator+(const Vector3d &a,const Vector3d &b);
00092   
00093   friend Vector3d operator/(const Vector3d &a,double n);
00094   friend Vector3d operator*(const Vector3d &a,double n);
00095   friend Vector3d operator/(double n,const Vector3d &a);
00096   friend Vector3d operator*(double n,const Vector3d &a);
00097 
00098   friend Vector3d operator-(const Vector3d &v);
00099 
00100   friend Vector3d operator*(const Matrix3x3 &M, const Vector3d &v);
00101   friend Vector3d operator*(const Vector3d &v, const Matrix3x3 &M);
00102 
00103   friend Quaternion operator*(const Vector3d &v, const Quaternion &q);
00104   friend Quaternion operator*(const Quaternion &q, const Vector3d &v);
00105 };
00106 
00107 #include "vector3d.cc"
00108 
00109 #endif

Generated on Mon Jun 17 19:53:44 2002 for Svas Server by doxygen1.2.16