-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVector3.h
73 lines (60 loc) · 1.55 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef _VECTOR3_H_
#define _VECTOR3_H_
#include <string>
using namespace std;
class Vector3 {
//protected:
//float x, y, z;
public:
float x, y, z;
// {x=0.0; y=0.0; z=0.0;}
Vector3();
// {x=x0; y=y0; z=z0;}
Vector3(float, float, float);
// {x=x0; y=y0; z=z0;}
void set(float, float, float);
// index=0 -> x; index=1 -> y; index>=2 -> z
float get(int);
// get X value
float getX();
// get Y value
float getY();
// get Z value
float getZ();
// overload [], i=0 -> x; i=1 -> y; i>=2 -> z
float operator[](const int i);
// {x+=a.x; y+=a.y; z+=a.z;}
void add(Vector3&);
// {x=a.x+b.x; y=a.y+b.y; z=a.z+b.z;}
void add(Vector3 &a, Vector3 &b);
// overload +
Vector3 operator+(const Vector3 &other) const;
// {x-=a.x; y-=a.y; z-=a.z;}
void subtract(Vector3 &a);
// {x=a.x-b.x; y=a.y-b.y; z=a.z-b.z;}
void subtract(Vector3 &a, Vector3 &b);
// overload -
Vector3 operator-(const Vector3 &other) const;
void divide(float a);
// {x=-x; y=-y; z=-z;}
void negate();
// {x=-a.x; y=-a.y; z=-a.z;}
void negate(Vector3 &a);
// {x*=s; y*=s; z*=s;}
void scale(float s);
// {x=s*a.x; y=s*a.y; z=s*a.z;}
void scale(float s, Vector3 &a);
// {return x*a.x+y*a.y+z*a.z;}
float dot(Vector3 &a);
// {x=a.y*b.z-a.z*b.y; y=a.z*b.x-a.x*b.z; z=a.x*b.y-a.y*b.x;}
void cross(Vector3 &a, Vector3 &b);
// {return sqrt(x*x+y*y+z*z);}
float magnitude();
// {scale(1.0/magnitude());}
void normalize();
// print components
void print();
// string representation of components
string toString();
};
#endif