Panda3D
physxMeshHash.h
1 // Filename: physMeshHash.h
2 // Created by: enn0x (13Sep10)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PHYSXMESHHASH_H
16 #define PHYSXMESHHASH_H
17 
18 #include "config_physx.h"
19 
20 #include "pvector.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : PhysxMeshHash
24 // Description : Utility class used in building links between a
25 // tetrahedron mesh (soft body) and a triangle mesh
26 // used for rendering the soft body.
27 ////////////////////////////////////////////////////////////////////
29 
30 public:
31  PhysxMeshHash();
32  ~PhysxMeshHash();
33 
34  void reset();
35 
36  void set_grid_spacing(float spacing);
37  INLINE NxF32 get_grid_spacing() const;
38 
39  void add(const NxBounds3 &bounds, int itemIndex);
40  void add(const NxVec3 &pos, int itemIndex);
41 
42  void query(const NxBounds3 &bounds, pvector<int> &itemIndices, int maxIndices=-1);
43  void query_unique(const NxBounds3 &bounds, pvector<int> &itemIndices, int maxIndices=-1);
44 
45  void query(const NxVec3 &pos, pvector<int> &itemIndices, int maxIndices=-1);
46  void query_unique(const NxVec3 &pos, pvector<int> &itemIndices, int maxIndices=-1);
47 
48 private:
49  struct MeshHashRoot {
50  int first;
51  int timeStamp;
52  };
53 
54  struct MeshHashEntry {
55  int itemIndex;
56  int next;
57  };
58 
59  NxI32 _time;
60  NxF32 _spacing;
61  NxF32 _invSpacing;
62 
63  static const int _hashIndexSize = 17011;
64  MeshHashRoot _hashIndex[_hashIndexSize];
65 
66  pvector<MeshHashEntry> _entries;
67 
68  INLINE int hash_function(int xi, int yi, int zi) const;
69  INLINE void cell_coord_of(const NxVec3 &v, int &xi, int &yi, int &zi) const;
70 
71  void compress_indices(pvector<int> &itemIndices);
72  void quick_sort(pvector<int> &itemIndices, int l, int r);
73 
74 };
75 
76 #include "physxMeshHash.I"
77 
78 #endif // PHYSXMESHHASH_H
Utility class used in building links between a tetrahedron mesh (soft body) and a triangle mesh used ...
Definition: physxMeshHash.h:28