OPC_HybridModel.h 6.1 KB

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