Rig -> Control
This commit is contained in:
parent
0bce0d1599
commit
ff97981e2a
3 changed files with 1584 additions and 660 deletions
File diff suppressed because it is too large
Load diff
|
@ -12,9 +12,8 @@ public class Control
|
|||
public ValveFilter valveFilter;
|
||||
|
||||
public bool connected;
|
||||
public InputDevice headDevice, lHandDevice, rHandDevice;
|
||||
public Vector3 headTrackedPos, lHandTrackedPos, rHandTrackedPos;
|
||||
public Quaternion headTrackedRot, lHandTrackedRot, rHandTrackedRot;
|
||||
public Physical headset, leftHand, rightHand;
|
||||
public Con offCon, mainCon;
|
||||
|
||||
public void Set(InspectorSetter setter)
|
||||
{
|
||||
|
@ -31,27 +30,31 @@ public class Control
|
|||
public void Start(Logic logic)
|
||||
{
|
||||
this.logic = logic;
|
||||
|
||||
headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head);
|
||||
lHandDevice = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand);
|
||||
rHandDevice = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
|
||||
|
||||
oculusFilter.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()
|
||||
{
|
||||
// General
|
||||
connected = headDevice.isValid && (lHandDevice.isValid || rHandDevice.isValid);
|
||||
connected = headset.device.isValid && (leftHand.device.isValid || rightHand.device.isValid);
|
||||
if (!connected)
|
||||
return;
|
||||
|
||||
|
||||
XRDevice.DisableAutoXRCameraTracking(Camera.main, true);
|
||||
|
||||
// headDevice.TryGetFeatureValue();
|
||||
// need to update...
|
||||
headset.Update(logic.world.rig);
|
||||
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?
|
||||
|
||||
|
@ -59,4 +62,74 @@ public class Control
|
|||
oculusFilter.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;
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ public class Rig
|
|||
|
||||
[Header("References")]
|
||||
public GameObject disconnected;
|
||||
public Transform rig, head, con, lCon, hangingRod;
|
||||
public Transform rigTransform, head, con, lCon, hangingRod;
|
||||
public Camera recordCam;
|
||||
|
||||
[HideInInspector]
|
||||
|
@ -58,14 +58,15 @@ public class Rig
|
|||
public Lerper lerper;
|
||||
public void Update()
|
||||
{
|
||||
Control control = world.logic.control;
|
||||
// Apply to Transforms
|
||||
Quaternion flip = Quaternion.identity;
|
||||
head.localPosition = InputTracking.GetLocalPosition(XRNode.Head);
|
||||
head.localRotation = InputTracking.GetLocalRotation(XRNode.Head);
|
||||
con.localPosition = InputTracking.GetLocalPosition(XRNode.RightHand);
|
||||
con.localRotation = InputTracking.GetLocalRotation(XRNode.RightHand);
|
||||
lCon.localPosition = InputTracking.GetLocalPosition(XRNode.LeftHand);
|
||||
lCon.localRotation = InputTracking.GetLocalRotation(XRNode.LeftHand);
|
||||
head.localPosition = control.headset.pos;
|
||||
head.localRotation = control.headset.rot;
|
||||
con.localPosition = control.rightHand.pos;
|
||||
con.localRotation = control.rightHand.rot;
|
||||
lCon.localPosition = control.leftHand.pos;
|
||||
lCon.localRotation = control.leftHand.rot;
|
||||
|
||||
// °inview
|
||||
// if (OVRInput.GetDown(OVRInput.Button.PrimaryHandTrigger, ovrCon))
|
||||
|
@ -92,7 +93,7 @@ public class Rig
|
|||
// Shake
|
||||
boxShake = Vector3.Lerp(boxShake, (boxShake - boxOffset) * 0.5f, 13 * Time.deltaTime);
|
||||
boxOffset += boxShake * 13 * Time.deltaTime;
|
||||
rig.position += boxOffset;
|
||||
rigTransform.position += boxOffset;
|
||||
|
||||
// Hanging Rod
|
||||
hangingRod.position = pivotPos;
|
||||
|
|
Reference in a new issue