コード例 #1
0
        //
        // Alternative 1.5. Similar to Alternative 1, but we know the up vector at both the start and end position
        //

        public static InterpolationTransform GetTransform_InterpolateBetweenUpVectors(
            _Curve curve, float t, Vector3 upRefStart, Vector3 upRefEnd)
        {
            //Position on the curve at point t
            Vector3 pos = curve.GetPosition(t);

            //Forward direction (tangent) on the curve at point t
            Vector3 forwardDir = curve.GetTangent(t);

            //Interpolate between the start and end up vector to get an up vector at a t position
            Vector3 interpolatedUpDir = Vector3.Normalize(BezierLinear.GetPosition(upRefStart, upRefEnd, t));

            MyQuaternion orientation = InterpolationTransform.GetOrientation_UpRef(forwardDir, interpolatedUpDir);

            InterpolationTransform trans = new InterpolationTransform(pos, orientation);

            return(trans);
        }
コード例 #2
0
        public static InterpolationTransform GetTransform_UpRef(_Curve curve, float t, Vector3 upRef)
        {
            //Position on the curve at point t
            Vector3 pos = curve.GetPosition(t);

            //Forward direction (tangent) on the curve at point t
            Vector3 forwardDir = curve.GetTangent(t);

            //A simple way to get the other directions is to use LookRotation with just forward dir as parameter
            //Then the up direction will always be the world up direction, and it calculates the right direction
            //This idea is not working for all possible curve orientations
            //MyQuaternion orientation = new MyQuaternion(forwardDir);

            //Your own reference up vector
            MyQuaternion orientation = InterpolationTransform.GetOrientation_UpRef(forwardDir, upRef);

            InterpolationTransform trans = new InterpolationTransform(pos, orientation);

            return(trans);
        }
コード例 #3
0
        //Not defined for a single point, you always need a previous transform
        //public static InterpolationTransform InterpolationTransform GetTransform_RotationMinimisingFrame()
        //{

        //}


        public static List <InterpolationTransform> GetTransforms_RotationMinimisingFrame(_Curve curve, List <float> tValues, Vector3 upRef)
        {
            List <InterpolationTransform> transforms = new List <InterpolationTransform>();

            for (int i = 0; i < tValues.Count; i++)
            {
                float t = tValues[i];

                //Position on the curve at point t
                Vector3 position = curve.GetPosition(t);

                //Forward direction (tangent) on the curve at point t
                Vector3 tangent = curve.GetTangent(t);

                //At first pos we dont have a previous transform
                if (i == 0)
                {
                    //Just use one of the other algorithms available to generate a transform at a single position
                    MyQuaternion orientation = InterpolationTransform.GetOrientation_UpRef(tangent, upRef);

                    InterpolationTransform transform = new InterpolationTransform(position, orientation);

                    transforms.Add(transform);
                }
                else
                {
                    //To calculate the orientation for this point, we need data from the previous point on the curve
                    InterpolationTransform previousTransform = transforms[i - 1];

                    MyQuaternion orientation = InterpolationTransform.GetOrientation_RotationFrame(position, tangent, previousTransform);

                    InterpolationTransform transform = new InterpolationTransform(position, orientation);

                    transforms.Add(transform);
                }
            }

            return(transforms);
        }