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 code for hybrid models. 12 * \file OPC_HybridModel.h 13 * \author Pierre Terdiman 14 * \date May, 18, 2003 15 */ 16 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 18 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 19 // Include Guard 20 #ifndef __OPC_HYBRIDMODEL_H__ 21 #define __OPC_HYBRIDMODEL_H__ 22 23 //! Leaf descriptor 24 struct LeafTriangles 25 { 26 udword Data; //!< Packed data 27 28 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 29 /** 30 * Gets number of triangles in the leaf. 31 * \return number of triangles N, with 0 < N <= 16 32 */ 33 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// GetNbTrianglesLeafTriangles34 inline_ udword GetNbTriangles() const { return (Data & 15)+1; } 35 36 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 37 /** 38 * Gets triangle index for this leaf. Indexed model's array of indices retrieved with HybridModel::GetIndices() 39 * \return triangle index 40 */ 41 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// GetTriangleIndexLeafTriangles42 inline_ udword GetTriangleIndex() const { return Data>>4; } SetDataLeafTriangles43 inline_ void SetData(udword nb, udword index) { ASSERT(nb>0 && nb<=16); nb--; Data = (index<<4)|(nb&15); } 44 }; 45 46 class OPCODE_API HybridModel : public BaseModel 47 { 48 public: 49 // Constructor/Destructor 50 HybridModel(); 51 virtual ~HybridModel(); 52 53 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 54 /** 55 * Builds a collision model. 56 * \param create [in] model creation structure 57 * \return true if success 58 */ 59 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 60 override(BaseModel) bool Build(const OPCODECREATE& create); 61 62 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 63 /** 64 * Gets the number of bytes used by the tree. 65 * \return amount of bytes used 66 */ 67 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 68 override(BaseModel) udword GetUsedBytes() const; 69 70 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 71 /** 72 * Refits the collision model. This can be used to handle dynamic meshes. Usage is: 73 * 1. modify your mesh vertices (keep the topology constant!) 74 * 2. refit the tree (call this method) 75 * \return true if success 76 */ 77 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 78 override(BaseModel) bool Refit(); 79 80 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 81 /** 82 * Gets array of triangles. 83 * \return array of triangles 84 */ 85 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// GetLeafTriangles()86 inline_ const LeafTriangles* GetLeafTriangles() const { return mTriangles; } 87 88 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 89 /** 90 * Gets array of indices. 91 * \return array of indices 92 */ 93 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// GetIndices()94 inline_ const udword* GetIndices() const { return mIndices; } 95 96 private: 97 udword mNbLeaves; //!< Number of leaf nodes in the model 98 LeafTriangles* mTriangles; //!< Array of mNbLeaves leaf descriptors 99 udword mNbPrimitives; //!< Number of primitives in the model 100 udword* mIndices; //!< Array of primitive indices 101 102 // Internal methods 103 void Release(); 104 }; 105 106 #endif // __OPC_HYBRIDMODEL_H__ 107