コード例 #1
0
    /// <summary>
    /// Starts the track.
    /// </summary>
    /// <returns>
    /// The track.
    /// </returns>
    /// <param name='trackName'>
    /// Track name prefab name in Resource folder
    /// </param>
    /// <param name='relativeTf'>
    /// Relative tf.
    /// </param>
    /// <param name='trackRelative'>
    /// Track relative.
    /// </param>
    public CameraTrack StartTrack(string trackName, Transform relativeTf, bool trackRelative = false)
    {
        CameraTrack track = null;

        if (!_mCamTrackList.TryGetValue(trackName, out track))
        {
            Object     obj = Resources.Load(trackName);
            GameObject go  = GameObject.Instantiate(obj) as GameObject;

            go.name = trackName;
            track   = go.GetComponent <CameraTrack>() as CameraTrack;

            _mCamTrackList.Add(trackName, track);
        }

        if (trackRelative)
        {
            track.Restart(relativeTf.position);
        }
        else
        {
            track.Restart();
        }

        return(track);
    }
        private static async Task CreateCameraKeyframe(MapView mapView, MapPoint orig_cameraPoint, ProjectionTransformation transformation,
                                                       CameraTrack cameraTrack, TimeSpan currentTimespanValue, double pitch, double heading, bool ignoreRotation = false, bool ignoreTranslation = false)
        {
            await QueuedTask.Run(() =>
            {
                Keyframe keyFrame = null;
                MapPoint projected_cameraPoint = (MapPoint)GeometryEngine.Instance.ProjectEx(orig_cameraPoint, transformation);

                if (mapView.ViewingMode == MapViewingMode.Map)
                {
                    var camera = new Camera(projected_cameraPoint.X, projected_cameraPoint.Y, CameraZOffset, heading, null, CameraViewpoint.LookAt);
                    keyFrame   = cameraTrack.CreateKeyframe(camera, currentTimespanValue, AnimationTransition.FixedArc, .5);
                }
                else
                {
                    var camera = new Camera(projected_cameraPoint.X, projected_cameraPoint.Y, (projected_cameraPoint.Z + CameraZOffset), pitch, heading, null, CameraViewpoint.LookAt);
                    keyFrame   = cameraTrack.CreateKeyframe(camera, currentTimespanValue, AnimationTransition.FixedArc, .5);
                }

                if (ignoreRotation)
                {
                    CameraKeyframe camKey    = keyFrame as CameraKeyframe;
                    camKey.HeadingTransition = AnimationTransition.None;
                    camKey.RollTransition    = AnimationTransition.None;
                    camKey.PitchTransition   = AnimationTransition.None;
                }
                if (ignoreTranslation)
                {
                    CameraKeyframe camKey = keyFrame as CameraKeyframe;
                    camKey.XTransition    = AnimationTransition.None;
                    camKey.YTransition    = AnimationTransition.None;
                    camKey.ZTransition    = AnimationTransition.None;
                }
            });
        }
コード例 #3
0
    /// <summary>
    /// Starts the nivose track.
    /// </summary>
    /// <returns>
    /// The nivose track.
    /// </returns>
    /// <param name='trackName'>
    /// Track name.
    /// </param>
    /// <param name='dataSlot'>
    /// Data slot.
    /// </param>
    public CameraTrack StartNivoseTrack(string trackName, SkillDataSlot dataSlot)
    {
        Vector3 tStartPos  = Globals.Instance.MPlayerManager.GetWarship(dataSlot._attackerID).U3DGameObject.transform.position;
        Vector3 tTargetPos = Vector3.zero;

        foreach (SkillDataSlot.AttackTargetData data in dataSlot._attackTargetDataList.Values)
        {
            if (data._isPrimaryTarget)
            {
                WarshipL target = Globals.Instance.MPlayerManager.GetWarship(data._targetID);
                tTargetPos = target.U3DGameObject.transform.position;

                break;
            }
        }

        CameraTrack track = null;

        if (!_mCamTrackList.TryGetValue(trackName, out track))
        {
            Object     obj = Resources.Load(trackName);
            GameObject go  = GameObject.Instantiate(obj) as GameObject;
            go.name = trackName;
            track   = go.GetComponent <CameraTrack>() as CameraTrack;
            _mCamTrackList.Add(trackName, track);
        }

        track.RestartNivoseTrack(true, tStartPos, tTargetPos);

        return(track);
    }
コード例 #4
0
        /// <summary>
        /// Gets the current input movement.
        /// </summary>
        /// <returns></returns>
        public Vector3 GetTarget(CameraTrack cameraInfo, GameObject reference)
        {
            var mX = GetAxis("AimHorizontal");
            var mZ = GetAxis("AimVertical");

            var camera = cameraInfo == null?
                         null : CameraManager.Instance.GetCamera(cameraInfo.CameraNumber);

            if (UseMouse && camera != null && (UnityEngine.Input.GetMouseButton(0) ||
                                               UnityEngine.Input.GetMouseButton(1)))
            {
                var mouse = UnityEngine.Input.mousePosition;
                mouse.z = (camera.transform.position - reference.transform.position).magnitude;

                var mouseTarget = camera.ScreenToWorldPoint(mouse) - reference.transform.position;
                mouseTarget.y = 0;
                return(mouseTarget);
            }

            var input = new Vector3(mX, 0, mZ);

            input.Normalize();

            return(input);
        }
コード例 #5
0
    /// <summary>
    /// Initializes MonoBehaviour.
    /// </summary>
    void Start()
    {
        _rigidbody   = GetComponent <Rigidbody>();
        _cameraTrack = GetComponent <CameraTrack>();
        _status      = GetComponent <CharacterStatus>();
        //_collider = GetComponent<CapsuleCollider>();

        //_lastPosition = transform.position;
    }
