2 * OPCODE - Optimized Collision Detection
3 * http://www.codercorner.com/Opcode.htm
5 * Copyright (c) 2001-2008 Pierre Terdiman, pierre@codercorner.com
7 This software is provided 'as-is', without any express or implied warranty.
8 In no event will the authors be held liable for any damages arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it freely,
11 subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
14 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
15 3. This notice may not be removed or altered from any source distribution.
18 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20 * Contains base model interface.
21 * \file OPC_BaseModel.cpp
22 * \author Pierre Terdiman
25 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
29 * The base class for collision models.
32 * \author Pierre Terdiman
36 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
42 using namespace Opcode;
44 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
48 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49 OPCODECREATE::OPCODECREATE()
52 mSettings.mRules = SPLIT_SPLATTER_POINTS | SPLIT_GEOM_CENTER;
53 mSettings.mLimit = 1; // Mandatory for complete trees
56 #ifdef __MESHMERIZER_H__
57 mCollisionHull = false;
58 #endif // __MESHMERIZER_H__
59 mKeepOriginal = false;
63 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
68 BaseModel::BaseModel() : mIMesh(null), mModelCode(0), mSource(null), mTree(null)
72 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77 BaseModel::~BaseModel()
82 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84 * Releases everything.
86 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87 void BaseModel::ReleaseBase()
89 DELETESINGLE(mSource);
93 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
95 * Creates an optimized tree according to user-settings, and setups mModelCode.
96 * \param no_leaf [in] true for "no leaf" tree
97 * \param quantized [in] true for quantized tree
98 * \return true if success
100 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
101 bool BaseModel::CreateTree(bool no_leaf, bool quantized)
106 if(no_leaf) mModelCode |= OPC_NO_LEAF;
107 else mModelCode &= ~OPC_NO_LEAF;
109 if(quantized) mModelCode |= OPC_QUANTIZED;
110 else mModelCode &= ~OPC_QUANTIZED;
112 // Create the correct class
113 if(mModelCode & OPC_NO_LEAF)
115 if(mModelCode & OPC_QUANTIZED) mTree = new AABBQuantizedNoLeafTree;
116 else mTree = new AABBNoLeafTree;
120 if(mModelCode & OPC_QUANTIZED) mTree = new AABBQuantizedTree;
121 else mTree = new AABBCollisionTree;
128 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
130 * Refits the collision model. This can be used to handle dynamic meshes. Usage is:
131 * 1. modify your mesh vertices (keep the topology constant!)
132 * 2. refit the tree (call this method)
133 * \return true if success
135 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
136 bool BaseModel::Refit()
138 // Refit the optimized tree
139 return mTree->Refit(mIMesh);
141 // Old code kept for reference : refit the source tree then rebuild !
142 // if(!mSource) return false;
144 // mSource->Refit(&mTB);
146 // return mTree->Build(mSource);