Exemplo n.º 1
0
 /// <summary>
 /// Selectively reset to default
 /// </summary>
 /// <param name="prev"></param>
 /// <param name="def"></param>
 /// <param name="delta"></param>
 public CameraProperties(
     CameraProperties prev,
     CameraProperties def,
     CameraDelta delta) : this(prev)
 {
     if (delta.ResetTranslation)
     {
         Translation = def.Translation;
     }
     if (delta.ResetRotation)
     {
         Rotation = def.Rotation;
     }
     if (delta.ResetPivotDistance)
     {
         PivotDistance = def.PivotDistance;
     }
     if (delta.ResetFov)
     {
         Fov = def.Fov;
     }
     if (delta.ResetNear)
     {
         Near = def.Near;
     }
     if (delta.ResetFar)
     {
         Far = def.Far;
     }
 }
Exemplo n.º 2
0
 public void Move(CameraDelta delta, double frametime = 1)
 {
     Properties = new CameraProperties(
         Properties, delta, View, RotationSpeed, frametime
         );
     Properties = new CameraProperties(Properties, Default, delta);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Apply delta
        /// </summary>
        /// <param name="prev"></param>
        /// <param name="delta"></param>
        /// <param name="view"></param>
        /// <param name="rotSpeed"></param>
        /// <param name="frametime"></param>
        public CameraProperties(
            CameraProperties prev,
            CameraDelta delta,
            Matrix4x4 view,
            double rotSpeed  = 1,
            double frametime = 1) : this(prev)
        {
            var rotmat = new Matrix4x4(VMath.Inverse(view))
            {
                row4 = new Vector4D(0, 0, 0, 1)
            };
            if (delta.SetTranslation)
            {
                Translation = prev.Translation + rotmat * (delta.Translation * frametime);
            }

            if (delta.SetRotation)
            {
                var inputrotmat = new Matrix4x4(InputView)
                {
                    row4 = new Vector4D(0, 0, 0, 1)
                };
                var inrotq  = Quaternion.RotationMatrix(inputrotmat.ToSlimDXMatrix());
                var rottime = frametime * rotSpeed;
                var rotq    = Quaternion.RotationYawPitchRoll((float)(delta.PitchYawRoll.y * rottime),
                                                              (float)(delta.PitchYawRoll.x * rottime), (float)(delta.PitchYawRoll.z * rottime));
                //Rotation = Quaternion.Normalize(inrotq * rotq * Quaternion.Invert(inrotq) * Rotation);
                Rotation = Quaternion.Normalize(prev.Rotation * Quaternion.Invert(inrotq) * rotq * inrotq);
            }

            if (delta.SetPivotDistance)
            {
                PivotDistance = Math.Max(0, prev.PivotDistance + delta.PivotDistance * frametime);
            }

            if (delta.SetFov)
            {
                var nfov = VMath.Map(prev.Fov, 0.01, 0.45, 0, 1, TMapMode.Clamp);
                nfov += delta.Fov * frametime * (nfov + 0.05);
                Fov   = VMath.Map(nfov, 0, 1, 0.01, 0.45, TMapMode.Clamp);
            }

            if (delta.SetNear)
            {
                Near = Math.Max(0, prev.Near + delta.Near * frametime);
            }

            if (delta.SetFar)
            {
                Far = Math.Max(0, prev.Far + delta.Far * frametime);
            }
        }
Exemplo n.º 4
0
        public void Move(CameraDelta delta, double frametime = 1)
        {
            var rotmat = new Matrix4x4(VMath.Inverse(View))
            {
                row4 = new Vector4D(0, 0, 0, 1)
            };

            if (delta.SetTranslation)
            {
                Translation += rotmat * (delta.Translation * frametime);
            }
            if (delta.SetRotation)
            {
                var inputrotmat = new Matrix4x4(InputView)
                {
                    row4 = new Vector4D(0, 0, 0, 1)
                };
                var inrotq  = Quaternion.RotationMatrix(inputrotmat.ToSlimDXMatrix());
                var rottime = frametime * RotationSpeed;
                var rotq    = Quaternion.RotationYawPitchRoll((float)(delta.PitchYawRoll.y * rottime), (float)(delta.PitchYawRoll.x * rottime), (float)(delta.PitchYawRoll.z * rottime));
                //Rotation = Quaternion.Normalize(inrotq * rotq * Quaternion.Invert(inrotq) * Rotation);
                Rotation = Quaternion.Normalize(Rotation * Quaternion.Invert(inrotq) * rotq * inrotq);
            }
            if (delta.SetPivotDistance)
            {
                PivotDistance = Math.Max(0, PivotDistance + delta.PivotDistance * frametime);
            }
            if (delta.SetFov)
            {
                var nfov = VMath.Map(Fov, 0.01, 0.45, 0, 1, TMapMode.Clamp);
                nfov += delta.Fov * frametime * (nfov + 0.05);
                Fov   = VMath.Map(nfov, 0, 1, 0.01, 0.45, TMapMode.Clamp);
            }
            if (delta.SetNear)
            {
                Near = Math.Max(0, Near + delta.Near * frametime);
            }
            if (delta.SetFar)
            {
                Far = Math.Max(0, Far + delta.Far * frametime);
            }

            if (Default != null)
            {
                if (delta.ResetTranslation)
                {
                    Translation = new Vector3D(Default.Translation);
                }
                if (delta.ResetRotation)
                {
                    Rotation = new Quaternion(Default.Rotation.X, Default.Rotation.Y, Default.Rotation.Z, Default.Rotation.W);
                }
                if (delta.ResetPivotDistance)
                {
                    PivotDistance = Default.PivotDistance;
                }
                if (delta.ResetFov)
                {
                    Fov = Default.Fov;
                }
                if (delta.ResetNear)
                {
                    Near = Default.Near;
                }
                if (delta.ResetFar)
                {
                    Far = Default.Far;
                }
            }
        }