コード例 #6
0
    public void StartFlight(CameraTrack cameraTrack, PlayerMovement playerController)
    {
        _cameraTrack      = cameraTrack;
        _playerController = playerController;

        _canControl     = true;
        _flightDuration = FlightDuration;
        Direction       = Direction.RotateY(transform.localRotation.eulerAngles.y);
    }
コード例 #7
0
    //! tzz added for pause the track by name
    public void PauseTrack(string trackName)
    {
        CameraTrack track = null;

        if (_mCamTrackList.TryGetValue(trackName, out track))
        {
            track.Stop();
        }
    }
コード例 #8
0
    public override void OnDestroyScene()
    {
        gameSceneState = null;

        subStageList = null;
        heliPlayer   = null;
        cameraTrack  = null;

        Destroy(field.gameObject);
    }
コード例 #9
0
    /// <summary>
    /// Raises the attack event.
    /// </summary>
    public override void OnAttack(WeaponHitbox hitbox)
    {
        if (_cameraTrack == null || _playerController == null)
        {
            _playerController = Parent.GetComponent <PlayerMovement>();
            _cameraTrack      = Parent.GetComponent <CameraTrack>();
        }

        _hitbox = hitbox as BoomerangHitbox;
        _hitbox.StartFlight(_cameraTrack, _playerController);
    }
        //Use this method if you want keyframes ONLY at line vertices. This is good if the line is highly densified.
        //However, you will get sharp turns at corners because there is no attempt to smooth the animation
        public static async Task CreateKeyframes_AtVertices(MapView mapView, SpatialReference layerSpatRef, ProjectionTransformation transformation,
                                                            CameraTrack cameraTrack, Polyline lineGeom, IEnumerator <ReadOnlySegmentCollection> segments,
                                                            int segmentCount, double pathLength)
        {
            double segmentLength  = 0;
            int    num_iterations = 0;

            segments.Reset();

            //process each segment depending upon its type - straight line or arc
            while (segments.MoveNext())
            {
                ReadOnlySegmentCollection seg = segments.Current;
                double accumulatedDuration    = mapView.Map.Animation.Duration.TotalSeconds + ((mapView.Map.Animation.Duration.TotalSeconds > 0) ? ANIMATION_APPEND_TIME : 0); // 0;

                foreach (Segment s in seg)
                {
                    segmentLength = Math.Sqrt((s.EndPoint.X - s.StartPoint.X) * (s.EndPoint.X - s.StartPoint.X) +
                                              (s.EndPoint.Y - s.StartPoint.Y) * (s.EndPoint.Y - s.StartPoint.Y) +
                                              (s.EndPoint.Z - s.StartPoint.Z) * (s.EndPoint.Z - s.StartPoint.Z));

                    double segmentDuration = (TotalDuration / pathLength) * segmentLength;

                    MapPoint startPt = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(s.StartPoint.X, s.StartPoint.Y, s.StartPoint.Z, layerSpatRef));

                    MapPoint endPt = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(s.EndPoint.X, s.EndPoint.Y, s.EndPoint.Z, layerSpatRef));

                    //create keyframe at start vertex of path in map space
                    double   timeSpanValue    = accumulatedDuration;
                    TimeSpan keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);
                    SetPitchAndHeadingForLine(startPt, endPt);
                    await CreateCameraKeyframe(mapView, startPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);

                    //Create a keyframe at end point of segment only for the end point of last segment
                    //Otherwise we will get duplicate keyframes at end of one segment and start of the next one
                    if (num_iterations == segmentCount - 1)
                    {
                        timeSpanValue    = accumulatedDuration + segmentDuration;
                        keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);

                        if (SelectedCameraView == "Face target")
                        {
                            SetPitchAndHeadingForLine(endPt, TargetPoint);
                        }

                        await CreateCameraKeyframe(mapView, endPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);
                    }

                    accumulatedDuration += segmentDuration;
                    num_iterations++;
                }
            }
        }
コード例 #11
0
ファイル: PdaHelper.cs プロジェクト: slgrobotics/QuakeMap
        public static string exportSingleFile(string tileName, string srcPath, bool neverWrapPdb)
        {
            string newSrcPath = srcPath;

            string fileNameDst = tileName + ".jpg";
            string dstPath     = Path.Combine(Project.exportDestFolder, fileNameDst);

            // format conversions:
            switch (Project.pdaExportImageFormat)
            {
            case 0:                             // bmp websafe
            case 1:                             // bmp optimized
                newSrcPath  = CameraTrack.convertAndSaveTileImage(tileName, srcPath, Path.GetTempPath());
                fileNameDst = tileName + ".bmp";
                dstPath     = Path.Combine(Project.exportDestFolder, fileNameDst);
                break;

            case 2:                             // jpeg
                break;
            }

            // now either pack it in PDB, or just copy to destination:
            if (!neverWrapPdb && Project.pdaExportWrapPdb)
            {
                PalmPdbFormat ppf         = new PalmPdbFormat();
                string        catalogName = tileName;          //dstPath;

                string fileNamePdb = tileName + ".pdb";
                dstPath = Path.Combine(Project.exportDestFolder, fileNamePdb);

                int format = Project.pdaExportImageFormat + (Project.pdaExportUseWebsafeGrayscalePalette ? 4 : 0);
                ppf.PackImageIntoPdb(catalogName, newSrcPath, dstPath, format);
            }
            else
            {
                if (File.Exists(dstPath))
                {
                    File.Delete(dstPath);
                }
                File.Copy(newSrcPath, dstPath, true);
            }

            // get rid of temp file:
            if (!newSrcPath.Equals(srcPath))
            {
                try
                {
                    File.Delete(newSrcPath);
                }
                catch {}
            }
            return(dstPath);
        }
