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 code for hybrid models.
21 * \file OPC_HybridModel.h
22 * \author Pierre Terdiman
25 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
29 #ifndef __OPC_HYBRIDMODEL_H__
30 #define __OPC_HYBRIDMODEL_H__
35 udword Data; //!< Packed data
37 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
39 * Gets number of triangles in the leaf.
40 * \return number of triangles N, with 0 < N <= 16
42 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
43 inline_ udword GetNbTriangles() const { return (Data & 15)+1; }
45 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
47 * Gets triangle index for this leaf. Indexed model's array of indices retrieved with HybridModel::GetIndices()
48 * \return triangle index
50 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
51 inline_ udword GetTriangleIndex() const { return Data>>4; }
52 inline_ void SetData(udword nb, udword index) { ASSERT(nb>0 && nb<=16); nb--; Data = (index<<4)|(nb&15); }
55 class OPCODE_API HybridModel : public BaseModel
58 // Constructor/Destructor
60 virtual ~HybridModel();
62 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
64 * Builds a collision model.
65 * \param create [in] model creation structure
66 * \return true if success
68 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
69 override(BaseModel) bool Build(const OPCODECREATE& create);
71 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
73 * Gets the number of bytes used by the tree.
74 * \return amount of bytes used
76 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77 override(BaseModel) udword GetUsedBytes() const;
79 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
81 * Refits the collision model. This can be used to handle dynamic meshes. Usage is:
82 * 1. modify your mesh vertices (keep the topology constant!)
83 * 2. refit the tree (call this method)
84 * \return true if success
86 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87 override(BaseModel) bool Refit();
89 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
91 * Gets array of triangles.
92 * \return array of triangles
94 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
95 inline_ const LeafTriangles* GetLeafTriangles() const { return mTriangles; }
97 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
99 * Gets array of indices.
100 * \return array of indices
102 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103 inline_ const udword* GetIndices() const { return mIndices; }
106 udword mNbLeaves; //!< Number of leaf nodes in the model
107 LeafTriangles* mTriangles; //!< Array of mNbLeaves leaf descriptors
108 udword mNbPrimitives; //!< Number of primitives in the model
109 udword* mIndices; //!< Array of primitive indices
115 #endif // __OPC_HYBRIDMODEL_H__