All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CollisionBvhNode.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Collision.h"
6 #include "SingleSphere.h"
7 #include "Types.h"
8 #include "AllVertexTypes.h"
9 
10 #include "VectorMath.h"
11 
12 namespace Eegeo
13 {
14  namespace Collision
15  {
17  {
18  public:
19 
21  {}
22 
23  CollisionBvhNode(const Eegeo::Rendering::VertexTypes::ShortPositionVertex& quantizedSphereCentre, u16 quantizedSphereRadius, u32 packedRanges);
24 
25  static CollisionBvhNode Make(const Eegeo::Rendering::VertexTypes::ShortPositionVertex& quantizedSphereCentre, u16 quantizedSphereRadius, int firstChildIndex, int childCount, bool isLeaf);
26 
27  const Eegeo::Rendering::VertexTypes::ShortPositionVertex& QuantizedSphereCentre() const { return m_quantizedSphereCentre; }
28  u16 QuantizedSphereRadius() const { return m_quantizedSphereRadius; }
29 
30  inline int FirstChildIndex() const;
31  inline int ChildCount() const;
32  inline bool IsLeafNode() const;
33 
34  private:
36  u16 m_quantizedSphereRadius;
37  u32 m_packedRanges;
38 
39  enum
40  {
41  ChildCountBits = 12,
42  ChildCountMask = (1 << ChildCountBits) - 1,
43 
44  FirstChildIndexBits = 19,
45  FirstChildIndexShift = ChildCountBits,
46  MaxFirstChildIndex = (1 << FirstChildIndexBits) - 1,
47  FirstChildIndexMask = MaxFirstChildIndex << FirstChildIndexShift,
48 
49  IsLeafShift = FirstChildIndexShift + FirstChildIndexBits,
50  IsLeafMask = (1 << IsLeafShift)
51  };
52  };
53 
54  inline int CollisionBvhNode::FirstChildIndex() const
55  {
56  return (m_packedRanges & FirstChildIndexMask) >> FirstChildIndexShift;
57  }
58 
59  inline int CollisionBvhNode::ChildCount() const
60  {
61  return m_packedRanges & ChildCountMask;
62  }
63 
64  inline bool CollisionBvhNode::IsLeafNode() const
65  {
66  return ((m_packedRanges & IsLeafMask) != 0) ? true : false;
67  }
68  }
69 }