-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtillen_math.h
100 lines (77 loc) · 2.63 KB
/
tillen_math.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#pragma once
#include <iostream>
#include <string>
class TillenArray2
{
public:
union
{
struct { double x, y; };
double val[2];
};
TillenArray2(double v0 = 0, double v1 = 0);
~TillenArray2();
TillenArray2 operator+ (const TillenArray2& a) const;
TillenArray2 operator- (const TillenArray2& a) const;
TillenArray2 operator* (double factor) const;
double operator* (const TillenArray2& factor) const;
friend std::ostream& operator<<(std::ostream& output, const TillenArray2& a);
TillenArray2 array_add(const TillenArray2& a) const;
TillenArray2 array_sub(const TillenArray2& a) const;
TillenArray2 array_multi(double factor) const;
double array_dot(const TillenArray2& a) const;
double array_cross(const TillenArray2& a) const;
std::string to_str() const;
};
class TillenArray3
{
public:
union
{
struct { double x, y, z; };
struct { double r, g, b; };
double val[3];
};
TillenArray3(double v0 = 0, double v1 = 0, double v2 = 0);
~TillenArray3();
TillenArray3 operator+ (const TillenArray3& a) const;
TillenArray3 operator- (const TillenArray3& a) const;
TillenArray3 operator* (double factor) const;
double operator* (const TillenArray3& factor) const;
friend std::ostream& operator<<(std::ostream& output, const TillenArray3& a);
TillenArray3 array_add(const TillenArray3& a) const;
TillenArray3 array_sub(const TillenArray3& a) const;
TillenArray3 array_multi(double factor) const;
double array_dot(const TillenArray3& a) const;
TillenArray3 array_cross(const TillenArray3& a) const;
std::string to_str() const;
};
class TillenArray4
{
public:
union
{
struct { double x, y, z, w; };
struct { double r, g, b, a; };
double val[4];
};
TillenArray4(double v0 = 0, double v1 = 0, double v2 = 0, double v3 = 0);
~TillenArray4();
TillenArray4 operator+ (const TillenArray4& a) const;
TillenArray4 operator- (const TillenArray4& a) const;
TillenArray4 operator* (double factor) const;
double operator* (const TillenArray4& factor) const;
friend std::ostream& operator<<(std::ostream& output, const TillenArray4& a);
TillenArray4 array_add(const TillenArray4& a) const;
TillenArray4 array_sub(const TillenArray4& a) const;
TillenArray4 array_multi(double factor) const;
double array_dot(const TillenArray4& a) const;
std::string to_str() const;
};
typedef TillenArray2 TillenVec2;
typedef TillenArray3 TillenVec3;
typedef TillenArray4 TillenVec4;
typedef TillenArray3 TillenColorRGB;
typedef TillenArray4 TillenColorRGBA;
int get_intersection_between_sphere_and_ray(TillenArray2& res, const TillenVec3& ray_start, const TillenVec3& ray_end, const TillenVec3& sphere_center, double sphere_radius);
int test_tillen_math();