Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Menithal committed Feb 20, 2020
2 parents 14103d5 + ec4bcb9 commit 03939e6
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 94 deletions.
96 changes: 75 additions & 21 deletions MACPlugin/ActionCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,21 @@ public ActionCamera(ActionCameraSettings pluginSettings,
public virtual void SetPluginSettings(ActionCameraSettings settings)
{
pluginSettings = settings;
fov = settings.cameraDefaultFov;
}

abstract public void ApplyBehavior(ref Vector3 cameraTarget, ref Vector3 lookAtTarget,
LivPlayerEntity player, bool isCameraAlreadyPlaced);

public virtual Quaternion GetRotation(Vector3 lookDirection, LivPlayerEntity player)
{
return Quaternion.LookRotation(lookDirection);
}
}

public class SimpleActionCamera : ActionCamera
{
public Vector3 lookAtOffset = new Vector3(0f, 0, 0.1f);
public Vector3 lookAtOffset = new Vector3(0f, 0, 0.25f);
public SimpleActionCamera(ActionCameraSettings settings, float timeBetweenChange, Vector3 offset, bool removeHead = false, bool staticCamera = false) :
base(settings, timeBetweenChange, offset, removeHead, staticCamera)
{
Expand All @@ -88,6 +94,53 @@ public override void ApplyBehavior(ref Vector3 cameraTarget, ref Vector3 lookAtT
cameraTarget.y = Mathf.Clamp(cameraTarget.y, player.head.position.y * 0.2f, player.head.position.y * 1.2f);
}
}
public class ScopeActionCamera : ActionCamera
{
public Vector3 lookAtOffset = new Vector3(0f, 0f, 10f);

Transform dominantHand;
Transform nonDominantHand;
Vector3 dominantEye;
Vector3 lookAtDirection;
public ScopeActionCamera(ActionCameraSettings settings) :
base(settings, 0.1f, Vector3.zero, true)
{
SetPluginSettings(settings);
}
public override void SetPluginSettings(ActionCameraSettings settings)
{
base.SetPluginSettings(settings);
offset = new Vector3(0, -settings.cameraGunEyeVerticalOffset, 0);
timeBetweenChange = settings.cameraGunSmoothing;
fov = settings.cameraGunFov;
}
public override Quaternion GetRotation(Vector3 lookDirection, LivPlayerEntity player)
{
return Quaternion.LookRotation(lookAtDirection, Vector3.up);
}
public override void ApplyBehavior(ref Vector3 cameraTarget, ref Vector3 lookAtTarget, LivPlayerEntity player, bool isCameraAlreadyPlaced)
{
// Automatic determination which is closest?
if (pluginSettings.rightHandDominant)
{
dominantHand = player.rightHand;
nonDominantHand = player.leftHand;
dominantEye = player.rightEye + player.head.rotation * offset;
}
else
{
dominantHand = player.leftHand;
nonDominantHand = player.rightHand;
dominantEye = player.leftEye + player.head.rotation * offset;
}

lookAtDirection = (nonDominantHand.position - dominantHand.position);
// We will override the lookAtTarget and use GetRotation to define the actual rotation.
lookAtTarget = Vector3.zero;
cameraTarget = dominantEye;// Vector3.Lerp(dominantEye, lookAtTarget, pluginSettings.cameraGunZoom);
}
}

public class ShoulderActionCamera : ActionCamera
{
// This one really needs an intermediary camera
Expand All @@ -108,7 +161,7 @@ public ShoulderActionCamera(ActionCameraSettings settings) :
}
public override void SetPluginSettings(ActionCameraSettings settings)
{
pluginSettings = settings;
base.SetPluginSettings(settings);
timeBetweenChange = settings.cameraShoulderPositioningTime / (settings.inBetweenCameraEnabled ? 2 : 1);
betweenCamera.timeBetweenChange = timeBetweenChange;
betweenCamera.SetPluginSettings(settings);
Expand All @@ -124,10 +177,10 @@ public void CalculateOffset()
float y = pluginSettings.cameraShoulderDistance * Mathf.Cos(radianAngle);
float x = pluginSettings.cameraShoulderDistance * Mathf.Sin(radianAngle);

Vector3 calculatedOffset = new Vector3(x, 0.4f, -y);
Vector3 calculatedOffset = new Vector3(x, 0.5f, -y);

// PluginLog.Log("ShoulderActionCamera", "Calculated Offset " + calculatedOffset + " vs " + offset);
// Gotta be from back not from front.
// PluginLog.Log("ShoulderActionCamera", "Calculated Offset " + calculatedOffset + " vs " + offset);
// Gotta be from back not from front.
// calculatedOffset.z = -Mathf.Sqrt(Mathf.Abs(Mathf.Pow(offset.z, 2) - Mathf.Pow(offset.x, 2)));
this.offset = calculatedOffset;
}
Expand All @@ -143,22 +196,21 @@ public override void ApplyBehavior(ref Vector3 cameraTarget, ref Vector3 lookAtT
*/

sbyte estimatedSide = (player.headRRadialDelta.x < 0 ? NEGATIVE_SBYTE : POSITIVE_SBYTE);
if (!swappingSides && Mathf.Abs(player.headRRadialDelta.x) > 3 &&
player.timerHelper.actionCameraTimer > this.timeBetweenChange &&
if (!swappingSides && Mathf.Abs(player.headRRadialDelta.x) > pluginSettings.cameraShoulderSensitivity &&
player.timerHelper.cameraActionTimer > this.timeBetweenChange &&
estimatedSide != currentSide)
{
PluginLog.Log("ShoulderCamera", "Swapping sides " + estimatedSide);
swappingSides = true;
destinationSide = estimatedSide;
player.timerHelper.ResetActionCameraTimer();
player.timerHelper.ResetCameraActionTimer();
}
else if (swappingSides && player.timerHelper.actionCameraTimer > this.timeBetweenChange )
else if (swappingSides && player.timerHelper.cameraActionTimer > this.timeBetweenChange)
{
swappingSides = false;

currentSide = destinationSide;
PluginLog.Log("ShoulderCamera", "Done Swapping");
player.timerHelper.ResetActionCameraTimer();
player.timerHelper.ResetCameraActionTimer();
}

if (swappingSides && pluginSettings.inBetweenCameraEnabled)
Expand Down Expand Up @@ -196,10 +248,10 @@ public FPSCamera(ActionCameraSettings settings, float timeBetweenChange) : base(
public class FullBodyActionCamera : ActionCamera
{
// This one really needs an intermediary camera
private Vector3 lookAtOffset = new Vector3(0f, 0f, 0.5f);
private Vector3 lookAtOffset = Vector3.zero;
private readonly SimpleActionCamera betweenCamera;
private bool swappingSides = false;

public FullBodyActionCamera(ActionCameraSettings settings) :
base(settings, 0, Vector3.zero, false, false)
{
Expand All @@ -222,7 +274,7 @@ public void CalculateOffset()

Vector3 calculatedOffset = new Vector3(x, 0.4f, y);

// calculatedOffset.z = Mathf.Sqrt(Mathf.Abs(Mathf.Pow(offset.z, 2f) - Mathf.Pow(offset.x, 2f)));
// calculatedOffset.z = Mathf.Sqrt(Mathf.Abs(Mathf.Pow(offset.z, 2f) - Mathf.Pow(offset.x, 2f)));
PluginLog.Log("FullBodyActionCamera", "Calculated Position " + calculatedOffset);
PluginLog.Log("FullBodyActionCamera", "Calculated timeBetweenChange " + timeBetweenChange);
offset = calculatedOffset;
Expand All @@ -235,30 +287,32 @@ public override void SetPluginSettings(ActionCameraSettings settings)
betweenCamera.timeBetweenChange = timeBetweenChange;
betweenCamera.SetPluginSettings(settings);

betweenCamera.offset = new Vector3(0, 1f, settings.cameraBodyLookAtForward);
betweenCamera.offset = new Vector3(0, 1f, settings.cameraBodyDistance);


CalculateOffset();
}
public override void ApplyBehavior(ref Vector3 cameraTarget, ref Vector3 lookAtTarget, LivPlayerEntity player, bool isCameraAlreadyPlaced)
{
Vector3 cameraPositionOffsetTarget = offset;

sbyte estimatedSide = (player.headRRadialDelta.x < 0 ? NEGATIVE_SBYTE : POSITIVE_SBYTE);
if (!swappingSides && Mathf.Abs(player.headRRadialDelta.x) > 3 &&
player.timerHelper.actionCameraTimer > this.timeBetweenChange &&
if (!swappingSides && Mathf.Abs(player.headRRadialDelta.x) > pluginSettings.cameraBodySensitivity &&
player.timerHelper.cameraActionTimer > this.timeBetweenChange &&
estimatedSide != currentSide)
{
PluginLog.Log("FullBodyActionCamera", "Swapping sides " + estimatedSide);
swappingSides = true;
destinationSide = estimatedSide;
player.timerHelper.ResetActionCameraTimer();
player.timerHelper.ResetCameraActionTimer();
}
else if (swappingSides && player.timerHelper.actionCameraTimer > this.timeBetweenChange)
else if (swappingSides && player.timerHelper.cameraActionTimer > this.timeBetweenChange)
{
swappingSides = false;
currentSide = destinationSide;

PluginLog.Log("FullBodyActionCamera", "Done Swapping ");
player.timerHelper.ResetActionCameraTimer();
player.timerHelper.ResetCameraActionTimer();
}

if (swappingSides && pluginSettings.inBetweenCameraEnabled)
Expand All @@ -274,7 +328,7 @@ public override void ApplyBehavior(ref Vector3 cameraTarget, ref Vector3 lookAtT
// Floor and Ceiling Avoidance. Camera should not be too high or too low in ratio to player head position
cameraTarget.y = Mathf.Clamp(cameraTarget.y, player.head.position.y * 0.2f, player.head.position.y * 1.2f);


lookAtTarget = (player.waist.position + player.head.TransformPoint(lookAtOffset)) / 2;

if (pluginSettings.cameraVerticalLock)
Expand Down
Loading

0 comments on commit 03939e6

Please sign in to comment.