void localMotion(EasyInputVR.Core.Motion motion) { curOrientationXValue.text = motion.currentOrientationEuler.x.ToString(); curOrientationYValue.text = motion.currentOrientationEuler.y.ToString(); curOrientationZValue.text = motion.currentOrientationEuler.z.ToString(); curAngVelXValue.text = motion.currentAngVel.x.ToString(); curAngVelYValue.text = motion.currentAngVel.y.ToString(); curAngVelZValue.text = motion.currentAngVel.z.ToString(); curPosXValue.text = motion.currentPos.x.ToString(); curPosYValue.text = motion.currentPos.y.ToString(); curPosZValue.text = motion.currentPos.z.ToString(); curAccXValue.text = motion.currentAcc.x.ToString(); curAccYValue.text = motion.currentAcc.y.ToString(); curAccZValue.text = motion.currentAcc.z.ToString(); curDerVelXValue.text = motion.currentVel.x.ToString(); curDerVelYValue.text = motion.currentVel.y.ToString(); curDerVelZValue.text = motion.currentVel.z.ToString(); curDerPosXValue.text = motion.posSinceLastReset.x.ToString(); curDerPosYValue.text = motion.posSinceLastReset.y.ToString(); curDerPosZValue.text = motion.posSinceLastReset.z.ToString(); curTotVelSinceResetXValue.text = motion.totalVelSinceLastReset.x.ToString(); curTotVelSinceResetYValue.text = motion.totalVelSinceLastReset.y.ToString(); curTotVelSinceResetZValue.text = motion.totalVelSinceLastReset.z.ToString(); curTotAngVelSinceResetXValue.text = motion.totalAngularVelSinceLastReset.x.ToString(); curTotAngVelSinceResetYValue.text = motion.totalAngularVelSinceLastReset.y.ToString(); curTotAngVelSinceResetZValue.text = motion.totalAngularVelSinceLastReset.z.ToString(); }
void trackThrow(EasyInputVR.Core.Motion motion) { //get into a -180 to 180 range motion.currentOrientationEuler.z = (motion.currentOrientationEuler.z > 180f) ? (motion.currentOrientationEuler.z - 360f) : motion.currentOrientationEuler.z; if (throwInProcess) { //there are a couple of factors that you see in a bowling motion if you look at the telemetry //left or right handed can be determined from the x axis user acceleration during the backswing (doesn't matter in this demo but if we had animation of a player could be used for that) //hardness of throw can use the user acceleration z axis during the forward swing (higher value harder throw) //spin can be determined from the x and z axis during forward part of the throw //aim of shot is the hardest as some drift will have already occured (the aim is really only dictated by //the direction going the last few frames before release of the button) best place to gauge this is the velocity //vector but there will have been some drift and in tests the sensors on board aren't good enough //so instead user will actually pick aim before throw //base hardness off current velocity.z (light throw tends to be around 1.0 and really hard around 3.0) //in terms of the game the lightest throw should be 450 and the hardest be 700 if (EasyInputHelper.isGearVR) { if (motion.totalVelSinceLastReset.z < -5f) { //currentThrow.z = 200f + (10f * -motion.totalVelSinceLastReset.z); currentThrowForce = (-motion.totalVelSinceLastReset.z); } else { //we hit and released the button but we didn't really do the motion //currentThrow.z = 30f; currentThrowForce = 3; } } else { //we hit and released the button but we didn't really do the motion //currentThrow.z = 30f; currentThrowForce = 3; } //calculate the x component off the previously detemined aim (degreesOff) //currentThrow.x = degreesOff * (currentThrow.z / 100); //base spin off of angular velocity //if (motion.totalAngularVelSinceLastReset.z < 20f && motion.totalAngularVelSinceLastReset.z > -20f) //{ // currentTorque.z = 0f; //} //else //{ // if (EasyInputHelper.isGearVR) // currentTorque.z = -motion.totalAngularVelSinceLastReset.z / 8f; //} } }
void localMotion(EasyInputVR.Core.Motion motion) { //accelerometers due to gravity can really only sense 2 axis (can't filter out gravity) //here we convert those 2 axis into horizontal and vertical and normalize horizontal = motion.currentOrientationEuler.z; vertical = motion.currentOrientationEuler.x; //get into a -180 to 180 range horizontal = (horizontal > 180f) ? (horizontal - 360f) : horizontal; vertical = (vertical > 180f) ? (vertical - 360f) : vertical; horizontal = horizontal / normalizeDegrees; vertical = vertical / normalizeDegrees; horizontal *= -sensitivity * Time.deltaTime * 100f; vertical *= -sensitivity * Time.deltaTime * 100f; actionVector3 = EasyInputUtilities.getControllerVector3(horizontal, vertical, tiltHorizontal, tiltVertical); switch (action) { case EasyInputConstants.ACTION_TYPE.Position: transform.position += actionVector3; break; case EasyInputConstants.ACTION_TYPE.Rotation: transform.Rotate(actionVector3, Space.World); break; case EasyInputConstants.ACTION_TYPE.LocalPosition: transform.Translate(actionVector3); break; case EasyInputConstants.ACTION_TYPE.LocalRotation: transform.Rotate(actionVector3); break; case EasyInputConstants.ACTION_TYPE.LocalScale: transform.localScale += actionVector3; break; default: Debug.Log("Invalid Action"); break; } }
void localMotion(EasyInputVR.Core.Motion motion) { if (laserPointer == null || !this.gameObject.activeInHierarchy) { return; } if (reticle != null) { reticle.SetActive(true); } offsetPosition = motion.currentPos; offsetPosition.y += heightOffset; if (laserPointer.transform.parent == null) { laserPointer.transform.localPosition = initialPosition + offsetPosition; } else { laserPointer.transform.localPosition = offsetPosition; } laserPointer.transform.localRotation = motion.currentOrientation; if (motion.currentPos != Vector3.zero) { line.enabled = true; } else { //not valid so disable and don't bother with the raycast so return line.enabled = false; return; } end = EasyInputConstants.NOT_VALID; //origin line.SetPosition(0, laserPointer.transform.position); if (colliderRaycast && Physics.Raycast(laserPointer.transform.position, laserPointer.transform.forward, out rayHit, reticleDistance, layersToCheck)) { end = rayHit.point; if (rayHit.transform != null && rayHit.transform.gameObject != null) { if (lastHitGameObject == null) { //we weren't hitting anything before and now we are EasyInputUtilities.notifyEvents(rayHit, lastRayHit, lastHitGameObject, true, true, false); } else if (lastHitGameObject == rayHit.transform.gameObject) { //we are hitting the same object as last frame EasyInputUtilities.notifyEvents(rayHit, lastRayHit, lastHitGameObject, true, false, false); } else if (lastHitGameObject != rayHit.transform.gameObject) { //we are hitting a different object than last frame EasyInputUtilities.notifyEvents(rayHit, lastRayHit, lastHitGameObject, true, true, true); } lastHitGameObject = rayHit.transform.gameObject; lastRayHit = rayHit.point; } } //endpoint //line.SetPosition(1, end); if (end != EasyInputConstants.NOT_VALID) { if (reticle != null) { reticle.transform.position = end; reticle.transform.localScale = initialReticleSize * .6f * (Mathf.Sqrt((end - laserPointer.transform.position).magnitude / reticleDistance)); } if ((end - laserPointer.transform.position).magnitude < laserDistance) { line.SetPosition(1, end); } else { line.SetPosition(1, laserPointer.transform.position + laserPointer.transform.forward * laserDistance); } } else { //didn't hit anything if (colliderRaycast) { //raycast enabled but didn't hit anything if (lastHitGameObject != null) { EasyInputUtilities.notifyEvents(rayHit, lastRayHit, lastHitGameObject, false, false, true); lastHitGameObject = null; lastRayHit = EasyInputConstants.NOT_VALID; } } if (reticle != null) { reticle.transform.position = laserPointer.transform.position + laserPointer.transform.forward * reticleDistance; reticle.transform.localScale = initialReticleSize; } line.SetPosition(1, laserPointer.transform.position + laserPointer.transform.forward * laserDistance); } if (reticle != null) { reticle.GetComponent <MeshRenderer>().material.color = reticleColor; } //UI based interactions if (UIRaycast && InputModule != null && (motion.currentPos != Vector3.zero)) { InputModule.setUIRay(laserPointer.transform.position, laserPointer.transform.rotation, reticleDistance); uiHitPosition = InputModule.getuiHitPosition(); if (uiHitPosition != EasyInputConstants.NOT_VALID && (end == EasyInputConstants.NOT_VALID || (end - laserPointer.transform.position).magnitude > (uiHitPosition - laserPointer.transform.position).magnitude)) { if ((uiHitPosition - laserPointer.transform.position).magnitude < reticleDistance) { reticle.transform.position = uiHitPosition; reticle.transform.localScale = initialReticleSize * .6f * (Mathf.Sqrt((uiHitPosition - laserPointer.transform.position).magnitude / reticleDistance)); } } } }
void localMotion(EasyInputVR.Core.Motion motion) { myOrientation = motion.currentOrientationEuler; }
void localMotion(EasyInputVR.Core.Motion motion) { if (laserPointer == null || !this.gameObject.activeInHierarchy) { return; } offsetPosition = motion.currentPos; offsetPosition.y += heightOffset; if (laserPointer.transform.parent == null) { laserPointer.transform.localPosition = initialPosition + offsetPosition; } else { laserPointer.transform.localPosition = offsetPosition; } laserPointer.transform.localRotation = motion.currentOrientation; if (motion.currentPos != Vector3.zero) { line.enabled = true; } else { line.enabled = false; return; } end = EasyInputConstants.NOT_VALID; //set the number of positions like we aren't going to hit anything #if UNITY_5_3 || UNITY_5_4 line.SetVertexCount(segmentsCount); #endif #if UNITY_5_5 line.numPositions = segmentsCount; #endif #if !(UNITY_5_3 || UNITY_5_4 || UNITY_5_5) line.positionCount = segmentsCount; #endif //origin line.SetPosition(0, laserPointer.transform.position); previous.transform.position = laserPointer.transform.position; previous.transform.forward = laserPointer.transform.forward; for (int i = 1; i < segmentsCount; i++) { //first set the position like it didn't hit anything line.SetPosition(i, (previous.transform.position + previous.transform.forward * segmentLength)); //now do the raycast if (colliderRaycast && Physics.Raycast(previous.transform.position, previous.transform.forward, out rayHit, segmentLength, layersToCheck)) { end = rayHit.point; line.SetPosition(i, end); //we hit something so adjust the number of positions #if UNITY_5_3 || UNITY_5_4 line.SetVertexCount(i + 1); #endif #if UNITY_5_5 line.numPositions = i + 1; #endif #if !(UNITY_5_3 || UNITY_5_4 || UNITY_5_5) line.positionCount = i + 1; #endif if (rayHit.transform != null && rayHit.transform.gameObject != null) { if (lastHitGameObject == null) { //we weren't hitting anything before and now we are EasyInputUtilities.notifyEvents(rayHit, lastRayHit, lastHitGameObject, true, true, false); } else if (lastHitGameObject == rayHit.transform.gameObject) { //we are hitting the same object as last frame EasyInputUtilities.notifyEvents(rayHit, lastRayHit, lastHitGameObject, true, false, false); } else if (lastHitGameObject != rayHit.transform.gameObject) { //we are hitting a different object than last frame EasyInputUtilities.notifyEvents(rayHit, lastRayHit, lastHitGameObject, true, true, true); } lastHitGameObject = rayHit.transform.gameObject; lastRayHit = rayHit.point; } //break out of the loop since we hit something break; } previous.transform.position = previous.transform.position + previous.transform.forward * segmentLength; previous.transform.rotation = Quaternion.AngleAxis(segmentCurveDegrees, previous.transform.right) * previous.transform.rotation; } //hit something if (end != EasyInputConstants.NOT_VALID) { if (reticle != null) { reticle.SetActive(true); reticle.transform.position = end; reticle.transform.localScale = initialReticleSize * .6f * (Mathf.Sqrt((end - laserPointer.transform.position).magnitude / reticleDistance)); } } else { //didn't hit anything if (colliderRaycast) { //raycast enabled but didn't hit anything if (lastHitGameObject != null) { EasyInputUtilities.notifyEvents(rayHit, lastRayHit, lastHitGameObject, false, false, true); lastHitGameObject = null; lastRayHit = EasyInputConstants.NOT_VALID; } } if (reticle != null) { reticle.SetActive(false); reticle.transform.position = previous.transform.position; reticle.transform.localScale = initialReticleSize; } } if (reticle != null) { reticle.GetComponent <MeshRenderer>().material.color = reticleColor; } //UI based interactions if (UIRaycast && InputModule != null && (motion.currentPos != Vector3.zero)) { InputModule.setUIRay(laserPointer.transform.position, laserPointer.transform.rotation, reticleDistance); uiHitPosition = InputModule.getuiHitPosition(); if (uiHitPosition != EasyInputConstants.NOT_VALID && (end == EasyInputConstants.NOT_VALID || (end - laserPointer.transform.position).magnitude > (uiHitPosition - laserPointer.transform.position).magnitude)) { reticle.SetActive(false); if ((uiHitPosition - laserPointer.transform.position).magnitude < reticleDistance) { reticle.transform.position = uiHitPosition; reticle.transform.localScale = initialReticleSize * .6f * (Mathf.Sqrt((uiHitPosition - laserPointer.transform.position).magnitude / reticleDistance)); } } } }
void trackThrow(EasyInputVR.Core.Motion motion) { //get into a -180 to 180 range motion.currentOrientationEuler.z = (motion.currentOrientationEuler.z > 180f) ? (motion.currentOrientationEuler.z - 360f) : motion.currentOrientationEuler.z; if (throwInProcess) { //there are a couple of factors that you see in a bowling motion if you look at the telemetry //left or right handed can be determined from the x axis user acceleration during the backswing (doesn't matter in this demo but if we had animation of a player could be used for that) //hardness of throw can use the user acceleration z axis during the forward swing (higher value harder throw) //spin can be determined from the x and z axis during forward part of the throw //aim of shot is the hardest as some drift will have already occured (the aim is really only dictated by //the direction going the last few frames before release of the button) best place to gauge this is the velocity //vector but there will have been some drift and in tests the sensors on board aren't good enough //so instead user will actually pick aim before throw //base hardness off current velocity.z (light throw tends to be around 1.0 and really hard around 3.0) //in terms of the game the lightest throw should be 450 and the hardest be 700 if (EasyInputHelper.isGearVR) { if (motion.totalVelSinceLastReset.z < -5f) { currentThrow.z = 200f + (10f * -motion.totalVelSinceLastReset.z); } else { //we hit and released the button but we didn't really do the motion currentThrow.z = 10f; } } else { //we hit and released the button but we didn't really do the motion currentThrow.z = 10f; } //calculate the x component off the previously detemined aim (degreesOff) currentThrow.x = degreesOff * (currentThrow.z / 100); //base spin off of angular velocity if (motion.totalAngularVelSinceLastReset.z < 20f && motion.totalAngularVelSinceLastReset.z > -20f) { currentTorque.z = 0f; } else { if (EasyInputHelper.isGearVR) { currentTorque.z = -motion.totalAngularVelSinceLastReset.z / 8f; } } } else if (!throwInProcess && !preventThrowAgain) { if (motion.currentOrientationEuler.z < aimDegreesClamp && motion.currentOrientationEuler.z > -aimDegreesClamp) { temp = aimArrow.localRotation.eulerAngles; temp.y = 270f - motion.currentOrientationEuler.z; aimArrow.localRotation = Quaternion.Euler(temp); //aim will get expressed in the x component of currentThrow and is a percentage of the z component //number of degrees of aim arrow is rotation times current throw z component divided by 100 //we won't know the z component until we throw the ball degreesOff = aimArrow.localRotation.eulerAngles.y - 270f; } } }