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.h
13
* \author Pierre Terdiman
16
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20
#ifndef __OPC_BASEMODEL_H__
21
#define __OPC_BASEMODEL_H__
23
//! Model creation structure
24
struct OPCODE_API OPCODECREATE
29
MeshInterface* mIMesh; //!< Mesh interface (access to triangles & vertices) (*)
30
BuildSettings mSettings; //!< Builder's settings
31
bool mNoLeaf; //!< true => discard leaf nodes (else use a normal tree)
32
bool mQuantized; //!< true => quantize the tree (else use a normal tree)
33
#ifdef __MESHMERIZER_H__
34
bool mCollisionHull; //!< true => use convex hull + GJK
35
#endif // __MESHMERIZER_H__
36
bool mKeepOriginal; //!< true => keep a copy of the original tree (debug purpose)
37
bool mCanRemap; //!< true => allows OPCODE to reorganize client arrays
39
// (*) This pointer is saved internally and used by OPCODE until collision structures are released,
40
// so beware of the object's lifetime.
45
OPC_QUANTIZED = (1<<0), //!< Compressed/uncompressed tree
46
OPC_NO_LEAF = (1<<1), //!< Leaf/NoLeaf tree
47
OPC_SINGLE_NODE = (1<<2) //!< Special case for 1-node models
50
class OPCODE_API BaseModel
53
// Constructor/Destructor
57
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
59
* Builds a collision model.
60
* \param create [in] model creation structure
61
* \return true if success
63
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
64
virtual bool Build(const OPCODECREATE& create) = 0;
66
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
68
* Gets the number of bytes used by the tree.
69
* \return amount of bytes used
71
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
72
virtual udword GetUsedBytes() const = 0;
74
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76
* Refits the collision model. This can be used to handle dynamic meshes. Usage is:
77
* 1. modify your mesh vertices (keep the topology constant!)
78
* 2. refit the tree (call this method)
79
* \return true if success
81
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86
* Gets the source tree.
87
* \return generic tree
89
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90
inline_ const AABBTree* GetSourceTree() const { return mSource; }
92
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
95
* \return the collision tree
97
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
98
inline_ const AABBOptimizedTree* GetTree() const { return mTree; }
100
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103
* \return the collision tree
105
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
106
inline_ AABBOptimizedTree* GetTree() { return mTree; }
108
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110
* Gets the number of nodes in the tree.
111
* Should be 2*N-1 for normal trees and N-1 for optimized ones.
112
* \return number of nodes
114
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
115
inline_ udword GetNbNodes() const { return mTree->GetNbNodes(); }
117
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
119
* Checks whether the tree has leaf nodes or not.
120
* \return true if the tree has leaf nodes (normal tree), else false (optimized tree)
122
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
123
inline_ BOOL HasLeafNodes() const { return !(mModelCode & OPC_NO_LEAF); }
125
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
127
* Checks whether the tree is quantized or not.
128
* \return true if the tree is quantized
130
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
131
inline_ BOOL IsQuantized() const { return mModelCode & OPC_QUANTIZED; }
133
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
135
* Checks whether the model has a single node or not. This special case must be handled separately.
136
* \return true if the model has only 1 node
138
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
139
inline_ BOOL HasSingleNode() const { return mModelCode & OPC_SINGLE_NODE; }
141
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
143
* Gets the model's code.
144
* \return model's code
146
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
147
inline_ udword GetModelCode() const { return mModelCode; }
149
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
151
* Gets the mesh interface.
152
* \return mesh interface
154
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
155
inline_ const MeshInterface* GetMeshInterface() const { return mIMesh; }
157
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
159
* Sets the mesh interface.
160
* \param imesh [in] mesh interface
162
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
163
inline_ void SetMeshInterface(const MeshInterface* imesh) { mIMesh = imesh; }
166
const MeshInterface* mIMesh; //!< User-defined mesh interface
167
udword mModelCode; //!< Model code = combination of ModelFlag(s)
168
AABBTree* mSource; //!< Original source tree
169
AABBOptimizedTree* mTree; //!< Optimized tree owned by the model
172
bool CreateTree(bool no_leaf, bool quantized);
175
#endif //__OPC_BASEMODEL_H__