1 | #include "ViewCell.h"
|
---|
2 | #include "Mesh.h"
|
---|
3 | #include "MeshKdTree.h"
|
---|
4 | #include "Triangle3.h"
|
---|
5 |
|
---|
6 | ViewCell::ViewCell(): mMesh(NULL)
|
---|
7 | {
|
---|
8 | }
|
---|
9 |
|
---|
10 | ViewCell::ViewCell(Mesh *mesh): mMesh(mesh), mPvs(NULL) |
---|
11 | { |
---|
12 | } |
---|
13 | |
---|
14 | ViewCell::~ViewCell() |
---|
15 | { |
---|
16 | // NOTE: should I really do this here? (I know that there is only one mesh per view cell) |
---|
17 | DEL_PTR(mMesh); |
---|
18 | } |
---|
19 | |
---|
20 | Mesh *ViewCell::GetMesh() |
---|
21 | { |
---|
22 | return mMesh; |
---|
23 | } |
---|
24 | |
---|
25 | BspPvs *ViewCell::GetPVS() |
---|
26 | { |
---|
27 | return mPvs; |
---|
28 | } |
---|
29 | |
---|
30 | AxisAlignedBox3 ViewCell::GetBox()
|
---|
31 | {
|
---|
32 | return mMesh->mBox;
|
---|
33 | }
|
---|
34 |
|
---|
35 | int ViewCell::CastRay(Ray &ray)
|
---|
36 | {
|
---|
37 | return 0;
|
---|
38 | }
|
---|
39 |
|
---|
40 | bool ViewCell::IsConvex() |
---|
41 | { |
---|
42 | return mMesh->mIsConvex; |
---|
43 | } |
---|
44 | |
---|
45 | bool ViewCell::IsWatertight() |
---|
46 | { |
---|
47 | return mMesh->mIsWatertight; |
---|
48 | } |
---|
49 | |
---|
50 | float ViewCell::IntersectionComplexity() |
---|
51 | { |
---|
52 | return (float)mMesh->mFaces.size(); |
---|
53 | } |
---|
54 | |
---|
55 | int ViewCell::Type() const
|
---|
56 | {
|
---|
57 | return VIEWCELL;
|
---|
58 | }
|
---|
59 |
|
---|
60 | void ViewCell::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal)
|
---|
61 | {
|
---|
62 | point = Vector3(0,0,0);
|
---|
63 | }
|
---|
64 |
|
---|
65 | void ViewCell::DeriveViewCells(const ObjectContainer &objects,
|
---|
66 | ViewCellContainer &viewCells,
|
---|
67 | const int maxViewCells)
|
---|
68 | {
|
---|
69 | // maximal max viewcells
|
---|
70 | int limit = maxViewCells > 0 ? Min((int)objects.size(), maxViewCells) : (int)objects.size();
|
---|
71 |
|
---|
72 | for (int i = 0; i < limit; ++i)
|
---|
73 | {
|
---|
74 | Intersectable *object = objects[i];
|
---|
75 |
|
---|
76 | // extract the mesh instances
|
---|
77 | if (object->Type() == Intersectable::MESH_INSTANCE)
|
---|
78 | {
|
---|
79 | MeshInstance *inst = dynamic_cast<MeshInstance *>(object);
|
---|
80 |
|
---|
81 | ViewCell *viewCell = new ViewCell(inst->GetMesh());
|
---|
82 | viewCells.push_back(viewCell);
|
---|
83 | }
|
---|
84 | //TODO: transformed meshes
|
---|
85 | }
|
---|
86 | } |
---|
87 | |
---|
88 | ViewCell *ViewCell::ExtrudeViewCell(const Triangle3 &baseTri, const float height) |
---|
89 | {
|
---|
90 | // one mesh per view cell
|
---|
91 | Mesh *mesh = new Mesh();
|
---|
92 |
|
---|
93 | //-- construct prism
|
---|
94 |
|
---|
95 | // bottom
|
---|
96 | mesh->mFaces.push_back(new Face(2,1,0));
|
---|
97 | // top
|
---|
98 | mesh->mFaces.push_back(new Face(3,4,5));
|
---|
99 | // sides
|
---|
100 | mesh->mFaces.push_back(new Face(1, 4, 3, 0));
|
---|
101 | mesh->mFaces.push_back(new Face(2, 5, 4, 1));
|
---|
102 | mesh->mFaces.push_back(new Face(3, 5, 2, 0));
|
---|
103 |
|
---|
104 | //--- extrude new vertices for top of prism
|
---|
105 | Vector3 triNorm = baseTri.GetNormal();
|
---|
106 |
|
---|
107 | Triangle3 topTri;
|
---|
108 |
|
---|
109 | // add base vertices and calculate top vertices
|
---|
110 | for (int i = 0; i < 3; ++i)
|
---|
111 | {
|
---|
112 | mesh->mVertices.push_back(baseTri.mVertices[i]);
|
---|
113 | topTri.mVertices[i] = baseTri.mVertices[i] + height * triNorm;
|
---|
114 | }
|
---|
115 |
|
---|
116 | // add top vertices
|
---|
117 | for (int i = 0; i < 3; ++i)
|
---|
118 | mesh->mVertices.push_back(topTri.mVertices[i]);
|
---|
119 |
|
---|
120 | mesh->Preprocess();
|
---|
121 |
|
---|
122 | return new ViewCell(mesh); |
---|
123 | } |
---|