Files
FlaxEngine/Source/Engine/Physics/Colliders/CapsuleCollider.h
Wojtek Figat b4fe3a44aa Merge branch 'rot-colliders' of https://github.com/Tryibion/FlaxEngine into Tryibion-rot-colliders
# Conflicts:
#	Source/Engine/Physics/Colliders/CapsuleCollider.cpp
#	Source/Engine/Physics/Colliders/Collider.cpp
2024-03-04 20:12:32 +01:00

107 lines
3.3 KiB
C++

// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
#pragma once
#include "Collider.h"
#include "Engine/Core/Math/OrientedBoundingBox.h"
/// <summary>
/// The collider orientation direction.
/// </summary>
API_ENUM() enum class ColliderOrientationDirection
{
/// <summary>
/// Orient to the X-Axis.
/// </summary>
XAxis,
/// <summary>
/// Orient to the Y-Axis.
/// </summary>
YAxis,
/// <summary>
/// Orient to the Z-Axis.
/// </summary>
ZAxis
};
/// <summary>
/// A capsule-shaped primitive collider.
/// </summary>
/// <remarks>Capsules are cylinders with a half-sphere at each end centered at the origin and extending along the X axis, and two hemispherical ends.</remarks>
/// <seealso cref="Collider" />
API_CLASS(Attributes="ActorContextMenu(\"New/Physics/Colliders/Capsule Collider\"), ActorToolbox(\"Physics\")")
class FLAXENGINE_API CapsuleCollider : public Collider
{
API_AUTO_SERIALIZATION();
DECLARE_SCENE_OBJECT(CapsuleCollider);
private:
float _radius;
float _height;
OrientedBoundingBox _orientedBox;
ColliderOrientationDirection _direction;
public:
/// <summary>
/// Gets the radius of the sphere, measured in the object's local space.
/// </summary>
/// <remarks>The sphere radius will be scaled by the actor's world scale.</remarks>
API_PROPERTY(Attributes="EditorOrder(100), DefaultValue(20.0f), EditorDisplay(\"Collider\")")
FORCE_INLINE float GetRadius() const
{
return _radius;
}
/// <summary>
/// Sets the radius of the sphere, measured in the object's local space.
/// </summary>
/// <remarks>The sphere radius will be scaled by the actor's world scale. </remarks>
API_PROPERTY() void SetRadius(float value);
/// <summary>
/// Gets the height of the capsule, measured in the object's local space between the centers of the hemispherical ends.
/// </summary>
/// <remarks>The capsule height will be scaled by the actor's world scale.</remarks>
API_PROPERTY(Attributes="EditorOrder(110), DefaultValue(100.0f), EditorDisplay(\"Collider\")")
FORCE_INLINE float GetHeight() const
{
return _height;
}
/// <summary>
/// Sets the height of the capsule, measured in the object's local space between the centers of the hemispherical ends.
/// </summary>
/// <remarks>The capsule height will be scaled by the actor's world scale.</remarks>
API_PROPERTY() void SetHeight(float value);
/// <summary>
/// Gets the orientation direction of the capsule collider.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(111), DefaultValue(typeof(ColliderOrientationDirection), \"YAxis\"), EditorDisplay(\"Collider\")")
FORCE_INLINE ColliderOrientationDirection GetColliderDirection() const
{
return _direction;
}
/// <summary>
/// Sets the orientation direction of the capsule collider.
/// </summary>
API_PROPERTY() void SetColliderDirection(ColliderOrientationDirection value);
public:
// [Collider]
#if USE_EDITOR
void OnDebugDrawSelected() override;
#endif
bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override;
protected:
// [Collider]
void UpdateBounds() override;
void GetGeometry(CollisionShape& collision) override;
#if USE_EDITOR
void DrawPhysicsDebug(RenderView& view) override;
#endif
};