# source:golgotha/src/max_plugin/sdk_inc/point3.h@80Tweet

Last change on this file since 80 was 80, checked in by Sam Hocevar, 14 years ago
• Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
• Property svn:keywords set to Id
File size: 4.3 KB
Line
1/**********************************************************************
2 *<
3        FILE: point3.h
4
5        DESCRIPTION: Class definitions for Point3
6
7        CREATED BY: Dan Silva
8
9        HISTORY:
10
12 **********************************************************************/
13
14#ifndef _POINT3_H
15
16#define _POINT3_H
17
18class Point3 {
19public:
20        float x,y,z;
21
22        // Constructors
23        Point3(){}
24        Point3(float X, float Y, float Z)  { x = X; y = Y; z = Z;  }
25        Point3(double X, double Y, double Z) { x = (float)X; y = (float)Y; z = (float)Z; }
26        Point3(int X, int Y, int Z) { x = (float)X; y = (float)Y; z = (float)Z; }
27        Point3(const Point3& a) { x = a.x; y = a.y; z = a.z; }
28        Point3(float af[3]) { x = af[0]; y = af[1]; z = af[2]; }
29
30        // Access operators
31        float& operator[](int i) { return (&x)[i]; }
32        const float& operator[](int i) const { return (&x)[i]; }
33
34        // Conversion function
35        operator float*() { return(&x); }
36
37        // Unary operators
38        Point3 operator-() const { return(Point3(-x,-y,-z)); }
39        Point3 operator+() const { return *this; }
40
41        // Assignment operators
42        inline Point3& operator-=(const Point3&);
43        inline Point3& operator+=(const Point3&);
44        inline Point3& operator*=(float);
45        inline Point3& operator/=(float);
46        inline Point3& operator*=(const Point3&);       // element-by-element multiply.
47
48        // Test for equality
49        int operator==(const Point3& p) const { return ((p.x==x)&&(p.y==y)&&(p.z==z)); }
50
51        // Binary operators
52        inline  Point3 operator-(const Point3&) const;
53        inline  Point3 operator+(const Point3&) const;
54        inline  Point3 operator/(const Point3&) const;
55        inline  Point3 operator*(const Point3&) const;
56
57        DllExport Point3 operator^(const Point3&) const;        // CROSS PRODUCT
58        };
59
60
61float DllExport Length(const Point3&);
62float DllExport LengthSquared(const Point3&);
63int DllExport MaxComponent(const Point3&);  // the component with the maximum abs value
64int DllExport MinComponent(const Point3&);  // the component with the minimum abs value
65Point3 DllExport Normalize(const Point3&); // Return a unit vector.
66
67
68// RB: moved this here from object.h
69class Ray {
70        public:
71                Point3 p;   // point of origin
72                Point3 dir; // unit vector
73        };
74
75
76// Inlines:
77
78inline float Length(const Point3& v) {
79        return (float)sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
80        }
81
82inline float LengthSquared(const Point3& v) {
83        return (v.x*v.x+v.y*v.y+v.z*v.z);
84        }
85
86inline Point3& Point3::operator-=(const Point3& a) {
87        x -= a.x;       y -= a.y;       z -= a.z;
88        return *this;
89        }
90
91inline Point3& Point3::operator+=(const Point3& a) {
92        x += a.x;       y += a.y;       z += a.z;
93        return *this;
94        }
95
96inline Point3& Point3::operator*=(float f) {
97        x *= f;   y *= f;       z *= f;
98        return *this;
99        }
100
101inline Point3& Point3::operator/=(float f) {
102        x /= f; y /= f; z /= f;
103        return *this;
104        }
105
106inline Point3& Point3::operator*=(const Point3& a) {
107        x *= a.x;       y *= a.y;       z *= a.z;
108        return *this;
109        }
110
111inline Point3 Point3::operator-(const Point3& b) const {
112        return(Point3(x-b.x,y-b.y,z-b.z));
113        }
114
115inline Point3 Point3::operator+(const Point3& b) const {
116        return(Point3(x+b.x,y+b.y,z+b.z));
117        }
118
119inline Point3 Point3::operator/(const Point3& b) const {
120        return Point3(x/b.x,y/b.y,z/b.z);
121        }
122
123inline Point3 Point3::operator*(const Point3& b) const {
124        return Point3(x*b.x, y*b.y, z*b.z);
125        }
126
127
128inline Point3 operator*(float f, const Point3& a) {
129        return(Point3(a.x*f, a.y*f, a.z*f));
130        }
131
132inline Point3 operator*(const Point3& a, float f) {
133        return(Point3(a.x*f, a.y*f, a.z*f));
134        }
135
136inline Point3 operator/(const Point3& a, float f) {
137        return(Point3(a.x/f, a.y/f, a.z/f));
138        }
139
140inline Point3 operator+(const Point3& a, float f) {
141        return(Point3(a.x+f, a.y+f, a.z+f));
142        }
143
144inline float DotProd(const Point3& a, const Point3& b) {
145        return(a.x*b.x+a.y*b.y+a.z*b.z);
146        }
147
148Point3 DllExport CrossProd(const Point3& a, const Point3& b);   // CROSS PRODUCT
149
150
151// Compress a normal vector from 12 to 4 bytes.
152// the vector has to be <= 1.0 in length.
153// The decompressed vector has absolute error <.001 in each
154// component.
155ULONG DllExport CompressNormal(Point3 p);
156Point3 DllExport DeCompressNormal(ULONG n);
157
158#endif
159
Note: See TracBrowser for help on using the repository browser.