I am trying to simulate a click on GearVR inside a webview.
Since the content in webview can be any website, it is not under a controlled environment, I need the user to click on the headset, get the X and Y position in the webview and simulate a click.
I've tried the MotionEvent.obtain, but it needs the x and y positions first to simulate a click, and I don't have, since it is not a real touch.
Any ideas?
Any help would be great.
I've been looking around to see if I can get absolute coordinates from MotionEvent but i don't think that's possible [1].
However, you can get the X and Y position of what the user is currently looking at by performing a ray trace (depending on how you've implemented your application), and then correlate the hit point as a result of that trace to your web view to infer a "click". Hope this helps!
https://github.com/Samsung/GearVRf/issues/231
Yes to add to #DarkTemplar's response, cast a ray from your virtual position in the direction of your looking direction. Your webview is probably mapped to a quad in space I assume. Then you perform a ray-plane intersection, then check if the intersection point is in the quad. If it is, figure out the relative coordinate of the intersection within the quad and then simulate the click there.
You are encouraged to check out
https://github.com/samsung/gearvrf/wiki
more developers can help you there
Related
I'm using Java to create a simple game in 2D.
However, I would like to get the DX of the mouse so that i can move a certain object to a different place with my mouse in my game.
When i was learning a bit of LWJGL, there was a method called
Mouse.getDX()/~.getDY()
It returns the movement on the x/y axis since last time getDY() was called.
But I'm not sure how to get such value without using any other libraries like LWJGL. I only know how to get the Mouse Position using the MouseListener interface. Or is there anything I've done wrong? Thanks if you can answer :)
See this StackOverflow: Get Mouse Position
It gives information on how to get the mouse position and gives links to the java API for more details.
Or, use this tutorial to write your own listener, storing the last known position to obtain the delta: https://docs.oracle.com/javase/tutorial/uiswing/events/mousemotionlistener.html
For those of you who have played Madness Interactive, one of the most frustrating things is when the cursor leaves the game area, and you accidentally click. This causes the game to defocus and your character dies in a matter of seconds. To fix this, I'd like to make a java application that I can run in the background that will hold the cursor inside the screen until I press a key, like ESC or something.
I see two ways of implementing this, but I don't know if either of them are workable.
Make an AWT frame that matches the size of Madness Interactive's render area, and control the cursor using that.
Use some out-of-context operating system calls to keep the cursor in a given area.
Advantage of approach #1: Much easier to implement resizing of the frame so that user can see the shape and position of the enclosed area.
Potential Problems with approach #1: The AWT Frame would likely need to steal focus from the browser window the game is running in, making the whole solution pointless.
My question is, are either of these approaches viable? If not, is there a viable option?
EDIT: I am willing to use another programming language if necessary.
EDIT2: I might develop a browser plugin for this, but I've never done that kind of development before. I'll research it.
If you're still interested in working in Java, here's a possible solution for you.
First, in order to limit the cursor within an area, you could use the Java Robot class.
mouseMove(int x, int y);
Then, you could use AWT's MouseInfo to get the position of the mouse cursor.
PointerInfo mouseInfo = MouseInfo.getPointerInfo();
Point point = mouseInfo.getLocation();
int x = (int) point.getX();
int y = (int) point.getY();
Then, whenever the x and y value of the mouse cursor go beyond a certain point, move them back using the Java Robot class.
If this is for a browser-based game, consider writing a greasemonkey script, which acts as a browser extension that can be filtered to only run on the game's site.
In the simplest case, assume the clickable regions are (0,0) - (300,400), then you can add the following event handler to the page:
$(document).on('click', function(event) {
if (event.pageX > 300 || event.pageY > 400) {
return false;
}
});
You can further refine your script to do the following:
resize the browser to be the perfect size for playing the game
instead of checking the absolute x,y coords of the click, check if it is inside an element of the page that you don't want to receive the click
add custom key bindings to umm.. help you at the game
write a javascript bot that can play the game itself
How do you get the sensitivity of a mouse, change it, and then apply it to the mouse?
-Progress removed, showed the speed of clicking instead of the speed of moving-
I have researched this "everywhere", but there is nothing on this subject.
First of all I think arg0.getXOnScreen will give You the absolute x coordinate of the mouse, not the old position as You're assuming by defining variable named oldX. getX should give you the position within the panel or (sth like widget i do not know the api you are using). The second thing is... what do You mean 'sensitivity of mouse' Do you want to change global system settings for mouse from java ? I do not think it is even possible. Look here this will require You to add jni lib to project and invoke some native libs, so You make your code platform dependent.
You would probably have to tinker with the Robot class and listnening for mouse events. So you'd have to listen for mouse pressed events and after that use robot to move the mouse 3x more pixels than the mouse is actually moving, then you'd have to do a mouse up event via the Robot class, reposition the mouse to the original position followed by a mouse down event via the robot.
See how this can be problematic? This would be extremely use case driven and not something to do generically. I've been doing Java a long time so I could probably pull it off but it is not something a novice could probably do because other issues would come up that need resolution during the debugging process.
Noticed this thread when dealing with a 3d API that rotates the view WAY TO SLOW.
I have an image in VTK that I'm viewing with vtkImageViewer2, and I want to zoom in on a point the user clicks on. I am working in Java. Does anyone know how to do this?
Thanks
I realize you ask for Java, but my experience doing this has been with c++; equivalent java syntax should work, minus the customizability.
Take a look at these examples for picking and zooming. Also, if you set the interactor style to 'image', the mouse wheel should cause a zoom to wherever the cursor is. You probably don't want to do literally what you asked, but rather either do rubberband zoom or have the mousewheel for zooming. Clicking should do something, not just change the view.
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/PickingAPixel2
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/RubberBandZoom
Depending on what you mean by zoom you want to either change the position and direction of the camera (likely) or change the frustum (unlikely).
Have a look at the methods setPosition() and setFocalPoint() in class vtkCamera. Here is the documentation of vtkCamera:
http://www.vtk.org/doc/nightly/html/classvtkCamera.html
I want to build up a GUI area where users can click randomly. Then I want to retrieve the cartesian (x,y) coordinates of those points where the user clicked. Which GUI component is suitable for my task. Also, I want to have any point as big as a usual dot (maybe 3 pixels or more - does this depend on resolution? And if I change the screen resolution of the monitor during the program execution, does the coordinate change?)
I usually work in web programming and I am totally novice in this area. Any pointers to good background reading would help greatly.
Thanks.
http://download.oracle.com/javase/tutorial/uiswing/events/mouselistener.html
Is this what you're searching for?
as for changing resolution,
I believe you need a listener which changes/updates the size, though I'm pretty much not familiar with that, sorry.