-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape.h
34 lines (27 loc) · 946 Bytes
/
shape.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
#pragma once
#include "point.h"
#include "matrix.h"
#include "material.h"
#include "ray.h"
// common base class for sphere, triangle, etc.
class Shape
{
public:
Matrix objectToWorld; // transformation to place/deform the shape in scene
Matrix worldToObject; // the inverse transformation (cached for performance)
Material material;
Shape() : objectToWorld(id4Matrix), worldToObject(id4Matrix) {}
Shape(Shape &sh) :
objectToWorld(sh.objectToWorld),
worldToObject(sh.worldToObject),
material(sh.material) {}
void setTransform(Matrix m) {
objectToWorld = m;
worldToObject = m.inverse();
}
// calculate the normal vector at a certain suface point.
virtual Vector getNormalAt(const Point& worldp) const = 0;
// cast a ray into shape, return true if ray intersects shape.
// return ray's t-value in case of intersection
virtual bool intersect(const Ray& worldRay, float& tHit) const = 0;
};