Exemplo n.º 1
0
 /// <summary>
 /// Align the object with the spline. Transforms object so that its origin is on the spline.
 /// </summary>
 /// <returns></returns>
 public static void AlignToSpline(
     Mesh mesh,
     Vector3 axis, 
     Vector3 splineRotationAxis,
     Gem.Math.Spline spline,
     float distance)
 {
     Morph(mesh, (v) =>
         {
             var splinePoint = spline.Point(distance);
             var splineTangent = spline.Tangent(distance);
             var m = Matrix.CreateFromAxisAngle(Vector3.Normalize(splineRotationAxis),
                 Gem.Math.Vector.AngleBetweenVectors(axis, splineTangent));
             return splinePoint + Vector3.Transform(v, m);
         });
 }
Exemplo n.º 2
0
        /// <summary>
        /// Morph the object onto a spline. Expects the object's origin to already be aligned with the spline.
        /// </summary>
        /// <returns></returns>
        public static void MorphToSpline(
            Mesh mesh,
            Vector3 axis, 
            Gem.Math.Spline spline)
        {
            Morph(mesh, (v) =>
                {
                    var distance = Gem.Math.Vector.ProjectAOntoB(v, axis).Length() / axis.Length();
                    var splinePoint = spline.Point(distance);
                    var splineTangent = spline.Tangent(distance);
                    var rel = (axis * distance) - v;
                    var m = Matrix.CreateFromAxisAngle(Vector3.Normalize(spline.RotationAxis),//splineRotationAxis),
                        Gem.Math.Vector.AngleBetweenVectors(axis, splineTangent));

                    return splinePoint + Vector3.Transform(rel, m);
                });
        }