-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_object.h
87 lines (75 loc) · 2.42 KB
/
basic_object.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
#ifndef BASIC_OBJECTH
#define BASIC_OBJECTH
#include "ray.cpp"
class Material; // Alert the compiler that the pointer currentMaterial is to a class
// This struct is used to prevent the use of 6 paramaters in every function
struct objectData{
double t;
double u;
double v;
Vector3D p;
Vector3D normal;
Material *currentMaterial;
};
class BasicObject {
public:
virtual ~BasicObject(){}; // Implemented in childs
virtual bool hit(const Ray &r, double tMin, double tMax, objectData &objData) const = 0;
};
// This class holds another BasicObject and reverses the normals
class FlippedBasicObject : public BasicObject {
public:
FlippedBasicObject(BasicObject *_basicObject);
~FlippedBasicObject();
virtual bool hit(const Ray &r, double tMin, double tMax, objectData &objData) const;
private:
BasicObject *basicObject;
};
class Sphere: public BasicObject {
public:
Sphere(Vector3D _center, double _radius, Material *_material);
~Sphere();
virtual bool hit(const Ray &ray, double tMin, double tMax, objectData &objData) const;
private:
Vector3D center;
double radius;
Material *material;
};
class Cube: public BasicObject {
public:
Cube(Vector3D _center, double _size, Vector3D _material);
~Cube();
virtual bool hit(const Ray &r, double tMin, double tMax, objectData &objData) const;
private:
Vector3D center;
double size;
BasicObject *cubeObjects;
};
class Plane: public BasicObject {
public:
Plane(double _a, double _b, double _c, double _d, double _z, Material *_material);
virtual ~Plane(){}; // Implemented in childs
virtual bool hit(const Ray &r, double tMin, double tMax, objectData &objData) const;
protected:
Material *material;
double a,b,c,d,z;
};
class PlaneXY: public Plane {
public:
using Plane::Plane;
~PlaneXY();
virtual bool hit(const Ray &r, double tMin, double tMax, objectData &objData) const;
};
class PlaneYZ: public Plane {
public:
using Plane::Plane;
~PlaneYZ();
virtual bool hit(const Ray &r, double tMin, double tMax, objectData &objData) const;
};
class PlaneXZ: public Plane {
public:
using Plane::Plane;
~PlaneXZ();
virtual bool hit(const Ray &r, double tMin, double tMax, objectData &objData) const;
};
#endif