コード例 #1
0
            static public void Lerp(ref BlendedCameraOutput result, ref BlendedCameraOutput from, ref BlendedCameraOutput to,
                                    CameraLerp.LerpStyle style, float interpolatePos, float interpolatePitch, float interpolateYaw)
            {
                if (interpolatePos >= 1f && interpolatePitch >= 1.0f && interpolateYaw >= 1.0f)
                {
                    result = to;
                    return;
                }

                switch (style)
                {
                case CameraLerp.LerpStyle.positionToPosition:

                    Vector3 fromPosition   = from.CalculatePosition();
                    Vector3 toPosition     = to.CalculatePosition();
                    Vector3 resultPosition = fromPosition + ((toPosition - fromPosition) * interpolatePos);
                    result.distFromLookAt = from.distFromLookAt + ((to.distFromLookAt - from.distFromLookAt) * interpolatePos);
                    Vector3 toEuler   = to.rotation.eulerAngles;
                    Vector3 fromEuler = from.rotation.eulerAngles;
                    Vector3 lerpEuler = Vector3.zero;
                    lerpEuler.x = Mathf.LerpAngle(fromEuler.x, toEuler.x, interpolatePitch);
                    lerpEuler.y = Mathf.LerpAngle(fromEuler.y, toEuler.y, interpolateYaw);
                    //result.rotation = Quaternion.Slerp(from.rotation, to.rotation, interpolate);
                    result.rotation = Quaternion.Euler(lerpEuler);
                    result.lookAt   = resultPosition + GameUtils.CalculateForward(result.rotation) * result.distFromLookAt;
                    break;

                case CameraLerp.LerpStyle.keepTargetOnScreen:
                    result.distFromLookAt = from.distFromLookAt + ((to.distFromLookAt - from.distFromLookAt) * interpolatePos);
                    //result.rotation = Quaternion.Slerp(from.rotation, to.rotation, interpolatePos);
                    Vector3 toEulerK   = to.rotation.eulerAngles;
                    Vector3 fromEulerK = from.rotation.eulerAngles;
                    Vector3 lerpEulerK = Vector3.zero;
                    lerpEulerK.x = Mathf.LerpAngle(fromEulerK.x, toEulerK.x, interpolatePitch);
                    lerpEulerK.y = Mathf.LerpAngle(fromEulerK.y, toEulerK.y, interpolateYaw);
                    //result.rotation = Quaternion.Slerp(from.rotation, to.rotation, interpolate);
                    result.rotation = Quaternion.Euler(lerpEulerK);
                    result.lookAt   = from.lookAt + ((to.lookAt - from.lookAt) * interpolatePos);
                    break;

                default:
                    result = to;
                    break;
                }
            }
コード例 #2
0
    // calculate what the look at point is based on the inputs
    public Vector3 CalculateLookAt(Vector3 targetPosition, Vector3 camPos, Quaternion camRotation)
    {
        Vector3 planeNormal = targetPosition - camPos;

        if (GameUtils.NormalizeXZ(ref planeNormal))
        {
            _plane.SetNormalAndPosition(planeNormal, targetPosition);

            Vector3 forward = GameUtils.CalculateForward(camRotation);

            _ray.origin    = camPos;
            _ray.direction = forward;

            float dist = 0f;
            if (_plane.Raycast(_ray, out dist))
            {
                return(camPos + forward * dist);
            }
        }
        return(targetPosition);
    }
コード例 #3
0
 public void SetPosition(Vector3 position)
 {
     _gameCameraLookAt = position + (GameUtils.CalculateForward(_gameCameraRotation) * _gameCameraDistanceFromLookat);
 }
コード例 #4
0
 public void GetPosition(ref Vector3 position)
 {
     position = _gameCameraLookAt - (GameUtils.CalculateForward(_gameCameraRotation) * _gameCameraDistanceFromLookat);
 }
コード例 #5
0
 public Vector3 CalculatePosition()
 {
     return(lookAt - GameUtils.CalculateForward(rotation) * distFromLookAt);
 }