// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #include "Collider.h" #include "Engine/Core/Math/OrientedBoundingBox.h" /// /// A capsule-shaped primitive collider. /// /// Capsules are cylinders with a half-sphere at each end centered at the origin and extending along the X axis, and two hemispherical ends. /// API_CLASS(Attributes="ActorContextMenu(\"New/Physics/Colliders/Capsule Collider\"), ActorToolbox(\"Physics\")") class FLAXENGINE_API CapsuleCollider : public Collider { DECLARE_SCENE_OBJECT(CapsuleCollider); private: float _radius; float _height; OrientedBoundingBox _orientedBox; public: /// /// Gets the radius of the sphere, measured in the object's local space. /// /// The sphere radius will be scaled by the actor's world scale. API_PROPERTY(Attributes="EditorOrder(100), DefaultValue(20.0f), EditorDisplay(\"Collider\")") FORCE_INLINE float GetRadius() const { return _radius; } /// /// Sets the radius of the sphere, measured in the object's local space. /// /// The sphere radius will be scaled by the actor's world scale. API_PROPERTY() void SetRadius(float value); /// /// Gets the height of the capsule, measured in the object's local space between the centers of the hemispherical ends. /// /// The capsule height will be scaled by the actor's world scale. API_PROPERTY(Attributes="EditorOrder(110), DefaultValue(100.0f), EditorDisplay(\"Collider\")") FORCE_INLINE float GetHeight() const { return _height; } /// /// Sets the height of the capsule, measured in the object's local space between the centers of the hemispherical ends. /// /// The capsule height will be scaled by the actor's world scale. API_PROPERTY() void SetHeight(float value); public: // [Collider] #if USE_EDITOR void OnDebugDrawSelected() override; #endif bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override; void Serialize(SerializeStream& stream, const void* otherObj) override; void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override; protected: // [Collider] void UpdateBounds() override; void GetGeometry(CollisionShape& collision) override; #if USE_EDITOR void DrawPhysicsDebug(RenderView& view) override; #endif };