private void Create_Click(object sender, EventArgs e) { int check = FieldCheck(); if (check == 0) { string cmd; IAgExecCmdResult result; IAgConversionUtility converter = CommonData.StkRoot.ConversionUtility; string objectPath = CommonData.SelectedObjectClass + "/" + CommonData.SelectedObjectName; int numPoints = Int32.Parse(NumPoints.Text); double startTime = Double.Parse(StartTime.Text); double duration = Double.Parse(Duration.Text); double currentTime; double startDeg = Double.Parse(StartDeg.Text); double stopDeg = Double.Parse(StopDeg.Text); double b = Double.Parse(MinorAxisLength.Text); double a = Double.Parse(MajorAxisLength.Text); double zOffset = Double.Parse(ZOffset.Text); double multiplier = Math.PI / 180; double theta; double rotation1deg = Double.Parse(Rotation1Deg.Text); double rotation2deg = Double.Parse(Rotation2Deg.Text); double x; double y; double z; double[,] rotation1 = new double[3, 3]; double[,] rotation2 = new double[3, 3]; double[,] finalRotation = new double[3, 3]; double[] position = new double[3]; double[] newPosition = new double[3]; int startKey = 1; int key; int error = 0; int error1 = 0; string errorCode = null; string pathName = null; double step = duration / numPoints; string currentTimeStr = null; if (NewPath.Checked) { try { pathName = PathName.Text; startKey = 1; result = CommonData.StkRoot.ExecuteCommand("VO_R * CameraControl GetPaths"); string resultStr = result[0].Replace("\"", ""); string[] pathNames = resultStr.Split(null); foreach (var path in pathNames) { if (path == pathName) { CommonData.StkRoot.ExecuteCommand("VO * CameraControl CameraPath Delete Name \"" + pathName + "\""); } } CommonData.StkRoot.ExecuteCommand("VO * CameraControl CameraPath Add Name \"" + pathName + "\""); CommonData.StkRoot.ExecuteCommand("VO * CameraControl KeyframeProps \"" + pathName + "\" ReferenceAxes \"" + objectPath + " VVLH(CBF) Axes\""); CommonData.StkRoot.ExecuteCommand("VO * CameraControl 3DWindowProps FollowMode off OrientVecEditMode on ActivePath \"" + pathName + "\""); } catch (Exception) { errorCode = errorCode + " 1"; error1++; } } else if (AddToPath.Checked) { try { pathName = AddPathName.Text; //CommonData.StkRoot.ExecuteCommand("VO * CameraControl KeyframeProps \"" + pathName + "\" ReferenceAxes \"" + objectPath + " VVLH(CBF) Axes\""); CommonData.StkRoot.ExecuteCommand("VO * CameraControl 3DWindowProps FollowMode off OrientVecEditMode on ActivePath \"" + pathName + "\""); pathName = AddPathName.Text; result = CommonData.StkRoot.ExecuteCommand("VO_R * CameraControl GetKeyframeData \"" + pathName + "\" Data Time"); string[] separator = new string[] { "\" \"" }; string[] times = result[0].Split(separator, StringSplitOptions.None); startKey = times.Length + 1; currentTimeStr = converter.ConvertDate("EpSec", "UTCG", (startTime + 1).ToString()); CommonData.StkRoot.ExecuteCommand("SetAnimation * CurrentTime \"" + currentTimeStr + "\""); } catch (Exception) { errorCode = errorCode + " 2"; error1++; } } for (int i = 0; i <= numPoints; i++) { try { CommonData.StkRoot.ExecuteCommand("VO * CameraControl Keyframes \"" + pathName + "\" Add"); } catch (Exception) { errorCode = errorCode + " 3"; error1++; } } try { CommonData.StkRoot.ExecuteCommand("VO * CameraControl KeyframeProps \"" + pathName + "\" ReferenceAxes \"" + objectPath + " VVLH(CBF) Axes\""); } catch (Exception) { errorCode = errorCode + " 4"; error1++; } for (int i = 0; i <= numPoints; i++) { theta = startDeg + i * (stopDeg - startDeg) / numPoints; currentTime = startTime + i * (duration / numPoints); currentTimeStr = converter.ConvertDate("EpSec", "UTCG", currentTime.ToString()); x = a * Math.Cos(theta * multiplier); y = b * Math.Sin(theta * multiplier); if (PreRotation.Checked) { z = zOffset; } else { z = 0.0; } position[0] = x; position[1] = y; position[2] = z; if (Rotation1Axis.SelectedIndex != 0) { rotation1 = MatrixFunctions.RotateAbout(Rotation1Axis.SelectedIndex, rotation1deg, "deg"); if (Rotation2Axis.SelectedIndex != 0) { rotation2 = MatrixFunctions.RotateAbout(Rotation2Axis.SelectedIndex, rotation2deg, "deg"); finalRotation = MatrixFunctions.MatrixMultiply(rotation1, rotation2); } else { finalRotation = rotation1; } newPosition = MatrixFunctions.RotateVector(finalRotation, position); if (PostRotation.Checked) { newPosition[2] = newPosition[2] + zOffset; } } else { newPosition[0] = x; newPosition[1] = y; if (PreRotation.Checked) { newPosition[2] = z; } else { newPosition[2] = z + zOffset; } } key = startKey + i; try { cmd = "VO * CameraControl Keyframes \"" + pathName + "\" Modify " + key.ToString() + " Position " + newPosition[0].ToString() + " " + newPosition[1].ToString() + " " + newPosition[2].ToString() + " FieldOfView " + FOVValue.Text + " Time \"" + currentTimeStr + "\""; CommonData.StkRoot.ExecuteCommand(cmd); } catch (Exception) { error++; } } try { CommonData.StkRoot.ExecuteCommand("VO * CameraControl KeyframeProps \"" + pathName + "\" ReferenceAxes \"" + objectPath + " TopoCentric Axes\""); } catch (Exception) { } if (error != 0) { MessageBox.Show("Could not create " + error.ToString() + " keyframes"); } if (error1 != 0) { MessageBox.Show("Error Code(s): " + errorCode); } PopulateCurrentPaths(); } }