OPCODE_Model Class Reference

List of all members.

Public Methods

 OPCODE_Model ()
 ~OPCODE_Model ()
bool Build (const OPCODECREATE &create)
__forceinline const AABBOptimizedTree * GetTree () const
__forceinline const AABBTreeGetSourceTree () const
__forceinline bool HasLeafNodes () const
__forceinline bool IsQuantized () const
udword GetNbNodes () const
udword GetUsedBytes () const

Detailed Description

The main collision wrapper, for all trees. Supported trees are:
  • Normal trees (2*N-1 nodes, full size)
  • No-leaf trees (N-1 nodes, full size)
  • Quantized trees (2*N-1 nodes, half size)
  • Quantized no-leaf trees (N-1 nodes, half size)
Usage:

1) Build an OPCODE_Model using a creation structure:

        OPCODE_Model Sample;

        OPCODECREATE OPCC;
        OPCC.NbTris     = ...;
        OPCC.NbVerts    = ...;
        OPCC.Tris       = ...;
        OPCC.Verts      = ...;
        OPCC.Rules      = ...;
        OPCC.NoLeaf     = ...;
        OPCC.Quantized  = ...;
        Sample.Build(OPCC);

2) Create a tree collider and setup it:

3) Setup object callbacks. Geometry & topology are NOT stored in the collision system, in order to save some ram. So, when the system needs them to perform accurate intersection tests, you're requested to provide the triangle-vertices corresponding to a given face index.

Ex:

        static void ColCallback(udword triangleindex, VertexPointers& triangle, udword userdata)
        {
            // Get back Mesh0 or Mesh1 (you also can use 2 different callbacks)
            Mesh* MyMesh = (Mesh*)userdata;
            // Get correct triangle in the app-controlled database
            const Triangle* Tri = MyMesh->GetTriangle(triangleindex);
            // Setup pointers to vertices for the collision system
            triangle.Vertex[0] = MyMesh->GetVertex(Tri->mVRef[0]);
            triangle.Vertex[1] = MyMesh->GetVertex(Tri->mVRef[1]);
            triangle.Vertex[2] = MyMesh->GetVertex(Tri->mVRef[2]);
        }

        // Setup callbacks
        TC.SetUserData0(udword(Mesh0));
        TC.SetUserData1(udword(Mesh1));
        TC.SetCallbackObj0(ColCallback);
        TC.SetCallbackObj1(ColCallback);

Of course, you should make this callback as fast as possible. And you're also not supposed to modify the geometry *after* the collision trees have been built. The alternative was to store the geometry & topology in the collision system as well (as in RAPID) but we have found this approach to waste a lot of ram in many cases.

4) Perform a collision query

        // Setup cache
        static BVTCache ColCache;
        ColCache.Model0 = &Model0;
        ColCache.Model1 = &Model1;

        // Collision query
        bool IsOk = TC.Collide(ColCache, World0, World1);

        // Get collision status => if true, objects overlap
        bool Status = TC.GetContactStatus();

        // Number of colliding pairs and list of pairs
        udword NbPairs = TC.GetNbPairs();
        Pair* p = TC.GetPairs()

5) Stats

        Model0.GetUsedBytes()   = number of bytes used for this collision tree
        TC.GetNbBVBVTests()     = number of BV-BV overlap tests performed during last query
        TC.GetNbPrimPrimTests() = number of Triangle-Triangle overlap tests performed during last query
        TC.GetNbBVPrimTests()   = number of Triangle-BV overlap tests performed during last query

Author:
Pierre Terdiman
Version:
1.0
Date:
March, 20, 2001


Constructor & Destructor Documentation

OPCODE_Model::OPCODE_Model  
 

Constructor.

OPCODE_Model::~OPCODE_Model  
 

Destructor.


Member Function Documentation

bool OPCODE_Model::Build const OPCODECREATE   create
 

Builds a collision model.

Parameters:
create  [in] model creation structure
Returns:
true if success

udword OPCODE_Model::GetNbNodes   const [inline]
 

Gets the number of nodes in the tree. Should be 2*N-1 for normal trees and N-1 for optimized ones.

Returns:
number of nodes

__forceinline const AABBTree* OPCODE_Model::GetSourceTree   const [inline]
 

A method to access the source tree.

Returns:
generic tree

__forceinline const AABBOptimizedTree* OPCODE_Model::GetTree   const [inline]
 

A method to access the tree.

Returns:
the collision tree

udword OPCODE_Model::GetUsedBytes   const [inline]
 

Gets the number of bytes used by the tree.

Returns:
amount of bytes used

__forceinline bool OPCODE_Model::HasLeafNodes   const [inline]
 

Checks whether the tree has leaf nodes or not.

Returns:
true if the tree has leaf nodes (normal tree), else false (optimized tree)

__forceinline bool OPCODE_Model::IsQuantized   const [inline]
 

Checks whether the tree is quantized or not.

Returns:
true if the tree is quantized


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


Flat Four Engine
Copyright (C) 2001 by 379, Inc.
This page generated by Doxygen