CollisionShape.pkg 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 { return physicsWorld_; }
  55. /// Return shape type.
  56. ShapeType GetShapeType() const { return shapeType_; }
  57. /// Return shape size.
  58. const Vector3& GetSize() const { return size_; }
  59. /// Return offset position.
  60. const Vector3& GetPosition() const { return position_; }
  61. /// Return offset rotation.
  62. const Quaternion& GetRotation() const { return rotation_; }
  63. /// Return collision margin.
  64. float GetMargin() const { return margin_; }
  65. /// Return triangle mesh / convex hull model.
  66. Model* GetModel() const { return model_; }
  67. /// Return model LOD level.
  68. unsigned GetLodLevel() const { return lodLevel_; }
  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. // Properties:
  80. tolua_property__get_set ShapeType shapeType;
  81. tolua_property__get_set const Vector3& size;
  82. tolua_property__get_set const Vector3& position;
  83. tolua_property__get_set const Quaternion& rotation;
  84. tolua_property__get_set float margin;
  85. tolua_property__get_set Model* model;
  86. tolua_property__get_set unsigned lodLevel;
  87. tolua_readonly tolua_property__get_set BoundingBox worldBoundingBox;
  88. };