Main Page | Class List | File List

Vector3D.h

00001 /*      Floating point Vector 3D class
00002 
00003         Last Modified   6/4/00
00004 */
00005 
00006 #ifndef __VECTOR3D_H_
00007 #define __VECTOR3D_H_
00008 
00010 
00011 class Point3D;
00012 
00013 class   Vector3D
00014 {
00015 private:
00016         float   x,y,z;
00017 
00018 public:
00019 
00020         Vector3D();                                                                     // constructs a zero vector
00021         Vector3D(float x, float y, float z);
00022 
00023         Vector3D(const Point3D &p, const Point3D &q);   // create vector PQ
00024 
00025 //      ~Vector3D();
00026 
00028 
00029         void    Round(void);                                                                                                            // round values to within decimal places
00030         void    Zero_Clamp(void);                                                                                                       // clamp values to 0
00031 
00032         int             IsUnit(void)                                                                                    const;          // test if this vector is a unit vector
00033         int             IsZero(void)                                                                                    const;          // test if this vector is zero
00034         int             IsParallel(const Vector3D &v)                                                   const;          // true if two vectors are parallel, Vectors CANNOT be zero
00035 
00036         float   GetX()                                                                                                  const;          // returns the value of individual components of this vector
00037         float   GetY()                                                                                                  const;
00038         float   GetZ()                                                                                                  const;
00039 
00040         void    GetValues(float &x, float &y, float &z)                                 const;          // get the values of this vector
00041         void    SetValues(const float x, const float y, const float z);                         // set the values of this vector
00042         void    CreateVector(const Point3D &p, const Point3D &q);                                       // create a vector PQ
00043 
00045 
00046         double  DotProduct(const Vector3D &v)                                                   const;          // returns dot product (cos theta) for UNIT VECTORS only. Vectors CANNOT be zero. returns -1 to 1
00047         void    CrossProduct(const Vector3D &a, const Vector3D &b);                                     // NORMALIZED cross product and store result in this vector, FOR UNIT VECTORS ONLY. May return (0,0,0) meaning vectors are parallel
00048         double  GetAngleDeg(const Vector3D &v)                                                  const;          // get angle in degrees between the UNIT VECTORS. returns 0 - 180
00049         double  GetAngleRad(const Vector3D &v)                                                  const;          // get angle in rads between the UNIT VECTORS.
00050 
00051         double  Length(void)                                                                                    const;          // length of this vector
00052 
00054 
00055         double  Normalize(void);                // normalizes the vector and return the length of the vector
00056         void    Scale(float s);                 // scale the vector
00057         void    Negate(void);                   // vector go in opposite direction
00058 
00060 
00061         // opengl
00062         void    glTranslate(void)                                       const;          // translate the current opengl matrix with this vector
00063         void    glRotate(const float angle)                     const;          // rotate angle around axis specified by this vector in deg
00064 
00066 
00067         // operators
00068         Vector3D        operator*(const Vector3D &v)    const;          // Unit cross product, for UNIT VECTORS ONLY. May return 0,0,0 meaning vectors are parallel
00069 
00070 // dangerous - remove for now
00071 //      Vector3D        operator*(const float s)                const;          // scale vector by s
00072 
00073         Vector3D        operator+(const Vector3D &v)    const;
00074         Vector3D        operator-(const Vector3D &v)    const;
00075         Vector3D        operator-()                                             const;          // negation
00076 
00077         Vector3D&       operator=(const Vector3D &v);                           // copy constructor
00078         Vector3D&       operator+=(const Vector3D &v);
00079         Vector3D&       operator-=(const Vector3D &v);
00080         Vector3D&       operator*=(const float s);                                      // scale vector by s
00081 
00082         int                     operator==(const Vector3D &v)   const;          // equality operator
00083         int                     operator!=(const Vector3D &v)   const;
00084 
00085 // debug
00086         void Print();
00087 };      // end class Vector3D
00088 
00090 
00091 #endif  // __VECTOR3D_H_

Generated on Mon Jan 26 22:13:13 2004 for fluid3 by doxygen 1.3.5