Add more utilities for Spline
This commit is contained in:
@@ -106,16 +106,29 @@ Vector3 Spline::GetSplineLocalPoint(int32 index) const
|
||||
|
||||
Transform Spline::GetSplineTransform(int32 index) const
|
||||
{
|
||||
CHECK_RETURN(index >= 0 && index < GetSplinePointsCount(), Vector3::Zero)
|
||||
CHECK_RETURN(index >= 0 && index < GetSplinePointsCount(), Transform::Identity)
|
||||
return _transform.LocalToWorld(Curve[index].Value);
|
||||
}
|
||||
|
||||
Transform Spline::GetSplineLocalTransform(int32 index) const
|
||||
{
|
||||
CHECK_RETURN(index >= 0 && index < GetSplinePointsCount(), Vector3::Zero)
|
||||
CHECK_RETURN(index >= 0 && index < GetSplinePointsCount(), Transform::Identity)
|
||||
return Curve[index].Value;
|
||||
}
|
||||
|
||||
Transform Spline::GetSplineTangent(int32 index, bool isIn)
|
||||
{
|
||||
return _transform.LocalToWorld(GetSplineLocalTangent(index, isIn));
|
||||
}
|
||||
|
||||
Transform Spline::GetSplineLocalTangent(int32 index, bool isIn)
|
||||
{
|
||||
CHECK_RETURN(index >= 0 && index < GetSplinePointsCount(), Transform::Identity)
|
||||
const auto& k = Curve[index];
|
||||
const auto& tangent = isIn ? k.TangentIn : k.TangentOut;
|
||||
return tangent + k.Value;
|
||||
}
|
||||
|
||||
int32 Spline::GetSplinePointsCount() const
|
||||
{
|
||||
return Curve.GetKeyframes().Count();
|
||||
@@ -263,6 +276,29 @@ void Spline::SetSplineLocalTransform(int32 index, const Transform& point, bool u
|
||||
UpdateSpline();
|
||||
}
|
||||
|
||||
void Spline::SetSplineTangent(int32 index, const Transform& point, bool isIn, bool updateSpline)
|
||||
{
|
||||
SetSplineLocalTangent(index, _transform.WorldToLocal(point), isIn, updateSpline);
|
||||
}
|
||||
|
||||
void Spline::SetSplineLocalTangent(int32 index, const Transform& point, bool isIn, bool updateSpline)
|
||||
{
|
||||
CHECK(index >= 0 && index < GetSplinePointsCount());
|
||||
auto& k = Curve[index];
|
||||
auto& tangent = isIn ? k.TangentIn : k.TangentOut;
|
||||
tangent = point - k.Value;
|
||||
if (updateSpline)
|
||||
UpdateSpline();
|
||||
}
|
||||
|
||||
void Spline::SetSplinePointTime(int32 index, float time, bool updateSpline)
|
||||
{
|
||||
CHECK(index >= 0 && index < GetSplinePointsCount());
|
||||
Curve[index].Time = time;
|
||||
if (updateSpline)
|
||||
UpdateSpline();
|
||||
}
|
||||
|
||||
void Spline::AddSplinePoint(const Vector3& point, bool updateSpline)
|
||||
{
|
||||
const Keyframe k(Curve.IsEmpty() ? 0.0f : Curve.GetKeyframes().Last().Time + 1.0f, Transform(_transform.WorldToLocal(point)));
|
||||
|
||||
@@ -138,6 +138,24 @@ public:
|
||||
/// <returns>The curve point transformation (local-space).</returns>
|
||||
API_FUNCTION() Transform GetSplineLocalTransform(int32 index) const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the spline curve point tangent at the given index (world-space).
|
||||
/// </summary>
|
||||
/// <remarks>Tangents are stored relative to the curve point but this methods converts them to be in world-space.</remarks>
|
||||
/// <param name="index">The curve keyframe index. Zero-based, smaller than GetSplinePointsCount().</param>
|
||||
/// <param name="isIn">True if get arrive tangent, otherwise gets leave tangent (in or out).</param>
|
||||
/// <returns>The transformation of the tangent to set (world-space).</returns>
|
||||
API_FUNCTION() Transform GetSplineTangent(int32 index, bool isIn);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the spline curve point tangent at the given index (local-space).
|
||||
/// </summary>
|
||||
/// <remarks>Tangents are stored relative to the curve point but this methods converts them to be in local-space of the actor.</remarks>
|
||||
/// <param name="index">The curve keyframe index. Zero-based, smaller than GetSplinePointsCount().</param>
|
||||
/// <param name="isIn">True if get arrive tangent, otherwise gets leave tangent (in or out).</param>
|
||||
/// <returns>The transformation of the tangent to set (world-space).</returns>
|
||||
API_FUNCTION() Transform GetSplineLocalTangent(int32 index, bool isIn);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount of points in the spline.
|
||||
/// </summary>
|
||||
@@ -218,7 +236,7 @@ public:
|
||||
/// Sets the spline curve at the given index (world-space).
|
||||
/// </summary>
|
||||
/// <param name="index">The curve keyframe index. Zero-based, smaller than GetSplinePointsCount().</param>
|
||||
/// <param name="point">The location of the point to set (world-space).</param>
|
||||
/// <param name="point">The transformation of the point to set (world-space).</param>
|
||||
/// <param name="updateSpline">True if update spline after adding the point, otherwise false.</param>
|
||||
API_FUNCTION() void SetSplineTransform(int32 index, const Transform& point, bool updateSpline = true);
|
||||
|
||||
@@ -226,10 +244,38 @@ public:
|
||||
/// Sets the spline curve at the given index (local-space).
|
||||
/// </summary>
|
||||
/// <param name="index">The curve keyframe index. Zero-based, smaller than GetSplinePointsCount().</param>
|
||||
/// <param name="point">The location of the point to set (local-space).</param>
|
||||
/// <param name="point">The transformation of the point to set (local-space).</param>
|
||||
/// <param name="updateSpline">True if update spline after adding the point, otherwise false.</param>
|
||||
API_FUNCTION() void SetSplineLocalTransform(int32 index, const Transform& point, bool updateSpline = true);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the spline curve point tangent at the given index (world-space).
|
||||
/// </summary>
|
||||
/// <remarks>Tangents are stored relative to the curve point but this methods converts them to be in world-space.</remarks>
|
||||
/// <param name="index">The curve keyframe index. Zero-based, smaller than GetSplinePointsCount().</param>
|
||||
/// <param name="point">The transformation of the tangent to set (world-space).</param>
|
||||
/// <param name="isIn">True if set arrive tangent, otherwise sets leave tangent (in or out).</param>
|
||||
/// <param name="updateSpline">True if update spline after adding the point, otherwise false.</param>
|
||||
API_FUNCTION() void SetSplineTangent(int32 index, const Transform& point, bool isIn, bool updateSpline = true);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the spline curve point tangent at the given index (local-space).
|
||||
/// </summary>
|
||||
/// <remarks>Tangents are stored relative to the curve point but this methods converts them to be in local-space of the actor.</remarks>
|
||||
/// <param name="index">The curve keyframe index. Zero-based, smaller than GetSplinePointsCount().</param>
|
||||
/// <param name="point">The transformation of the tangent to set (local-space).</param>
|
||||
/// <param name="isIn">True if set arrive tangent, otherwise sets leave tangent (in or out).</param>
|
||||
/// <param name="updateSpline">True if update spline after adding the point, otherwise false.</param>
|
||||
API_FUNCTION() void SetSplineLocalTangent(int32 index, const Transform& point, bool isIn, bool updateSpline = true);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the spline curve point time at the given index (world-space).
|
||||
/// </summary>
|
||||
/// <param name="index">The curve keyframe index. Zero-based, smaller than GetSplinePointsCount().</param>
|
||||
/// <param name="time">The time to set.</param>
|
||||
/// <param name="updateSpline">True if update spline after adding the point, otherwise false.</param>
|
||||
API_FUNCTION() void SetSplinePointTime(int32 index, float time, bool updateSpline = true);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the point to the spline curve (at the end).
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user