~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to extern/bullet/Bullet/CollisionShapes/OptimizedBvh.h

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Bullet Continuous Collision Detection and Physics Library
3
 
Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
 
 
5
 
This software is provided 'as-is', without any express or implied warranty.
6
 
In no event will the authors be held liable for any damages arising from the use of this software.
7
 
Permission is granted to anyone to use this software for any purpose, 
8
 
including commercial applications, and to alter it and redistribute it freely, 
9
 
subject to the following restrictions:
10
 
 
11
 
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12
 
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13
 
3. This notice may not be removed or altered from any source distribution.
14
 
*/
15
 
 
16
 
#ifndef OPTIMIZED_BVH_H
17
 
#define OPTIMIZED_BVH_H
18
 
#include "SimdVector3.h"
19
 
#include <vector>
20
 
 
21
 
class StridingMeshInterface;
22
 
 
23
 
/// OptimizedBvhNode contains both internal and leaf node information.
24
 
/// It hasn't been optimized yet for storage. Some obvious optimizations are:
25
 
/// Removal of the pointers (can already be done, they are not used for traversal)
26
 
/// and storing aabbmin/max as quantized integers.
27
 
/// 'subpart' doesn't need an integer either. It allows to re-use graphics triangle
28
 
/// meshes stored in a non-uniform way (like batches/subparts of triangle-fans
29
 
struct OptimizedBvhNode
30
 
{
31
 
 
32
 
        SimdVector3     m_aabbMin;
33
 
        SimdVector3     m_aabbMax;
34
 
 
35
 
//these 2 pointers are obsolete, the stackless traversal just uses the escape index
36
 
        OptimizedBvhNode*       m_leftChild;
37
 
        OptimizedBvhNode*       m_rightChild;
38
 
 
39
 
        int     m_escapeIndex;
40
 
 
41
 
        //for child nodes
42
 
        int     m_subPart;
43
 
        int     m_triangleIndex;
44
 
 
45
 
};
46
 
 
47
 
class NodeOverlapCallback
48
 
{
49
 
public:
50
 
        virtual ~NodeOverlapCallback() {};
51
 
 
52
 
        virtual void ProcessNode(const OptimizedBvhNode* node) = 0;
53
 
};
54
 
 
55
 
typedef std::vector<OptimizedBvhNode>   NodeArray;
56
 
 
57
 
 
58
 
///OptimizedBvh store an AABB tree that can be quickly traversed on CPU (and SPU,GPU in future)
59
 
class OptimizedBvh
60
 
{
61
 
        OptimizedBvhNode*       m_rootNode1;
62
 
        
63
 
        OptimizedBvhNode*       m_contiguousNodes;
64
 
        int                                     m_curNodeIndex;
65
 
 
66
 
        int                                     m_numNodes;
67
 
 
68
 
        NodeArray                       m_leafNodes;
69
 
 
70
 
public:
71
 
        OptimizedBvh() :m_rootNode1(0), m_numNodes(0) { }
72
 
        virtual ~OptimizedBvh() {};
73
 
        
74
 
        void    Build(StridingMeshInterface* triangles);
75
 
 
76
 
        OptimizedBvhNode*       BuildTree       (NodeArray&     leafNodes,int startIndex,int endIndex);
77
 
 
78
 
        int     CalcSplittingAxis(NodeArray&    leafNodes,int startIndex,int endIndex);
79
 
 
80
 
        int     SortAndCalcSplittingIndex(NodeArray&    leafNodes,int startIndex,int endIndex,int splitAxis);
81
 
        
82
 
        void    WalkTree(OptimizedBvhNode* rootNode,NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
83
 
        
84
 
        void    WalkStacklessTree(OptimizedBvhNode* rootNode,NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
85
 
        
86
 
 
87
 
        //OptimizedBvhNode*     GetRootNode() { return m_rootNode1;}
88
 
 
89
 
        int                                     GetNumNodes() { return m_numNodes;}
90
 
 
91
 
        void    ReportAabbOverlappingNodex(NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
92
 
 
93
 
        void    ReportSphereOverlappingNodex(NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
94
 
 
95
 
 
96
 
};
97
 
 
98
 
 
99
 
#endif //OPTIMIZED_BVH_H
100