NVector3.cpp
Go to the documentation of this file.
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 #include "NVector3.h"
00046 #include "Vector3.h"
00047 
00048 using namespace vrender;
00049 
00050 NVector3::NVector3(const Vector3 &u,bool normalization)
00051 {
00052   setXYZ(u[0],u[1],u[2],normalization);
00053 }
00054 /*
00055 Vector3 operator+(const NVector3 &u,const Vector3  &v)
00056 {
00057   return Vector3(u[0]+v[0],u[1]+v[1],u[2]+v[2]);
00058 }
00059 
00060 Vector3 operator+(const Vector3  &u,const NVector3 &v)
00061 {
00062   return Vector3(u[0]+v[0],u[1]+v[1],u[2]+v[2]);
00063 }
00064 
00065 Vector3 operator+(const NVector3 &u,const NVector3 &v)
00066 {
00067   return Vector3(u[0]+v[0],u[1]+v[1],u[2]+v[2]);
00068 }
00069 
00070 Vector3 operator-(const NVector3 &u,const Vector3  &v)
00071 {
00072   return Vector3(u[0]-v[0],u[1]-v[1],u[2]-v[2]);
00073 }
00074 
00075 Vector3 operator-(const Vector3  &u,const NVector3 &v)
00076 {
00077   return Vector3(u[0]-v[0],u[1]-v[1],u[2]-v[2]);
00078 }
00079 
00080 Vector3 operator-(const NVector3 &u,const NVector3 &v)
00081 {
00082   return Vector3(u[0]-v[0],u[1]-v[1],u[2]-v[2]);
00083 }
00084 */
00085 double vrender::operator*(const NVector3 &u,const Vector3  &v)
00086 {
00087   return u[0]*v[0] + u[1]*v[1] + u[2]*v[2];
00088 }
00089 
00090 double vrender::operator*(const Vector3  &u,const NVector3 &v)
00091 {
00092   return u[0]*v[0] + u[1]*v[1] + u[2]*v[2];
00093 }
00094 /*
00095 double operator*(const NVector3 &u,const NVector3 &v)
00096 {
00097   return u[0]*v[0] + u[1]*v[1] + u[2]*v[2];
00098 }
00099 
00100 Vector3 operator*(double r,const NVector3 &u)
00101 {
00102   return Vector3(r*u[0],r*u[1],r*u[2]);
00103 }
00104 
00105 Vector3 operator/(const NVector3 &u,double r)
00106 {
00107   return Vector3(u[0]/r,u[1]/r,u[2]/r);
00108 }
00109 
00110 
00111 Vector3 operator^(const NVector3 &u,const Vector3  &v)
00112 {
00113   return Vector3(       u[1]*v[2]-u[2]*v[1],
00114                         u[2]*v[0]-u[0]*v[2],
00115                         u[0]*v[1]-u[1]*v[0]);
00116 }
00117 
00118 Vector3 operator^(const Vector3  &u,const NVector3 &v)
00119 {
00120   return Vector3(       u[1]*v[2]-u[2]*v[1],
00121                         u[2]*v[0]-u[0]*v[2],
00122                         u[0]*v[1]-u[1]*v[0]);
00123 }
00124 
00125 Vector3 operator^(const NVector3 &u,const NVector3 &v)
00126 {
00127   return Vector3(       u[1]*v[2]-u[2]*v[1],
00128                         u[2]*v[0]-u[0]*v[2],
00129                         u[0]*v[1]-u[1]*v[0]);
00130 }
00131 */
00132 // -----------------------------------------------------------------------------
00134 NVector3::NVector3()
00135 {
00136   _n[0] = 1.0;
00137   _n[1] = 0.0;
00138   _n[2] = 0.0;
00139 }
00140 
00141 // -----------------------------------------------------------------------------
00143 NVector3::NVector3(const NVector3& u)
00144 {
00145   _n[0] = u._n[0] ;
00146   _n[1] = u._n[1] ;
00147   _n[2] = u._n[2] ;
00148 }
00149 // -----------------------------------------------------------------------------
00151 void NVector3::setXYZ(double x,double y,double z,bool normalization)
00152 {
00153   _n[0] = x;
00154   _n[1] = y;
00155   _n[2] = z;
00156   if ( normalization ) normalize();
00157 }
00158 
00159 // -----------------------------------------------------------------------------
00161 NVector3& NVector3::operator=(const NVector3& u)
00162 {
00163   if ( &u != this )
00164     {
00165         _n[0] = u[0];
00166         _n[1] = u[1];
00167         _n[2] = u[2];
00168     }
00169   return *this;
00170 }
00171 // -----------------------------------------------------------------------------
00173 std::ostream& operator<<(std::ostream& out,const NVector3& u)
00174 {
00175   out << u[0] << " " << u[1] << " " << u[2];
00176   return out;
00177 }
00178 
00179 // -----------------------------------------------------------------------------
00183 void NVector3::normalize()
00184 {
00185   double n = _n[0]*_n[0]+_n[1]*_n[1]+_n[2]*_n[2] ;
00186 
00187   if ( n > 0.0 )
00188     {
00189         _n[0] /= n;
00190         _n[1] /= n;
00191         _n[2] /= n;
00192     }
00193   else
00194     throw std::runtime_error("Attempt to normalize a null 3D vector.") ;
00195 }
00196 


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Jun 6 2019 17:31:58