Beispiel #1
0
        public void GoToPosition(TerrainView.Position p)
        {
            GetPosition(StartPosition);

            EndPosition = p;
            AnimationValue = 0.0;
        }
Beispiel #2
0
        private void MouseMotion()
        {
            if (DebugGUISwitcherInstance.MouseOverGUI) return;

            if (LeftMousePressed && Input.GetKey(KeyCode.LeftControl))
            {
                TargetPosition.Phi -= Input.GetAxis("Mouse X") * RotateSpeed;
                TargetPosition.Theta += Input.GetAxis("Mouse Y") * RotateSpeed;
            }
            else if (LeftMousePressed)
            {
                var oldPosition = View.CameraToWorldMatrix * Input.mousePosition.xy0();
                var position = View.CameraToWorldMatrix * PreviousMousePos.xy0;

                if (!(double.IsNaN(oldPosition.x) || double.IsNaN(oldPosition.y) || double.IsNaN(oldPosition.z) || double.IsNaN(position.x) || double.IsNaN(position.y) || double.IsNaN(position.z)))
                {
                    var currentPosition = new TerrainView.Position();

                    GetPosition(currentPosition);
                    SetPosition(TargetPosition);

                    View.Move(new Vector3d(oldPosition), new Vector3d(position), DragSpeed);

                    GetPosition(TargetPosition);
                    SetPosition(currentPosition);
                }
            }
            else if (RightMousePressed)
            {

            }

            PreviousMousePos = new Vector3d(Input.mousePosition);
        }
Beispiel #3
0
 private void GetPosition(TerrainView.Position p)
 {
     p.X = View.position.X;
     p.Y = View.position.Y;
     p.Theta = View.position.Theta;
     p.Phi = View.position.Phi;
     p.Distance = View.position.Distance;
 }
Beispiel #4
0
        private void Start()
        {
            View = GetComponent<TerrainView>();

            TargetPosition = new TerrainView.Position();
            StartPosition = new TerrainView.Position();
            EndPosition = new TerrainView.Position();
            PreviousMousePos = new Vector3d(Input.mousePosition);
        }
Beispiel #5
0
        public override void InitNode()
        {
            View = GetComponent <TerrainView>();

            TargetPosition   = new TerrainView.Position();
            StartPosition    = new TerrainView.Position();
            EndPosition      = new TerrainView.Position();
            PreviousMousePos = new Vector3d(Input.mousePosition);
        }
Beispiel #6
0
        private void SetPosition(TerrainView.Position p)
        {
            View.position.X = p.X;
            View.position.Y = p.Y;
            View.position.Theta = p.Theta;
            View.position.Phi = p.Phi;
            View.position.Distance = p.Distance;

            AnimationValue = -1.0;
        }
Beispiel #7
0
        public void JumpToPosition(TerrainView.Position p)
        {
            SetPosition(p);

            TargetPosition = p;
        }
Beispiel #8
0
        private void UpdateController(double dt)
        {
            var dzFactor = Math.Pow(1.02, Math.Min(dt, 1.0));

            if (NearPressed || ScrollOut)
            {
                TargetPosition.Distance = TargetPosition.Distance / (dzFactor * ZoomSpeed) / (ScrollOut ? ScrollWheelSpeed : 1.0f);
            }
            else if (FarPressed || ScrollIn)
            {
                TargetPosition.Distance = TargetPosition.Distance * dzFactor * ZoomSpeed * (ScrollIn ? ScrollWheelSpeed : 1.0f);
            }

            var currentPosition = new TerrainView.Position();

            GetPosition(currentPosition);
            SetPosition(TargetPosition);

            if (ForwardPressed || BackwardPressed)
            {
                var speed = Math.Max(View.GetHeight(), 1.0);

                if (ForwardPressed)
                {
                    View.MoveForward(speed * dt * MoveSpeed);
                }
                else if (BackwardPressed)
                {
                    View.MoveForward(-speed * dt * MoveSpeed);
                }
            }

            if (LeftPressed)
            {
                View.Turn(dt * TurnSpeed);
            }
            else if (RightPressed)
            {
                View.Turn(-dt * TurnSpeed);
            }

            GetPosition(TargetPosition);

            if (Smooth)
            {
                var lerp = 1.0 - Math.Exp(-dt * 2.301e-3);
                var interpolatedPosition = new TerrainView.Position();

                View.InterpolatePos(currentPosition, TargetPosition, lerp, ref interpolatedPosition);

                currentPosition.X = interpolatedPosition.X;
                currentPosition.Y = interpolatedPosition.Y;
                currentPosition.Theta = Mix(currentPosition.Theta, TargetPosition.Theta, lerp);
                currentPosition.Phi = Mix(currentPosition.Phi, TargetPosition.Phi, lerp);
                currentPosition.Distance = Mix(currentPosition.Distance, TargetPosition.Distance, lerp);

                SetPosition(currentPosition);
            }
            else
            {
                SetPosition(TargetPosition);
            }

        }