Skip to content

Commit

Permalink
Increased smoothness of rotations and made that configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirsario committed Oct 21, 2021
1 parent bb90ced commit 83d7fff
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ public class ConfigData extends BaseConfigData
public static final int ConfigVersion = 1;

public boolean enabled = true;
// Roll factors
public float strafingRollFactor = 1.0f;
public float strafingRollFactorWhenFlying = -1.0f;
public float strafingRollFactorWhenSwimming = -1.0f;
public float yawDeltaRollFactor = 1.0f;
// Pitch factors
public float verticalVelocityPitchFactor = 1.0f;
public float forwardVelocityPitchFactor = 1.0f;
// Interpolation speeds
public float horizontalVelocityInterpolationSpeed = 0.25f;
public float verticalVelocityInterpolationSpeed = 0.75f;
public float yawDeltaInterpolationSpeed = 1.0f;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public final class CameraSystem implements CameraUpdateCallback, ModifyCameraTra
//private static double prevYawDeltaRollOffset;
private static double yawDeltaRollOffset;
private static double yawDeltaRollTargetOffset;
private static double lerpSpeed = 1d;
private static Transform offsetTransform = new Transform();

public CameraSystem()
Expand Down Expand Up @@ -66,11 +65,11 @@ public void OnCameraUpdate(Entity focusedEntity, Camera camera, Transform camera
Vec2f relativeXZVelocity = Vec2fUtils.Rotate(new Vec2f((float)velocity.x, (float)velocity.z), 360f - (float)cameraTransform.eulerRot.y);

//X
VerticalVelocityPitchOffset(cameraTransform, offsetTransform, velocity, relativeXZVelocity, deltaTime, config.verticalVelocityPitchFactor);
ForwardVelocityPitchOffset(cameraTransform, offsetTransform, velocity, relativeXZVelocity, deltaTime, config.forwardVelocityPitchFactor);
VerticalVelocityPitchOffset(cameraTransform, offsetTransform, velocity, relativeXZVelocity, deltaTime, config.verticalVelocityPitchFactor, config.verticalVelocityInterpolationSpeed);
ForwardVelocityPitchOffset(cameraTransform, offsetTransform, velocity, relativeXZVelocity, deltaTime, config.forwardVelocityPitchFactor, config.horizontalVelocityInterpolationSpeed);
//Z
YawDeltaRollOffset(cameraTransform, offsetTransform, velocity, relativeXZVelocity, deltaTime, config.yawDeltaRollFactor);
StrafingRollOffset(cameraTransform, offsetTransform, velocity, relativeXZVelocity, deltaTime, strafingRollFactorToUse);
YawDeltaRollOffset(cameraTransform, offsetTransform, velocity, relativeXZVelocity, deltaTime, config.yawDeltaRollFactor, config.yawDeltaInterpolationSpeed);
StrafingRollOffset(cameraTransform, offsetTransform, velocity, relativeXZVelocity, deltaTime, strafingRollFactorToUse, config.horizontalVelocityInterpolationSpeed);

prevCameraYaw = cameraTransform.eulerRot.y;
}
Expand All @@ -84,7 +83,7 @@ public Transform ModifyCameraTransform(Camera camera, Transform transform)
);
}

