Debian Codegraph @

source/unix/odesrc/OPCODE/OPC_BaseModel.h

raw
1 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 /*
3 * OPCODE - Optimized Collision Detection
4 * Copyright (C) 2001 Pierre Terdiman
5 * Homepage: http://www.codercorner.com/Opcode.htm
6 */
7 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8
9 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10 /**
11 * Contains base model interface.
12 * \file OPC_BaseModel.h
13 * \author Pierre Terdiman
14 * \date May, 18, 2003
15 */
16 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
17
18 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19 // Include Guard
20 #ifndef __OPC_BASEMODEL_H__
21 #define __OPC_BASEMODEL_H__
22
23 //! Model creation structure
24 struct OPCODE_API OPCODECREATE
25 {
26 //! Constructor
27 inline_ OPCODECREATE():
28 mIMesh(null),
29 mSettings(SPLIT_SPLATTER_POINTS | SPLIT_GEOM_CENTER),
30 mNoLeaf(true),
31 mQuantized(true),
32 #ifdef __MESHMERIZER_H__
33 mCollisionHull(false),
34 #endif // __MESHMERIZER_H__
35 mKeepOriginal(false),
36 mCanRemap(false)
37 {
38 }
39
40 inline_ OPCODECREATE(MeshInterface *IMesh, const BuildSettings &Settings, bool NoLeaf, bool Quantized):
41 mIMesh(IMesh),
42 mSettings(Settings),
43 mNoLeaf(NoLeaf),
44 mQuantized(Quantized),
45 #ifdef __MESHMERIZER_H__
46 mCollisionHull(false),
47 #endif // __MESHMERIZER_H__
48 mKeepOriginal(false),
49 mCanRemap(false)
50 {
51 }
52
53 MeshInterface* mIMesh; //!< Mesh interface (access to triangles & vertices) (*)
54 BuildSettings mSettings; //!< Builder's settings
55 bool mNoLeaf; //!< true => discard leaf nodes (else use a normal tree)
56 bool mQuantized; //!< true => quantize the tree (else use a normal tree)
57 #ifdef __MESHMERIZER_H__
58 bool mCollisionHull; //!< true => use convex hull + GJK
59 #endif // __MESHMERIZER_H__
60 bool mKeepOriginal; //!< true => keep a copy of the original tree (debug purpose)
61 bool mCanRemap; //!< true => allows OPCODE to reorganize client arrays
62
63 // (*) This pointer is saved internally and used by OPCODE until collision structures are released,
64 // so beware of the object's lifetime.
65 };
66
67 enum ModelFlag
68 {
69 OPC_QUANTIZED = (1<<0), //!< Compressed/uncompressed tree
70 OPC_NO_LEAF = (1<<1), //!< Leaf/NoLeaf tree
71 OPC_SINGLE_NODE = (1<<2) //!< Special case for 1-node models
72 };
73
74 class OPCODE_API BaseModel
75 {
76 public:
77 // Constructor/Destructor
78 BaseModel();
79 virtual ~BaseModel();
80
81 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82 /**
83 * Builds a collision model.
84 * \param create [in] model creation structure
85 * \return true if success
86 */
87 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88 virtual bool Build(const OPCODECREATE& create) = 0;
89
90 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
91 /**
92 * Gets the number of bytes used by the tree.
93 * \return amount of bytes used
94 */
95 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
96 virtual udword GetUsedBytes() const = 0;
97
98 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
99 /**
100 * Refits the collision model. This can be used to handle dynamic meshes. Usage is:
101 * 1. modify your mesh vertices (keep the topology constant!)
102 * 2. refit the tree (call this method)
103 * \return true if success
104 */
105 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
106 virtual bool Refit();
107
108 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
109 /**
110 * Gets the source tree.
111 * \return generic tree
112 */
113 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
114 inline_ const AABBTree* GetSourceTree() const { return mSource; }
115
116 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117 /**
118 * Gets the tree.
119 * \return the collision tree
120 */
121 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
122 inline_ const AABBOptimizedTree* GetTree() const { return mTree; }
123
124 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
125 /**
126 * Gets the tree.
127 * \return the collision tree
128 */
129 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
130 inline_ AABBOptimizedTree* GetTree() { return mTree; }
131
132 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
133 /**
134 * Gets the number of nodes in the tree.
135 * Should be 2*N-1 for normal trees and N-1 for optimized ones.
136 * \return number of nodes
137 */
138 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
139 inline_ udword GetNbNodes() const { return mTree->GetNbNodes(); }
140
141 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
142 /**
143 * Checks whether the tree has leaf nodes or not.
144 * \return true if the tree has leaf nodes (normal tree), else false (optimized tree)
145 */
146 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
147 inline_ BOOL HasLeafNodes() const { return !(mModelCode & OPC_NO_LEAF); }
148
149 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
150 /**
151 * Checks whether the tree is quantized or not.
152 * \return true if the tree is quantized
153 */
154 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
155 inline_ BOOL IsQuantized() const { return mModelCode & OPC_QUANTIZED; }
156
157 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
158 /**
159 * Checks whether the model has a single node or not. This special case must be handled separately.
160 * \return true if the model has only 1 node
161 */
162 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
163 inline_ BOOL HasSingleNode() const { return mModelCode & OPC_SINGLE_NODE; }
164
165 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
166 /**
167 * Gets the model's code.
168 * \return model's code
169 */
170 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
171 inline_ udword GetModelCode() const { return mModelCode; }
172
173 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
174 /**
175 * Gets the mesh interface.
176 * \return mesh interface
177 */
178 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
179 inline_ const MeshInterface* GetMeshInterface() const { return mIMesh; }
180
181 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
182 /**
183 * Sets the mesh interface.
184 * \param imesh [in] mesh interface
185 */
186 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
187 inline_ void SetMeshInterface(const MeshInterface* imesh) { mIMesh = imesh; }
188
189 protected:
190 const MeshInterface* mIMesh; //!< User-defined mesh interface
191 udword mModelCode; //!< Model code = combination of ModelFlag(s)
192 AABBTree* mSource; //!< Original source tree
193 AABBOptimizedTree* mTree; //!< Optimized tree owned by the model
194 // Internal methods
195 void ReleaseBase();
196 bool CreateTree(bool no_leaf, bool quantized);
197 };
198
199 #endif //__OPC_BASEMODEL_H__