-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrimitive.cpp
60 lines (52 loc) · 1.56 KB
/
Primitive.cpp
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
/*
Primitive.cpp
*/
#include <iostream>
#include "Primitive.h"
Primitive::Primitive(Shape* shape)
{
this->shape = shape;
this->material = new Material();
}
Primitive::~Primitive()
{
}
int Primitive::getIntersectionPoint(const Ray& ray, Intersection& intersection, const double dt)
{
return shape->getIntersectionPoint(ray, intersection, dt);
}
bool Primitive::doesRayIntersect(const Ray& ray, const float tmax, const double dt)
{
// This seems hacky.
if (this->material->type == EMISSIVE) {
return false;
} else {
return shape->doesRayIntersect(ray, tmax, dt);
}
}
void Primitive::setAmbient(const glm::dvec3& ambient)
{
this->ambient = ambient;
}
void Primitive::setMaterial(const Material& material)
{
this->material->diffuse = glm::vec3(material.diffuse);
this->material->specular = glm::vec3(material.specular);
this->material->emission = glm::vec3(material.emission);
this->material->shininess = material.shininess;
this->material->alpha = material.alpha;
this->material->rindex = material.rindex;
this->material->type = material.type;
}
void Primitive::setTransformation(glm::dmat4& transformation)
{
this->transformation = transformation;
this->inverseTransformation = glm::inverse(transformation);
glm::mat3 tempTransformation;
for (int i = 0; i < 3; i++) {
for (int k = 0; k < 3; k++) {
tempTransformation[i][k] = transformation[i][k];
this->inverseTranspose[i][k] = this->inverseTransformation[k][i];
}
}
}