public ROS.Pose getPose() { ROS.Pose pose = new ROS.Pose(); string msg = getMsg(); JsonUtility.FromJsonOverwrite(msg, pose); clearMsg(); // Debug.Log(JsonUtility.ToJson(pose)); return(pose); }
// Update is called once per frame void Update() { OVRInput.Update(); // Has to be called at the beginning to interact with OVRInput. // Retrieve buttons status buttons[0] = OVRInput.Get(OVRInput.Button.One) ? 1 : 0; buttons[1] = OVRInput.Get(OVRInput.Button.Two) ? 1 : 0; buttons[2] = OVRInput.Get(OVRInput.Button.Three) ? 1 : 0; buttons[3] = OVRInput.Get(OVRInput.Button.Four) ? 1 : 0; buttons[9] = OVRInput.Get(OVRInput.Button.PrimaryThumbstick) ? 1 : 0; buttons[10] = OVRInput.Get(OVRInput.Button.SecondaryThumbstick) ? 1 : 0; // Retrieve axes status Vector2 axisStickLeft = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick); axes[0] = axisStickLeft.x; axes[1] = axisStickLeft.y; axes[2] = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger); Vector2 axisStickRight = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick); axes[3] = axisStickRight.x; axes[4] = axisStickRight.y; axes[5] = OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger); // Send buttons and axes to ROS. rosClient.publish(buttons, 11, axes, 8); // Read position from ROS. if (rosClient.isPoseAvailable()) { ROS.Pose pose = rosClient.getPose(); Debug.Log(JsonUtility.ToJson(pose)); gameObject.transform.position = pose.position.toUnityCoordSys(positionScale); if (enableRotation) { gameObject.transform.eulerAngles = pose.orientation.toUnityCoordSys(); Debug.Log("Euler: " + gameObject.transform.eulerAngles.ToString()); } } }