-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vector3.h
55 lines (48 loc) · 1.61 KB
/
Vector3.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef _VECTOR3_H_
#define _VECTOR3_H_ 1
/**
* this class defines a what a 3-D vector should behave
*/
class Vector3{
public:
// constructors
Vector3();
Vector3(double _x,double _y,double _z);
Vector3(const Vector3 &_orig);
double operator[](int i)const;
double &operator[](int i);
double getX()const;
double getY()const;
double getZ()const;
void setX(double _x);
void setY(double _y);
void setZ(double _z);
// operators
friend Vector3 operator+(const Vector3 &v1,const Vector3 &v2);
friend Vector3 operator-(const Vector3 &v1,const Vector3 &v2);
friend Vector3 operator*(const Vector3 &v1,double scale);
friend Vector3 operator*(double scale,const Vector3 &v1);
friend Vector3 operator/(const Vector3 &v1,double scale);
friend Vector3 operator/(double scale,const Vector3 &v1);
friend Vector3 cross(const Vector3 &v1,const Vector3 &v2);
friend double dot(const Vector3 &v1,const Vector3 &v2);
friend bool operator==(const Vector3 &v1,const Vector3 &v2);
friend bool operator!=(const Vector3 &v1,const Vector3 &v2);
const Vector3 &operator+()const;
Vector3 operator-()const;
Vector3 &operator+=(const Vector3 &v);
Vector3 &operator-=(const Vector3 &v);
Vector3 &operator*=(double scale);
Vector3 &operator/=(double scale);
// return the length of the vector
double length()const;
// return the square of the length of the vector
double sqrLength()const;
// return the normalized vector of a given vector
friend Vector3 normalize(const Vector3 &v);
friend double sqr(const Vector3 &v);
friend Vector3 applyScale(const Vector3 &scale,const Vector3 &p);
private:
double x,y,z;
};
#endif // _VECTOR3_H_