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

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

debugged bsp

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