OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreLodOutsideMarker.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __OutsideMarker_H__
29 #define __OutsideMarker_H__
30 
31 #include "OgreLodPrerequisites.h"
32 #include "OgreLodData.h"
34 
35 namespace Ogre
36 {
40 {
41 public:
47  LodOutsideMarker(LodData::VertexList & vertexList, Real boundingSphereRadius, Real walkAngle);
48  void markOutside();
49  MeshPtr createConvexHullMesh(const String& meshName,
50  const String& resourceGroupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
51 
53  return getOutsideData(v)->isOuterWallVertex;
54  }
55 
56 private:
58 
59  struct CHTriangle {
60  bool removed; // Whether the triangle is excluded from hull.
61  CHVertex* vertex[3];
63  void computeNormal();
64  };
65 
66 
67  struct OutsideData
68  {
72  };
73 
78 
79 
80 
81 
82  const Real mEpsilon;
87 
91 
93  return &mVertexListOrig[LodData::getVectorIDFromPointer(mOutsideData, d)];
94  }
96  return &mOutsideData[LodData::getVectorIDFromPointer(mVertexListOrig, v)];
97  }
98 
99  void initHull();
100  void createTriangle(CHVertex* v1, CHVertex* v2, CHVertex* v3);
101  Real getTetrahedronVolume(CHVertex* v0, CHVertex* v1, CHVertex* v2, CHVertex* v3);
102  Real getPointToLineSqraredDistance(CHVertex* x1, CHVertex* x2, CHVertex* vertex);
103  void generateHull();
104  size_t addVertex(CHVertex* vertex);
105  void addEdge(CHEdgeList& edges, CHVertex* a, CHVertex* b);
106  void cleanHull();
107  bool isVisible(CHTriangle* triangle, Vector3& vertex);
108  CHVertex* getFurthestVertex(CHTriangle* hull);
109  void getVisibleTriangles(const CHVertex* target, CHTrianglePList& visibleTriangles);
110  void getHorizon(const CHTrianglePList& tri, CHEdgeList& );
111  void fillHorizon(CHEdgeList& e, CHVertex* target);
112  void markVertices();
113  template<typename T>
114  void addHullTriangleVertices(std::vector<CHVertex*>& stack, T tri);
115  Real pointToLineDir(const Vector3& ptarget, const Vector3& p0, const Vector3& p1, const Vector3& p2, const Vector3& n);
117  bool isInsideTriangle(const Vector3& ptarget, const CHTriangle& tri);
118  bool isInsideLine(const Vector3& ptarget, const Vector3& p0, const Vector3& p1);
119  bool isSamePosition(const Vector3& p0, const Vector3& p1);
120 };
121 }
122 
123 #endif /* ifndef __OutsideMarker_H__ */
bool isVertexOutside(LodData::Vertex *v)
Returns a mesh containing the Convex Hull shape.
float Real
Software floating point type.
CHTrianglePList mVisibleTriangles
Contains the current triangles of the convex hull.
Real mWalkAngle
Centroid of the convex hull.
This class will mark vertices of a mesh, which are visible from far away (from outside).
static String DEFAULT_RESOURCE_GROUP_NAME
Default resource group name.
OutsideDataList mOutsideData
Source of input and output of the algorithm.
static size_t getVectorIDFromPointer(const std::vector< T, A > &vec, const T *pointer)
Definition: OgreLodData.h:156
vector< Vertex >::type VertexList
Definition: OgreLodData.h:56
LodData::VertexList & mVertexListOrig
Temporary vector for the horizon edges, when inserting a new vertex into the hull.
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
#define _OgreLodExport
CHEdgeList mEdges
Temporary vector for addVisibleEdges function (prevent allocation every call).
vector< CHTriangle >::type CHTriangleList
vector< CHTriangle * >::type CHTrianglePList
LodData::Vertex * getVertex(OutsideData *d)
Angle limit, when walking inside for marking vertices.
_StringBase String
Definition: OgreCommon.h:53
CHTriangleList mHull
Amount of allowed floating point error if 4 vertices are on the same plane.
OutsideData * getOutsideData(LodData::Vertex *v)
vector< OutsideData >::type OutsideDataList
vector< std::pair< CHVertex *, CHVertex * > >::type CHEdgeList