-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfloat3.cpp
More file actions
53 lines (39 loc) · 1010 Bytes
/
float3.cpp
File metadata and controls
53 lines (39 loc) · 1010 Bytes
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
#include "float3.h"
#include <iostream>
float3::float3(const float3& a) : float3(a.x, a.y, a.z){}
float3::float3(float _x, float _y, float _z)
{
x = _x;
y = _y;
z = _z;
}
float3::float3(float _x) : float3(_x, _x, _x)
{
}
float3::float3() : float3(0.f, 0.f, 0.f)
{
}
void float3::print()
{
std::cout << x << ", " << y << ", " << z << std::endl;
}
std::ostream& operator<<(std::ostream& out, const float3& a)
{
out << a.x << ", " << a.y << ", " << a.z;
return out;
}
float3 operator *(const float& a, const float3& b) {return float3(b.x * a, b.y * a, b.z * a);}
float3 operator -(const float3& a, const float3& b) {return float3(a.x - b.x, a.y - b.y, a.z - b.z);}
float dot (const float3& a, const float3& b) {return a.x * b.x + a.y * b.y + a.z * b.z;}
float3 cross (const float3& a, const float3& b)
{
float3 out;
out.x = a.y * b.z - a.z * b.y;
out.y = a.z * b.x - a.x * b.z;
out.z = a.x * b.y - a.y * b.x;
return out;
}
float3 normalize(float3 a)
{
return a.normalize();
}