00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _LUXRAYS_NORMAL_H
00023 #define _LUXRAYS_NORMAL_H
00024
00025 #include "luxrays/core/geometry/vector.h"
00026
00027 namespace luxrays {
00028
00029 class Normal {
00030 public:
00031
00032
00033 Normal(float _x = 0, float _y = 0, float _z = 0)
00034 : x(_x), y(_y), z(_z) {
00035 }
00036
00037 Normal operator-() const {
00038 return Normal(-x, -y, -z);
00039 }
00040
00041 Normal operator+(const Normal &v) const {
00042 return Normal(x + v.x, y + v.y, z + v.z);
00043 }
00044
00045 Normal & operator+=(const Normal &v) {
00046 x += v.x;
00047 y += v.y;
00048 z += v.z;
00049 return *this;
00050 }
00051
00052 Normal operator-(const Normal &v) const {
00053 return Normal(x - v.x, y - v.y, z - v.z);
00054 }
00055
00056 Normal & operator-=(const Normal &v) {
00057 x -= v.x;
00058 y -= v.y;
00059 z -= v.z;
00060 return *this;
00061 }
00062
00063 Normal operator*(float f) const {
00064 return Normal(f*x, f*y, f * z);
00065 }
00066
00067 Normal & operator*=(float f) {
00068 x *= f;
00069 y *= f;
00070 z *= f;
00071 return *this;
00072 }
00073
00074 Normal operator/(float f) const {
00075 float inv = 1.f / f;
00076 return Normal(x * inv, y * inv, z * inv);
00077 }
00078
00079 Normal & operator/=(float f) {
00080 float inv = 1.f / f;
00081 x *= inv;
00082 y *= inv;
00083 z *= inv;
00084 return *this;
00085 }
00086
00087 float LengthSquared() const {
00088 return x * x + y * y + z*z;
00089 }
00090
00091 float Length() const {
00092 return sqrtf(LengthSquared());
00093 }
00094
00095 explicit Normal(const Vector &v) : x(v.x), y(v.y), z(v.z) {
00096 }
00097
00098 float operator[](int i) const {
00099 return (&x)[i];
00100 }
00101
00102 float &operator[](int i) {
00103 return (&x)[i];
00104 }
00105
00106 float x, y, z;
00107 };
00108
00109 inline Normal operator*(float f, const Normal &n) {
00110 return Normal(f * n.x, f * n.y, f * n.z);
00111 }
00112
00113 inline Vector::Vector(const Normal &n)
00114 : x(n.x), y(n.y), z(n.z) {
00115 }
00116
00117 inline std::ostream &operator<<(std::ostream &os, const Normal &v) {
00118 os << "Normal[" << v.x << ", " << v.y << ", " << v.z << "]";
00119 return os;
00120 }
00121
00122 inline Normal Normalize(const Normal &n) {
00123 return n / n.Length();
00124 }
00125
00126 inline float Dot(const Normal &n1, const Normal &n2) {
00127 return n1.x * n2.x + n1.y * n2.y + n1.z * n2.z;
00128 }
00129
00130 inline float AbsDot(const Normal &n1, const Normal &n2) {
00131 return fabsf(n1.x * n2.x + n1.y * n2.y + n1.z * n2.z);
00132 }
00133
00134 }
00135
00136 #endif