コード例 #12
0
    public override void OnInspectorGUI()
    {
        _target = target as CameraTrack;

        if (Application.isPlaying)
        {
            DrawRuntimeInspector();
        }
        else
        {
            DrawEditorInspector();
        }
    }
コード例 #13
0
    public void ResumeTrack(string trackName, int index)
    {
        CameraTrack track = null;

        if (_mCamTrackList.TryGetValue(trackName, out track))
        {
            if (index != -1)
            {
                track.Index = index;
            }
            track.Resume();
        }
    }
コード例 #14
0
        void MoveCamera()
        {
            if (head != null)
            {
                Vector3 camPos = cam.transform.position;
                camPos.y = head.transform.position.y;
                cam.transform.position = camPos;

                CameraTrack camScript = cam.GetComponent <CameraTrack>();
                if (camScript != null)
                {
                    camScript.target = head.transform;
                }
            }
        }
コード例 #15
0
    //! return end stop position
    public KeyFrameInfo StopTrack(string trackName)
    {
        KeyFrameInfo t_endPos = null;

        CameraTrack track = null;

        if (_mCamTrackList.TryGetValue(trackName, out track))
        {
            t_endPos = track.Stop();

            _mCamTrackList.Remove(trackName);
            GameObject.Destroy(track.gameObject);
        }

        return(t_endPos);
    }
コード例 #16
0
    /**
     *	by lsj for the case of port defense battle
     */
    public virtual void InitBattleData()
    {
        GUIRadarScan.Hide();

        // !!!! follow 3 function order can't be changed !!!!
        InitCameraPos();
        BeginBattleLogic();
        PlayBattleCameraTrack();

        // tzz added for create the selected prefab effection
        //
        if (m_battleSelectedPrefab != null)
        {
            GameObject.Destroy(m_battleSelectedPrefab);
        }

        Object t_obj = Resources.Load(BattleShipSelectedPrefab);

        m_battleSelectedPrefab = GameObject.Instantiate(t_obj) as GameObject;
        m_battleSelectedPrefab.SetActiveRecursively(false);

        GameObject.DontDestroyOnLoad(m_battleSelectedPrefab);

        // start create
        // Add Finger event
        Globals.Instance.MFingerEvent.Add3DEventListener(this);
        this.SetFingerEventActive(true);

        // Add sneak attack effect
        if (_battleResult.SneakAttackType != GameData.BattleGameData.SneakAttackType.FACE_ATTACK)
        {
            Globals.Instance.M3DItemManager.PlaySneakEffect(_battleResult, null);
        }

        if (CustomCameraState)
        {
            Globals.Instance.MCamTrackController.StopTrack(FightCameraTrack);

            KeyFrameInfo[] t_cameraInfo = m_battleCameraTrack.keyFrameInfos;
            KeyFrameInfo   t_endPos     = t_cameraInfo[t_cameraInfo.Length - 1];

            CameraTrack.ITweenMoveTo(Globals.Instance.MSceneManager.mMainCamera.gameObject, t_endPos, null, 1.0f);
        }


        _mBattleState = EBattleState.DO_STEP;
    }
コード例 #17
0
    public override void Initialize()
    {
        base.Initialize();

        // if not custom camera stat
        // play the camera track
        if (!BattleStatus.CustomCameraState && _mSkillUser.Property.WarshipIsAttacker)
        {
            switch (_mSkillDataSlot.MSkillData.BasicData.SkillType)
            {
            case ESkillType.SINGLE_NIVOSE:
                _mCamTrackName = "PathPoints/NivoseSingleTrack";
                break;

            case ESkillType.GROUP_NIVOSE:
                _mCamTrackName = "PathPoints/NivoseGroupTrack";
                break;

            case ESkillType.GROUP_REPAIR_NIVOSE:
                _mCamTrackName = "PathPoints/NivoseGroupRepairTrack";
                break;
            }

            Globals.Instance.MCamTrackController.StopAllTracks();

            CameraTrack tCameraTrack = Globals.Instance.MCamTrackController.StartNivoseTrack(_mCamTrackName, _mSkillDataSlot);

            // tzz modified
            // for the the Battle status camera track
            //
            if (tCameraTrack != null && tCameraTrack.keyFrameInfos.Length >= 1)
            {
                if (GameStatusManager.Instance.MBattleStatus != null)
                {
                    CameraTrack tBattleCT = GameStatusManager.Instance.MBattleStatus.GetCurrBattleFightCameraTrack();

                    if (tBattleCT != null && tBattleCT.keyFrameInfos.Length >= 1)
                    {
                        // replace the final key
                        //
                        tCameraTrack.keyFrameInfos[tCameraTrack.keyFrameInfos.Length - 1] = tBattleCT.keyFrameInfos[tBattleCT.keyFrameInfos.Length - 1];
                    }
                }
            }
        }
    }
コード例 #18
0
    private void OnEnable()
    {
        _target           = target as CameraTrack;
        _serializedTarget = new SerializedObject(target);

        _cameraProp          = _serializedTarget.FindProperty("_cameraToMove");
        _playOnAwakeProp     = _serializedTarget.FindProperty("_playOnAwake");
        _speedCurveProp      = _serializedTarget.FindProperty("_speed");
        _positionsProp       = _serializedTarget.FindProperty("_positions");
        _onCompleteTrackProp = _serializedTarget.FindProperty("onCompleteTrack");
        _eventsProp          = _serializedTarget.FindProperty("_events");

        _target.CheckPositionNames();

        _positionsExpanded = EditorPrefs.HasKey(_EDITOR_VAR_POSITIONS_EXPANDED_PATH) ?
                             EditorPrefs.GetBool(_EDITOR_VAR_POSITIONS_EXPANDED_PATH) : false;
        _eventsExpanded = EditorPrefs.HasKey(_EDITOR_VAR_EVENTS_EXPANDED_PATH) ?
                          EditorPrefs.GetBool(_EDITOR_VAR_EVENTS_EXPANDED_PATH) : false;
    }
