GearVRf icon indicating copy to clipboard operation
GearVRf copied to clipboard

Problem With onTouchEvent and button presses

Open SteveGreatApe opened this issue 7 years ago • 5 comments

Hi, I'm trying to get some code going using the Samsung controller to navigate the scene. I want use the touchpad on the controller for player movements. I'm intercepting events in the Activity's onTouchEvent call.

@Override
public boolean onTouchEvent(MotionEvent event) {
    Log.d("MyActivity", "onTouchEvent: " + event);
    ...do something...
    return super.onTouchEvent(event);
}

I'm getting input okay while I'm not pressing either the trigger or the touchpad button itself, but while either of those are depressed the x,y co-ordindates coming back are always x=1280.0 y=720.0. Needless to say this is making it rather awkward when I don't want the player to become stuck whenever a button's depressed.

Is this the right way to receive this input, I would have expected the onEvent callback in GVRCursorController.ControllerEventListener to have delivered these through getMotionEvent(), but I'm not getting any motion events at all from the controller.

Also I can't find any way of getting the orientation of the controller, other than through attaching a GVRSceneObject to it and reading back this objects orientation, surely there must be a proper interface to retrieve the controllers orientation?

SteveGreatApe avatar Jun 22 '17 09:06 SteveGreatApe

Hi @SteveGreatApe ,

I've replicated your problem. It seems that processing the motion events may not be the best way to get the information you desire from the controller. If you're using the 3.2 release version of GearVRf, it seems like you can get all of the information you desire by downcasting your GVRCursorController to a OvrGearController:

To query the device specific information from the Gear Controller make sure to type cast the returned {@link GVRCursorController} to {@link OvrGearController} like below: OvrGearController controller = (OvrGearController) gvrCursorController;

After the downcast, you should be able to call getRotation to get the controller orientation and getTouch to get the touch coordinates.

However, please note that this class will be renamed to GearCursorController and refactored as a private class in the next release, and you should be able to obtain the information through some event API rather than by explicitly downcasting the GVRCursorController.

-Jon

J0Nreynolds avatar Jun 23 '17 17:06 J0Nreynolds

Hi, thanks for the reply. I had looked into downcasting the controller to OvrGearController, but it struck me as this wasn't intended behavior as the OvrGearController class isn't public, so the only way to access it through downcasting is to create my own wrapper class under the same org.gearvrf package name.

Having done that I tried to access the rotation through the getRotation() call as suggested, but most of the time this returns null due to currentControllerEvent.isRecycled() returning true. same problem applies to getTouch().

As far as I can see, the only way to access this information is to modify the GearVRf code to extract the touch and rotation data out of the event class in it's onDrawFrame() call and then add functions to access that extracted data into OvrGearController.

SteveGreatApe avatar Jun 26 '17 06:06 SteveGreatApe

@SteveGreatApe Take a look at https://github.com/Samsung/GearVRf/pull/1254 and let us know whether it would work for you.

liaxim avatar Jun 26 '17 18:06 liaxim

@SteveGreatApe If you do the downcast in a GVRCursorController.ControllerEventListener, the getRotation and getTouch should return non-null values. Also, the OvrGearController is a public class in release 3.2, but it was modified sometime after the release to be private.

Nonetheless, if you plan on using newer versions of the framework, please look at @liaxim's pull request, which seems like a more proper way of accessing the information you desire.

J0Nreynolds avatar Jun 26 '17 19:06 J0Nreynolds

We need to expose the complete touchpad information (maximum coordinates, size in mm) from ovrInputTrackedRemoteCapabilities before closing this issue.

liaxim avatar Jun 29 '17 14:06 liaxim