Panda3D
|
00001 // Filename: physMeshHash.I 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 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: PhysxMeshHash::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE PhysxMeshHash:: 00022 PhysxMeshHash() { 00023 00024 _time = 1; 00025 MeshHashRoot *r = _hashIndex; 00026 00027 for (int i=0; i < _hashIndexSize; i++) { 00028 r->first = -1; 00029 r->timeStamp = 0; 00030 r++; 00031 } 00032 00033 _spacing = 0.25f; 00034 _invSpacing = 1.0f / _spacing; 00035 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: PhysxMeshHash::Destructor 00040 // Access: Public 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 INLINE PhysxMeshHash:: 00044 ~PhysxMeshHash() { 00045 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: PhysxMeshHash::hash_function 00050 // Access: Private 00051 // Description: 00052 //////////////////////////////////////////////////////////////////// 00053 INLINE int PhysxMeshHash:: 00054 hash_function(int xi, int yi, int zi) const { 00055 00056 unsigned int h = (xi * 92837111)^(yi * 689287499)^(zi * 283923481); 00057 return h % _hashIndexSize; 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: PhysxMeshHash::cell_coord_of 00062 // Access: Private 00063 // Description: 00064 //////////////////////////////////////////////////////////////////// 00065 INLINE void PhysxMeshHash:: 00066 cell_coord_of(const NxVec3 &v, int &xi, int &yi, int &zi) const { 00067 00068 xi = (int)(v.x * _invSpacing); if (v.x < 0.0f) xi--; 00069 yi = (int)(v.y * _invSpacing); if (v.y < 0.0f) yi--; 00070 zi = (int)(v.z * _invSpacing); if (v.z < 0.0f) zi--; 00071 } 00072 00073 //////////////////////////////////////////////////////////////////// 00074 // Function: PhysxMeshHash::get_grid_spacing 00075 // Access: Public 00076 // Description: 00077 //////////////////////////////////////////////////////////////////// 00078 INLINE NxF32 PhysxMeshHash:: 00079 get_grid_spacing() const { 00080 00081 return 1.0f / _invSpacing; 00082 } 00083 00084