CollisionShape.pkg 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. $#include "CollisionShape.h"
  2. /// Collision shape type.
  3. enum ShapeType
  4. {
  5. SHAPE_BOX = 0,
  6. SHAPE_SPHERE,
  7. SHAPE_STATICPLANE,
  8. SHAPE_CYLINDER,
  9. SHAPE_CAPSULE,
  10. SHAPE_CONE,
  11. SHAPE_TRIANGLEMESH,
  12. SHAPE_CONVEXHULL,
  13. SHAPE_TERRAIN
  14. };
  15. /// Physics collision shape component.
  16. class CollisionShape : public Component
  17. {
  18. public:
  19. /// Set as a box.
  20. void SetBox(const Vector3& size, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
  21. /// Set as a sphere.
  22. void SetSphere(float diameter, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
  23. /// Set as a static plane.
  24. void SetStaticPlane(const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
  25. /// Set as a cylinder.
  26. void SetCylinder(float diameter, float height, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
  27. /// Set as a capsule.
  28. void SetCapsule(float diameter, float height, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
  29. /// Set as a cone.
  30. void SetCone(float diameter, float height, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
  31. /// Set as a triangle mesh.
  32. void SetTriangleMesh(Model* model, unsigned lodLevel = 0, const Vector3& scale = Vector3::ONE, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
  33. /// Set as a convex hull from Model.
  34. void SetConvexHull(Model* model, unsigned lodLevel = 0, const Vector3& scale = Vector3::ONE, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
  35. /// Set as a terrain. Only works if the same scene node contains a Terrain component.
  36. void SetTerrain();
  37. /// Set shape type.
  38. void SetShapeType(ShapeType type);
  39. /// Set shape size.
  40. void SetSize(const Vector3& size);
  41. /// Set offset position.
  42. void SetPosition(const Vector3& position);
  43. /// Set offset rotation.
  44. void SetRotation(const Quaternion& rotation);
  45. /// Set offset transform.
  46. void SetTransform(const Vector3& position, const Quaternion& rotation);
  47. /// Set collision margin.
  48. void SetMargin(float margin);
  49. /// Set triangle mesh / convex hull model.
  50. void SetModel(Model* model);
  51. /// Set model LOD level.
  52. void SetLodLevel(unsigned lodLevel);
  53. /// Return physics world.
  54. PhysicsWorld* GetPhysicsWorld() const;
  55. /// Return shape type.
  56. ShapeType GetShapeType() const;
  57. /// Return shape size.
  58. const Vector3& GetSize() const;
  59. /// Return offset position.
  60. const Vector3& GetPosition() const;
  61. /// Return offset rotation.
  62. const Quaternion& GetRotation() const;
  63. /// Return collision margin.
  64. float GetMargin() const;
  65. /// Return triangle mesh / convex hull model.
  66. Model* GetModel() const;
  67. /// Return model LOD level.
  68. unsigned GetLodLevel() const;
  69. /// Return world-space bounding box.
  70. BoundingBox GetWorldBoundingBox() const;
  71. /// Update the new collision shape to the RigidBody.
  72. void NotifyRigidBody(bool updateMass = true);
  73. /// Set model attribute.
  74. void SetModelAttr(ResourceRef value);
  75. /// Return model attribute.
  76. ResourceRef GetModelAttr() const;
  77. /// Release the collision shape.
  78. void ReleaseShape();
  79. };