1
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3
* OPCODE - Optimized Collision Detection
4
* Copyright (C) 2001 Pierre Terdiman
5
* Homepage: http://www.codercorner.com/Opcode.htm
7
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11
* Contains base model interface.
12
* \file OPC_BaseModel.cpp
13
* \author Pierre Terdiman
16
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20
* The base class for collision models.
23
* \author Pierre Terdiman
27
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
29
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
33
using namespace Opcode;
35
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
39
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
40
OPCODECREATE::OPCODECREATE()
43
mSettings.mRules = SPLIT_SPLATTER_POINTS | SPLIT_GEOM_CENTER;
44
mSettings.mLimit = 1; // Mandatory for complete trees
47
#ifdef __MESHMERIZER_H__
48
mCollisionHull = false;
49
#endif // __MESHMERIZER_H__
50
mKeepOriginal = false;
54
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
59
BaseModel::BaseModel() : mIMesh(null), mModelCode(0), mSource(null), mTree(null)
63
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
68
BaseModel::~BaseModel()
73
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75
* Releases everything.
77
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
78
void BaseModel::ReleaseBase()
80
DELETESINGLE(mSource);
84
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86
* Creates an optimized tree according to user-settings, and setups mModelCode.
87
* \param no_leaf [in] true for "no leaf" tree
88
* \param quantized [in] true for quantized tree
89
* \return true if success
91
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
92
bool BaseModel::CreateTree(bool no_leaf, bool quantized)
97
if(no_leaf) mModelCode |= OPC_NO_LEAF;
98
else mModelCode &= ~OPC_NO_LEAF;
100
if(quantized) mModelCode |= OPC_QUANTIZED;
101
else mModelCode &= ~OPC_QUANTIZED;
103
// Create the correct class
104
if(mModelCode & OPC_NO_LEAF)
106
if(mModelCode & OPC_QUANTIZED) mTree = new AABBQuantizedNoLeafTree;
107
else mTree = new AABBNoLeafTree;
111
if(mModelCode & OPC_QUANTIZED) mTree = new AABBQuantizedTree;
112
else mTree = new AABBCollisionTree;
119
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
121
* Refits the collision model. This can be used to handle dynamic meshes. Usage is:
122
* 1. modify your mesh vertices (keep the topology constant!)
123
* 2. refit the tree (call this method)
124
* \return true if success
126
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
127
bool BaseModel::Refit()
129
// Refit the optimized tree
130
return mTree->Refit(mIMesh);
132
// Old code kept for reference : refit the source tree then rebuild !
133
// if(!mSource) return false;
135
// mSource->Refit(&mTB);
137
// return mTree->Build(mSource);