Example #1
0
    private Vector3 GetNormalInternal(SegmentParameter sParam)
    {
        SplineNode n0; SplineNode n1;
        SplineNode n2; SplineNode n3;

        splineInterpolator.GetNodeData(splineNodesInternal, sParam.normalizedIndex, AutoClose, out n0, out n1, out n2, out n3);

        Vector3 normal0;
        Vector3 normal1;
        Vector3 normal2;
        Vector3 normal3;

        if (normalMode == NormalMode.UseNodeNormal)
        {
            normal0 = n0.transform.TransformDirection(n0.normal).normalized;
            normal1 = n1.transform.TransformDirection(n1.normal).normalized;
            normal2 = n2.transform.TransformDirection(n2.normal).normalized;
            normal3 = n3.transform.TransformDirection(n3.normal).normalized;
        }
        else
        {
            normal0 = n0.transform.up;
            normal1 = n1.transform.up;
            normal2 = n2.transform.up;
            normal3 = n3.transform.up;
        }

        if (splineInterpolator is HermiteInterpolator)
        {
            HermiteInterpolator hermiteInterpolator = splineInterpolator as HermiteInterpolator;
            hermiteInterpolator.RecalcVectors(this, n0, n1, ref normal2, ref normal3);
        }

        return(splineInterpolator.InterpolateVector(sParam.normalizedParam, normal0, normal1, normal2.normalized, normal3.normalized, 0).normalized);
    }
Example #2
0
    /// <summary>
    /// This function returns a rotation on the spline for a parameter between 0 and 1
    /// </summary>
    /// <returns>
    /// A rotation on the spline..
    /// </returns>
    /// <param name='param'>
    /// A normalized spline parameter ([0..1]).
    /// </param>
    public Quaternion GetOrientationOnSpline(float param)
    {
        if (!HasNodes)
        {
            return(Quaternion.identity);
        }

        switch (rotationMode)
        {
        case RotationMode.Tangent:
            SegmentParameter sParam = RecalculateParameter(param);

            Vector3 tangent = GetTangentInternal(sParam);
            Vector3 normal  = GetNormalInternal(sParam);

            if (tangent.sqrMagnitude == 0f || normal.sqrMagnitude == 0f)
            {
                return(Quaternion.identity);
            }

            return(Quaternion.LookRotation(tangent, normal));

        case RotationMode.Node:
            return(GetRotationInternal(RecalculateParameter(param)));

        default:
            return(Quaternion.identity);
        }
    }
	private Quaternion GetRotationInternal( SegmentParameter sParam )
	{
		Quaternion Q0 = GetNode( sParam.normalizedIndex,-1 ).Transform.rotation;
		Quaternion Q1 = GetNode( sParam.normalizedIndex, 0 ).Transform.rotation;
		Quaternion Q2 = GetNode( sParam.normalizedIndex, 1 ).Transform.rotation;
		Quaternion Q3 = GetNode( sParam.normalizedIndex, 2 ).Transform.rotation;
		
		Quaternion T1 = GetSquadIntermediate( Q0, Q1, Q2 );
		Quaternion T2 = GetSquadIntermediate( Q1, Q2, Q3 );
		
		return GetQuatSquad( sParam.normalizedParam, Q1, Q2, T1, T2 );
	}
	private Vector3 GetPositionInternal( SegmentParameter sParam )
	{
		SplineNode n0;
		SplineNode n1;
		SplineNode n2;
		SplineNode n3;
		
		GetAdjacentNodes( sParam, out n0, out n1, out n2, out n3 );
		
		Vector3 P0 = n0.Position; 
		Vector3 P1 = n1.Position;
		Vector3 P2 = n2.Position; 
		Vector3 P3 = n3.Position;
		
		RecalcVectors( n0, n1, ref P2, ref P3 );
			
		return InterpolatePosition( sParam.normalizedParam, P0, P1, P2, P3 );
	}
	private double GetValueInternal( SegmentParameter sParam )
	{
		SplineNode n0;
		SplineNode n1;
		SplineNode n2;
		SplineNode n3;
		
		GetAdjacentNodes( sParam, out n0, out n1, out n2, out n3 );
		
		double P0 = n0.customValue; 
		double P1 = n1.customValue;
		double P2 = n2.customValue; 
		double P3 = n3.customValue;
		
		RecalcScalars( n0, n1, ref P2, ref P3 );
		
		return InterpolateValue( sParam.normalizedParam, P0, P1, P2, P3 );
	}
	private void GetAdjacentNodes( SegmentParameter sParam, out SplineNode node0, out SplineNode node1, out SplineNode node2, out SplineNode node3 )
	{
		switch( interpolationMode )
		{
		case InterpolationMode.BSpline:
			node0 = GetNode( sParam.normalizedIndex,-1 );
			node1 = GetNode( sParam.normalizedIndex, 0 );
			node2 = GetNode( sParam.normalizedIndex, 1 );
			node3 = GetNode( sParam.normalizedIndex, 2 );
			
			return;
			
		case InterpolationMode.Hermite:
			node0 = GetNode( sParam.normalizedIndex, 0 );
			node1 = GetNode( sParam.normalizedIndex, 1 );
			node2 = GetNode( sParam.normalizedIndex,-1 );
			node3 = GetNode( sParam.normalizedIndex, 2 );
			
			return;
			
		case InterpolationMode.Linear:
		case InterpolationMode.Bezier:
		default:
			node0 = GetNode( sParam.normalizedIndex, 0 );
			node1 = GetNode( sParam.normalizedIndex, 1 );
			node2 = GetNode( sParam.normalizedIndex, 2 );
			node3 = GetNode( sParam.normalizedIndex, 3 );
			
			return;
		}
	}
Example #7
0
 private Quaternion GetRotationInternal(SegmentParameter sParam)
 {
     return(splineInterpolator.InterpolateRotation(this, sParam.normalizedParam, sParam.normalizedIndex, AutoClose, splineNodesInternal, 0));
 }
Example #8
0
 private float GetValueInternal(SegmentParameter sParam)
 {
     return(splineInterpolator.InterpolateValue(this, sParam.normalizedParam, sParam.normalizedIndex, AutoClose, splineNodesInternal, 0));
 }
Example #9
0
 private Vector3 GetCurvatureInternal(SegmentParameter sParam)
 {
     return(splineInterpolator.InterpolateVector(this, sParam.normalizedParam, sParam.normalizedIndex, AutoClose, splineNodesInternal, 2));
 }