private void RecreateLineGeometry(IElement elem, IAGAnimationTrack pTrack, IAGKeyframe pKeyframe, IPoint new_pos)
        {
            IGeometry        newGeometry = new PolylineClass();
            IPointCollection newPointCol = (IPointCollection)newGeometry;

            IAGAnimationTrackKeyframes trackKeyframes = (IAGAnimationTrackKeyframes)pTrack;
            int    tCount  = trackKeyframes.KeyframeCount;
            object missing = Type.Missing;

            for (int i = 0; i < tCount; i++)
            {
                IAGKeyframe tempKeyframe = trackKeyframes.get_Keyframe(i);
                newPointCol.AddPoint((IPoint)tempKeyframe.get_PropertyValue(0), ref missing, ref missing);
                if ((IPoint)tempKeyframe.get_PropertyValue(0) == (IPoint)pKeyframe.get_PropertyValue(0))
                {
                    break;
                }
            }
            if (new_pos != null)
            {
                newPointCol.AddPoint(new_pos, ref missing, ref missing);
            }

            elem.Geometry = newGeometry;
        }
Exemplo n.º 2
0
        //function for creating specified number of graphics between keyframe positions
        public void generatePathBtwnKFrames()
        {
            int numPtsBtwnKFrames = 0;

            //this is the from point for the lines connecting the interpolated point graphics
            IPoint  previousPt   = new PointClass();
            IZAware prevPtZAware = (IZAware)previousPt;

            prevPtZAware.ZAware = true;
            previousPt.PutCoords(0, 0);

            //this is the line connecting the interpolated camera positions
            IPolyline connectingLine = new PolylineClass();
            IZAware   lineZAware     = (IZAware)connectingLine;

            lineZAware.ZAware = true;

            if (theCamForm.ptsBtwnKframeTextBox.Text != "")
            {
                numPtsBtwnKFrames = Convert.ToInt32(theCamForm.ptsBtwnKframeTextBox.Text);
            }
            else
            {
                MessageBox.Show("Please enter the number of points to be created");
                return;
            }
            theCamForm.playButton.Enabled         = false;
            theCamForm.stopButton.Enabled         = false;
            theCamForm.generatePathButton.Enabled = false;

            addGraphicLayer();

            string selectedTrack = theCamForm.animTracksListBox.SelectedItem.ToString();

            animationTracks.FindTrack(selectedTrack, out animationTrack);

            IAGAnimationTrackKeyframes kFrames = (IAGAnimationTrackKeyframes)animationTrack;

            int kFrameCount = kFrames.KeyframeCount;

            //loop over the keyframes in the selected camera track
            for (int i = 0; i < kFrameCount; i++)
            {
                IAGKeyframe currentKeyframe = kFrames.get_Keyframe(i);
                IAGKeyframe prevKeyframe;
                IAGKeyframe nextKeyframe;
                IAGKeyframe afterNextKeyframe;

                //if else statements to determine the keyframe arguments to the interpolate method
                //this is needed because the first and the last keyframes should be handled differently
                //than the middle keyframes
                if (i > 0)
                {
                    prevKeyframe = kFrames.get_Keyframe(i - 1);
                }

                else
                {
                    prevKeyframe = kFrames.get_Keyframe(i);
                }

                if (i < kFrameCount - 1)
                {
                    nextKeyframe = kFrames.get_Keyframe(i + 1);
                }
                else
                {
                    nextKeyframe = kFrames.get_Keyframe(i);
                }

                if (i < kFrameCount - 2)
                {
                    afterNextKeyframe = kFrames.get_Keyframe(i + 2);
                }
                else
                {
                    //this should be equal to the nextKeyFrame for the last keyframe
                    afterNextKeyframe = nextKeyframe;//kFrames.get_Keyframe(i);
                }

                double origCamLat, origCamLong, origCamAlt;
                double interLat, interLong, interAlt;
                double tarLat, tarLong, tarAlt;
                double interTarLat, interTarLong, interTarAlt;

                globeCamera.GetObserverLatLonAlt(out origCamLat, out origCamLong, out origCamAlt);
                globeCamera.GetTargetLatLonAlt(out tarLat, out tarLong, out tarAlt);


                IAGAnimationContainer pAnimContainer = animationTracks.AnimationObjectContainer;

                object objToInterpolate = (object)globeCamera;

                double timeDiff = nextKeyframe.TimeStamp - currentKeyframe.TimeStamp;

                //interpolate positions between keyframes and draw the graphics
                for (int j = 0; j < numPtsBtwnKFrames + 1; j++)
                {
                    double timeToInterpolate = currentKeyframe.TimeStamp + j * (timeDiff / (numPtsBtwnKFrames + 1));

                    //for 0 to n-1 keyframes
                    if (i >= 0 & i < kFrameCount - 1)
                    {
                        currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 4, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe);
                        currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 5, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe);
                        currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 6, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe);
                        currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 1, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe);
                        currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 2, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe);
                        currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 3, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe);

                        globeCamera.GetObserverLatLonAlt(out interLat, out interLong, out interAlt);
                        globeCamera.GetTargetLatLonAlt(out interTarLat, out interTarLong, out interTarAlt);

                        globeCamera.SetObserverLatLonAlt(origCamLat, origCamLong, origCamAlt);
                        globeCamera.SetTargetLatLonAlt(tarLat, tarLong, tarAlt);

                        IPoint  pObs      = new PointClass();
                        IZAware obsZAware = (IZAware)pObs;
                        obsZAware.ZAware = true;
                        pObs.X           = interLong;
                        pObs.Y           = interLat;
                        pObs.Z           = interAlt * 1000;

                        double symbolSize = 10000;

                        if (pObs.Z >= 10000)
                        {
                            symbolSize = 10000 + pObs.Z / 10;
                        }
                        else
                        {
                            symbolSize = pObs.Z;
                        }

                        if (j == 0)
                        {
                            addPointGraphicElements(pObs, 2552550, symbolSize);
                        }
                        else
                        {
                            addPointGraphicElements(pObs, 16732415, symbolSize);
                        }

                        connectingLine.FromPoint = previousPt;
                        connectingLine.ToPoint   = pObs;

                        if (i == 0 & j == 0)
                        {
                        }
                        else
                        {
                            addLineGraphicElements(connectingLine, 150150150);
                        }

                        previousPt.PutCoords(pObs.X, pObs.Y);
                        previousPt.Z = pObs.Z;

                        //add camera to target orientation
                        if (theCamForm.camToTargetDirectionCheckBox.Checked == true)
                        {
                            cameraToTargetDirection(interLat, interLong, interAlt, interTarLat, interTarLong, interTarAlt);
                        }

                        globeDisplay.RefreshViewers();
                    }

                    //for last keyframe
                    else if (i == kFrameCount - 1)
                    {
                        if (j == 0)
                        {
                            currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 4, 1, nextKeyframe, prevKeyframe, afterNextKeyframe);
                            currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 5, 1, nextKeyframe, prevKeyframe, afterNextKeyframe);
                            currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 6, 1, nextKeyframe, prevKeyframe, afterNextKeyframe);
                            currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 1, 1, nextKeyframe, prevKeyframe, afterNextKeyframe);
                            currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 2, 1, nextKeyframe, prevKeyframe, afterNextKeyframe);
                            currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 3, 1, nextKeyframe, prevKeyframe, afterNextKeyframe);

                            globeCamera.GetObserverLatLonAlt(out interLat, out interLong, out interAlt);
                            globeCamera.GetTargetLatLonAlt(out interTarLat, out interTarLong, out interTarAlt);

                            globeCamera.SetObserverLatLonAlt(origCamLat, origCamLong, origCamAlt);
                            globeCamera.SetTargetLatLonAlt(tarLat, tarLong, tarAlt);

                            IPoint  pObs      = new PointClass();
                            IZAware obsZAware = (IZAware)pObs;
                            obsZAware.ZAware = true;
                            pObs.X           = interLong;
                            pObs.Y           = interLat;
                            pObs.Z           = interAlt * 1000;

                            double symbolSize = 10000;

                            if (pObs.Z >= 10000)
                            {
                                symbolSize = 10000 + pObs.Z / 10;
                            }
                            else
                            {
                                symbolSize = pObs.Z;
                            }

                            connectingLine.FromPoint = previousPt;
                            connectingLine.ToPoint   = pObs;

                            addPointGraphicElements(pObs, 2552550, symbolSize);
                            addLineGraphicElements(connectingLine, 150150150);

                            //add camera to target orientation
                            if (theCamForm.camToTargetDirectionCheckBox.Checked == true)
                            {
                                cameraToTargetDirection(interLat, interLong, interAlt, interTarLat, interTarLong, interTarAlt);
                            }

                            globeDisplay.RefreshViewers();
                        }
                    }
                }
            }

            //enable buttons
            theCamForm.playButton.Enabled         = true;
            theCamForm.generatePathButton.Enabled = true;
        }
        public static void CreateMapGraphicTrack(ICreateGraphicTrackOptions pOptions, IAGAnimationTracks tracks, IAGAnimationContainer pContainer)
        {
            pOptions.PathGeometry = SimplifyPath2D(pOptions.PathGeometry, pOptions.ReverseOrder, pOptions.SimplificationFactor);
            IAGAnimationType animType = new AnimationTypeMapGraphic();

            //remove tracks with the same name if overwrite is true
            if (pOptions.OverwriteTrack == true)
            {
                IArray trackArray = new ArrayClass();
                trackArray = tracks.get_TracksOfType(animType);
                int count = trackArray.Count;
                for (int i = 0; i < count; i++)
                {
                    IAGAnimationTrack temp = (IAGAnimationTrack)trackArray.get_Element(i);
                    if (temp.Name == pOptions.TrackName)
                    {
                        tracks.RemoveTrack(temp);
                    }
                }
            }

            //create the new track
            IAGAnimationTrack          animTrack          = tracks.CreateTrack(animType);
            IAGAnimationTrackKeyframes animTrackKeyframes = (IAGAnimationTrackKeyframes)animTrack;

            animTrackKeyframes.EvenTimeStamps = false;

            animTrack.Name = pOptions.TrackName;

            IGeometry        path            = pOptions.PathGeometry;
            IPointCollection pointCollection = (IPointCollection)path;

            ICurve curve      = (ICurve)path;
            double length     = curve.Length;
            double accuLength = 0;

            //loop through all points to create the keyframes
            int pointCount = pointCollection.PointCount;

            if (pointCount <= 1)
            {
                return;
            }
            for (int i = 0; i < pointCount; i++)
            {
                IPoint currentPoint = pointCollection.get_Point(i);

                IPoint nextPoint = new PointClass();
                if (i < pointCount - 1)
                {
                    nextPoint = pointCollection.get_Point(i + 1);
                }

                IPoint lastPoint = new PointClass();
                if (i == 0)
                {
                    lastPoint = currentPoint;
                }
                else
                {
                    lastPoint = pointCollection.get_Point(i - 1);
                }

                IAGKeyframe tempKeyframe = animTrackKeyframes.CreateKeyframe(i);

                //set keyframe properties
                double x;
                double y;
                currentPoint.QueryCoords(out x, out y);
                tempKeyframe.set_PropertyValue(0, currentPoint);
                tempKeyframe.Name = "Map Graphic keyframe " + i.ToString();

                //set keyframe timestamp
                accuLength += CalculateDistance(lastPoint, currentPoint);
                double timeStamp = accuLength / length;
                tempKeyframe.TimeStamp = timeStamp;

                double x1;
                double y1;
                double angle;
                if (i < pointCount - 1)
                {
                    nextPoint.QueryCoords(out x1, out y1);
                    if ((y1 - y) > 0)
                    {
                        angle = Math.Acos((x1 - x) / Math.Sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)));
                    }
                    else
                    {
                        angle = 6.2832 - Math.Acos((x1 - x) / Math.Sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)));
                    }
                    tempKeyframe.set_PropertyValue(1, angle);
                }
                else
                {
                    IAGKeyframe lastKeyframe = animTrackKeyframes.get_Keyframe(i - 1);
                    tempKeyframe.set_PropertyValue(1, lastKeyframe.get_PropertyValue(1));
                }
            }

            //attach the point element
            if (pOptions.PointElement != null)
            {
                animTrack.AttachObject(pOptions.PointElement);
            }

            //attach the track extension, which contains a line element for trace
            IMapGraphicTrackExtension graphicTrackExtension = new MapGraphicTrackExtension();

            graphicTrackExtension.ShowTrace = pOptions.AnimatePath;
            IAGAnimationTrackExtensions trackExtensions = (IAGAnimationTrackExtensions)animTrack;

            trackExtensions.AddExtension(graphicTrackExtension);
        }