1 | #include "ViewCell.h"
|
---|
2 | #include "Mesh.h"
|
---|
3 | #include "Intersectable.h"
|
---|
4 | #include "MeshKdTree.h"
|
---|
5 | #include "Triangle3.h"
|
---|
6 |
|
---|
7 | ViewCell::ViewCell(): MeshInstance(NULL)
|
---|
8 | {
|
---|
9 | }
|
---|
10 |
|
---|
11 | ViewCell::ViewCell(Mesh *mesh): MeshInstance(mesh) |
---|
12 | { |
---|
13 | } |
---|
14 | |
---|
15 | ViewCellPvs &ViewCell::GetPvs() |
---|
16 | { |
---|
17 | return mPvs; |
---|
18 | } |
---|
19 | |
---|
20 | int ViewCell::Type() const
|
---|
21 | {
|
---|
22 | return VIEW_CELL;
|
---|
23 | }
|
---|
24 |
|
---|
25 | void ViewCell::DeriveViewCells(const ObjectContainer &objects,
|
---|
26 | ViewCellContainer &viewCells,
|
---|
27 | const int maxViewCells)
|
---|
28 | {
|
---|
29 | // maximal max viewcells
|
---|
30 | int limit = maxViewCells > 0 ? Min((int)objects.size(), maxViewCells) : (int)objects.size();
|
---|
31 |
|
---|
32 | for (int i = 0; i < limit; ++ i)
|
---|
33 | {
|
---|
34 | Intersectable *object = objects[i];
|
---|
35 |
|
---|
36 | // extract the mesh instances
|
---|
37 | if (object->Type() == Intersectable::MESH_INSTANCE)
|
---|
38 | {
|
---|
39 | MeshInstance *inst = dynamic_cast<MeshInstance *>(object);
|
---|
40 |
|
---|
41 | ViewCell *viewCell = new ViewCell(inst->GetMesh());
|
---|
42 | viewCells.push_back(viewCell);
|
---|
43 | }
|
---|
44 | //TODO: transformed meshes
|
---|
45 | }
|
---|
46 | } |
---|
47 | |
---|
48 | ViewCell *ViewCell::ExtrudeViewCell(const Triangle3 &baseTri, const float height) |
---|
49 | {
|
---|
50 | // one mesh per view cell
|
---|
51 | Mesh *mesh = new Mesh();
|
---|
52 |
|
---|
53 | //-- construct prism
|
---|
54 |
|
---|
55 | // bottom
|
---|
56 | mesh->mFaces.push_back(new Face(2,1,0));
|
---|
57 | // top
|
---|
58 | mesh->mFaces.push_back(new Face(3,4,5));
|
---|
59 | // sides
|
---|
60 | mesh->mFaces.push_back(new Face(1, 4, 3, 0));
|
---|
61 | mesh->mFaces.push_back(new Face(2, 5, 4, 1));
|
---|
62 | mesh->mFaces.push_back(new Face(3, 5, 2, 0));
|
---|
63 |
|
---|
64 | //--- extrude new vertices for top of prism
|
---|
65 | Vector3 triNorm = baseTri.GetNormal();
|
---|
66 |
|
---|
67 | Triangle3 topTri;
|
---|
68 |
|
---|
69 | // add base vertices and calculate top vertices
|
---|
70 | for (int i = 0; i < 3; ++ i)
|
---|
71 | mesh->mVertices.push_back(baseTri.mVertices[i]);
|
---|
72 |
|
---|
73 | // add top vertices
|
---|
74 | for (i = 0; i < 3; ++ i)
|
---|
75 | mesh->mVertices.push_back(baseTri.mVertices[i] + height * triNorm);
|
---|
76 |
|
---|
77 | mesh->Preprocess();
|
---|
78 |
|
---|
79 | return new ViewCell(mesh); |
---|
80 | } |
---|
81 | |
---|
82 | void ViewCell::AddPassingRay(const Ray &ray, const int contributions) |
---|
83 | { |
---|
84 | mPassingRays.AddRay(ray, contributions); |
---|
85 | } |
---|