예제 #1
0
        private float getFixedVsVelocityFactor(Vehicle veh, float speedCoeff)
        {
            // If the car isn't moving, default to looking forwards
            if (veh.Velocity.Magnitude() < nearlySttopedSpeed)
            {
                return(0f);
            }
            else
            {
                // for bikes, always look at velocity
                if (isCycleOrByke)
                {
                    return(1f);
                }

                // if veh is in air, look at is velocity
                if (veh.IsInAir || veh.CurrentGear == 0)
                {
                    return(1f);
                }
                else // if is on the ground. fit camera (mostly) behind vehicle (for better drift control)
                {
                    // Different factors for low/high speed
                    return(Mathr.Lerp(velocityInfluenceLowSpeed, velocityInfluence, Mathr.Clamp(speedCoeff / lowSpeedLimit, 0f, 1f)));
                }
            }
        }
예제 #2
0
        private void LoadSettings()
        {
            // general

            /*customCamEnabled = Settings.GetValue<bool>("general", "enabled", customCamEnabled);
             * distanceOffset = Settings.GetValue<float>("general", "distanceOffset", distanceOffset);
             * heightOffset = Settings.GetValue<float>("general", "heightOffset", heightOffset);
             * fov = Settings.GetValue<float>("general", "fov", fov);
             * increaseDistanceAtHighSpeed = Settings.GetValue<bool>("general", "increaseDistanceAtHighSpeed", increaseDistanceAtHighSpeed);
             * accelerationAffectsCamDistance = Settings.GetValue<bool>("general", "accelerationAffectsCamDistance", accelerationAffectsCamDistance);
             * useEasingForCamDistance = Settings.GetValue<bool>("general", "useEasingForCamDistance", useEasingForCamDistance);
             *
             * // advanced
             * lookFrontOffset = Settings.GetValue<float>("advanced", "lookFrontOffset", lookFrontOffset);
             * lookFrontOffsetLowSpeed = Settings.GetValue<float>("advanced", "lookFrontOffsetLowSpeed", lookFrontOffsetLowSpeed);
             * cameraRotationSpeed = Settings.GetValue<float>("advanced", "cameraRotationSpeed", cameraRotationSpeed);
             * cameraRotationSpeedLowSpeed = Settings.GetValue<float>("advanced", "cameraRotationSpeedLowSpeed", cameraRotationSpeedLowSpeed);
             * generalMovementSpeed = Settings.GetValue<float>("advanced", "generalMovementSpeed", generalMovementSpeed);
             * extraCamHeight = Settings.GetValue<float>("advanced", "extraCamHeight", extraCamHeight);
             *
             * //key-mappings
             * toggleEnabledKey = Settings.GetValue<Keys>("keymappings", "toggleEnabledKey", toggleEnabledKey);
             * toggleDebugKey = Settings.GetValue<Keys>("keymappings", "toggleDebugKey", toggleDebugKey);*/

            // Sanitize
            generalMovementSpeed = Mathr.Clamp(generalMovementSpeed, 0.1f, 10f);
        }
