Comments

jetdv wrote on 12/23/2020, 1:59 PM

This might help get you started:

VideoTrack vidtrack = track as VideoTrack;
TrackMotionKeyframe trackKeyframe = vidtrack.TrackMotion.MotionKeyframes[0];
PositionKeyframeTM(trackKeyframe, CurWidth, CurHeight, vwWidth, vwHeight, ISA);
        public void PositionKeyframeTM(TrackMotionKeyframe keyframe, int cWidth, int cHeight, int vwWidth, int vwHeight, bool ISA)
        {
            int divamt = vwWidth;
            if (vwHeight > vwWidth) divamt = vwHeight;

            keyframe.Width = keyframe.Width / divamt;// ((scrWidth * vwWidth) - cLeft - lOffset);// cLeft;
            keyframe.Height = keyframe.Height / divamt;// ((scrHeight * vwHeight) - cTop - tOffset);//cTop;

            double cLeft = ((keyframe.Width / 2) * (vwWidth - 1) * -1) + keyframe.Width * cWidth;
            double cTop = ((keyframe.Height / 2) * (vwHeight - 1)) + (keyframe.Height * cHeight * -1);

            float lOffset = 0;
            float tOffset = 0;

            keyframe.PositionX = cLeft + lOffset;
            keyframe.PositionY = cTop + tOffset;
        }

Or, very simply, if you're adding a track and immediately adjusting it:

                VideoTrack track = new VideoTrack(trackIndex++);
                vegas.Project.Tracks.Add(track);
                TrackMotionKeyframe mkf = track.TrackMotion.MotionKeyframes[0];
                mkf.Width = trackWidth;
                mkf.Height = trackHeight;
                mkf.PositionX = startX + (x*trackWidth);
                mkf.PositionY = startY - (y*trackHeight);

And here's an example changing the rotation in 3D Track Motion

  var endKeyframe = myTrack3D.TrackMotion.InsertMotionKeyframe(
     new Timecode(picInterval * (i - 1) + moveInterval)
  );
  endKeyframe.Height = endKeyframe.Height * picWidth / endKeyframe.Width;
  endKeyframe.Width = picWidth;
  //generating random rotation it's not different enough from the previos one
  do {
    newRotation = (Math.random() - 0.5) * 2 * maxRotationDegree;
  } while (Math.abs(newRotation - prevRotation) <= minRotationDifference);  
  endKeyframe.OrientationZ = newRotation; 

Hopefully that will help you get started in the right direction.