コード例 #19
0
ファイル: DlgPdaExport.cs プロジェクト: slgrobotics/QuakeMap
        public DlgPdaExport(CameraTrack cameraTrack)
        {
            m_cameraTrack     = cameraTrack;
            m_defaultFileName = "pmapdata" + m_defaultExt;

            InitializeComponent();

            if (m_selectedFileName == null)
            {
                m_selectedFileName = Path.Combine(Project.pdaInitialDirectory, m_defaultFileName);
            }
            fileTextBox.Text = m_selectedFileName;

            saveButton.Enabled = fileTextBox.Text.Length > 0;

            setRadioButtons();

            Project.setDlgIcon(this);
        }
コード例 #20
0
ファイル: CameraTrack.cs プロジェクト: kenruze/jamtools
    public static CameraTrack SortCameraZones()
    {
        CameraTrack oldCamera = s_currentCamera;

        s_occupiedCameraZones.Sort(new CompareCameraTrackPriority());
        for (int i = 0; i < s_occupiedCameraZones.Count; i++)
        {
            if (s_occupiedCameraZones[i] == null)
            {
                s_occupiedCameraZones.RemoveAt(i);
                --i;
            }
        }

        if (debug_messages)
        {
            print("list cameras");
            for (int i = 0; i < s_occupiedCameraZones.Count; i++)
            {
                print(s_occupiedCameraZones[i].m_priority);
            }
            print("list over");
        }
        if (s_occupiedCameraZones.Count == 0)
        {
            s_currentCamera = null;
        }
        else if (oldCamera != s_occupiedCameraZones[0])
        {
            s_occupiedCameraZones[0].ActivateCamera();
        }

        if (oldCamera != null && oldCamera != s_currentCamera)
        {
            oldCamera.m_activated = false;
        }

        return(s_currentCamera);
    }
