Bullet Collision Detection & Physics Library
btGImpactBvh.h
Go to the documentation of this file.
1#ifndef BT_GIMPACT_BVH_H_INCLUDED
2#define BT_GIMPACT_BVH_H_INCLUDED
3
7/*
8This source file is part of GIMPACT Library.
9
10For the latest info, see http://gimpact.sourceforge.net/
11
12Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
13email: projectileman@yahoo.com
14
15
16This software is provided 'as-is', without any express or implied warranty.
17In no event will the authors be held liable for any damages arising from the use of this software.
18Permission is granted to anyone to use this software for any purpose,
19including commercial applications, and to alter it and redistribute it freely,
20subject to the following restrictions:
21
221. 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.
232. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
243. This notice may not be removed or altered from any source distribution.
25*/
26
28
29#include "btBoxCollision.h"
30#include "btTriangleShapeEx.h"
31#include "btGImpactBvhStructs.h"
32
34class btPairSet : public btAlignedObjectArray<GIM_PAIR>
35{
36public:
38 {
39 reserve(32);
40 }
41 inline void push_pair(int index1, int index2)
42 {
44 }
45
46 inline void push_pair_inv(int index1, int index2)
47 {
49 }
50};
51
52class GIM_BVH_DATA_ARRAY : public btAlignedObjectArray<GIM_BVH_DATA>
53{
54};
55
56class GIM_BVH_TREE_NODE_ARRAY : public btAlignedObjectArray<GIM_BVH_TREE_NODE>
57{
58};
59
62{
63protected:
66
67protected:
70 int startIndex, int endIndex, int splitAxis);
71
73
75
76public:
78 {
79 m_num_nodes = 0;
80 }
81
85
87 {
89 m_num_nodes = 0;
90 }
91
94 {
95 return m_num_nodes;
96 }
97
100 {
101 return m_node_array[nodeindex].isLeafNode();
102 }
103
105 {
106 return m_node_array[nodeindex].getDataIndex();
107 }
108
110 {
111 bound = m_node_array[nodeindex].m_bound;
112 }
113
115 {
116 m_node_array[nodeindex].m_bound = bound;
117 }
118
120 {
121 return nodeindex + 1;
122 }
123
125 {
126 if (m_node_array[nodeindex + 1].isLeafNode()) return nodeindex + 2;
127 return nodeindex + 1 + m_node_array[nodeindex + 1].getEscapeIndex();
128 }
129
131 {
132 return m_node_array[nodeindex].getEscapeIndex();
133 }
134
136 {
137 return &m_node_array[index];
138 }
139
141};
142
144
150{
151public:
153
155 virtual bool is_trimesh() const = 0;
156 virtual int get_primitive_count() const = 0;
157 virtual void get_primitive_box(int prim_index, btAABB& primbox) const = 0;
160};
161
163
168{
169protected:
172
173protected:
174 //stackless refit
175 void refit();
176
177public:
180 {
182 }
183
186 {
188 }
189
191 {
194 return totalbox;
195 }
196
198 {
200 }
201
203 {
204 return m_primitive_manager;
205 }
206
209
212 {
213 refit();
214 }
215
217 void buildSet();
218
221
225 {
227 transbox.appy_transform(transform);
229 }
230
232 bool rayQuery(
233 const btVector3& ray_dir, const btVector3& ray_origin,
235
238 {
239 return true;
240 }
241
244 {
246 }
247
250 {
251 return m_box_tree.getNodeCount();
252 }
253
256 {
258 }
259
261 {
263 }
264
266 {
268 }
269
271 {
273 }
274
276 {
278 }
279
281 {
283 }
284
286 {
288 }
289
291 {
293 }
294
296 {
297 return m_box_tree.get_node_pointer(index);
298 }
299
300#ifdef TRI_COLLISION_PROFILING
301 static float getAverageTreeCollisionTime();
302#endif //TRI_COLLISION_PROFILING
303
307};
308
309#endif // BT_GIMPACT_BVH_H_INCLUDED
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:27
#define SIMD_FORCE_INLINE
Definition btScalar.h:98
Node Structure for trees.
Axis aligned box.
void appy_transform(const btTransform &trans)
Apply a transform to an AABB.
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0),...
void push_back(const GIM_PAIR &_Val)
Basic Box tree structure.
void _build_sub_tree(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex)
int _calc_splitting_axis(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex)
GIM_BVH_TREE_NODE_ARRAY m_node_array
int getRightNode(int nodeindex) const
void getNodeBound(int nodeindex, btAABB &bound) const
int m_num_nodes
void setNodeBound(int nodeindex, const btAABB &bound)
int getNodeCount() const
node count
void clearNodes()
const GIM_BVH_TREE_NODE * get_node_pointer(int index=0) const
int getNodeData(int nodeindex) const
int getLeftNode(int nodeindex) const
int _sort_and_calc_splitting_index(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex, int splitAxis)
bool isLeafNode(int nodeindex) const
tells if the node is a leaf
void build_tree(GIM_BVH_DATA_ARRAY &primitive_boxes)
prototype functions for box tree management
int getEscapeNodeIndex(int nodeindex) const
Structure for containing Boxes.
void buildSet()
this rebuild the entire set
bool isTrimesh() const
tells if this set is a trimesh
int getRightNode(int nodeindex) const
int getNodeCount() const
node count
btAABB getGlobalBox() const
bool isLeafNode(int nodeindex) const
tells if the node is a leaf
int getLeftNode(int nodeindex) const
bool boxQueryTrans(const btAABB &box, const btTransform &transform, btAlignedObjectArray< int > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
bool boxQuery(const btAABB &box, btAlignedObjectArray< int > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
void setPrimitiveManager(btPrimitiveManagerBase *primitive_manager)
void getNodeBound(int nodeindex, btAABB &bound) const
int getEscapeNodeIndex(int nodeindex) const
void getNodeTriangle(int nodeindex, btPrimitiveTriangle &triangle) const
bool hasHierarchy() const
tells if this set has hierarcht
btPrimitiveManagerBase * getPrimitiveManager() const
const GIM_BVH_TREE_NODE * get_node_pointer(int index=0) const
btGImpactBvh()
this constructor doesn't build the tree. you must call buildSet
int getNodeData(int nodeindex) const
bool rayQuery(const btVector3 &ray_dir, const btVector3 &ray_origin, btAlignedObjectArray< int > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
btBvhTree m_box_tree
btPrimitiveManagerBase * m_primitive_manager
void update()
node manager prototype functions
void setNodeBound(int nodeindex, const btAABB &bound)
static void find_collision(btGImpactBvh *boxset1, const btTransform &trans1, btGImpactBvh *boxset2, const btTransform &trans2, btPairSet &collision_pairs)
btGImpactBvh(btPrimitiveManagerBase *primitive_manager)
this constructor doesn't build the tree. you must call buildSet
A pairset array.
void push_pair(int index1, int index2)
void push_pair_inv(int index1, int index2)
Prototype Base class for primitive classification.
virtual void get_primitive_triangle(int prim_index, btPrimitiveTriangle &triangle) const =0
retrieves only the points of the triangle, and the collision margin
virtual ~btPrimitiveManagerBase()
virtual bool is_trimesh() const =0
determines if this manager consist on only triangles, which special case will be optimized
virtual int get_primitive_count() const =0
virtual void get_primitive_box(int prim_index, btAABB &primbox) const =0
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition btTransform.h:30
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
Overlapping pair.
Definition gim_pair.h:7