Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AABBCollisionNode Class Reference

#include <OPC_OptimizedTree.h>

Related Functions

(Note that these are not member functions.)

 _BuildCollisionTree (AABBCollisionNode *linear, const udword box_id, udword &current_id, const AABBTreeNode *current_node)
 

Detailed Description

Definition at line 62 of file OPC_OptimizedTree.h.

Friends And Related Function Documentation

_BuildCollisionTree ( AABBCollisionNode linear,
const udword  box_id,
udword current_id,
const AABBTreeNode current_node 
)
related

Builds an implicit tree from a standard one. An implicit tree is a complete tree (2*N-1 nodes) whose negative box pointers and primitive pointers have been made implicit, hence packing 3 pointers in one.

Layout for implicit trees: Node:

  • box
  • data (32-bits value)

if data's LSB = 1 => remaining bits are a primitive pointer else remaining bits are a P-node pointer, and N = P + 1

Parameters
linear[in] base address of destination nodes
box_id[in] index of destination node
current_id[in] current running index
current_node[in] current node from input tree

Definition at line 101 of file OPC_OptimizedTree.cpp.

102 {
103  // Current node from input tree is "current_node". Must be flattened into "linear[boxid]".
104 
105  // Store the AABB
106  current_node->GetAABB()->GetCenter(linear[box_id].mAABB.mCenter);
107  current_node->GetAABB()->GetExtents(linear[box_id].mAABB.mExtents);
108  // Store remaining info
109  if(current_node->IsLeaf())
110  {
111  // The input tree must be complete => i.e. one primitive/leaf
112  OPASSERT(current_node->GetNbPrimitives()==1);
113  // Get the primitive index from the input tree
114  udword PrimitiveIndex = current_node->GetPrimitives()[0];
115  // Setup box data as the primitive index, marked as leaf
116  linear[box_id].mData = (PrimitiveIndex<<1)|1;
117  }
118  else
119  {
120  // To make the negative one implicit, we must store P and N in successive order
121  udword PosID = current_id++; // Get a new id for positive child
122  udword NegID = current_id++; // Get a new id for negative child
123  // Setup box data as the forthcoming new P pointer
124  linear[box_id].mData = (uintptr_t)&linear[PosID];
125  // Make sure it's not marked as leaf
126  OPASSERT(!(linear[box_id].mData&1));
127  // Recurse with new IDs
128  _BuildCollisionTree(linear, PosID, current_id, current_node->GetPos());
129  _BuildCollisionTree(linear, NegID, current_id, current_node->GetNeg());
130  }
131 }

The documentation for this class was generated from the following files: