45 #ifndef _VRENDER_VECTOR3_H
46 #define _VRENDER_VECTOR3_H
51 # define FLT_MAX 9.99E20f
74 Vector3 (
double,
double,
double);
81 inline double x()
const {
return _xyz[0]; }
82 inline double y()
const {
return _xyz[1]; }
83 inline double z()
const {
return _xyz[2]; }
84 inline void setX(
double r) { _xyz[0] = r; }
85 inline void setY(
double r) { _xyz[1] = r; }
86 inline void setZ(
double r) { _xyz[2] = r; }
87 inline void setXYZ (
double x,
double y,
double z) { _xyz[0] = x; _xyz[1] = y; _xyz[2] = z; }
93 inline Vector3& operator= (
const Vector3& u) { _xyz[0] = u._xyz[0]; _xyz[1] = u._xyz[1]; _xyz[2] = u._xyz[2];
return *
this; }
109 _xyz[0] += v._xyz[0];
110 _xyz[1] += v._xyz[1];
111 _xyz[2] += v._xyz[2];
117 _xyz[0] -= v._xyz[0];
118 _xyz[1] -= v._xyz[1];
119 _xyz[2] -= v._xyz[2];
123 inline Vector3& operator*= (
double f) { _xyz[0] *= f; _xyz[1] *= f; _xyz[2] *= f;
return *
this;}
124 inline Vector3& operator/= (
double f) { _xyz[0] /= f; _xyz[1] /= f; _xyz[2] /= f;
return *
this;}
136 return Vector3(_xyz[0]+u._xyz[0],_xyz[1]+u._xyz[1],_xyz[2]+u._xyz[2]);
140 return Vector3(_xyz[0]-u._xyz[0],_xyz[1]-u._xyz[1],_xyz[2]-u._xyz[2]);
143 inline double operator*(
const Vector3& u)
const
145 return _xyz[0]*u._xyz[0] + _xyz[1]*u._xyz[1] + _xyz[2]*u._xyz[2];
150 return Vector3( _xyz[1]*v._xyz[2] - _xyz[2]*v._xyz[1],
151 _xyz[2]*v._xyz[0] - _xyz[0]*v._xyz[2],
152 _xyz[0]*v._xyz[1] - _xyz[1]*v._xyz[0]);
155 Vector3 operator/ (
double v) {
return Vector3(_xyz[0]/v,_xyz[1]/v,_xyz[2]/v); }
156 Vector3 operator* (
double v) {
return Vector3(_xyz[0]*v,_xyz[1]*v,_xyz[2]*v); }
164 double norm ()
const;
171 friend std::ostream& operator<< (std::ostream&,
const Vector3&);
174 double operator[] (
int i)
const
177 throw std::runtime_error(
"Out of bounds in Vector3::operator[]") ;
182 double& operator[] (
int i)
185 throw std::runtime_error(
"Out of bounds in Vector3::operator[]") ;
double norm() const
Norm.
double infNorm() const
Infinite norm.
~Vector3()
Default destructor.
double squareNorm() const
Square norm (self dot product)