Started working on boundingboxes.
This commit is contained in:
21
source/include/boundingbox.h
Normal file
21
source/include/boundingbox.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* DoRayMe - a quick and dirty Raytracer
|
||||
* Bounding box header
|
||||
*
|
||||
* Created by Manoël Trapier
|
||||
* Copyright (c) 2020 986-Studio.
|
||||
*
|
||||
*/
|
||||
#ifndef DORAYME_BOUNDINGBOX_H
|
||||
#define DORAYME_BOUNDINGBOX_H
|
||||
|
||||
struct BoundingBox
|
||||
{
|
||||
Tuple min;
|
||||
Tuple max;
|
||||
|
||||
BoundingBox() : min(-0, -0, -0), max(0, 0, 0) { };
|
||||
BoundingBox(Tuple min, Tuple max) : min(min), max(max) { };
|
||||
};
|
||||
|
||||
#endif //DORAYME_BOUNDINGBOX_H
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
double maxCap;
|
||||
|
||||
Cone() : minCap(-INFINITY), maxCap(INFINITY), isClosed(false), Shape(SHAPE_CONE) {};
|
||||
BoundingBox getBounds();
|
||||
};
|
||||
|
||||
#endif /* DORAYME_CONE_H */
|
||||
|
||||
@@ -28,6 +28,8 @@ public:
|
||||
double maxCap;
|
||||
|
||||
Cylinder() : minCap(-INFINITY), maxCap(INFINITY), isClosed(false), Shape(SHAPE_CYLINDER) {};
|
||||
|
||||
BoundingBox getBounds();
|
||||
};
|
||||
|
||||
#endif //DORAYME_CYLINDER_H
|
||||
|
||||
@@ -32,6 +32,8 @@ public:
|
||||
|
||||
Intersect intersect(Ray r);
|
||||
|
||||
BoundingBox getBounds();
|
||||
|
||||
Group();
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ private:
|
||||
|
||||
public:
|
||||
Plane() : Shape(SHAPE_PLANE) { };
|
||||
BoundingBox getBounds();
|
||||
};
|
||||
|
||||
#endif //DORAYME_PLANE_H
|
||||
|
||||
@@ -16,6 +16,7 @@ class Shape;
|
||||
#include <matrix.h>
|
||||
#include <intersect.h>
|
||||
#include <material.h>
|
||||
#include <boundingbox.h>
|
||||
|
||||
enum ShapeType
|
||||
{
|
||||
@@ -51,13 +52,15 @@ public:
|
||||
public:
|
||||
Shape(ShapeType = SHAPE_NONE);
|
||||
|
||||
Intersect intersect(Ray r);
|
||||
virtual Intersect intersect(Ray r);
|
||||
Tuple normalAt(Tuple point);
|
||||
|
||||
//virtual Bounds getBounds();
|
||||
/* Bouding box points are always world value */
|
||||
virtual BoundingBox getBounds();
|
||||
|
||||
void updateTransform();
|
||||
Tuple worldToObject(Tuple point) { return this->inverseTransform * point; };
|
||||
Tuple objectToWorld(Tuple point) { return this->transformMatrix * point; };
|
||||
Tuple normalToWorld(Tuple normalVector);
|
||||
|
||||
void setTransform(Matrix transform);
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
double x, y, z, w;
|
||||
|
||||
public:
|
||||
Tuple() : x(0), y(0), z(0), w(0.0) {};
|
||||
Tuple(double x, double y, double z) : x(x), y(y), z(z), w(0.0) {};
|
||||
Tuple(double x, double y, double z, double w) : x(x), y(y), z(z), w(w) {};
|
||||
bool isPoint() { return (this->w == 1.0); };
|
||||
@@ -39,6 +40,7 @@ public:
|
||||
Tuple operator/(const double &b) const { return Tuple(this->x / b, this->y / b,
|
||||
this->z / b, this->w / b); };
|
||||
|
||||
void set(double nX, double nY, double nZ) { this->x = nX; this->y = nY; this->z = nZ; };
|
||||
double magnitude();
|
||||
Tuple normalise();
|
||||
double dot(const Tuple &b);
|
||||
@@ -49,12 +51,14 @@ public:
|
||||
class Point: public Tuple
|
||||
{
|
||||
public:
|
||||
Point() : Tuple(0, 0, 0, 1.0) {};
|
||||
Point(double x, double y, double z) : Tuple(x, y, z, 1.0) {};
|
||||
};
|
||||
|
||||
class Vector: public Tuple
|
||||
{
|
||||
public:
|
||||
Vector() : Tuple(0, 0, 0, 0.0) {};
|
||||
Vector(double x, double y, double z) : Tuple(x, y, z, 0.0) {};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user