forked from rtpHarry/Sokoban
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vector3.h
66 lines (53 loc) · 1.72 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
// Vector3.h: interface for the CVector3 class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_VECTOR3_H__6BA61D2F_AB00_4903_8CD3_920EE6CDB144__INCLUDED_)
#define AFX_VECTOR3_H__6BA61D2F_AB00_4903_8CD3_920EE6CDB144__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CVector3
////////////
// A vector class for holding the xyz of a vector
////////////////////////
// This is our basic 3D point/vector class
struct CVector3
{
public:
// A default constructor
CVector3() {}
// This is our constructor that allows us to initialize our data upon creating an instance
CVector3(float X, float Y, float Z)
{
x = X; y = Y; z = Z;
}
// Here we overload the + operator so we can add vectors together
CVector3 operator+(CVector3 vVector)
{
// Return the added vectors result.
return CVector3(vVector.x + x, vVector.y + y, vVector.z + z);
}
// Here we overload the - operator so we can subtract vectors
CVector3 operator-(CVector3 vVector)
{
// Return the subtracted vectors result
return CVector3(x - vVector.x, y - vVector.y, z - vVector.z);
}
// Here we overload the * operator so we can multiply by scalars
CVector3 operator*(float num)
{
// Return the scaled vector
return CVector3(x * num, y * num, z * num);
}
// Here we overload the / operator so we can divide by a scalar
CVector3 operator/(float num)
{
// Return the scale vector
return CVector3(x / num, y / num, z / num);
}
//cast to pointer to float for glVertex3fv etc
operator float* () const {return (float*) this;}
operator const float* () const {return (const float*) this;}
float x, y, z;
};
#endif // !defined(AFX_VECTOR3_H__6BA61D2F_AB00_4903_8CD3_920EE6CDB144__INCLUDED_)