-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.h
139 lines (122 loc) · 3.98 KB
/
scene.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// -----------------------------------------------------------
// scene.h
// 2004 - Jacco Bikker - [email protected] - www.bik5.com - <><
// -----------------------------------------------------------
#ifndef I_SCENE_H
#define I_SCENE_H
#include "raytracer.h"
namespace Raytracer {
// Intersection method return values
#define HIT 1 // Ray hit primitive
#define MISS 0 // Ray missed primitive
#define INPRIM -1 // Ray started inside primitive
// -----------------------------------------------------------
// Material class definition
// -----------------------------------------------------------
class Material
{
public:
Material();
void SetColor( Color& a_Color ) { m_Color = a_Color; }
Color GetColor() { return m_Color; }
void SetDiffuse( float a_Diff ) { m_Diff = a_Diff; }
void SetSpecular( float a_Spec ) { m_Spec = a_Spec; }
void SetReflection( float a_Refl ) { m_Refl = a_Refl; }
void SetRefraction( float a_Refr ) { m_Refr = a_Refr; }
float GetSpecular() { return m_Spec; }
float GetDiffuse() { return m_Diff; }
float GetReflection() { return m_Refl; }
float GetRefraction() { return m_Refr; }
void SetRefrIndex( float a_Refr ) { m_RIndex = a_Refr; }
float GetRefrIndex() { return m_RIndex; }
private:
Color m_Color;
float m_Refl, m_Refr;
float m_Diff, m_Spec;
float m_RIndex;
};
// -----------------------------------------------------------
// Primitive class definition
// -----------------------------------------------------------
class Primitive
{
public:
enum
{
SPHERE = 1,
PLANE
};
Primitive() : m_Name( 0 ), m_Light( false ) {};
Material* GetMaterial() { return &m_Material; }
void SetMaterial( Material& a_Mat ) { m_Material = a_Mat; }
virtual int GetType() = 0;
virtual int Intersect( Ray& a_Ray, float& a_Dist ) = 0;
virtual vector3 GetNormal( vector3& a_Pos ) = 0;
virtual Color GetColor( vector3& ) { return m_Material.GetColor(); }
virtual void Light( bool a_Light ) { m_Light = a_Light; }
bool IsLight() { return m_Light; }
void SetName( char* a_Name );
char* GetName() { return m_Name; }
bool front;
bool flag;
void inFront() { front = false;}
void setFront(){ front = true;}
bool getFront(){ return front;}
protected:
Material m_Material;
char* m_Name;
bool m_Light;
};
// -----------------------------------------------------------
// Sphere primitive class definition
// -----------------------------------------------------------
class Sphere : public Primitive
{
public:
int GetType() { return SPHERE; }
Sphere( vector3& a_Centre, float a_Radius ) :
m_Centre( a_Centre ), m_SqRadius( a_Radius * a_Radius ),
m_Radius( a_Radius ), m_RRadius( 1.0f / a_Radius ) {};
vector3& GetCentre() { return m_Centre; }
float GetSqRadius() { return m_SqRadius; }
int Intersect( Ray& a_Ray, float& a_Dist );
vector3 GetNormal( vector3& a_Pos ) { return (a_Pos - m_Centre) * m_RRadius; }
private:
vector3 m_Centre;
float m_SqRadius, m_Radius, m_RRadius;
};
// -----------------------------------------------------------
// PlanePrim primitive class definition
// -----------------------------------------------------------
class PlanePrim : public Primitive
{
public:
int GetType() { return PLANE; }
PlanePrim( vector3& a_Normal, float a_D ) : m_Plane( plane( a_Normal, a_D ) ) {};
vector3& GetNormal() { return m_Plane.N; }
float GetD() { return m_Plane.D; }
int Intersect( Ray& a_Ray, float& a_Dist );
vector3 GetNormal( vector3& a_Pos );
private:
plane m_Plane;
};
// -----------------------------------------------------------
// Scene class definition
// -----------------------------------------------------------
class Scene
{
public:
Scene() : m_Primitives( 0 ), m_Primitive( 0 ) {};
~Scene();
void SphereTree( int& a_Prim, float a_Radius, vector3 a_Pos, int a_Depth );
void InitScene();
int GetNrPrimitives() { return m_Primitives; }
int GetFrPrimitives() { return f_Primitives; }
Primitive* GetPrimitive( int a_Idx ) { return m_Primitive[a_Idx]; }
private:
int m_Primitives;
int f_Primitives;
Primitive** m_Primitive;
};
}; // namespace Raytracer
#endif