public void Move(CameraDelta delta, double frametime = 1) { Properties = new CameraProperties( Properties, delta, View, RotationSpeed, frametime ); Properties = new CameraProperties(Properties, Default, delta); }
/// <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; } }
/// <summary> /// Copy /// </summary> /// <param name="prev"></param> public CameraProperties(CameraProperties prev) { InputView = prev.InputView; Translation = prev.Translation; Rotation = prev.Rotation; PivotDistance = prev.PivotDistance; Fov = prev.Fov; Near = prev.Near; Far = prev.Far; }
public CameraProperties Lerp(CameraProperties other, double alpha) { return(new CameraProperties( InputView, VMath.Lerp(Translation, other.Translation, alpha), Quaternion.Slerp(Rotation, other.Rotation, (float)alpha), VMath.Lerp(PivotDistance, other.PivotDistance, alpha), VMath.Lerp(Fov, other.Fov, alpha), Near, Far )); }
/// <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); } }