private void VerticalVelocityPitchOffset(Transform inputTransform, Transform outputTransform, Vec3d velocity, Vec2f relativeXZVelocity, double deltaTime, float intensity)
private void VerticalVelocityPitchOffset(Transform inputTransform, Transform outputTransform, Vec3d velocity, Vec2f relativeXZVelocity, double deltaTime, float intensity, float lerpSpeed)
{
double verticalVelocityPitchOffset = velocity.y * 2.75d;

Expand All @@ -97,7 +96,7 @@ private void VerticalVelocityPitchOffset(Transform inputTransform, Transform out
outputTransform.eulerRot = outputTransform.eulerRot.add(verticalVelocityPitchOffset * intensity, 0d, 0d);
}

private void ForwardVelocityPitchOffset(Transform inputTransform, Transform outputTransform, Vec3d velocity, Vec2f relativeXZVelocity, double deltaTime, float intensity)
private void ForwardVelocityPitchOffset(Transform inputTransform, Transform outputTransform, Vec3d velocity, Vec2f relativeXZVelocity, double deltaTime, float intensity, float lerpSpeed)
{
double forwardVelocityPitchOffset = relativeXZVelocity.y * 5d;

Expand All @@ -106,7 +105,7 @@ private void ForwardVelocityPitchOffset(Transform inputTransform, Transform outp
outputTransform.eulerRot = outputTransform.eulerRot.add(forwardVelocityPitchOffset * intensity, 0d, 0d);
}

private void YawDeltaRollOffset(Transform inputTransform, Transform outputTransform, Vec3d velocity, Vec2f relativeXZVelocity, double deltaTime, float intensity)
private void YawDeltaRollOffset(Transform inputTransform, Transform outputTransform, Vec3d velocity, Vec2f relativeXZVelocity, double deltaTime, float intensity, float lerpSpeed)
{
double yawDelta = prevCameraYaw - inputTransform.eulerRot.y;

Expand All @@ -124,7 +123,7 @@ private void YawDeltaRollOffset(Transform inputTransform, Transform outputTransf
yawDeltaRollTargetOffset = MathUtils.Lerp(yawDeltaRollTargetOffset, 0d, deltaTime * 0.35d);
}

private void StrafingRollOffset(Transform inputTransform, Transform outputTransform, Vec3d velocity, Vec2f relativeXZVelocity, double deltaTime, float intensity)
private void StrafingRollOffset(Transform inputTransform, Transform outputTransform, Vec3d velocity, Vec2f relativeXZVelocity, double deltaTime, float intensity, float lerpSpeed)
{
double strafingRollOffset = -relativeXZVelocity.x * 15d;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ public static ConfigBuilder GetConfigBuilder()

//Entries
general.addEntry(CreateBooleanEntry(entryBuilder, "enabled", true, config.enabled, value -> config.enabled = value));
// Roll factors
general.addEntry(CreateFloatFactorEntry(entryBuilder, "strafingRollFactor", 1.0f, config.strafingRollFactor, value -> config.strafingRollFactor = value));
general.addEntry(CreateFloatFactorEntry(entryBuilder, "strafingRollFactorWhenFlying", -1.0f, config.strafingRollFactorWhenFlying, value -> config.strafingRollFactorWhenFlying = value));
general.addEntry(CreateFloatFactorEntry(entryBuilder, "strafingRollFactorWhenSwimming", -1.0f, config.strafingRollFactorWhenSwimming, value -> config.strafingRollFactorWhenSwimming = value));
general.addEntry(CreateFloatFactorEntry(entryBuilder, "yawDeltaRollFactor", 1.0f, config.yawDeltaRollFactor, value -> config.yawDeltaRollFactor = value));
// Pitch factors
general.addEntry(CreateFloatFactorEntry(entryBuilder, "verticalVelocityPitchFactor", 1.0f, config.verticalVelocityPitchFactor, value -> config.verticalVelocityPitchFactor = value));
general.addEntry(CreateFloatFactorEntry(entryBuilder, "forwardVelocityPitchFactor", 1.0f, config.forwardVelocityPitchFactor, value -> config.forwardVelocityPitchFactor = value));

// Interpolation factors
general.addEntry(CreateFloatFactorEntry(entryBuilder, "horizontalVelocityInterpolationSpeed", 0.25f, config.horizontalVelocityInterpolationSpeed, value -> config.horizontalVelocityInterpolationSpeed = value));
general.addEntry(CreateFloatFactorEntry(entryBuilder, "verticalVelocityInterpolationSpeed", 0.75f, config.verticalVelocityInterpolationSpeed, value -> config.verticalVelocityInterpolationSpeed = value));
general.addEntry(CreateFloatFactorEntry(entryBuilder, "yawDeltaInterpolationSpeed", 1.0f, config.yawDeltaInterpolationSpeed, value -> config.yawDeltaInterpolationSpeed = value));

return builder;
}
//Entry Helpers
Expand Down
11 changes: 10 additions & 1 deletion src/main/resources/assets/cameraoverhaul/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"cameraoverhaul.config.category.general": "General",
"cameraoverhaul.config.enabled.name": "Enable the mod's effects",
"cameraoverhaul.config.enabled.tooltip": "Toggles all of the mod's features.",

"cameraoverhaul.config.strafingrollfactor.name": "Strafing Roll Factor",
"cameraoverhaul.config.strafingrollfactor.tooltip": "Controls the strength of the camera roll rotation caused by strafing, or sideway horizontal velocity.",
"cameraoverhaul.config.strafingrollfactorwhenflying.name": "Strafing Roll Factor When Elytra Flying",
Expand All @@ -11,8 +12,16 @@
"cameraoverhaul.config.strafingrollfactorwhenswimming.tooltip": "Controls the strength of the camera roll rotation when swimming",
"cameraoverhaul.config.yawdeltarollfactor.name": "Mouselook Roll Factor",
"cameraoverhaul.config.yawdeltarollfactor.tooltip": "Controls the strength of the camera roll rotation caused by turning around horizontally.",

"cameraoverhaul.config.verticalvelocitypitchfactor.name": "Vertical Velocity Pitch Factor",
"cameraoverhaul.config.verticalvelocitypitchfactor.tooltip": "Controls the strength of the camera pitch rotation offset caused by vertical velocity.",
"cameraoverhaul.config.forwardvelocitypitchfactor.name": "Forward Velocity Pitch Factor",
"cameraoverhaul.config.forwardvelocitypitchfactor.tooltip": "Controls the strength of the camera pitch rotation offset caused by moving forward or backwards."
"cameraoverhaul.config.forwardvelocitypitchfactor.tooltip": "Controls the strength of the camera pitch rotation offset caused by moving forward or backwards.",

"cameraoverhaul.config.horizontalvelocityinterpolationspeed.name": "Horizontal Velocity Interpolation Speed",
"cameraoverhaul.config.horizontalvelocityinterpolationspeed.tooltip": "Controls the smoothness of camera pitch & roll rotations caused by moving horizontally.",
"cameraoverhaul.config.verticalvelocityinterpolationspeed.name": "Vertical Velocity Interpolation Speed",
"cameraoverhaul.config.verticalvelocityinterpolationspeed.tooltip": "Controls the smoothness of camera pitch rotations caused by moving vertically.",
"cameraoverhaul.config.yawdeltainterpolationspeed.name": "Mouselook Roll Interpolation Speed",
"cameraoverhaul.config.yawdeltainterpolationspeed.tooltip": "Controls the smoothness of camera roll rotations caused by turning around horizontally."
}

0 comments on commit 83d7fff

Please sign in to comment.