mirror of
https://udrimavric.com/MAVRIC/Stratasys-450mc-VR.git
synced 2025-01-22 15:18:33 -05:00
Simplified rotate and scale target classes, added to thumbwheel
This commit is contained in:
parent
cd5af28a09
commit
1542176845
File diff suppressed because it is too large
Load Diff
@ -11,20 +11,10 @@ namespace Interactions
|
||||
private bool isHovering;
|
||||
|
||||
[SerializeField] private Vector3 scrollAxis = Vector3.up;
|
||||
|
||||
public RotateTarget rotator;
|
||||
|
||||
[SerializeField] private MeshRenderer meshRenderer;
|
||||
|
||||
[SerializeField] private Material onMat, offMat;
|
||||
|
||||
|
||||
public TextMeshProUGUI text;
|
||||
[SerializeField] private float scrollScale = 1000;
|
||||
|
||||
public void OnHoverEntered(HoverEnterEventArgs args)
|
||||
{
|
||||
|
||||
}
|
||||
public RotateTarget rotator;
|
||||
public ScaleTarget scalar;
|
||||
|
||||
public void OnSelected(SelectEnterEventArgs args)
|
||||
{
|
||||
@ -35,7 +25,6 @@ namespace Interactions
|
||||
{
|
||||
if (isHovering) yield break;
|
||||
isHovering = true;
|
||||
meshRenderer.material = onMat;
|
||||
Vector3 previousPos = mover.position;
|
||||
|
||||
while (isHovering)
|
||||
@ -44,21 +33,15 @@ namespace Interactions
|
||||
|
||||
Vector3 currentPos = mover.position;
|
||||
|
||||
//Calculate the difference in position only along one axis
|
||||
Vector3 diff = (previousPos - currentPos);
|
||||
diff = new Vector3(diff.x * scrollAxis.x, diff.y * scrollAxis.y, diff.z * scrollAxis.z);
|
||||
|
||||
text.text = diff.ToString("0.00000");
|
||||
float diffTotal = (diff.x + diff.y + diff.z) * scrollScale;
|
||||
|
||||
previousPos = currentPos;
|
||||
rotator.Rotate(diff);
|
||||
rotator.Rotate(diffTotal);
|
||||
scalar.Scale(diffTotal);
|
||||
}
|
||||
|
||||
meshRenderer.material = offMat;
|
||||
}
|
||||
|
||||
public void OnHoverExited(HoverExitEventArgs args)
|
||||
{
|
||||
//isHovering = false;
|
||||
}
|
||||
|
||||
public void OnUnSelected(SelectExitEventArgs args)
|
||||
|
@ -10,39 +10,15 @@ public class RotateTarget : MonoBehaviour
|
||||
[SerializeField] private Transform target;
|
||||
|
||||
[SerializeField] private float speed = 10f;
|
||||
[Range(0f, 1f)]
|
||||
[SerializeField] private float inputValue = 0f;
|
||||
[Range(-1f, 1f)]
|
||||
[SerializeField, ReadOnly] private float direction = 0f;
|
||||
[SerializeField] private bool invertDirection = false;
|
||||
private void Update()
|
||||
|
||||
[SerializeField] private Vector3 rotationAxis = Vector3.right;
|
||||
|
||||
public void Rotate(float amount)
|
||||
{
|
||||
if (target == null) return;
|
||||
return;
|
||||
amount *= Time.deltaTime;
|
||||
|
||||
RemapDirection();
|
||||
|
||||
target.RotateAround(target.position, target.up, speed * direction * Time.deltaTime);
|
||||
}
|
||||
amount *= speed;
|
||||
|
||||
private void RemapDirection(float min = -1f, float max = 1f)
|
||||
{
|
||||
direction = Mathf.Lerp(min, max, inputValue);
|
||||
direction *= invertDirection ? -1f : 1f;
|
||||
}
|
||||
|
||||
public void SetDirectionValue(float value) => inputValue = value;
|
||||
|
||||
public void Rotate(Vector3 value)
|
||||
{
|
||||
float totalRot = value.x + value.y + value.z;
|
||||
|
||||
totalRot *= Time.deltaTime;
|
||||
|
||||
totalRot *= speed;
|
||||
|
||||
Vector3 axis = Vector3.forward;
|
||||
|
||||
target.Rotate(axis,totalRot);
|
||||
target.Rotate(rotationAxis,amount);
|
||||
}
|
||||
}
|
||||
|
@ -14,33 +14,14 @@ public class ScaleTarget : MonoBehaviour
|
||||
[SerializeField] private Vector3 scaleAxis = Vector3.right;
|
||||
|
||||
[SerializeField] private float speed = 1f;
|
||||
[Range(0f, 1f)]
|
||||
[SerializeField] private float inputValue = 0f;
|
||||
[Range(-1f, 1f)]
|
||||
[SerializeField, ReadOnly] private float direction = 0f;
|
||||
[SerializeField] private bool invertDirection = false;
|
||||
|
||||
private void Update()
|
||||
public void Scale(float value)
|
||||
{
|
||||
if (target == null) return;
|
||||
|
||||
RemapDirection();
|
||||
|
||||
target.localScale += scaleAxis * (speed * direction * Time.deltaTime);
|
||||
|
||||
// Clamp the scale but only on the scale axis
|
||||
target.localScale += scaleAxis * (value * speed * Time.deltaTime);
|
||||
var clampedScale = target.localScale;
|
||||
clampedScale.x = Mathf.Clamp(clampedScale.x, minScale, maxScale);
|
||||
clampedScale.y = Mathf.Clamp(clampedScale.y, minScale, maxScale);
|
||||
clampedScale.z = Mathf.Clamp(clampedScale.z, minScale, maxScale);
|
||||
target.localScale = clampedScale;
|
||||
}
|
||||
|
||||
private void RemapDirection(float min = -1f, float max = 1f)
|
||||
{
|
||||
direction = Mathf.Lerp(min, max, inputValue);
|
||||
direction *= invertDirection ? -1f : 1f;
|
||||
}
|
||||
|
||||
public void SetDirectionValue(float value) => inputValue = value;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user