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

WP_Point3D.h

Go to the documentation of this file.
00001 /* Copyright (C) 2001 W.P. van Paassen - peter@paassen.tmfweb.nl
00002 
00003    This program is free software; you can redistribute it and/or modify it under
00004    the terms of the GNU General Public License as published by the Free
00005    Software Foundation; either version 2 of the License, or (at your
00006    option) any later version.
00007 
00008    This program is distributed in the hope that it will be useful, but WITHOUT
00009    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00010    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00011    for more details.
00012 
00013    You should have received a copy of the GNU General Public License
00014    along with this program; see the file COPYING.  If not, write to the Free
00015    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
00016 
00017 #ifndef WP_POINT3D_H
00018 #define WP_POINT3D_H
00019 
00020 #include "WP_Def.h"
00021 #include "WP_Matrix3D.h"
00022 #include "WP_Vector3D.h"
00023 
00024 namespace WPCG
00025 {
00044 class WP_Point3D
00045 {
00046 public:
00047 
00048   WP_Point3D(){ data[0] = data[1] = data[2] = 0.0; data[3] = 1.0f;};
00049 
00055   WP_Point3D(scalar x, scalar y, scalar z){ data[0] = x; data[1] = y; data[2] = z; data[3] = 1.0f;};
00056   
00057   ~WP_Point3D(){};
00058 
00059   //copy constructor
00060 
00061   inline WP_Point3D(const WP_Point3D& p)
00062     {
00063       data[0] = p.data[0];
00064       data[1] = p.data[1];
00065       data[2] = p.data[2];
00066     }
00067 
00073   inline WP_Point3D& operator=(const WP_Point3D& p)
00074     {
00075       if (this == &p)
00076         return *this;
00077       
00078       data[0] = p.data[0];
00079       data[1] = p.data[1];
00080       data[2] = p.data[2];
00081       return *this;
00082     }
00083   
00089   inline WP_Point3D& operator*=(const WP_Matrix3D& m)
00090     {
00091       WP_Point3D copy = *this;
00092       data[0] = m.data[0] * copy.data[0] + m.data[4] * copy.data[1] + m.data[8] * copy.data[2] + m.data[12];
00093       data[1] = m.data[1] * copy.data[0] + m.data[5] * copy.data[1] + m.data[9] * copy.data[2] + m.data[13];
00094       data[2] = m.data[2] * copy.data[0] + m.data[6] * copy.data[1] + m.data[10] * copy.data[2] + m.data[14];
00095       
00096       return *this;
00097     }
00098 
00104   inline WP_Point3D& operator+=(const WP_Vector3D& v)
00105     {
00106       data[0] += v.data[0]; 
00107       data[1] += v.data[1];
00108       data[2] += v.data[2];
00109       return *this;
00110     }
00111 
00117   WP_Point3D& operator-=(const WP_Vector3D& v)
00118     {
00119       data[0] -= v.data[0]; 
00120       data[1] -= v.data[1];
00121       data[2] -= v.data[2];
00122       return *this;
00123     }
00124 
00130   inline WP_Vector3D operator-(const WP_Point3D& p) const
00131     {
00132       return WP_Vector3D(data[0] - p.data[0], data[1] - p.data[1], data[2] - p.data[2]);
00133     }
00134 
00140   inline WP_Point3D operator-(const WP_Vector3D& v) const
00141     {
00142       return WP_Point3D(data[0] - v.data[0], data[1] - v.data[1], data[2] - v.data[2]);
00143     }
00144 
00150   inline WP_Vector3D operator+(const WP_Point3D& p) const
00151     {
00152       return WP_Vector3D(data[0] + p.data[0], data[1] + p.data[1], data[2] + p.data[2]);
00153     }
00154 
00160   inline WP_Point3D operator+(const WP_Vector3D& v) const
00161     {
00162       return WP_Point3D(data[0] + v.data[0], data[1] + v.data[1], data[2] + v.data[2]);
00163     }
00164   
00169   inline void set(const WP_Vector3D& v)
00170     {
00171       data[0] = v.data[0]; 
00172       data[1] = v.data[1]; 
00173       data[2] = v.data[2];
00174     }
00175 
00180   inline WP_Vector3D toVector() const
00181     {
00182       return WP_Vector3D(data[0], data[1], data[2]);
00183     }
00184 
00188   inline void draw() const
00189     {
00190       glBegin(GL_POINTS);
00191       glVertex3fv(data);
00192       glEnd();
00193     }
00194   
00198   scalar data[4];
00199 };
00200 }
00201 #endif
00202 

Generated on Tue Jan 28 20:26:34 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002