vector.h
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef NL_VECTOR_H
00025 #define NL_VECTOR_H
00026
00027 #include "types_nl.h"
00028
00029 #include <cmath>
00030 #include <string>
00031
00032 #include "stream.h"
00033
00034 namespace NLMISC
00035 {
00036
00037 class IStream;
00038
00039
00046 class CVector
00047 {
00048 public:
00049 float x,y,z;
00050
00051 public:
00053 static const CVector Null;
00055 static const CVector I;
00057 static const CVector J;
00059 static const CVector K;
00060
00061 public:
00063
00064
00065 CVector() {}
00067 CVector(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
00069 CVector(const CVector &v) : x(v.x), y(v.y), z(v.z) {}
00071
00073
00074 CVector &operator+=(const CVector &v);
00075 CVector &operator-=(const CVector &v);
00076 CVector &operator*=(float f);
00077 CVector &operator/=(float f);
00078 CVector operator+(const CVector &v) const;
00079 CVector operator-(const CVector &v) const;
00080 CVector operator*(float f) const;
00081 CVector operator/(float f) const;
00082 CVector operator-() const;
00084
00086
00087
00088 float operator*(const CVector &v) const;
00092 CVector operator^(const CVector &v) const;
00094 float norm() const;
00096 float sqrnorm() const;
00098 void normalize();
00100 CVector normed() const;
00102
00104
00105 void set(float _x, float _y, float _z);
00106 bool operator==(const CVector &v) const;
00107 bool operator!=(const CVector &v) const;
00108 bool isNull() const;
00110 bool operator<(const CVector &v) const;
00120 void sphericToCartesian(float r, float theta,float phi);
00126 void cartesianToSpheric(float &r, float &theta,float &phi) const;
00128 void minof(const CVector &a, const CVector &b);
00130 void maxof(const CVector &a, const CVector &b);
00132 void serial(IStream &f);
00134
00137 std::string asString() const { return toString(); }
00138
00140 std::string toString() const;
00141
00142
00143 friend CVector operator*(float f, const CVector &v0);
00144 };
00145
00146
00147 inline CVector blend(const CVector &v0, const CVector &v1, float lambda)
00148 {
00149 float invLambda = 1.f - lambda;
00150 return CVector(invLambda * v0.x + lambda * v1.x,
00151 invLambda * v0.y + lambda * v1.y,
00152 invLambda * v0.z + lambda * v1.z);
00153 }
00154
00155
00156 }
00157
00158
00159 #include "vector_inline.h"
00160
00161
00162 #endif // NL_VECTOR_H
00163
00164