-
Notifications
You must be signed in to change notification settings - Fork 1
/
Shape.h
57 lines (48 loc) · 1.17 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once
#include <ei/vector.hpp>
#include "../PBRT/ParamSet.h"
#include "../parser_exception.h"
#include "../PBRT/Material.h"
#include "../PBRT/Light.h"
using Vector = ei::Vec3;
using Matrix = ei::Matrix<float, 4, 4>;
using ei::Vec4;
class Shape
{
public:
virtual ~Shape()
{
}
virtual void init(ParamSet& set) = 0;
virtual void applyTransform(const Matrix& mat) = 0;
virtual void applyTransformFront(const Matrix& mat) = 0;
void setMaterial(std::shared_ptr<Material> mat)
{
m_material = mat;
}
void setAreaLight(std::shared_ptr<AreaLight> l)
{
assert(m_material);
m_material->areaLight = l;
}
virtual Shape* clone() const = 0;
static Vector transformPoint(const Vector& p, const Matrix& mat)
{
Vec4 v4 = mat * Vec4(p.x, p.y, p.z, 1.0f);
return Vector(v4.x, v4.y, v4.z);
}
static Vector transformVector(const Vector& p, const Matrix& mat)
{
Vec4 v4 = mat * Vec4(p.x, p.y, p.z, 0.0f);
return Vector(v4.x, v4.y, v4.z);
}
const Material& getMaterial() const
{
assert(m_material);
return *m_material;
}
virtual void flipNormals() = 0;
virtual size_t estimateSize(size_t vertexSize) const = 0;
private:
std::shared_ptr<Material> m_material;
};