예제 #3
0
        private Transform UpdateCameraRear(Ped player, Vehicle veh)
        {
            // smooth out current rotation and position
            currentRotation = Mathr.QuaternionNLerp(currentRotation, rearCamCurrentTransform.quaternion, (responsivenessMultiplier * generalMovementSpeed) * getDeltaTime());
            currentPos      = Vector3.Lerp(currentPos, rearCamCurrentTransform.position, Mathr.Clamp01((responsivenessMultiplier * generalMovementSpeed) * getDeltaTime()));

            Quaternion look;

            var wantedPos = veh.Position + (veh.ForwardVector * finalDummyOffset);

            // If veh has towed vehicle, increase camera distance by towed vehicle longitude

            // should camera be attached to vehicle's back or back his velocity
            var fixedVsVelocity = getFixedVsVelocityFactor(veh, speedCoeff);

            // Compute camera position rear the vechicle
            var wantedPosFixed = wantedPos - Vector3.Transform(Extensions.RelativeFront, veh.Quaternion) * fullLongitudeOffset;

            // smooth out velocity
            smoothVelocity = Mathr.Vector3SmoothDamp(smoothVelocity, Vector3.Normalize(veh.Velocity), ref smoothVelocitySmDamp, generalMovementSpeed, 9999999f, responsivenessMultiplier * getDeltaTime());
            // Compute camera postition rear the direction of the vehcle
            if (speedCoeff >= stoppedSpeed)
            {
                wantedPosVelocity = wantedPos + Vector3.Transform(Extensions.RelativeBottom, Mathr.QuaternionLookRotation(smoothVelocity)) * fullLongitudeOffset;
            }

            // Smooth factor between two above cam positions
            smoothFixedVsVelocity = Mathr.Lerp(smoothFixedVsVelocity, fixedVsVelocity, (fixedVsVelocitySpeed) * getDeltaTime());

            if (!isCycleOrByke)
            {
                tempSmoothVsVl        = Mathr.Lerp(tempSmoothVsVl, Mathr.Clamp(speedCoeff / 2.3f, 0.025f, 1f), (fixedVsVelocitySpeed / 20f));
                smoothFixedVsVelocity = Mathr.Lerp(0f, smoothFixedVsVelocity, tempSmoothVsVl);
            }

            wantedPos = Vector3.Lerp(wantedPosFixed, wantedPosVelocity, Mathr.Clamp01(smoothFixedVsVelocity));

            //currentPos = Vector3.Lerp(currentPos, wantedPos, Mathr.Clamp01((responsivenessMultiplier * cameraStickiness) * getDeltaTime()));
            currentPos = Vector3.Lerp(currentPos, wantedPos, Mathr.Clamp01((responsivenessMultiplier * cameraStickiness) * getDeltaTime()));

            //rearCamCurrentTransform.position = currentPos;
            mainCamera.PointAt(pointAt);
            look = Extensions.Euler(mainCamera.Rotation);

            // Rotate the camera towards the velocity vector.
            var finalCamRotationSpeed = Mathr.Lerp(cameraRotationSpeedLowSpeed, cameraRotationSpeed, ((speedCoeff / lowSpeedLimit) * 1.32f) * getDeltaTime() * 51f);

            look = Mathr.QuaternionNLerp(currentRotation, look, (1.8f * finalCamRotationSpeed) * getDeltaTime());

            //// Auto align over time
            //if (alignmentSpeed > 0.001f)
            //{
            //    var wantedRot = veh.Rotation;
            //    //wantedRot.y = 0f;
            //    //look = Mathr.QuaternionNLerp(look, Quaternion.Euler(wantedRot), (alignmentSpeed * getDeltaTime()) * (1 - smoothIsInAir));

            //    Transform alignTr = new Transform(currentPos + fullHeightOffset, Quaternion.Identity);
            //    alignTr.PointAt(pointAt);
            //    alignTr.quaternion = Quaternion.Lerp(alignTr.quaternion, Quaternion.Euler(wantedRot), alignmentSpeed * getDeltaTime() * (1 - smoothIsInAir));

            //    currentPos = veh.Position + fullHeightOffset + (alignTr.quaternion * Vector3.RelativeBack * (fullLongitudeOffset + currentDistanceIncrement));
            //}


            // Fix stuttering (mantain camera distance fixed in local space)
            Transform fixedDistanceTr = new Transform(currentPos + fullHeightOffset + (Extensions.WorldUp * extraCamHeight), Quaternion.Identity);

            fixedDistanceTr.PointAt(pointAt);

            Quaternion rotInitial = fixedDistanceTr.quaternion;

            // Auto alignment (WIP)

            //Vector3 rotBehindVector = veh.Position + fullHeightOffset - (veh.Quaternion * Vector3.RelativeFront * (fullLongitudeOffset + currentDistanceIncrement));
            //rotBehindVector.Z = fixedDistanceTr.position.Z;

            //Quaternion rotBehind = Mathr.LookAt(rotBehindVector, pointAt);

            //Quaternion finalRot = Quaternion.Lerp(rotInitial, rotBehind, alignmentSpeed * (1 - smoothIsInAir) * (1 - smoothIsRearGear));

            //fixedDistanceTr.position = veh.Position + fullHeightOffset + (finalRot * Vector3.RelativeBack * (fullLongitudeOffset + currentDistanceIncrement));
            // End Autoalignment

            fixedDistanceTr.position = veh.Position + fullHeightOffset + (Extensions.WorldUp * extraCamHeight) + (Vector3.Transform(Extensions.RelativeBack, rotInitial) * (fullLongitudeOffset + currentDistanceIncrement));

            //fixedDistanceTr.position = fixedDistanceTr.position + fullHeightOffset;

            var transform = new Transform();

            transform.position = fixedDistanceTr.position;
            //transform.position = currentPos + fullHeightOffset;
            transform.rotation   = look.ToEulerAngles();
            transform.quaternion = look;

            rearCamCurrentTransform = transform;

            return(transform);
        }