-
Notifications
You must be signed in to change notification settings - Fork 3
/
SceneObjectBox.c
49 lines (33 loc) · 1.26 KB
/
SceneObjectBox.c
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
#include "SceneObjectBox.h"
#include "randf.h"
#include <math.h>
const SceneObjectVTable sceneObjectBoxVTable = (SceneObjectVTable) {
&sceneObjectBoxIntersectRay,
&sceneObjectBoxEmitPhotons,
&sceneObjectBoxRadiantFlux
};
SceneObjectBox makeSceneObjectBox (const Vector size, const Material *material) {
return (SceneObjectBox) {makeSceneObject(&sceneObjectBoxVTable), makeBox(size), material};
}
defineAllocator(SceneObjectBox)
Intersection sceneObjectBoxIntersectRay(const SceneObject *superobject, const Ray ray) {
const SceneObjectBox *object = (SceneObjectBox *) superobject;
Intersection intersection = bIntersect(object->box, ray);
intersection.material = object->material;
return intersection;
}
bool sceneObjectBoxEmitPhotons(const SceneObject *superobject, const int numPhotons, PhotonContainer *photons) {
// TODO: Implement this. Use code from SceneObjectSphere.
return false;
}
Color sceneObjectBoxRadiantFlux(const SceneObject *superobject) {
const SceneObjectBox *object = (SceneObjectBox *) superobject;
Color averageIrradiance = materialIrradience(object->material);
Vector size = object->box.size;
float surfaceArea = (
size.x * size.y +
size.y * size.z +
size.z * size.x
) * 2;
return csMul(averageIrradiance, surfaceArea);
}