-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.h
More file actions
148 lines (132 loc) · 2.9 KB
/
object.h
File metadata and controls
148 lines (132 loc) · 2.9 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#ifndef _OBJECT_H_
#define _OBJECT_H_
#include <cmath>
#include "vector.h"
#include "fimage.h"
#include "scene.h"
#include "defines.h"
extern unsigned int *state;
//class Scene;
struct hit;
class Texture {
public:
Texture();
enum Pattern{NONE,CHECKER,IMAGE};
Vec color;
Vec color2;
Vec color3;
double reflection;
double opacity;
double refraction;
Pattern pattern;
double scale;
fimage* image;
double imageVert[3][2];
double intensity;
};
class Object {
public:
enum Geometry{NONE,PLANE,TRIANGLE,POLY,SPHERE};
Texture texture;
Vec origin;
virtual void Speak();
virtual hit Trace(Vec, Vec);
virtual void SetNormal(Vec);
virtual Vec GetNormal();
virtual void SetNormal(double, double, double);
virtual void Setu(Vec);
virtual void SetRadius(double);
virtual void SetIntensity(double);
virtual void AddVert(double, double, double);
virtual void AddVert(Vec);
virtual void SetVert(int, double, double, double);
virtual void SetVert(Vec, Vec, Vec);
virtual Vec Color(hit);
};
class Plane : public Object {
Vec normal;
Vec u; // rotation
public:
hit Trace(Vec o, Vec d);
void SetNormal(Vec v);
void SetNormal(double x, double y, double z);
Vec GetNormal();
void Setu(Vec v);
Vec Getu();
Vec Color(hit);
void Speak();
void SetIntensity(double);
};
class Triangle : public Object {
public:
Vec vert[3];
Vec normal;
Geometry type();
void Speak();
void AddVert(double, double, double);
void AddVert(Vec);
void SetVert(int, double, double, double);
void SetVert(Vec x, Vec y, Vec z);
void CalcNorm();
hit Trace(Vec o, Vec d);
Vec Color(hit);
bool Inside(Vec v);
Vec Barycentric(Vec);
void SetIntensity(double);
};
class Poly : public Object {
public:
Vec *vertices;
double nVertices;
Vec normal;
void Speak();
void SetIntensity(double);
};
class Sphere : public Object {
public:
double radius;
Vec u; //rotation
Vec v; //rotation
void SetRadius(double r);
hit Trace(Vec o, Vec d);
Vec Color(hit);
void Speak();
void SetIntensity(double);
};
class Light : public Object {
public:
double intensity;
void SetIntensity(double);
void SetRadius(double r);
Vec RandomSpot();
double radius;
Light();
};
struct hit {
Vec location;
Vec normal;
double distance;
bool contact;
Object *object;
Vec barycentric;
hit(Object * o, Vec l, double d, Vec n) {
object = o;
location = l;
normal = n;
distance = d;
contact = 1;
}
hit(Object * o, Vec l, double d, Vec n, Vec b) {
barycentric = b;
object = o;
location = l;
normal = n;
distance = d;
contact = 1;
}
hit(bool c) {
contact = c;
object = NULL;
}
};
#endif