Panda3D
physxMeshHash.I
1 // Filename: physMeshHash.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: PhysxMeshHash::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE PhysxMeshHash::
22 PhysxMeshHash() {
23 
24  _time = 1;
25  MeshHashRoot *r = _hashIndex;
26 
27  for (int i=0; i < _hashIndexSize; i++) {
28  r->first = -1;
29  r->timeStamp = 0;
30  r++;
31  }
32 
33  _spacing = 0.25f;
34  _invSpacing = 1.0f / _spacing;
35 
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: PhysxMeshHash::Destructor
40 // Access: Public
41 // Description:
42 ////////////////////////////////////////////////////////////////////
43 INLINE PhysxMeshHash::
44 ~PhysxMeshHash() {
45 
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: PhysxMeshHash::hash_function
50 // Access: Private
51 // Description:
52 ////////////////////////////////////////////////////////////////////
53 INLINE int PhysxMeshHash::
54 hash_function(int xi, int yi, int zi) const {
55 
56  unsigned int h = (xi * 92837111)^(yi * 689287499)^(zi * 283923481);
57  return h % _hashIndexSize;
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: PhysxMeshHash::cell_coord_of
62 // Access: Private
63 // Description:
64 ////////////////////////////////////////////////////////////////////
65 INLINE void PhysxMeshHash::
66 cell_coord_of(const NxVec3 &v, int &xi, int &yi, int &zi) const {
67 
68  xi = (int)(v.x * _invSpacing); if (v.x < 0.0f) xi--;
69  yi = (int)(v.y * _invSpacing); if (v.y < 0.0f) yi--;
70  zi = (int)(v.z * _invSpacing); if (v.z < 0.0f) zi--;
71 }
72 
73 ////////////////////////////////////////////////////////////////////
74 // Function: PhysxMeshHash::get_grid_spacing
75 // Access: Public
76 // Description:
77 ////////////////////////////////////////////////////////////////////
78 INLINE NxF32 PhysxMeshHash::
79 get_grid_spacing() const {
80 
81  return 1.0f / _invSpacing;
82 }
83 
84