-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBasics.h
120 lines (93 loc) · 2.17 KB
/
Basics.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//
// Created by debowin on 10/9/17.
//
#ifndef FRAYTRACER_COMPONENTS_H
#define FRAYTRACER_COMPONENTS_H
#include <cmath>
struct Colour{
float r, g, b;
Colour& operator=(Colour c){
r = c.r;
g = c.g;
b = c.b;
return *this;
}
Colour operator+(Colour c){
return {r+c.r, g+c.g, b+c.b};
}
Colour operator-(Colour c){
return {r-c.r, g-c.g, b-c.b};
}
Colour operator*(Colour c){
return {r*c.r, g*c.g, b*c.b};
}
Colour operator*(float k){
return {r*k, g*k, b*k};
}
Colour operator/(float k){
return {r/k, g/k, b/k};
}
};
void setRGB(Colour* colour, float r, float g, float b);
bool isBlack(Colour colour);
struct Vector3D{
float x, y, z;
Vector3D& operator=(Vector3D v){
x = v.x;
y = v.y;
z = v.z;
return *this;
}
bool operator==(Vector3D v){
return x == v.x && y == v.y && z == v.z;
}
Vector3D operator+(Vector3D v){
return {x+v.x, y+v.y, z+v.z};
}
Vector3D operator-(Vector3D v){
return {x-v.x, y-v.y, z-v.z};
}
float operator*(Vector3D v){
// dot product
return x*v.x + y*v.y + z*v.z;
}
Vector3D operator*(float c){
return {x*c, y*c, z*c};
}
Vector3D operator^(Vector3D v){
// cross product
return {y*v.z - z*v.y, z*v.x-x*v.z, x*v.y - y*v.x};
}
Vector3D operator-(){
return {-x, -y, -z};
}
};
void setXYZ(Vector3D* vector, float x, float y, float z);
Vector3D normalize(Vector3D vector);
float magnitude(Vector3D vector);
float angleBetween(Vector3D u, Vector3D v);
// Ray Triangle Intersections
struct Matrix3D{
float a, b, c,
d, e, f,
g, h, i;
Matrix3D& operator=(Matrix3D m){
a = m.a; b = m.b; c = m.c;
d = m.d; e = m.e; f = m.f;
g = m.g; h = m.h; i = m.i;
return *this;
}
};
Matrix3D setColumn(Matrix3D, Vector3D col, int colId);
float determinant(Matrix3D mat);
struct Light{
Colour c;
Vector3D v;
};
struct SpotLight{
Colour c;
Vector3D p;
Vector3D d;
float angle1, angle2;
};
#endif //FRAYTRACER_COMPONENTS_H