source: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp @ 265

Revision 265, 2.4 KB checked in by mattausch, 19 years ago (diff)

did bsp stuff

RevLine 
[235]1#include "ViewCell.h"
2#include "Mesh.h"
3#include "MeshKdTree.h"
4#include "Triangle3.h"
5
[265]6ViewCell::ViewCell(): mMesh(NULL)
7{
8}
[235]9
10ViewCell::ViewCell(Mesh *mesh): mMesh(mesh), mPvs(NULL)
11{
12}
13
[261]14ViewCell::~ViewCell()
15{
[262]16        // NOTE: should I really do this here? (I know that there is only one mesh per view cell)
[261]17        DEL_PTR(mMesh);
18}
19
[235]20Mesh *ViewCell::GetMesh()
21{
22        return mMesh;
23}
24
25BspPvs *ViewCell::GetPVS()
26{
27        return mPvs;
28}
29
30AxisAlignedBox3 ViewCell::GetBox()
31{
32        return mMesh->mBox;
33}
34 
35int ViewCell::CastRay(Ray &ray)
36{
37        return 0;
38}
39 
40bool ViewCell::IsConvex()
41{
42        return mMesh->mIsConvex;
43}
44
45bool ViewCell::IsWatertight()
46{
47        return mMesh->mIsWatertight;
48}
49
50float ViewCell::IntersectionComplexity()
51{
[239]52        return (float)mMesh->mFaces.size();
[235]53}
54
55int ViewCell::Type() const
56{
57        return VIEWCELL;
58}
59
60void  ViewCell::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal)
61{
62        point = Vector3(0,0,0);
63}
64
65void ViewCell::DeriveViewCells(const ObjectContainer &objects,
66                                                           ViewCellContainer &viewCells,
[239]67                                                           const int maxViewCells)
[235]68{
[237]69        // maximal max viewcells
[245]70        int limit = maxViewCells > 0 ? Min((int)objects.size(), maxViewCells) : (int)objects.size();
[237]71
[239]72        for (int i = 0; i < limit; ++i)
[235]73        {
74                Intersectable *object = objects[i];
[256]75               
[235]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                }
[237]84                //TODO: transformed meshes
[235]85        }
[245]86}
[260]87
[261]88ViewCell *ViewCell::ExtrudeViewCell(const Triangle3 &baseTri, const float height)
[260]89{
[261]90        // one mesh per view cell
[260]91        Mesh *mesh = new Mesh();
[261]92       
93        //-- construct prism
[260]94
[261]95        // bottom
[264]96        mesh->mFaces.push_back(new Face(2,1,0));
[261]97        // top
[264]98    mesh->mFaces.push_back(new Face(3,4,5));
[261]99        // sides
[264]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));
[261]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)
[262]118                mesh->mVertices.push_back(topTri.mVertices[i]);
[261]119       
[263]120        mesh->Preprocess();
121
[260]122        return new ViewCell(mesh);
123}
Note: See TracBrowser for help on using the repository browser.