コード例 #21
0
ファイル: CameraTrack.cs プロジェクト: kenruze/jamtools
    //█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█

    public void ActivateCamera()
    {
        //Debug.Log("Activating Camera " + name);
        s_currentCamera = this;
        m_activated     = true;
    }
        //Use this method to create a keyframe at every n-second of the specified animation duration
        public static async Task CreateKeyframes_EveryNSeconds(MapView mapView, SpatialReference layerSpatRef, ProjectionTransformation transformation,
                                                               CameraTrack cameraTrack, IEnumerator <ReadOnlySegmentCollection> segments,
                                                               int segmentCount, double pathLength, double keyEveryNSecond = 1)
        {
            double segmentLength   = 0;
            int    numKeysToCreate = (int)(TotalDuration / keyEveryNSecond); //approximately
            double createKeyAtDist = pathLength / numKeysToCreate;

            double skippedDistance     = 0;
            double accumulatedDuration = mapView.Map.Animation.Duration.TotalSeconds + ((mapView.Map.Animation.Duration.TotalSeconds > 0) ? ANIMATION_APPEND_TIME : 0); // 0;

            int num_iterations = 0;

            segments.Reset();

            List <MapPoint> pointsForKeyframes = new List <MapPoint>();

            MapPoint pathEndPt = null;

            //process each segment depending upon its type - straight line or arc
            while (segments.MoveNext())
            {
                ReadOnlySegmentCollection seg = segments.Current;

                foreach (Segment s in seg)
                {
                    segmentLength = Math.Sqrt((s.EndPoint.X - s.StartPoint.X) * (s.EndPoint.X - s.StartPoint.X) +
                                              (s.EndPoint.Y - s.StartPoint.Y) * (s.EndPoint.Y - s.StartPoint.Y) +
                                              (s.EndPoint.Z - s.StartPoint.Z) * (s.EndPoint.Z - s.StartPoint.Z));

                    double segmentDuration = (TotalDuration / pathLength) * segmentLength;

                    //straight line segments
                    if (s.SegmentType == SegmentType.Line)
                    {
                        MapPoint startPt = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(s.StartPoint.X, s.StartPoint.Y, s.StartPoint.Z, layerSpatRef));

                        MapPoint endPt = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(s.EndPoint.X, s.EndPoint.Y, s.EndPoint.Z, layerSpatRef));

                        //add start of path to points collection
                        if (num_iterations == 0)
                        {
                            pointsForKeyframes.Add(startPt);
                        }

                        if (num_iterations == segmentCount - 1 || segmentCount == 1)
                        {
                            pathEndPt = endPt; //store path end pt. This will be the last keyframe.
                        }

                        double distCoveredAlongSeg = Math.Abs(createKeyAtDist - skippedDistance); //we are accouunting for skipped distances from previous segments

                        if (distCoveredAlongSeg < segmentLength)
                        {
                            MapPoint keyPt = await CreatePointAlongSegment(startPt, endPt, distCoveredAlongSeg, layerSpatRef);

                            //add point to collection
                            pointsForKeyframes.Add(keyPt);

                            //skipped distance is used now, reset to zero
                            skippedDistance = 0;

                            //are more keyframes possible for this segment
                            bool moreKeysPossible = ((segmentLength - distCoveredAlongSeg) >= createKeyAtDist);

                            while (moreKeysPossible)
                            {
                                double keyAtDistAlongSeg = distCoveredAlongSeg + createKeyAtDist;

                                keyPt = await CreatePointAlongSegment(startPt, endPt, keyAtDistAlongSeg, layerSpatRef);

                                //add point to collection
                                pointsForKeyframes.Add(keyPt);

                                distCoveredAlongSeg += createKeyAtDist;

                                moreKeysPossible = ((segmentLength - distCoveredAlongSeg) > createKeyAtDist);
                            }

                            //if any segment length left then add to skipped distance
                            skippedDistance += (segmentLength - distCoveredAlongSeg);
                        }
                        else
                        {
                            //add this segment's length to skipped distance as no keyframe could be created along it
                            skippedDistance += segmentLength;
                        }
                    }
                    else if (s.SegmentType == SegmentType.EllipticArc)
                    {
                        EllipticArcSegment ellipArc = s as EllipticArcSegment;
                        MapPoint           startPt  = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(s.StartPoint.X, s.StartPoint.Y, s.StartPoint.Z, layerSpatRef));

                        MapPoint endPt = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(s.EndPoint.X, s.EndPoint.Y, s.EndPoint.Z, layerSpatRef));

                        double   radius   = Math.Sqrt((ellipArc.CenterPoint.X - startPt.X) * (ellipArc.CenterPoint.X - startPt.X) + (ellipArc.CenterPoint.Y - startPt.Y) * (ellipArc.CenterPoint.Y - startPt.Y));
                        double   angle    = ellipArc.CentralAngle;
                        MapPoint centerPt = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(ellipArc.CenterPoint.X, ellipArc.CenterPoint.Y, (s.StartPoint.Z + s.EndPoint.Z) / 2, layerSpatRef));

                        //add start of path to points collection
                        if (num_iterations == 0)
                        {
                            pointsForKeyframes.Add(startPt);
                        }

                        if (num_iterations == segmentCount - 1 || segmentCount == 1)
                        {
                            pathEndPt = endPt; //store path end pt. This will be the last keyframe.
                        }

                        double distCoveredAlongSeg = Math.Abs(createKeyAtDist - skippedDistance); //we are accouunting for skipped distances from previous segments

                        if (distCoveredAlongSeg < segmentLength)
                        {
                            MapPoint keyPt = await CreatePointAlongArc(startPt, endPt, centerPt, angle *distCoveredAlongSeg / segmentLength, radius, layerSpatRef, ellipArc.IsMinor, ellipArc.IsCounterClockwise);

                            //add point to collection
                            pointsForKeyframes.Add(keyPt);

                            //skipped distance is used now, reset to zero
                            skippedDistance = 0;

                            //are more keyframes possible for this segment
                            bool moreKeysPossible = ((segmentLength - distCoveredAlongSeg) >= createKeyAtDist);

                            while (moreKeysPossible)
                            {
                                double keyAtDistAlongSeg = distCoveredAlongSeg + createKeyAtDist;

                                keyPt = await CreatePointAlongArc(startPt, endPt, centerPt, angle *keyAtDistAlongSeg / segmentLength, radius, layerSpatRef, ellipArc.IsMinor, ellipArc.IsCounterClockwise);

                                //add point to collection
                                pointsForKeyframes.Add(keyPt);

                                distCoveredAlongSeg += createKeyAtDist;

                                moreKeysPossible = ((segmentLength - distCoveredAlongSeg) > createKeyAtDist);
                            }

                            //if any segment length left then add to skipped distance
                            skippedDistance += (segmentLength - distCoveredAlongSeg);
                        }
                        else
                        {
                            //add this segment's length to skipped distance as no keyframe could be created along it
                            skippedDistance += segmentLength;
                        }
                    }

                    num_iterations++;
                }
            }

            //now iterate over the points list and create keyframes

            double   timeSpanValue    = accumulatedDuration;
            TimeSpan keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);

            for (int i = 0; i < pointsForKeyframes.Count; i++)
            {
                MapPoint currentPt = pointsForKeyframes[i];
                MapPoint nextPt    = null;

                if (i + 1 < pointsForKeyframes.Count)
                {
                    nextPt = pointsForKeyframes[i + 1];
                }
                else
                {
                    nextPt = pathEndPt;
                }

                timeSpanValue    = i * keyEveryNSecond + accumulatedDuration;
                keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);

                SetPitchAndHeadingForLine(currentPt, nextPt);
                await CreateCameraKeyframe(mapView, currentPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);

                if (i == pointsForKeyframes.Count - 1 && skippedDistance > 0)
                {
                    keyframeTimespan = TimeSpan.FromSeconds(TotalDuration + accumulatedDuration);
                    await CreateCameraKeyframe(mapView, pathEndPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);
                }
            }
        }
        //Use this method for smoother turns at corners. Additionally this method processes straight line segments and arc segments separately
        //For arc segments a keyframe is created at every second. However a minimum of 5 keyframes are created for arcs.
        //So if arc segment length is less than 5 then we default to at least 5 keyframes. This is an attempt to stick to the path as much as possible.
        //For straight line segments, rotation is ignored at end point of each segment except for the end point of the path itself. Two keyframes with rotation
        //are created at certain distance (determined by LINE_CONSTRAINT_FACTOR) before and after the end point of each segment. This is an attempt to avoid
        //sharp turns at corners along the path.
        public static async Task CreateKeyframes_AlongPath(MapView mapView, SpatialReference layerSpatRef, ProjectionTransformation transformation,
                                                           CameraTrack cameraTrack, IEnumerator <ReadOnlySegmentCollection> segments,
                                                           int segmentCount, double pathLength)
        {
            double segmentLength  = 0;
            int    num_iterations = 0;

            segments.Reset();

            //process each segment depending upon its type - straight line or arc
            while (segments.MoveNext())
            {
                ReadOnlySegmentCollection seg = segments.Current;
                double accumulatedDuration    = mapView.Map.Animation.Duration.TotalSeconds + ((mapView.Map.Animation.Duration.TotalSeconds > 0) ? ANIMATION_APPEND_TIME : 0); // 0;

                foreach (Segment s in seg)
                {
                    double length3D = Math.Sqrt((s.EndPoint.X - s.StartPoint.X) * (s.EndPoint.X - s.StartPoint.X) +
                                                (s.EndPoint.Y - s.StartPoint.Y) * (s.EndPoint.Y - s.StartPoint.Y) +
                                                (s.EndPoint.Z - s.StartPoint.Z) * (s.EndPoint.Z - s.StartPoint.Z));


                    double segmentDuration = (TotalDuration / pathLength) * length3D;
                    segmentLength = length3D;

                    //straight line segments
                    if (s.SegmentType == SegmentType.Line)
                    {
                        MapPoint startPt = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(s.StartPoint.X, s.StartPoint.Y, s.StartPoint.Z *Z_CONVERSION_FACTOR, layerSpatRef));

                        MapPoint endPt = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(s.EndPoint.X, s.EndPoint.Y, s.EndPoint.Z *Z_CONVERSION_FACTOR, layerSpatRef));

                        //we will be creating three intermediate keyframes for staright segments only if segment length is more than a set threshold
                        //the threshold is just a guess and might have to be altered depending upon the path geometry. Should work for most cases though
                        MapPoint firstIntPoint = null;
                        MapPoint midIntPoint   = null;
                        MapPoint lastIntPoint  = null;

                        if (segmentLength >= STRAIGHT_SEGMENT_LENGTH_THRESHOLD)
                        {
                            //first intermediate point
                            firstIntPoint = await CreatePointAlongSegment(startPt, endPt, LINE_CONSTRAINT_FACTOR *segmentLength, layerSpatRef);

                            //mid point
                            midIntPoint = await CreatePointAlongSegment(startPt, endPt, 0.5 *segmentLength, layerSpatRef);

                            //last intermediate point
                            lastIntPoint = await CreatePointAlongSegment(startPt, endPt, (1 - LINE_CONSTRAINT_FACTOR) *segmentLength, layerSpatRef);
                        }

                        //create keyframe at start vertex of path in map space
                        double   timeSpanValue    = accumulatedDuration;
                        TimeSpan keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);

                        if (segmentLength >= STRAIGHT_SEGMENT_LENGTH_THRESHOLD)
                        {
                            SetPitchAndHeadingForLine(startPt, firstIntPoint);
                        }
                        else
                        {
                            SetPitchAndHeadingForLine(startPt, endPt);
                        }

                        //ignore rotation for all start vertices (which would also be end vertices of previous segments) EXCEPT for the first vertex of path
                        if (num_iterations == 0 || segmentLength < STRAIGHT_SEGMENT_LENGTH_THRESHOLD)
                        {
                            await CreateCameraKeyframe(mapView, startPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);
                        }
                        else
                        {
                            await CreateCameraKeyframe(mapView, startPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading, true, false);
                        }

                        if (segmentLength > STRAIGHT_SEGMENT_LENGTH_THRESHOLD)
                        {
                            //Create a keyframe at PATH_CONSTRAINT_FACTOR distance along the segment from start point
                            double distanceAlong = LINE_CONSTRAINT_FACTOR * segmentLength;
                            timeSpanValue    = accumulatedDuration + LINE_CONSTRAINT_FACTOR * segmentDuration;
                            keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);
                            SetPitchAndHeadingForLine(firstIntPoint, midIntPoint);
                            await CreateCameraKeyframe(mapView, firstIntPoint, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);

                            //Create a keyframe at middle of segment
                            distanceAlong    = 0.5 * segmentLength;
                            timeSpanValue    = accumulatedDuration + 0.5 * segmentDuration;
                            keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);
                            SetPitchAndHeadingForLine(midIntPoint, lastIntPoint);
                            //await CreateCameraKeyframe(mapView, midIntPoint, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);

                            //Create a keyframe at (1 - PATH_CONSTRAINT_FACTOR) distance along the segment from start point
                            distanceAlong    = (1 - LINE_CONSTRAINT_FACTOR) * segmentLength;
                            timeSpanValue    = accumulatedDuration + (1 - LINE_CONSTRAINT_FACTOR) * segmentDuration;
                            keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);
                            SetPitchAndHeadingForLine(lastIntPoint, endPt);
                            await CreateCameraKeyframe(mapView, lastIntPoint, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);
                        }

                        //Create a keyframe at end point of segment only for the end point of last segment
                        //Otherwise we will get duplicate keyframes at end of one segment and start of the next one
                        if (num_iterations == segmentCount - 1)
                        {
                            timeSpanValue    = accumulatedDuration + segmentDuration;
                            keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);

                            if (SelectedCameraView == "Face target")
                            {
                                SetPitchAndHeadingForLine(endPt, TargetPoint);
                            }

                            await CreateCameraKeyframe(mapView, endPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);
                        }
                    }
                    //processing for arcs - create a keyframe every second for arcs
                    //we will create a minimum of 5 keyframes along the arc
                    else if (s.SegmentType == SegmentType.EllipticArc && segmentDuration > 5)
                    {
                        EllipticArcSegment ellipArc = s as EllipticArcSegment;
                        MapPoint           startPt  = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(s.StartPoint.X, s.StartPoint.Y, s.StartPoint.Z, layerSpatRef));

                        MapPoint endPt = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(s.EndPoint.X, s.EndPoint.Y, s.EndPoint.Z, layerSpatRef));

                        double   radius   = Math.Sqrt((ellipArc.CenterPoint.X - startPt.X) * (ellipArc.CenterPoint.X - startPt.X) + (ellipArc.CenterPoint.Y - startPt.Y) * (ellipArc.CenterPoint.Y - startPt.Y));
                        double   angle    = ellipArc.CentralAngle;
                        MapPoint centerPt = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(ellipArc.CenterPoint.X, ellipArc.CenterPoint.Y, (s.StartPoint.Z + s.EndPoint.Z) / 2, layerSpatRef));

                        int num_keys = (int)segmentDuration;

                        MapPoint firstIntPoint = null;

                        //first intermediate keyframe for arc - needed for setting heading for start vertex
                        // >2 to account for start and end
                        if (num_keys > 2)
                        {
                            firstIntPoint = await CreatePointAlongArc(startPt, endPt, centerPt, angle / (num_keys - 1), radius, layerSpatRef, ellipArc.IsMinor, ellipArc.IsCounterClockwise);
                        }

                        //Create keyframe at start vertex of path in map space
                        double   timeSpanValue    = accumulatedDuration;
                        TimeSpan keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);

                        if (firstIntPoint != null)
                        {
                            SetPitchAndHeadingForLine(startPt, firstIntPoint);
                        }
                        else
                        {
                            SetPitchAndHeadingForLine(startPt, endPt);
                        }

                        //Ignore rotation for all start vertices EXCEPT for the first vertex of path
                        if (num_iterations == 0)
                        {
                            await CreateCameraKeyframe(mapView, startPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);
                        }
                        else
                        {
                            await CreateCameraKeyframe(mapView, startPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading, true, false);
                        }

                        //Loop to create intermediate keyframes at each second
                        for (int i = 0; i < num_keys - 2; i++)
                        {
                            MapPoint currentIntPoint = null;
                            MapPoint nextIntPoint    = null;

                            currentIntPoint = await CreatePointAlongArc(startPt, endPt, centerPt, (angle / (num_keys - 1)) *(i + 1), radius, layerSpatRef, ellipArc.IsMinor, ellipArc.IsCounterClockwise);

                            if (i < num_keys - 3)
                            {
                                nextIntPoint = await CreatePointAlongArc(startPt, endPt, centerPt, (angle / (num_keys - 1)) *(i + 2), radius, layerSpatRef, ellipArc.IsMinor, ellipArc.IsCounterClockwise);
                            }
                            else //for the last intermediate keyframe, heading/pitch has to be determined relative to the end point fo segment
                            {
                                nextIntPoint = endPt;
                            }
                            //timeSpanValue = accumulatedDuration + (i + 1) * 1; //at each second
                            timeSpanValue = accumulatedDuration + (i + 1) * (segmentDuration / (num_keys - 1));

                            keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);
                            SetPitchAndHeadingForLine(currentIntPoint, nextIntPoint);
                            await CreateCameraKeyframe(mapView, currentIntPoint, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);
                        }

                        //Create a keyframe at end point of segment only for the end point of last segment
                        if (num_iterations == segmentCount - 1)
                        {
                            timeSpanValue    = accumulatedDuration + segmentDuration;
                            keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);

                            if (SelectedCameraView == "Face target")
                            {
                                SetPitchAndHeadingForLine(endPt, TargetPoint);
                            }

                            await CreateCameraKeyframe(mapView, endPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);
                        }
                    }
                    //create a minimum of 5 keyframes along the arc
                    else if (s.SegmentType == SegmentType.EllipticArc)
                    {
                        EllipticArcSegment ellipArc = s as EllipticArcSegment;
                        MapPoint           startPt  = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(s.StartPoint.X, s.StartPoint.Y, s.StartPoint.Z, layerSpatRef));

                        MapPoint endPt = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(s.EndPoint.X, s.EndPoint.Y, s.EndPoint.Z, layerSpatRef));

                        double   radius   = Math.Sqrt((ellipArc.CenterPoint.X - startPt.X) * (ellipArc.CenterPoint.X - startPt.X) + (ellipArc.CenterPoint.Y - startPt.Y) * (ellipArc.CenterPoint.Y - startPt.Y));
                        double   angle    = ellipArc.CentralAngle;
                        MapPoint centerPt = await QueuedTask.Run(() => MapPointBuilder.CreateMapPoint(ellipArc.CenterPoint.X, ellipArc.CenterPoint.Y, (s.StartPoint.Z + s.EndPoint.Z) / 2, layerSpatRef));

                        //we are creating five intermediate keyframes for arcs
                        MapPoint firstIntPoint = await CreatePointAlongArc(startPt, endPt, centerPt, angle *ARC_CONSTRAINT_FACTOR, radius, layerSpatRef, ellipArc.IsMinor, ellipArc.IsCounterClockwise);

                        MapPoint secondIntPoint = await CreatePointAlongArc(startPt, endPt, centerPt, angle *ARC_CONSTRAINT_FACTOR * 2, radius, layerSpatRef, ellipArc.IsMinor, ellipArc.IsCounterClockwise);

                        MapPoint midIntPoint = await CreatePointAlongArc(startPt, endPt, centerPt, angle * 0.5, radius, layerSpatRef, ellipArc.IsMinor, ellipArc.IsCounterClockwise);

                        MapPoint secondLastIntPoint = await CreatePointAlongArc(startPt, endPt, centerPt, angle *(1 - ARC_CONSTRAINT_FACTOR * 2), radius, layerSpatRef, ellipArc.IsMinor, ellipArc.IsCounterClockwise);

                        MapPoint lastIntPoint = await CreatePointAlongArc(startPt, endPt, centerPt, angle *(1 - ARC_CONSTRAINT_FACTOR), radius, layerSpatRef, ellipArc.IsMinor, ellipArc.IsCounterClockwise);

                        //Create keyframe at start vertex of path in map space
                        double   timeSpanValue    = accumulatedDuration;
                        TimeSpan keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);
                        SetPitchAndHeadingForLine(startPt, firstIntPoint);

                        //Ignore rotation for all start vertices EXCEPT for the first vertex of path
                        if (num_iterations == 0)
                        {
                            await CreateCameraKeyframe(mapView, startPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);
                        }
                        else
                        {
                            await CreateCameraKeyframe(mapView, startPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading, true, false);
                        }

                        //await CreateCameraKeyframe(mapView, startPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);

                        //Create a keyframe at PATH_CONSTRAINT_FACTOR distance along the segment from start point
                        timeSpanValue    = accumulatedDuration + ARC_CONSTRAINT_FACTOR * segmentDuration;
                        keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);
                        SetPitchAndHeadingForLine(firstIntPoint, secondIntPoint);
                        await CreateCameraKeyframe(mapView, firstIntPoint, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);

                        //Create a keyframe at 2* PATH_CONSTRAINT_FACTOR distance along the segment from start point
                        timeSpanValue    = accumulatedDuration + ARC_CONSTRAINT_FACTOR * 2 * segmentDuration;
                        keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);
                        SetPitchAndHeadingForLine(secondIntPoint, midIntPoint);
                        await CreateCameraKeyframe(mapView, secondIntPoint, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);

                        //Create a keyframe at middle of segment
                        timeSpanValue    = accumulatedDuration + 0.5 * segmentDuration;
                        keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);
                        SetPitchAndHeadingForLine(midIntPoint, secondLastIntPoint);
                        await CreateCameraKeyframe(mapView, midIntPoint, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);

                        //Create a keyframe at (1 - PATH_CONSTRAINT_FACTOR * 2) distance along the segment from start point
                        timeSpanValue    = accumulatedDuration + (1 - ARC_CONSTRAINT_FACTOR * 2) * segmentDuration;
                        keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);
                        SetPitchAndHeadingForLine(secondLastIntPoint, lastIntPoint);
                        await CreateCameraKeyframe(mapView, secondLastIntPoint, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);

                        //Create a keyframe at (1 - PATH_CONSTRAINT_FACTOR) distance along the segment from start point
                        timeSpanValue    = accumulatedDuration + (1 - ARC_CONSTRAINT_FACTOR) * segmentDuration;
                        keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);
                        SetPitchAndHeadingForLine(lastIntPoint, endPt);
                        await CreateCameraKeyframe(mapView, lastIntPoint, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);

                        //Create a keyframe at end point of segment only for the end point of last segment
                        if (num_iterations == segmentCount - 1)
                        {
                            timeSpanValue    = accumulatedDuration + segmentDuration;
                            keyframeTimespan = TimeSpan.FromSeconds(timeSpanValue);

                            if (SelectedCameraView == "Face target")
                            {
                                SetPitchAndHeadingForLine(endPt, TargetPoint);
                            }

                            await CreateCameraKeyframe(mapView, endPt, transformation, cameraTrack, keyframeTimespan, _keyframePitch, _keyframeHeading);
                        }
                    }

                    accumulatedDuration += segmentDuration;
                    num_iterations++;
                }
            }
        }
