source: golgotha/src/maxtool/sdk_inc/dpoint3.h @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 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: 3.4 KB
Line 
1/**********************************************************************
2 *<
3        FILE: dpoint3.h
4
5        DESCRIPTION:
6
7        CREATED BY: Dan Silva
8
9        HISTORY:
10
11 *>     Copyright (c) 1994, All Rights Reserved.
12 **********************************************************************/
13
14#ifndef __DPOINT3__
15
16#define __DPOINT3__
17
18class ostream;
19
20class DPoint3 {
21public:
22        double x,y,z;
23
24        // Constructors
25        DPoint3(){}
26        DPoint3(double X, double Y, double Z)  { x = X; y = Y; z = Z;  }
27        DPoint3(const DPoint3& a) { x = a.x; y = a.y; z = a.z; }
28        DPoint3(double af[3]) { x = af[0]; y = af[1]; z = af[2]; }
29
30        // Access operators
31        double& operator[](int i) { return (&x)[i]; }     
32        const double& operator[](int i) const { return (&x)[i]; } 
33
34        // Conversion function
35        operator double*() { return(&x); }
36
37        // Unary operators
38        DPoint3 operator-() const { return(DPoint3(-x,-y,-z)); }
39        DPoint3 operator+() const { return *this; }
40
41        // Assignment operators
42        DllExport DPoint3& operator-=(const DPoint3&);
43        DllExport DPoint3& operator+=(const DPoint3&);
44        DllExport DPoint3& operator*=(double);
45        DllExport DPoint3& operator/=(double);
46
47        // Binary operators
48        DllExport DPoint3 operator-(const DPoint3&) const;
49        DllExport DPoint3 operator+(const DPoint3&) const;
50        DllExport double operator*(const DPoint3&) const;               // DOT PRODUCT
51        DllExport DPoint3 operator^(const DPoint3&) const;      // CROSS PRODUCT
52
53        };
54
55double DllExport Length(const DPoint3&);
56int DllExport MaxComponent(const DPoint3&);  // the component with the maximum abs value
57int DllExport MinComponent(const DPoint3&);  // the component with the minimum abs value
58DPoint3 DllExport Normalize(const DPoint3&); // Return a unit vector.
59
60DPoint3 DllExport operator*(double, const DPoint3&);    // multiply by scalar
61DPoint3 DllExport operator*(const DPoint3&, double);    // multiply by scalar
62DPoint3 DllExport operator/(const DPoint3&, double);    // divide by scalar
63
64ostream DllExport &operator<<(ostream&, const DPoint3&);
65         
66// Inlines:
67
68inline double Length(const DPoint3& v) {       
69        return (double)sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
70        }
71
72inline DPoint3& DPoint3::operator-=(const DPoint3& a) {
73        x -= a.x;       y -= a.y;       z -= a.z;
74        return *this;
75        }
76
77inline DPoint3& DPoint3::operator+=(const DPoint3& a) {
78        x += a.x;       y += a.y;       z += a.z;
79        return *this;
80        }
81
82inline DPoint3& DPoint3::operator*=(double f) {
83        x *= f;   y *= f;       z *= f;
84        return *this;
85        }
86
87inline DPoint3& DPoint3::operator/=(double f) {
88        x /= f; y /= f; z /= f;
89        return *this;
90        }
91
92inline DPoint3 DPoint3::operator-(const DPoint3& b) const {
93        return(DPoint3(x-b.x,y-b.y,z-b.z));
94        }
95
96inline DPoint3 DPoint3::operator+(const DPoint3& b) const {
97        return(DPoint3(x+b.x,y+b.y,z+b.z));
98        }
99
100inline double DPoint3::operator*(const DPoint3& b) const { 
101        return(x*b.x+y*b.y+z*b.z);     
102        }
103
104inline DPoint3 operator*(double f, const DPoint3& a) {
105        return(DPoint3(a.x*f, a.y*f, a.z*f));
106        }
107
108inline DPoint3 operator*(const DPoint3& a, double f) {
109        return(DPoint3(a.x*f, a.y*f, a.z*f));
110        }
111
112inline DPoint3 operator/(const DPoint3& a, double f) {
113        return(DPoint3(a.x/f, a.y/f, a.z/f));
114        }
115
116DPoint3 DllExport CrossProd(const DPoint3& a, const DPoint3& b);        // CROSS PRODUCT
117       
118double DllExport DotProd(const DPoint3& a, const DPoint3& b) ;          // DOT PRODUCT
119
120#endif
121
Note: See TracBrowser for help on using the repository browser.