00001 /* 00002 This file is part of the VRender library. 00003 Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr) 00004 Version 1.0.0, released on June 27, 2005. 00005 00006 http://artis.imag.fr/Members/Cyril.Soler/VRender 00007 00008 VRender is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 VRender is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with VRender; if not, write to the Free Software Foundation, Inc., 00020 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 00021 */ 00022 00023 /**************************************************************************** 00024 00025 Copyright (C) 2002-2013 Gilles Debunne. All rights reserved. 00026 00027 This file is part of the QGLViewer library version 2.4.0. 00028 00029 http://www.libqglviewer.com - contact@libqglviewer.com 00030 00031 This file may be used under the terms of the GNU General Public License 00032 versions 2.0 or 3.0 as published by the Free Software Foundation and 00033 appearing in the LICENSE file included in the packaging of this file. 00034 In addition, as a special exception, Gilles Debunne gives you certain 00035 additional rights, described in the file GPL_EXCEPTION in this package. 00036 00037 libQGLViewer uses dual licensing. Commercial/proprietary software must 00038 purchase a libQGLViewer Commercial License. 00039 00040 This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00041 WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00042 00043 *****************************************************************************/ 00044 00045 #ifndef _VRENDER_NVECTOR3_H 00046 #define _VRENDER_NVECTOR3_H 00047 00048 #include <iostream> 00049 #include <stdexcept> 00050 00051 namespace vrender 00052 { 00053 class Vector3; 00054 00055 class NVector3 00056 { 00057 public: 00058 NVector3(); 00059 NVector3(const NVector3& u); 00060 inline NVector3(double x,double y,double z,bool normalization=true) 00061 { 00062 setXYZ(x,y,z,normalization); 00063 } 00064 00065 NVector3(const Vector3 &u,bool normalization=true); 00066 00067 inline double x() const {return _n[0];} 00068 inline double y() const {return _n[1];} 00069 inline double z() const {return _n[2];} 00070 void setXYZ(double x,double y,double z,bool normalization=true); 00071 00072 NVector3& operator=(const NVector3& u); 00073 /* 00074 inline friend bool operator==(const NVector3 &u,const Vector3 &v) {return u.isEqualTo(v);} 00075 inline friend bool operator==(const Vector3 &u,const NVector3 &v) {return v.isEqualTo(u);} 00076 inline friend bool operator==(const NVector3 &u,const NVector3 &v) {return u.isEqualTo(v);} 00077 inline friend bool operator!=(const NVector3 &u,const Vector3 &v) {return !(u == v);} 00078 inline friend bool operator!=(const Vector3 &u,const NVector3 &v) {return !(u == v);} 00079 inline friend bool operator!=(const NVector3 &u,const NVector3 &v) {return !(u == v);} 00080 */ 00081 00082 inline friend NVector3 operator-(const NVector3 &u) { return NVector3(-u[0],-u[1],-u[2],false); } 00083 //inline friend Vector3 operator+(const NVector3 &u,const Vector3 &v); 00084 //inline friend Vector3 operator+(const Vector3 &u,const NVector3 &v); 00085 //inline friend Vector3 operator+(const NVector3 &u,const NVector3 &v); 00086 //inline friend Vector3 operator-(const NVector3 &u,const Vector3 &v); 00087 //inline friend Vector3 operator-(const Vector3 &u,const NVector3 &v); 00088 //inline friend Vector3 operator-(const NVector3 &u,const NVector3 &v); 00089 friend double operator*(const NVector3 &u,const Vector3 &v); 00090 friend double operator*(const Vector3 &u,const NVector3 &v); 00091 //inline friend double operator*(const NVector3 &u,const NVector3 &v); 00092 //inline friend Vector3 operator*(double r,const NVector3 &u); 00093 //inline friend Vector3 operator/(const NVector3 &u,double r); 00094 00095 //inline friend Vector3 operator^(const NVector3 &u,const Vector3 &v); 00096 //inline friend Vector3 operator^(const Vector3 &u,const NVector3 &v); 00097 //inline friend Vector3 operator^(const NVector3 &u,const NVector3 &v); 00098 00099 inline double norm() const {return 1.0;} 00100 inline double squareNorm() const {return 1.0;} 00101 friend std::ostream& operator<<(std::ostream &out,const NVector3 &u); 00102 00103 double operator[](int i) const 00104 { 00105 if((i < 0)||(i > 2)) 00106 throw std::runtime_error("Out of bounds in NVector3::operator[]") ; 00107 00108 return _n[i]; 00109 } 00110 00111 private: 00112 void normalize(); 00113 00114 double _n[3]; 00115 00116 }; // interface of NVector3 00117 00118 } 00119 00120 #endif // _NVECTOR3_H