コード例 #24
0
        private static async Task CreateCameraKeyframe(MapPoint orig_cameraPoint, ProjectionTransformation transformation, CameraTrack cameraTrack, TimeSpan currentTimespanValue)
        {
            await QueuedTask.Run(() =>
            {
                Keyframe keyFrame = null;
                MapPoint projected_cameraPoint = (MapPoint)GeometryEngine.Instance.ProjectEx(orig_cameraPoint, transformation);

                var camera = new Camera(projected_cameraPoint.X, projected_cameraPoint.Y, _cameraZOffset, _keyframeHeading, null, CameraViewpoint.LookAt);
                keyFrame   = cameraTrack.CreateKeyframe(camera, currentTimespanValue, AnimationTransition.FixedArc, .5);
            });
        }
コード例 #25
0
    public override void OnInitializeScene(ISceneInitData _initData)
    {
        initData = (GameSceneInitData)_initData;

        GameInstance.Inst.PlayBGM(new BgmEnum[] { BgmEnum.Game, BgmEnum.GameAmbient });

        field        = GenericPrefab.InstantiatePathFormat <Field>(initData.FieldId.ToString());
        cameraTrack  = field.GetCameraTrack();
        heliPlayer   = GenericPrefab.Instantiate <HeliPlayer>(cameraTrack.GetCameraJoint());
        subStageList = field.GetSubStageList();

        //GameSceneState
        {
            int       enemyCount  = 0;
            var       fistStage   = subStageList.FirstOrDefault();
            Transform firstTarget = null;
            if (fistStage != null)
            {
                var firstEnemy = fistStage.EnemyList.FirstOrDefault();
                enemyCount = fistStage.EnemyList.Count;
                if (firstEnemy != null)
                {
                    firstTarget = firstEnemy.TargetJoint;
                }
            }

            gameSceneState = new GameSceneState()
            {
                TargetEnemyList = fistStage.EnemyList.ToList(),
                HeliPlayerData  = new HeliPlayerData()
                {
                    Zoom   = false,
                    Target = firstTarget
                },
                SubStageId        = fistStage.SubStageId,
                NextSubStageId    = fistStage.NextSubStageId,
                LeftEnemyCount    = enemyCount,
                CurrentEnemyIndex = 0
            };
            fistStage.SetColliderActive(true);

            gameSceneState.InvalidTarget();
            heliPlayer.ApplyHeliPlayerData(gameSceneState.HeliPlayerData);
            view.ApplyGameSceneState(gameSceneState);
        }

        //init enemy
        {
            var enemyInitData = new EnemyInitData()
            {
                OnKillEnemy   = OnKillEnemy,
                OnRemoveEnemy = OnRemoveEnemy
            };

            foreach (var subStage in subStageList)
            {
                foreach (var enemy in subStage.EnemyList)
                {
                    enemy.Initialize(enemyInitData);
                }
            }
        }

        //Init CameraTrack
        cameraTrack.SetSubStage(1);

        startTime = Time.time;
        view.ApplyTime(Time.time - startTime);
    }