// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
namespace FlaxEngine
{
partial struct SpringParameters
{
///
/// Constructs a spring.
///
/// Spring strength. Force proportional to the position error.
/// Damping strength. Force proportional to the velocity error.
public SpringParameters(float stiffness, float damping)
{
Stiffness = stiffness;
Damping = damping;
}
}
partial struct LimitLinearRange
{
///
/// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
///
/// The lower distance of the limit. Must be less than upper.
/// The upper distance of the limit. Must be more than lower.
/// Distance from the limit at which it becomes active. Allows the solver to activate earlier than the limit is reached to avoid breaking the limit. Specify -1 for the default.
public LimitLinearRange(float lower, float upper, float contactDist = -1.0f)
{
ContactDist = contactDist;
Restitution = 0.0f;
Spring = new SpringParameters();
Lower = lower;
Upper = upper;
}
///
/// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the restitution parameter and will be pulled back towards the limit by the provided spring.
///
/// The lower distance of the limit. Must be less than upper.
/// The upper distance of the limit. Must be more than lower.
/// The spring that controls how are the bodies pulled back towards the limit when they breach it.
/// Controls how do objects react when the limit is reached, values closer to zero specify non-elastic collision, while those closer to one specify more elastic (i.e bouncy) collision. Must be in [0, 1] range.
public LimitLinearRange(float lower, float upper, SpringParameters spring, float restitution = 0.0f)
{
ContactDist = -1.0f;
Restitution = restitution;
Spring = spring;
Lower = lower;
Upper = upper;
}
}
partial struct LimitLinear
{
///
/// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
///
/// The distance at which the limit becomes active.
/// The distance from the limit at which it becomes active. Allows the solver to activate earlier than the limit is reached to avoid breaking the limit. Specify -1 for the default.
public LimitLinear(float extent, float contactDist = -1.0f)
{
ContactDist = contactDist;
Restitution = 0.0f;
Spring = new SpringParameters();
Extent = extent;
}
///
/// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the restitution parameter and will be pulled back towards the limit by the provided spring.
///
/// The distance at which the limit becomes active.
/// The spring that controls how are the bodies pulled back towards the limit when they breach it.
/// Controls how do objects react when the limit is reached, values closer to zero specify non-elastic collision, while those closer to one specify more elastic (i.e bouncy) collision. Must be in [0, 1] range.
public LimitLinear(float extent, SpringParameters spring, float restitution = 0.0f)
{
ContactDist = -1.0f;
Restitution = restitution;
Spring = spring;
Extent = extent;
}
}
partial struct LimitAngularRange
{
///
/// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
///
/// The lower angle of the limit (in degrees). Must be less than upper.
/// The upper angle of the limit (in degrees). Must be more than lower.
/// Distance from the limit at which it becomes active. Allows the solver to activate earlier than the limit is reached to avoid breaking the limit. Specify -1 for the default.
public LimitAngularRange(float lower, float upper, float contactDist = -1.0f)
{
ContactDist = contactDist;
Restitution = 0.0f;
Spring = new SpringParameters();
Lower = lower;
Upper = upper;
}
///
/// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the restitution parameter and will be pulled back towards the limit by the provided spring.
///
/// The lower angle of the limit. Must be less than upper.
/// The upper angle of the limit. Must be more than lower.
/// The spring that controls how are the bodies pulled back towards the limit when they breach it.
/// Controls how do objects react when the limit is reached, values closer to zero specify non-elastic collision, while those closer to one specify more elastic (i.e bouncy) collision. Must be in [0, 1] range.
public LimitAngularRange(float lower, float upper, SpringParameters spring, float restitution = 0.0f)
{
ContactDist = -1.0f;
Restitution = restitution;
Spring = spring;
Lower = lower;
Upper = upper;
}
}
partial struct LimitConeRange
{
///
/// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
///
/// The Y angle of the cone (in degrees). Movement is constrained between 0 and this angle on the Y axis.
/// The Z angle of the cone (in degrees). Movement is constrained between 0 and this angle on the Z axis.
/// Distance from the limit at which it becomes active. Allows the solver to activate earlier than the limit is reached to avoid breaking the limit. Specify -1 for the default.
public LimitConeRange(float yLimitAngle, float zLimitAngle, float contactDist = -1.0f)
{
ContactDist = contactDist;
Restitution = 0.0f;
Spring = new SpringParameters();
YLimitAngle = yLimitAngle;
ZLimitAngle = zLimitAngle;
}
///
/// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the restitution parameter and will be pulled back towards the limit by the provided spring.
///
/// The Y angle of the cone (in degrees). Movement is constrained between 0 and this angle on the Y axis.
/// The Z angle of the cone (in degrees). Movement is constrained between 0 and this angle on the Z axis.
/// The spring that controls how are the bodies pulled back towards the limit when they breach it.
/// Controls how do objects react when the limit is reached, values closer to zero specify non-elastic collision, while those closer to one specify more elastic (i.e bouncy) collision. Must be in [0, 1] range.
public LimitConeRange(float yLimitAngle, float zLimitAngle, SpringParameters spring, float restitution = 0.0f)
{
ContactDist = -1.0f;
Restitution = restitution;
Spring = spring;
YLimitAngle = yLimitAngle;
ZLimitAngle = zLimitAngle;
}
}
}