public virtual void OnNewPoses() { var valid = VivePose.IsValidEx(viveRole.roleType, viveRole.roleValue); if (valid) { TrackPose(VivePose.GetPoseEx(viveRole.roleType, viveRole.roleValue), m_origin); } if (ChangeProp.Set(ref m_isValid, valid)) { SetValid(m_isValid); } }
private void startZoom() { //Zoom mode Debug.Log("Zoom start"); isGrabbing = true; mode = "zoom"; initialPosR = VivePose.GetPoseEx(HandRole.RightHand, origin).pos; initialPosL = VivePose.GetPoseEx(HandRole.LeftHand, origin).pos; initialZoom = transform.localScale.x; //Take PUN ownership if necessary if (!this.photonView.IsMine) { this.GetComponent <PhotonView>().TransferOwnership(PhotonNetwork.LocalPlayer); } }
private void startRotate() { //Rotate mode Debug.Log("Rotate start"); isGrabbing = true; mode = "rotate"; initialPosR = VivePose.GetPoseEx(HandRole.RightHand, origin).pos; initialPosL = VivePose.GetPoseEx(HandRole.LeftHand, origin).pos; initialRotR = VivePose.GetPoseEx(HandRole.RightHand, origin).rot; initialRot = transform.rotation; //Take PUN ownership if necessary if (!this.photonView.IsMine) { this.GetComponent <PhotonView>().TransferOwnership(PhotonNetwork.LocalPlayer); } }
public Vector3 GetRotation(int index) { Quaternion rotation; switch (index) { case 1: rotation = VivePose.GetPoseEx(DeviceRole.Hmd).rot; break; case 2: rotation = VivePose.GetPoseEx(HandRole.LeftHand).rot; break; case 3: rotation = VivePose.GetPoseEx(HandRole.RightHand).rot; break; case 4: rotation = VivePose.GetPoseEx(TrackerRole.Tracker1).rot; break; case 5: rotation = VivePose.GetPoseEx(TrackerRole.Tracker2).rot; break; case 6: rotation = VivePose.GetPoseEx(TrackerRole.Tracker3).rot; break; default: rotation = new Quaternion(0, 0, 0, 0); break; } Vector3 normal = rotation.eulerAngles; normal.x -= 180; normal.x = Mathf.Abs(normal.x); normal.y -= 180; normal.y = Mathf.Abs(normal.y); normal.z -= 180; normal.z = Mathf.Abs(normal.z); return(normal); }
// Update is called once per frame void Update() { RigidPose pose = VivePose.GetPoseEx(HandRole.RightHand); //RigidPose pose2 = VivePose.GetPoseEx(TrackerRole.Tracker1); //print(pose1.pos.x + " " + pose1.pos.y + " " + pose1.pos.z); //set transform to the mid point between them //if (VivePose.IsValidEx(HandRole.RightHand) && VivePose.IsValidEx(TrackerRole.Tracker1)) //{ // transform.localPosition = Vector3.Lerp(pose1.pos, pose2.pos, 0.5f); // transform.localRotation = Quaternion.Lerp(pose1.rot, pose2.rot, 0.5f); //} if (ViveInput.GetPressEx(HandRole.RightHand, ControllerButton.Trigger)) { v = pose.pos - v0; } //print(v); }
private void startPan() { //Pan mode Debug.Log("Pan start"); isGrabbing = true; mode = "pan"; initialPosR = VivePose.GetPoseEx(HandRole.RightHand, origin).pos; initialPosL = VivePose.GetPoseEx(HandRole.LeftHand, origin).pos; if (!useInternalPan) { initialPos = transform.position; } else { initialPos = internalPan.transform.localPosition; } //Take PUN ownership if necessary if (!this.photonView.IsMine) { this.GetComponent <PhotonView>().TransferOwnership(PhotonNetwork.LocalPlayer); } }
Quaternion getRotation(int num) { Quaternion mRot; switch (num) { case 1: mRot = VivePose.GetPoseEx(DeviceRole.Hmd).rot; break; case 2: mRot = VivePose.GetPoseEx(HandRole.LeftHand).rot; break; case 3: mRot = VivePose.GetPoseEx(HandRole.RightHand).rot; break; case 4: mRot = VivePose.GetPoseEx(TrackerRole.Tracker1).rot; break; case 5: mRot = VivePose.GetPoseEx(TrackerRole.Tracker2).rot; break; case 6: mRot = VivePose.GetPoseEx(TrackerRole.Tracker3).rot; break; default: mRot = new Quaternion(0, 0, 0, 0); break; } return(mRot); }
Vector3 getPosition(int num) { Vector3 mPos; switch (num) { case 1: mPos = VivePose.GetPoseEx(DeviceRole.Hmd).pos; break; case 2: mPos = VivePose.GetPoseEx(HandRole.LeftHand).pos; break; case 3: mPos = VivePose.GetPoseEx(HandRole.RightHand).pos; break; case 4: mPos = VivePose.GetPoseEx(TrackerRole.Tracker1).pos; break; case 5: mPos = VivePose.GetPoseEx(TrackerRole.Tracker2).pos; break; case 6: mPos = VivePose.GetPoseEx(TrackerRole.Tracker3).pos; break; default: mPos = new Vector3(0, 0, 0); break; } return(mPos); }
public Vector3 GetPosition(int index) { Vector3 position; switch (index) { case 1: position = VivePose.GetPoseEx(DeviceRole.Hmd).pos; break; case 2: position = VivePose.GetPoseEx(HandRole.LeftHand).pos; break; case 3: position = VivePose.GetPoseEx(HandRole.RightHand).pos; break; case 4: position = VivePose.GetPoseEx(TrackerRole.Tracker1).pos; break; case 5: position = VivePose.GetPoseEx(TrackerRole.Tracker2).pos; break; case 6: position = VivePose.GetPoseEx(TrackerRole.Tracker3).pos; break; default: position = new Vector3(0, 0, 0); break; } return(position); }
//// Start is called before the first frame update void awake() { v0 = VivePose.GetPoseEx(HandRole.RightHand).pos; // last known position of left controller }
// Update is called once per frame void Update() { //Sanity check if (!ViveInput.Active) { Debug.LogWarning("ViveInput inactive"); } //Status overlay if (statusMsg != null) { statusMsg.text = mode; } //Collider update m_Collider = GetComponent <Collider>(); //LOCAL Interaction - differentiate for pan, zoom, rotate if (m_Collider.bounds.Contains(VivePose.GetPoseEx(HandRole.RightHand, origin).pos) && m_Collider.bounds.Contains(VivePose.GetPoseEx(HandRole.LeftHand, origin).pos) && ViveInput.GetPressDownEx(HandRole.RightHand, ControllerButton.Trigger) && ViveInput.GetPressDownEx(HandRole.LeftHand, ControllerButton.Trigger) && (!isGrabbing || (isGrabbing && mode != "zoom"))) { startZoom(); } else if (m_Collider.bounds.Contains(VivePose.GetPoseEx(HandRole.RightHand, origin).pos) && ViveInput.GetPressDownEx(HandRole.RightHand, ControllerButton.Trigger) && !isGrabbing) { startRotate(); } else if (m_Collider.bounds.Contains(VivePose.GetPoseEx(HandRole.LeftHand, origin).pos) && ViveInput.GetPressDownEx(HandRole.LeftHand, ControllerButton.Trigger) && !isGrabbing) { startPan(); } else if (m_Collider.bounds.Contains(VivePose.GetPoseEx(HandRole.RightHand, origin).pos) && ViveInput.GetPressDownEx(HandRole.RightHand, ControllerButton.Trigger) && isGrabbing && mode == "pan") { //Upgrade pan to zoom startZoom(); } else if (m_Collider.bounds.Contains(VivePose.GetPoseEx(HandRole.LeftHand, origin).pos) && ViveInput.GetPressDownEx(HandRole.LeftHand, ControllerButton.Trigger) && isGrabbing && mode == "rotate") { //Upgrade rotate to zoom startZoom(); } //Grab already occured, only update dependent on mode else if (isGrabbing) { if (mode == "zoom") { float zoomRaw = (VivePose.GetPoseEx(HandRole.LeftHand, origin).pos - VivePose.GetPoseEx(HandRole.RightHand, origin).pos).magnitude - (initialPosL - initialPosR).magnitude; //float scaleVal = Mathf.Clamp(initialZoom + zoomRaw,0.05f,6.0f); float scaleVal = initialZoom + (zoomRaw * initialZoom); transform.localScale = new Vector3(scaleVal, scaleVal, scaleVal); latestZoom = scaleVal; } else if (mode == "rotate") { var currentPose = VivePose.GetPoseEx(HandRole.RightHand, origin); Vector3 currentPos = currentPose.pos; Quaternion additionalRotation = Quaternion.identity; if (m_eulerAngles) { Vector3 eulerRot = new Vector3(); eulerRot.z = -((initialPosR.z - currentPos.z) * 100) % 360; eulerRot.y = ((initialPosR.x - currentPos.x) * 100) % 360; eulerRot.x = -((initialPosR.y - currentPos.y) * 100) % 360; additionalRotation = Quaternion.Euler(eulerRot); } else { Quaternion currentRot = currentPose.rot; additionalRotation = currentRot * Quaternion.Inverse(initialRotR);//Quaternion.Euler(eulerRot); } // This damping of rotation is broken for one axis, for some reason //Vector3 axis; //float angle; //additionalRotation.ToAngleAxis(out angle, out axis); //angle = angle * m_rotationScaling; //additionalRotation = Quaternion.AngleAxis(angle, axis); transform.rotation = additionalRotation * initialRot; latestRot = transform.rotation; } else if (mode == "pan") { latestPan = initialPosL - VivePose.GetPoseEx(HandRole.LeftHand, origin).pos; if (!useInternalPan) { transform.position = initialPos - latestPan; } else { internalPan.transform.localPosition = initialPos - latestPan; } latestPan = transform.position; } } //Grab release if (isGrabbing && (ViveInput.GetPressUpEx(HandRole.RightHand, ControllerButton.Trigger) || (ViveInput.GetPressUpEx(HandRole.LeftHand, ControllerButton.Trigger)))) { Debug.Log("End " + mode + " grab"); this.GetComponent <PhotonView>().TransferOwnership(0); isGrabbing = false; mode = "none"; } //REMOTE Interaction - only use values from network if not grabbed locally if (!isGrabbing && !this.GetComponent <PhotonView>().IsMine) { //Add incoming network translation / rotation (not really accounting for collisions or concurrency right now) //transform.position = Vector3.Lerp(transform.position, latestPos, Time.deltaTime * 2); this.transform.rotation = Quaternion.Lerp(transform.rotation, latestRot, Time.deltaTime * 2); this.transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(latestZoom, latestZoom, latestZoom), Time.deltaTime * 2); this.transform.position = Vector3.Lerp(transform.position, latestPan, Time.deltaTime * 2); if (useInternalPan) { this.internalPan.transform.localPosition = Vector3.Lerp(transform.position, latestPan, Time.deltaTime * 2); } } }