Panda3D
physxMeshHash.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file physxMeshHash.I
10  * @author enn0x
11  * @date 2010-09-13
12  */
13 
14 /**
15  *
16  */
17 INLINE PhysxMeshHash::
18 PhysxMeshHash() {
19 
20  _time = 1;
21  MeshHashRoot *r = _hashIndex;
22 
23  for (int i=0; i < _hashIndexSize; i++) {
24  r->first = -1;
25  r->timeStamp = 0;
26  r++;
27  }
28 
29  _spacing = 0.25f;
30  _invSpacing = 1.0f / _spacing;
31 
32 }
33 
34 /**
35  *
36  */
37 INLINE PhysxMeshHash::
38 ~PhysxMeshHash() {
39 
40 }
41 
42 /**
43  *
44  */
45 INLINE int PhysxMeshHash::
46 hash_function(int xi, int yi, int zi) const {
47 
48  unsigned int h = (xi * 92837111)^(yi * 689287499)^(zi * 283923481);
49  return h % _hashIndexSize;
50 }
51 
52 /**
53  *
54  */
55 INLINE void PhysxMeshHash::
56 cell_coord_of(const NxVec3 &v, int &xi, int &yi, int &zi) const {
57 
58  xi = (int)(v.x * _invSpacing); if (v.x < 0.0f) xi--;
59  yi = (int)(v.y * _invSpacing); if (v.y < 0.0f) yi--;
60  zi = (int)(v.z * _invSpacing); if (v.z < 0.0f) zi--;
61 }
62 
63 /**
64  *
65  */
66 INLINE NxF32 PhysxMeshHash::
67 get_grid_spacing() const {
68 
69  return 1.0f / _invSpacing;
70 }