Rig -> Control

This commit is contained in:
spatialfree 2020-12-13 19:50:58 -08:00
parent 0bce0d1599
commit ff97981e2a
3 changed files with 1584 additions and 660 deletions

File diff suppressed because it is too large Load diff

View file

@ -12,9 +12,8 @@ public class Control
public ValveFilter valveFilter; public ValveFilter valveFilter;
public bool connected; public bool connected;
public InputDevice headDevice, lHandDevice, rHandDevice; public Physical headset, leftHand, rightHand;
public Vector3 headTrackedPos, lHandTrackedPos, rHandTrackedPos; public Con offCon, mainCon;
public Quaternion headTrackedRot, lHandTrackedRot, rHandTrackedRot;
public void Set(InspectorSetter setter) public void Set(InspectorSetter setter)
{ {
@ -31,27 +30,31 @@ public class Control
public void Start(Logic logic) public void Start(Logic logic)
{ {
this.logic = logic; this.logic = logic;
headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head);
lHandDevice = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand);
rHandDevice = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
oculusFilter.Start(this); oculusFilter.Start(this);
valveFilter.Start(this); valveFilter.Start(this);
headset.device = InputDevices.GetDeviceAtXRNode(XRNode.Head);
leftHand.device = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand);
rightHand.device = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
} }
public void Update() public void Update()
{ {
// General // General
connected = headDevice.isValid && (lHandDevice.isValid || rHandDevice.isValid); connected = headset.device.isValid && (leftHand.device.isValid || rightHand.device.isValid);
if (!connected) if (!connected)
return; return;
XRDevice.DisableAutoXRCameraTracking(Camera.main, true); XRDevice.DisableAutoXRCameraTracking(Camera.main, true);
// headDevice.TryGetFeatureValue(); headset.Update(logic.world.rig);
// need to update... leftHand.Update(logic.world.rig);
rightHand.Update(logic.world.rig);
// handedness!
offCon.Update(leftHand, rightHand);
mainCon.Update(rightHand, leftHand);
// you can play with your left controller or your right (and?) RIG CLASS? // you can play with your left controller or your right (and?) RIG CLASS?
@ -59,4 +62,74 @@ public class Control
oculusFilter.Update(); oculusFilter.Update();
valveFilter.Update(); valveFilter.Update();
} }
}
[Serializable]
public class Physical
{
public InputDevice device;
public Vector3 pos, worldPos;
public Vector3 oldPos, oldWorldPos;
public Quaternion rot, oldRot, rotDelta;
public Vector3 vel, rotVel;
public void Update(Rig rig)
{
oldPos = pos; oldWorldPos = worldPos;
device.TryGetFeatureValue(CommonUsages.devicePosition, out pos);
worldPos = rig.rigTransform.position + pos;
oldRot = rot;
device.TryGetFeatureValue(CommonUsages.deviceRotation, out rot);
rotDelta = rot * Quaternion.Inverse(oldRot);
device.TryGetFeatureValue(CommonUsages.deviceVelocity, out vel);
device.TryGetFeatureValue(CommonUsages.deviceAngularVelocity, out rotVel);
}
}
[Serializable]
public class Con
{
public Tactile triggerBtn, gripBtn;
public float trigger, grip, stretch;
public Vector2 joystick;
public void Update(Physical mainHand, Physical offHand)
{
mainHand.device.TryGetFeatureValue(CommonUsages.trigger, out trigger);
mainHand.device.TryGetFeatureValue(CommonUsages.grip, out grip);
mainHand.device.TryGetFeatureValue(CommonUsages.primary2DAxis, out joystick);
bool state;
mainHand.device.TryGetFeatureValue(CommonUsages.triggerButton, out state); // change to custom float check?
triggerBtn.Update(state);
mainHand.device.TryGetFeatureValue(CommonUsages.gripButton, out state);
gripBtn.Update(state);
stretch = Vector3.Distance(mainHand.pos, offHand.pos);
}
}
[Serializable]
public class Tactile
{
public bool down, held, up;
public void Update(bool state)
{
down = up = false;
if (state && !held)
{
down = true;
}
if (!state && held)
{
up = true;
}
held = state;
}
} }

View file

@ -28,7 +28,7 @@ public class Rig
[Header("References")] [Header("References")]
public GameObject disconnected; public GameObject disconnected;
public Transform rig, head, con, lCon, hangingRod; public Transform rigTransform, head, con, lCon, hangingRod;
public Camera recordCam; public Camera recordCam;
[HideInInspector] [HideInInspector]
@ -58,14 +58,15 @@ public class Rig
public Lerper lerper; public Lerper lerper;
public void Update() public void Update()
{ {
Control control = world.logic.control;
// Apply to Transforms // Apply to Transforms
Quaternion flip = Quaternion.identity; Quaternion flip = Quaternion.identity;
head.localPosition = InputTracking.GetLocalPosition(XRNode.Head); head.localPosition = control.headset.pos;
head.localRotation = InputTracking.GetLocalRotation(XRNode.Head); head.localRotation = control.headset.rot;
con.localPosition = InputTracking.GetLocalPosition(XRNode.RightHand); con.localPosition = control.rightHand.pos;
con.localRotation = InputTracking.GetLocalRotation(XRNode.RightHand); con.localRotation = control.rightHand.rot;
lCon.localPosition = InputTracking.GetLocalPosition(XRNode.LeftHand); lCon.localPosition = control.leftHand.pos;
lCon.localRotation = InputTracking.GetLocalRotation(XRNode.LeftHand); lCon.localRotation = control.leftHand.rot;
// °inview // °inview
// if (OVRInput.GetDown(OVRInput.Button.PrimaryHandTrigger, ovrCon)) // if (OVRInput.GetDown(OVRInput.Button.PrimaryHandTrigger, ovrCon))
@ -92,7 +93,7 @@ public class Rig
// Shake // Shake
boxShake = Vector3.Lerp(boxShake, (boxShake - boxOffset) * 0.5f, 13 * Time.deltaTime); boxShake = Vector3.Lerp(boxShake, (boxShake - boxOffset) * 0.5f, 13 * Time.deltaTime);
boxOffset += boxShake * 13 * Time.deltaTime; boxOffset += boxShake * 13 * Time.deltaTime;
rig.position += boxOffset; rigTransform.position += boxOffset;
// Hanging Rod // Hanging Rod
hangingRod.position = pivotPos; hangingRod.position = pivotPos;