Beispiel #1
0
        public void UpdatePosition()
        {
            StrategicView = Radius > 175;

            if (StrategicView)
            {
                Pitch           = Angle_TopDown;
                interpolatedYaw = GameUtils.AngleNormalize(interpolatedYaw);
                Yaw             = 0;
            }
            else
            {
                Pitch = Angle_Side;
            }

            Radius = 10 + (ZoomLevel * ZoomLevel * ZoomLevel) / 150 * ForegroundGame.Map.width / 5000;

            float camLimits = Radius * 0.4f;

            if (camLimits > ForegroundGame.Map.width - camLimits)
            {
                target.X = ForegroundGame.Map.width * 0.5f;
            }
            else if (target.X > ForegroundGame.Map.width - camLimits)
            {
                target.X = ForegroundGame.Map.width - camLimits;
            }
            else if (target.X < camLimits)
            {
                target.X = camLimits;
            }

            if (camLimits > ForegroundGame.Map.height - camLimits)
            {
                target.Z = ForegroundGame.Map.height * 0.5f;
            }
            else if (target.Z > ForegroundGame.Map.height - camLimits)
            {
                target.Z = ForegroundGame.Map.height - camLimits;
            }
            else if (target.Z < camLimits)
            {
                target.Z = camLimits;
            }

            ForegroundGame.Map.GetHeight(target, ref target.Y);
            if (target.Y < ForegroundGame.Map.waterLevel)
            {
                target.Y = ForegroundGame.Map.waterLevel;
            }
        }
Beispiel #2
0
        private void CameraInputs(Point pnt)
        {
            if (InputHelper.rightDown)
            {
                if (!LastRightClick)
                {
                    clickPos = deltaPos = pnt;
                }
                float dx = pnt.X - deltaPos.X;
                deltaPos.X = pnt.X;
                float dy = pnt.Y - deltaPos.Y;
                deltaPos.Y = pnt.Y;
                dx        *= 0.01f * camera.ZoomLevel;
                dy        *= 0.01f * camera.ZoomLevel;

                camera.target.Z -= ((float)Math.Cos(camera.Yaw) * dy - (float)Math.Sin(camera.Yaw) * dx);
                camera.target.X -= ((float)Math.Sin(camera.Yaw) * dy + (float)Math.Cos(camera.Yaw) * dx);

                float camLimits = 10;
                if (camera.target.X < camLimits)
                {
                    camera.target.X = camLimits;
                }
                if (camera.target.Z < camLimits)
                {
                    camera.target.Z = camLimits;
                }
                if (camera.target.X > ForegroundGame.Map.width - camLimits)
                {
                    camera.target.X = ForegroundGame.Map.width - camLimits;
                }
                if (camera.target.Z > ForegroundGame.Map.height - camLimits)
                {
                    camera.target.Z = ForegroundGame.Map.height - camLimits;
                }
                ForegroundGame.Map.GetHeight(camera.target, ref camera.target.Y);
                if (camera.target.Y < ForegroundGame.Map.waterLevel)
                {
                    camera.target.Y = ForegroundGame.Map.waterLevel;
                }
            }
            else if (InputHelper.middleDown)
            {
                if (!LastMiddleClick)
                {
                    clickPos = deltaPos = pnt;
                }
                float dx = pnt.X - deltaPos.X;
                deltaPos.X = pnt.X;
                float dy = pnt.Y - deltaPos.Y;
                deltaPos.Y = pnt.Y;

                camera.Yaw   -= dx * 0.00085f * GameUtils.Pi;
                camera.Pitch += dy * 0.00085f * GameUtils.Pi;
                if (camera.Pitch < 0)
                {
                    camera.Pitch = 0;
                }
                if (camera.Pitch > (GameUtils.PiOver2 - 0.0001f))
                {
                    camera.Pitch = (GameUtils.PiOver2 - 0.0001f);
                }
            }
            else if (!InputHelper.middleDown)
            {
                if (LastMiddleClick)
                {
                    if (Vector2.Distance(new Vector2(clickPos.X, clickPos.Y), new Vector2(pnt.X, pnt.Y)) < 1)
                    {
                        camera.interpolatedYaw = GameUtils.AngleNormalize(camera.interpolatedYaw);
                        camera.Yaw             = 0;
                        camera.Pitch           = GameUtils.PiOver2 * 0.6f;
                    }
                }
            }
        }