Here are the examples of the csharp api Cinemachine.CameraState.InterpolatePosition(UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Vector3, float) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
19
View Source File : CameraState.cs
License : MIT License
Project Creator : BattleDawnNZ
License : MIT License
Project Creator : BattleDawnNZ
public static CameraState Lerp(CameraState stateA, CameraState stateB, float t)
{
t = Mathf.Clamp01(t);
float adjustedT = t;
CameraState state = new CameraState();
// Combine the blend hints intelligently
if (((stateA.BlendHint & stateB.BlendHint) & BlendHintValue.NoPosition) != 0)
state.BlendHint |= BlendHintValue.NoPosition;
if (((stateA.BlendHint & stateB.BlendHint) & BlendHintValue.NoOrientation) != 0)
state.BlendHint |= BlendHintValue.NoOrientation;
if (((stateA.BlendHint & stateB.BlendHint) & BlendHintValue.NoLens) != 0)
state.BlendHint |= BlendHintValue.NoLens;
if (((stateA.BlendHint | stateB.BlendHint) & BlendHintValue.SphericalPositionBlend) != 0)
state.BlendHint |= BlendHintValue.SphericalPositionBlend;
if (((stateA.BlendHint | stateB.BlendHint) & BlendHintValue.CylindricalPositionBlend) != 0)
state.BlendHint |= BlendHintValue.CylindricalPositionBlend;
if (((stateA.BlendHint | stateB.BlendHint) & BlendHintValue.NoLens) == 0)
state.Lens = LensSettings.Lerp(stateA.Lens, stateB.Lens, t);
else if (((stateA.BlendHint & stateB.BlendHint) & BlendHintValue.NoLens) == 0)
{
if ((stateA.BlendHint & BlendHintValue.NoLens) != 0)
state.Lens = stateB.Lens;
else
state.Lens = stateA.Lens;
}
state.ReferenceUp = Vector3.Slerp(stateA.ReferenceUp, stateB.ReferenceUp, t);
state.ShotQuality = Mathf.Lerp(stateA.ShotQuality, stateB.ShotQuality, t);
state.PositionCorrection = ApplyPosBlendHint(
stateA.PositionCorrection, stateA.BlendHint,
stateB.PositionCorrection, stateB.BlendHint,
state.PositionCorrection,
Vector3.Lerp(stateA.PositionCorrection, stateB.PositionCorrection, t));
state.OrientationCorrection = ApplyRotBlendHint(
stateA.OrientationCorrection, stateA.BlendHint,
stateB.OrientationCorrection, stateB.BlendHint,
state.OrientationCorrection,
Quaternion.Slerp(stateA.OrientationCorrection, stateB.OrientationCorrection, t));
// LookAt target
if (!stateA.HasLookAt || !stateB.HasLookAt)
state.ReferenceLookAt = kNoPoint;
else
{
// Re-interpolate FOV to preserve target composition, if possible
float fovA = stateA.Lens.FieldOfView;
float fovB = stateB.Lens.FieldOfView;
if (((stateA.BlendHint | stateB.BlendHint) & BlendHintValue.NoLens) == 0
&& !state.Lens.Orthographic && !Mathf.Approximately(fovA, fovB))
{
LensSettings lens = state.Lens;
lens.FieldOfView = InterpolateFOV(
fovA, fovB,
Mathf.Max((stateA.ReferenceLookAt - stateA.CorrectedPosition).magnitude, stateA.Lens.NearClipPlane),
Mathf.Max((stateB.ReferenceLookAt - stateB.CorrectedPosition).magnitude, stateB.Lens.NearClipPlane), t);
state.Lens = lens;
// Make sure we preserve the screen composition through FOV changes
adjustedT = Mathf.Abs((lens.FieldOfView - fovA) / (fovB - fovA));
}
// Linear interpolation of lookAt target point
state.ReferenceLookAt = Vector3.Lerp(
stateA.ReferenceLookAt, stateB.ReferenceLookAt, adjustedT);
}
// Raw position
state.RawPosition = ApplyPosBlendHint(
stateA.RawPosition, stateA.BlendHint,
stateB.RawPosition, stateB.BlendHint,
state.RawPosition, state.InterpolatePosition(
stateA.RawPosition, stateA.ReferenceLookAt,
stateB.RawPosition, stateB.ReferenceLookAt,
t));
// Interpolate the LookAt in Screen Space if requested
if (state.HasLookAt
&& ((stateA.BlendHint | stateB.BlendHint) & BlendHintValue.RadialAimBlend) != 0)
{
state.ReferenceLookAt = state.RawPosition + Vector3.Slerp(
stateA.ReferenceLookAt - state.RawPosition,
stateB.ReferenceLookAt - state.RawPosition, adjustedT);
}
// Clever orientation interpolation
Quaternion newOrient = state.RawOrientation;
if (((stateA.BlendHint | stateB.BlendHint) & BlendHintValue.NoOrientation) == 0)
{
Vector3 dirTarget = Vector3.zero;
if (state.HasLookAt)//&& ((stateA.BlendHint | stateB.BlendHint) & BlendHintValue.RadialAimBlend) == 0)
{
// If orientations are different, use LookAt to blend them
float angle = Quaternion.Angle(stateA.RawOrientation, stateB.RawOrientation);
if (angle > UnityVectorExtensions.Epsilon)
dirTarget = state.ReferenceLookAt - state.CorrectedPosition;
}
if (dirTarget.AlmostZero()
|| ((stateA.BlendHint | stateB.BlendHint) & BlendHintValue.IgnoreLookAtTarget) != 0)
{
// Don't know what we're looking at - can only slerp
newOrient = UnityQuaternionExtensions.SlerpWithReferenceUp(
stateA.RawOrientation, stateB.RawOrientation, t, state.ReferenceUp);
}
else
{
// Rotate while preserving our lookAt target
dirTarget = dirTarget.normalized;
if ((dirTarget - state.ReferenceUp).AlmostZero()
|| (dirTarget + state.ReferenceUp).AlmostZero())
{
// Looking up or down at the pole
newOrient = UnityQuaternionExtensions.SlerpWithReferenceUp(
stateA.RawOrientation, stateB.RawOrientation, t, state.ReferenceUp);
}
else
{
// Put the target in the center
newOrient = Quaternion.LookRotation(dirTarget, state.ReferenceUp);
// Blend the desired offsets from center
Vector2 deltaA = -stateA.RawOrientation.GetCameraRotationToTarget(
stateA.ReferenceLookAt - stateA.CorrectedPosition, stateA.ReferenceUp);
Vector2 deltaB = -stateB.RawOrientation.GetCameraRotationToTarget(
stateB.ReferenceLookAt - stateB.CorrectedPosition, stateB.ReferenceUp);
newOrient = newOrient.ApplyCameraRotation(
Vector2.Lerp(deltaA, deltaB, adjustedT), state.ReferenceUp);
}
}
}
state.RawOrientation = ApplyRotBlendHint(
stateA.RawOrientation, stateA.BlendHint,
stateB.RawOrientation, stateB.BlendHint,
state.RawOrientation, newOrient);
// Acreplacedulate the custom blendables and apply the weights
for (int i = 0; i < stateA.NumCustomBlendables; ++i)
{
CustomBlendable b = stateA.GetCustomBlendable(i);
b.m_Weight *= (1-t);
if (b.m_Weight > UnityVectorExtensions.Epsilon)
state.AddCustomBlendable(b);
}
for (int i = 0; i < stateB.NumCustomBlendables; ++i)
{
CustomBlendable b = stateB.GetCustomBlendable(i);
b.m_Weight *= t;
if (b.m_Weight > UnityVectorExtensions.Epsilon)
state.AddCustomBlendable(b);
}
return state;
}