-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector3.cpp
More file actions
96 lines (80 loc) · 1.31 KB
/
Copy pathvector3.cpp
File metadata and controls
96 lines (80 loc) · 1.31 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "vector3.hpp"
#include <cmath>
vector3::vector3():
x(0),y(0),z(0)
{}
vector3::vector3(vector3 const& v):
x(v.x),y(v.y), z(v.z)
{}
vector3&
vector3::operator=(vector3 const& v)
{
x=v.x;
y=v.y;
z=v.z;
return *this;
};
vector3
cross(vector3 const& a, vector3 const& b)
{
return vector3(a.y*b.z-a.z*b.y,
a.z*b.x-a.x*b.z,
a.x*b.y-a.y*b.x);
}
vector3::vector3(float const& _x, float const& _y, float const& _z):
x(_x),y(_y),z(_z)
{}
vector3
norm(vector3 const& v)
{
return v/len(v);
}
float
len(vector3 const& v)
{
return std::sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
}
vector3
operator+(vector3 const& a, vector3 const& b)
{
return vector3(a.x+b.x, a.y+b.y, a.z+b.z);
}
vector3
operator-(vector3 const& a, vector3 const& b)
{
return a + (b*-1);
}
vector3
operator*(vector3 const& a, float const& f)
{
return vector3(a.x*f, a.y*f, a.z*f);
}
vector3
operator/(vector3 const& a, float const& f)
{
return a * (1/f);
}
vector3&
vector3::operator+=(vector3 const& v)
{
*this=*this + v;
return *this;
}
vector3&
vector3::operator-=(vector3 const& v)
{
*this=*this - v;
return *this;
}
vector3&
vector3::operator*=(float const& f)
{
*this=*this*f;
return *this;
}
vector3&
vector3::operator/=(float const& f)
{
*this=*this/f;
return *this;
}