Ejemplo n.º 1
0
    // calculate which transform's we're interpolating between
    private void CalculateFromAndToTransformAndTime(ref PosAndQuat fromTransform, ref float fromTime,
                                                    ref PosAndQuat toTransform, ref float toTime)
    {
        CameraWayPoint fromWayPoint = null;
        CameraWayPoint toWayPoint   = null;

        CalculateFromAndToWayPointTransformAndTime(ref fromWayPoint, ref fromTransform, ref fromTime, ref toWayPoint, ref toTransform, ref toTime);
    }
Ejemplo n.º 2
0
    // calculate which way points we're interpolating between
    private void CalculateFromAndToWayPoint(ref CameraWayPoint fromWayPoint, ref CameraWayPoint toWayPoint)
    {
        PosAndQuat fromTransform = new PosAndQuat();
        float      fromTime      = 0f;

        PosAndQuat toTransform = new PosAndQuat();
        float      toTime      = 0f;

        CalculateFromAndToWayPointTransformAndTime(ref fromWayPoint, ref fromTransform, ref fromTime, ref toWayPoint, ref toTransform, ref toTime);
    }
Ejemplo n.º 3
0
    // calculate the camera transform for our current time in the cinematic
    private void CalculateCameraTransform()
    {
        PosAndQuat fromTransform = new PosAndQuat();
        float      fromTime      = 0f;

        PosAndQuat toTransform = new PosAndQuat();
        float      toTime      = 0f;

        CalculateFromAndToTransformAndTime(ref fromTransform, ref fromTime, ref toTransform, ref toTime);
        _currentCameraTransform = InterpolateBetween(fromTransform, fromTime, toTransform, toTime, GetCinematicCurrentTime());
    }
Ejemplo n.º 4
0
    // interpolate between two transforms
    private PosAndQuat InterpolateBetween(PosAndQuat fromTransform, float fromTime, PosAndQuat toTransform, float toTime, float time)
    {
        PosAndQuat interpolatedPosAndQuat = new PosAndQuat();
        float      clampedTime            = Mathf.Clamp(time, fromTime, Mathf.Max(fromTime, toTime));

        float       period             = (toTime - fromTime);
        const float ZeroTol            = 0.0001f;
        float       interpolationValue = (period > ZeroTol) ? (clampedTime - fromTime) / period : 0f;

        interpolationValue = Smooth(interpolationValue, cameraLerpSmoothing);

        interpolatedPosAndQuat.position = Vector3.Lerp(fromTransform.position, toTransform.position, interpolationValue);
        interpolatedPosAndQuat.rotation = Quaternion.Slerp(fromTransform.rotation, toTransform.rotation, interpolationValue);

        return(interpolatedPosAndQuat);
    }
Ejemplo n.º 5
0
    // calculate which transform's we're interpolating between
    private void CalculateFromAndToWayPointTransformAndTime(ref CameraWayPoint fromWayPoint, ref PosAndQuat fromTransform, ref float fromTime,
                                                            ref CameraWayPoint toWayPoint, ref PosAndQuat toTransform, ref float toTime)
    {
        float currentCinematicTime = GetCinematicCurrentTime();

        _cameraComponent.GetGameCameraTransform(ref fromTransform.position, ref fromTransform.rotation);
        toTransform = fromTransform;

        fromWayPoint = null;
        toWayPoint   = fromWayPoint;

        fromTime = 0f;
        for (int wayPoint = 0; wayPoint < cameraWayPoints.Count; ++wayPoint)
        {
            CameraWayPoint currentWayPoint = cameraWayPoints[wayPoint];

            fromTime += currentWayPoint.lerpInTime;
            if (currentCinematicTime < fromTime)
            {
                toTime      = fromTime;
                toTransform = currentWayPoint.CalculateTransform(_cameraComponent);
                toWayPoint  = currentWayPoint;

                fromTime -= currentWayPoint.lerpInTime;
                return;
            }
            fromTransform = currentWayPoint.CalculateTransform(_cameraComponent);
            fromWayPoint  = currentWayPoint;

            fromTime += currentWayPoint.holdTime;
            if (currentCinematicTime < fromTime)
            {
                toTime      = fromTime;
                toTransform = fromTransform;
                toWayPoint  = fromWayPoint;

                fromTime -= currentWayPoint.holdTime;
                return;
            }

            if (cameraWayPoints.Count - 1 == wayPoint)             // the last way point
            {
                toTime = fromTime + currentWayPoint.lerpOutTime;   // out length is only used on the last way point
            }
        }
    }
Ejemplo n.º 6
0
        public PosAndQuat CalculateTransform(CameraBase cameraComponent)
        {
            if (null == wayPointObject)
            {
                return(new PosAndQuat());                // can't do anything without a wayPointObject
            }

            PosAndQuat transform = new PosAndQuat();

            if (null == wayPointTarget)             // we have no target, so we get the transform from the normal fixed game camera
            {
                cameraComponent.GetGameCameraTransform(ref transform.position, ref transform.rotation);
                transform.position = wayPointObject.transform.position;
                return(transform);
            }

            // get our transform from the vector from wayPointObject to wayPointTarget
            Vector3 forward = wayPointTarget.transform.position - wayPointObject.transform.position;

            transform.position = wayPointObject.transform.position;
            transform.rotation = Quaternion.LookRotation(Vector3.Normalize(forward));
            return(transform);
        }