Working on worlds.

It's currently crashing.
This commit is contained in:
Godzil
2020-02-19 18:05:48 +00:00
parent efe46e2864
commit a82b67faa4
11 changed files with 195 additions and 15 deletions

View File

@@ -27,6 +27,10 @@ public:
public:
Light(LightType type = POINT_LIGHT, Tuple position=Point(0, 0, 0),
Colour intensity=Colour(1, 1, 1)) : type(type), position(position), intensity(intensity) { };
bool operator==(const Light &b) const { return this->intensity == b.intensity &&
this->position == b.position &&
this->type == b.type; };
};
#endif //DORAYME_LIGHT_H

View File

@@ -17,16 +17,25 @@ class Shape;
#include <intersect.h>
#include <material.h>
enum ShapeType
{
SHAPE_NONE,
SHAPE_SPHERE,
};
/* Base class for all object that can be presented in the world */
class Shape
{
private:
ShapeType type;
public:
Matrix transformMatrix;
Matrix inverseTransform;
Material material;
public:
Shape();
Shape(ShapeType = SHAPE_NONE);
virtual Intersect intersect(Ray r);
virtual Tuple normalAt(Tuple point);
@@ -35,6 +44,11 @@ public:
void setMaterial(Material material) { this->material = material; };
Ray transform(Ray r) { return Ray(this->transformMatrix * r.origin, this->transformMatrix * r.direction); };
Ray invTransform(Ray r) { return Ray(this->inverseTransform * r.origin, this->inverseTransform * r.direction); };
bool operator==(const Shape &b) const { return this->material == b.material &&
this->type == b.type &&
this->transformMatrix == b.transformMatrix; };
};
#endif //DORAYME_SHAPE_H

View File

@@ -16,6 +16,7 @@
class Sphere : public Shape
{
public:
Sphere() : Shape(SHAPE_SPHERE) { };
/* All sphere are at (0, 0, 0) and radius 1 in the object space */
virtual Intersect intersect(Ray r);
virtual Tuple normalAt(Tuple point);

View File

@@ -12,6 +12,8 @@
#include <stdint.h>
#include <light.h>
#include <shape.h>
#include <intersect.h>
#include <ray.h>
class World
{
@@ -23,11 +25,22 @@ private:
uint32_t allocatedObjectCount;
uint32_t allocatedLightCount;
Light *lightList;
Shape *shapeList;
Light* *lightList;
Shape* *objectList;
public:
World() : objectCount(0), lightCount(0) { };
World();
~World();
void addObject(Shape *s);
void addLight(Light *l);
/* Some debug things */
bool lightIsIn(Light &l);
bool objectIsIn(Shape &s);
Intersect intersect(Ray r);
};
#endif //DORAYME_WORLD_H

View File

@@ -13,14 +13,14 @@
/* Let's keep a single header for now, will see later */
class DefaultWorld : World
class DefaultWorld : public World
{
public:
DefaultWorld();
};
/* Not implemented yet */
class Hw3File : World
class Hw3File : public World
{
public:
Hw3File(const char *filename);