| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- $#include "CollisionShape.h"
- /// Collision shape type.
- enum ShapeType
- {
- SHAPE_BOX = 0,
- SHAPE_SPHERE,
- SHAPE_STATICPLANE,
- SHAPE_CYLINDER,
- SHAPE_CAPSULE,
- SHAPE_CONE,
- SHAPE_TRIANGLEMESH,
- SHAPE_CONVEXHULL,
- SHAPE_TERRAIN
- };
- /// Physics collision shape component.
- class CollisionShape : public Component
- {
- public:
- /// Set as a box.
- void SetBox(const Vector3& size, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
- /// Set as a sphere.
- void SetSphere(float diameter, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
- /// Set as a static plane.
- void SetStaticPlane(const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
- /// Set as a cylinder.
- void SetCylinder(float diameter, float height, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
- /// Set as a capsule.
- void SetCapsule(float diameter, float height, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
- /// Set as a cone.
- void SetCone(float diameter, float height, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
- /// Set as a triangle mesh.
- void SetTriangleMesh(Model* model, unsigned lodLevel = 0, const Vector3& scale = Vector3::ONE, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
- /// Set as a convex hull from Model.
- void SetConvexHull(Model* model, unsigned lodLevel = 0, const Vector3& scale = Vector3::ONE, const Vector3& position = Vector3::ZERO, const Quaternion& rotation = Quaternion::IDENTITY);
- /// Set as a terrain. Only works if the same scene node contains a Terrain component.
- void SetTerrain();
- /// Set shape type.
- void SetShapeType(ShapeType type);
- /// Set shape size.
- void SetSize(const Vector3& size);
- /// Set offset position.
- void SetPosition(const Vector3& position);
- /// Set offset rotation.
- void SetRotation(const Quaternion& rotation);
- /// Set offset transform.
- void SetTransform(const Vector3& position, const Quaternion& rotation);
- /// Set collision margin.
- void SetMargin(float margin);
- /// Set triangle mesh / convex hull model.
- void SetModel(Model* model);
- /// Set model LOD level.
- void SetLodLevel(unsigned lodLevel);
-
- /// Return physics world.
- PhysicsWorld* GetPhysicsWorld() const { return physicsWorld_; }
- /// Return shape type.
- ShapeType GetShapeType() const { return shapeType_; }
- /// Return shape size.
- const Vector3& GetSize() const { return size_; }
- /// Return offset position.
- const Vector3& GetPosition() const { return position_; }
- /// Return offset rotation.
- const Quaternion& GetRotation() const { return rotation_; }
- /// Return collision margin.
- float GetMargin() const { return margin_; }
- /// Return triangle mesh / convex hull model.
- Model* GetModel() const { return model_; }
- /// Return model LOD level.
- unsigned GetLodLevel() const { return lodLevel_; }
- /// Return world-space bounding box.
- BoundingBox GetWorldBoundingBox() const;
-
- /// Update the new collision shape to the RigidBody.
- void NotifyRigidBody(bool updateMass = true);
- /// Set model attribute.
- void SetModelAttr(ResourceRef value);
- /// Return model attribute.
- ResourceRef GetModelAttr() const;
- /// Release the collision shape.
- void ReleaseShape();
-
- // Properties:
- tolua_property__get_set ShapeType shapeType;
- tolua_property__get_set const Vector3& size;
- tolua_property__get_set const Vector3& position;
- tolua_property__get_set const Quaternion& rotation;
- tolua_property__get_set float margin;
- tolua_property__get_set Model* model;
- tolua_property__get_set unsigned lodLevel;
- tolua_readonly tolua_property__get_set BoundingBox worldBoundingBox;
- };
- ${
- // Patch for CollisionShape.worldBoundingBox property.
- #define TOLUA_DISABLE_tolua_get_CollisionShape_worldBoundingBox
- #define tolua_get_CollisionShape_worldBoundingBox tolua_PhysicsLuaAPI_CollisionShape_GetWorldBoundingBox00
- $}
|