Panda3D

physxMeshHash.h

00001 // Filename: physMeshHash.h
00002 // Created by: enn0x (13Sep10)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef PHYSXMESHHASH_H
00016 #define PHYSXMESHHASH_H
00017 
00018 #include "config_physx.h"
00019 
00020 #include "pvector.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //       Class : PhysxMeshHash
00024 // Description : Utility class used in building links between a
00025 //               tetrahedron mesh (soft body) and a triangle mesh
00026 //               used for rendering the soft body.
00027 ////////////////////////////////////////////////////////////////////
00028 class PhysxMeshHash {
00029 
00030 public:
00031   PhysxMeshHash();
00032   ~PhysxMeshHash();
00033 
00034   void reset();
00035 
00036   void set_grid_spacing(float spacing);
00037   INLINE NxF32 get_grid_spacing() const;
00038 
00039   void add(const NxBounds3 &bounds, int itemIndex);
00040   void add(const NxVec3 &pos, int itemIndex);
00041 
00042   void query(const NxBounds3 &bounds, pvector<int> &itemIndices, int maxIndices=-1);
00043   void query_unique(const NxBounds3 &bounds, pvector<int> &itemIndices, int maxIndices=-1);
00044 
00045   void query(const NxVec3 &pos, pvector<int> &itemIndices, int maxIndices=-1);
00046   void query_unique(const NxVec3 &pos, pvector<int> &itemIndices, int maxIndices=-1);
00047 
00048 private:
00049   struct MeshHashRoot {
00050     int first;
00051     int timeStamp;
00052   };
00053 
00054   struct MeshHashEntry {
00055     int itemIndex;
00056     int next;
00057   };
00058 
00059   NxI32 _time;
00060   NxF32 _spacing;
00061   NxF32 _invSpacing;
00062 
00063   static const int _hashIndexSize = 17011;
00064   MeshHashRoot _hashIndex[_hashIndexSize];
00065 
00066   pvector<MeshHashEntry> _entries;
00067 
00068   INLINE int hash_function(int xi, int yi, int zi) const;
00069   INLINE void cell_coord_of(const NxVec3 &v, int &xi, int &yi, int &zi) const;
00070 
00071   void compress_indices(pvector<int> &itemIndices);
00072   void quick_sort(pvector<int> &itemIndices, int l, int r);
00073 
00074 };
00075 
00076 #include "physxMeshHash.I"
00077 
00078 #endif // PHYSXMESHHASH_H
 All Classes Functions Variables Enumerations