Example #1
0
 private void Orbit(int x, int y, CameraMotionSettings cms, float dt)
 {
     Yaw   += x * cms.OrbitSpeed * dt;
     Yaw    = MathHelper.WrapAngle(Yaw);
     Pitch += y * cms.OrbitSpeed * dt;
     Pitch  = MathHelper.Clamp(Pitch, MIN_PITCH, MAX_PITCH);
 }
Example #2
0
        public void Update(CollisionGrid map, float dt)
        {
            CameraMotionSettings cms = MovementSettings;

            Scroll(camController.ScrollX, camController.ScrollZ, cms, dt);
            Orbit(camController.Yaw, camController.Pitch, cms, dt);
            int z;

            camController.GetZoom(out z);
            Zoom(z, dt);
            camTarget.X = MathHelper.Clamp(camTarget.X, 0, map.size.X);
            camTarget.Z = MathHelper.Clamp(camTarget.Z, 0, map.size.Y);
            //camOrigin.Y = Grey.Vox.Region.HEIGHT * 0.5f; // MathHelper.Clamp(camOrigin.Y, 0, Grey.Vox.Region.HEIGHT);
            camTarget.Y = map.HeightAt(new Vector2(camOrigin.X, camTarget.Z));

            bool reset;

            camController.GetResetDefault(out reset);
            if (reset)
            {
                Yaw       = INITIAL_CAMERA_YAW;
                Pitch     = INITIAL_CAMERA_PITCH;
                ZoomRatio = INITIAL_ZOOM_RATIO;
            }

            camOrigin = Tweens.LINEAR.GetValue(camOrigin, camTarget, TWEEN_FACTOR * dt);
            RecalculateView(map, MathHelper.Lerp(cms.MinDistance, cms.MaxDistance, ZoomRatio));
        }
Example #3
0
 public static CameraMotionSettings Lerp(CameraMotionSettings s1, CameraMotionSettings s2, float r)
 {
     return new CameraMotionSettings() {
         OrbitSpeed = MathHelper.Lerp(s1.OrbitSpeed, s2.OrbitSpeed, r),
         ScrollSpeed = MathHelper.Lerp(s1.ScrollSpeed, s2.ScrollSpeed, r),
         MinDistance = MathHelper.Lerp(s1.MinDistance, s2.MinDistance, r),
         MaxDistance = MathHelper.Lerp(s1.MaxDistance, s2.MaxDistance, r)
     };
 }
Example #4
0
 public static CameraMotionSettings Lerp(CameraMotionSettings s1, CameraMotionSettings s2, float r)
 {
     return(new CameraMotionSettings()
     {
         OrbitSpeed = MathHelper.Lerp(s1.OrbitSpeed, s2.OrbitSpeed, r),
         ScrollSpeed = MathHelper.Lerp(s1.ScrollSpeed, s2.ScrollSpeed, r),
         MinDistance = MathHelper.Lerp(s1.MinDistance, s2.MinDistance, r),
         MaxDistance = MathHelper.Lerp(s1.MaxDistance, s2.MaxDistance, r)
     });
 }
Example #5
0
        public Camera(Viewport v)
        {
            camOrigin    = INITIAL_CAMERA_ORIGIN;
            Yaw          = INITIAL_CAMERA_YAW;
            Pitch        = INITIAL_CAMERA_PITCH;
            ZoomRatio    = INITIAL_ZOOM_RATIO;
            lowSettings  = INITIAL_LOW_SETTINGS;
            highSettings = INITIAL_HIGH_SETTINGS;
            ZoomSpeed    = INITIAL_ZOOM_SPEED;
            RecalculateView(null, MovementSettings.MaxDistance);

            IsOrthographic = false;
            Projection     = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, v.AspectRatio, 0.01f, 2000f);
            camController  = new CameraController(v.Width, v.Height);

            holdVelocity = 0;
        }
Example #6
0
        private void Scroll(int x, int y, CameraMotionSettings cms, float dt)
        {
            // Lerp Velocities
            if (camController.ScrollX != 0 || camController.ScrollZ != 0)
            {
                holdVelocity += (dt / HOLD_TIME_SPAN);
            }
            else
            {
                holdVelocity = 0;
            }
            holdVelocity = MathHelper.Clamp(holdVelocity, 0, 1);
            dt           = Tweens.EASE.GetValue(0, dt, holdVelocity);

            camTarget.Y += camController.ScrollY * cms.ScrollSpeed * dt * (ZoomRatio + ZOOM_OFFSET);

            if (x == 0 && y == 0)
            {
                return;
            }

            Matrix camWorld = Matrix.Invert(mView);

            Vector3 forward = camWorld.Forward;

            forward.Y = 0;
            forward.Normalize();

            Vector3 right = camWorld.Right;

            right.Y = 0;
            right.Normalize();

            camTarget += forward * y * cms.ScrollSpeed * dt * (ZoomRatio + ZOOM_OFFSET);
            camTarget += right * x * cms.ScrollSpeed * dt * (ZoomRatio + ZOOM_OFFSET);
        }
Example #7
0
        public Camera(Viewport v)
        {
            camOrigin = INITIAL_CAMERA_ORIGIN;
            Yaw = INITIAL_CAMERA_YAW;
            Pitch = INITIAL_CAMERA_PITCH;
            ZoomRatio = INITIAL_ZOOM_RATIO;
            lowSettings = INITIAL_LOW_SETTINGS;
            highSettings = INITIAL_HIGH_SETTINGS;
            ZoomSpeed = INITIAL_ZOOM_SPEED;
            RecalculateView(null, MovementSettings.MaxDistance);

            IsOrthographic = false;
            Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, v.AspectRatio, 0.01f, 2000f);
            camController = new CameraController(v.Width, v.Height);

            holdVelocity = 0;
        }
Example #8
0
        private void Scroll(int x, int y, CameraMotionSettings cms, float dt)
        {
            // Lerp Velocities
            if(camController.ScrollX != 0 || camController.ScrollZ != 0)
                holdVelocity += (dt / HOLD_TIME_SPAN);
            else
                holdVelocity = 0;
            holdVelocity = MathHelper.Clamp(holdVelocity, 0, 1);
            dt = Tweens.EASE.GetValue(0, dt, holdVelocity);

            camTarget.Y += camController.ScrollY * cms.ScrollSpeed * dt * (ZoomRatio + ZOOM_OFFSET);

            if(x == 0 && y == 0) return;

            Matrix camWorld = Matrix.Invert(mView);

            Vector3 forward = camWorld.Forward;
            forward.Y = 0;
            forward.Normalize();

            Vector3 right = camWorld.Right;
            right.Y = 0;
            right.Normalize();

            camTarget += forward * y * cms.ScrollSpeed * dt * (ZoomRatio + ZOOM_OFFSET);
            camTarget += right * x * cms.ScrollSpeed * dt * (ZoomRatio + ZOOM_OFFSET);
        }
Example #9
0
 private void Orbit(int x, int y, CameraMotionSettings cms, float dt)
 {
     Yaw += x * cms.OrbitSpeed * dt;
     Yaw = MathHelper.WrapAngle(Yaw);
     Pitch += y * cms.OrbitSpeed * dt;
     Pitch = MathHelper.Clamp(Pitch, MIN_PITCH, MAX_PITCH);
 }