NVector3.h
Go to the documentation of this file.
1 /*
2  This file is part of the VRender library.
3  Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
4  Version 1.0.0, released on June 27, 2005.
5 
6  http://artis.imag.fr/Members/Cyril.Soler/VRender
7 
8  VRender is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  VRender is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with VRender; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
23 /****************************************************************************
24 
25  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
26 
27  This file is part of the QGLViewer library version 2.4.0.
28 
29  http://www.libqglviewer.com - contact@libqglviewer.com
30 
31  This file may be used under the terms of the GNU General Public License
32  versions 2.0 or 3.0 as published by the Free Software Foundation and
33  appearing in the LICENSE file included in the packaging of this file.
34  In addition, as a special exception, Gilles Debunne gives you certain
35  additional rights, described in the file GPL_EXCEPTION in this package.
36 
37  libQGLViewer uses dual licensing. Commercial/proprietary software must
38  purchase a libQGLViewer Commercial License.
39 
40  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
41  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42 
43 *****************************************************************************/
44 
45 #ifndef _VRENDER_NVECTOR3_H
46 #define _VRENDER_NVECTOR3_H
47 
48 #include <iostream>
49 #include <stdexcept>
50 
51 namespace vrender
52 {
53  class Vector3;
54 
55  class NVector3
56  {
57  public:
58  NVector3();
59  NVector3(const NVector3& u);
60  inline NVector3(double x,double y,double z,bool normalization=true)
61  {
62  setXYZ(x,y,z,normalization);
63  }
64 
65  NVector3(const Vector3 &u,bool normalization=true);
66 
67  inline double x() const {return _n[0];}
68  inline double y() const {return _n[1];}
69  inline double z() const {return _n[2];}
70  void setXYZ(double x,double y,double z,bool normalization=true);
71 
72  NVector3& operator=(const NVector3& u);
73  /*
74  inline friend bool operator==(const NVector3 &u,const Vector3 &v) {return u.isEqualTo(v);}
75  inline friend bool operator==(const Vector3 &u,const NVector3 &v) {return v.isEqualTo(u);}
76  inline friend bool operator==(const NVector3 &u,const NVector3 &v) {return u.isEqualTo(v);}
77  inline friend bool operator!=(const NVector3 &u,const Vector3 &v) {return !(u == v);}
78  inline friend bool operator!=(const Vector3 &u,const NVector3 &v) {return !(u == v);}
79  inline friend bool operator!=(const NVector3 &u,const NVector3 &v) {return !(u == v);}
80  */
81 
82  inline friend NVector3 operator-(const NVector3 &u) { return NVector3(-u[0],-u[1],-u[2],false); }
83  //inline friend Vector3 operator+(const NVector3 &u,const Vector3 &v);
84  //inline friend Vector3 operator+(const Vector3 &u,const NVector3 &v);
85  //inline friend Vector3 operator+(const NVector3 &u,const NVector3 &v);
86  //inline friend Vector3 operator-(const NVector3 &u,const Vector3 &v);
87  //inline friend Vector3 operator-(const Vector3 &u,const NVector3 &v);
88  //inline friend Vector3 operator-(const NVector3 &u,const NVector3 &v);
89  friend double operator*(const NVector3 &u,const Vector3 &v);
90  friend double operator*(const Vector3 &u,const NVector3 &v);
91  //inline friend double operator*(const NVector3 &u,const NVector3 &v);
92  //inline friend Vector3 operator*(double r,const NVector3 &u);
93  //inline friend Vector3 operator/(const NVector3 &u,double r);
94 
95  //inline friend Vector3 operator^(const NVector3 &u,const Vector3 &v);
96  //inline friend Vector3 operator^(const Vector3 &u,const NVector3 &v);
97  //inline friend Vector3 operator^(const NVector3 &u,const NVector3 &v);
98 
99  inline double norm() const {return 1.0;}
100  inline double squareNorm() const {return 1.0;}
101  friend std::ostream& operator<<(std::ostream &out,const NVector3 &u);
102 
103  double operator[](int i) const
104  {
105  if((i < 0)||(i > 2))
106  throw std::runtime_error("Out of bounds in NVector3::operator[]") ;
107 
108  return _n[i];
109  }
110 
111  private:
112  void normalize();
113 
114  double _n[3];
115 
116  }; // interface of NVector3
117 
118 }
119 
120 #endif // _NVECTOR3_H
NVector3(double x, double y, double z, bool normalization=true)
Definition: NVector3.h:60
double norm() const
Definition: NVector3.h:99
double y() const
Definition: NVector3.h:68
void setXYZ(double x, double y, double z, bool normalization=true)
Writing X,Y and Z coordinates.
Definition: NVector3.cpp:151
double operator[](int i) const
Definition: NVector3.h:103
friend NVector3 operator-(const NVector3 &u)
Definition: NVector3.h:82
NVector3()
Default constructor (the default normalized vector is (1,0,0))
Definition: NVector3.cpp:134
NVector3 & operator=(const NVector3 &u)
Assignment.
Definition: NVector3.cpp:161
friend std::ostream & operator<<(std::ostream &out, const NVector3 &u)
Out stream override: prints the 3 normalized vector components.
Definition: NVector3.cpp:173
friend double operator*(const NVector3 &u, const Vector3 &v)
double z() const
Definition: NVector3.h:69
double squareNorm() const
Definition: NVector3.h:100
double _n[3]
normalized vector
Definition: NVector3.h:114
double x() const
Definition: NVector3.h:67


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Mon Jun 10 2019 14:00:25