public void mapDataStructureToAction(int index) { //data accel.x = accelerometer[index].ACCELERATION_X; accel.y = accelerometer[index].ACCELERATION_Y; accel.z = accelerometer[index].ACCELERATION_Z; //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 = EasyWiFiUtilities.relativeAngleInAxis(Vector3.up, -accel, Vector3.forward) / normalizeDegrees; vertical = EasyWiFiUtilities.relativeAngleInAxis(Vector3.up, -accel, Vector3.right) / normalizeDegrees; horizontal *= -sensitivity; vertical *= sensitivity; actionVector3 = EasyWiFiUtilities.getControllerVector3(horizontal, vertical, tiltHorizontal, tiltVertical); switch (action) { case EasyWiFiConstants.ACTION_TYPE.Position: transform.position += actionVector3; break; case EasyWiFiConstants.ACTION_TYPE.Rotation: transform.Rotate(actionVector3, Space.World); break; case EasyWiFiConstants.ACTION_TYPE.LocalPosition: transform.Translate(actionVector3); break; case EasyWiFiConstants.ACTION_TYPE.LocalRotation: transform.Rotate(actionVector3); break; case EasyWiFiConstants.ACTION_TYPE.LocalScale: transform.localScale += actionVector3; break; default: Debug.Log("Invalid Action"); break; } }
public void steerBall(AccelerometerControllerType accelerometer) { //data accel.x = accelerometer.ACCELERATION_X; accel.y = accelerometer.ACCELERATION_Y; accel.z = accelerometer.ACCELERATION_Z; //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 = EasyWiFiUtilities.relativeAngleInAxis(Vector3.up, -accel, Vector3.forward) / normalizeDegrees; vertical = EasyWiFiUtilities.relativeAngleInAxis(Vector3.up, -accel, Vector3.right) / normalizeDegrees; horizontal *= -sensitivity; vertical *= -sensitivity; actionVectorPosition.x = horizontal; actionVectorPosition.y = 0f; actionVectorPosition.z = vertical; myRigidbody.AddForce(actionVectorPosition); }