#include "ViewCell.h" #include "Mesh.h" #include "MeshKdTree.h" #include "Triangle3.h" ViewCell::ViewCell(Mesh *mesh): mMesh(mesh), mPvs(NULL) { } ViewCell::~ViewCell() { // NOTE: should I really do this here? (I know that there is only one mesh per view cell) DEL_PTR(mMesh); } Mesh *ViewCell::GetMesh() { return mMesh; } BspPvs *ViewCell::GetPVS() { return mPvs; } AxisAlignedBox3 ViewCell::GetBox() { return mMesh->mBox; } int ViewCell::CastRay(Ray &ray) { return 0; } bool ViewCell::IsConvex() { return mMesh->mIsConvex; } bool ViewCell::IsWatertight() { return mMesh->mIsWatertight; } float ViewCell::IntersectionComplexity() { return (float)mMesh->mFaces.size(); } int ViewCell::Type() const { return VIEWCELL; } void ViewCell::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) { point = Vector3(0,0,0); } void ViewCell::DeriveViewCells(const ObjectContainer &objects, ViewCellContainer &viewCells, const int maxViewCells) { // maximal max viewcells int limit = maxViewCells > 0 ? Min((int)objects.size(), maxViewCells) : (int)objects.size(); for (int i = 0; i < limit; ++i) { Intersectable *object = objects[i]; // extract the mesh instances if (object->Type() == Intersectable::MESH_INSTANCE) { MeshInstance *inst = dynamic_cast(object); ViewCell *viewCell = new ViewCell(inst->GetMesh()); viewCells.push_back(viewCell); } //TODO: transformed meshes } } ViewCell *ViewCell::ExtrudeViewCell(const Triangle3 &baseTri, const float height) { // one mesh per view cell Mesh *mesh = new Mesh(); //-- construct prism // bottom mesh->mFaces.push_back(new Face(0,1,2)); // top mesh->mFaces.push_back(new Face(5,4,3)); // sides mesh->mFaces.push_back(new Face(0, 3, 4, 1)); mesh->mFaces.push_back(new Face(1, 4, 5, 2)); mesh->mFaces.push_back(new Face(0, 2, 5, 3)); //--- extrude new vertices for top of prism Vector3 triNorm = baseTri.GetNormal(); Triangle3 topTri; // add base vertices and calculate top vertices for (int i = 0; i < 3; ++i) { mesh->mVertices.push_back(baseTri.mVertices[i]); topTri.mVertices[i] = baseTri.mVertices[i] + height * triNorm; } // add top vertices for (int i = 0; i < 3; ++i) mesh->mVertices.push_back(topTri.mVertices[i]); return new ViewCell(mesh); }