I've made an input handler for strategy games, hope someone will find it useful.
Features:
spherical look with configurable limits (e.g. 10 to 90 degrees vertical axis and 0 to 180 degrees horizontal axis)
automatically adjusts the scrolling direction based on the camera orientation
input filters for scrolling, looking and zooming (pretty much everything)
fully configurable (including any custom coordinate system, eg: x and y as 2d location and z as height)
can seamlessly switch between software and hardware mouse
mouse pointer animation
cursor management
integrated follow object mode (a chase-cam that is more suitable for a strategy game)
demo with a full theme of animated cursors and most of usage examples
complete input filter framework that can be easily used in other handlers
spatial controller to smoothly move a spatial from point a to point b using a spring filter, while the destination (point b) is changing dynamically.
optional camera effects: one for smoothly taking over camera into strategicHandler mode and another for smoothly flying a camera to a desired location.
Controls:
Scroll the window by moving mouse to the edge of the screen or by using arrows on the keyboard.
Hold the right mouse button or LEFT_CONTROL to rotate the view with the mouse or use HOME <-> END, DEL <-> PAGE_DOWN.
Use mouse wheel or INSERT <-> PAGE_UP to zoom.
Press KEYPAD_ENTER to toggle between hardware and software mouse.
Hardware vs Software mouse:
If you are using the hardware mouse in windowed mode, your mouse will be able to leave window,
so you can have the game running and browse web for example.
Using the software mouse will lock the pointer inside the window so that it becomes possible to scroll
the screen by moving the mouse to the edge of the window.
Wow this is really great, I've been wanting to make a stategy game for a while and this takes some of the hard work out of it (I originaly started using soya3d a python 3d engine but after finding out about jmonkey it's out the door) I still have to learn more about java and jme but this has gotten me off to a running start. Thanks a lot.
I'll get on it right away, but if you cant wait, here are is how to make a quick fix:
What you need are two height values: one for camera and another one for the point the camera is looking at. You will have to change the StrategicHandler.update() method as follows:
So the update method has to query the terrainPage for those two hight values. Alternatively you can inject those two values before calling the update method. Either way, some modification to the update method and update sequence are needed. Yet another way is make all the transformations to the camera in game's update method, instead of controller's update method…
I've added some more features to strategicHandler, as well as done some overall polish…
new:
demo with terrain
code to adjust camera height based on terrain
mouse input filter while rotating view with the mouse
input filters for keyboard rotation and zoom
all the configuration code is there, everything is now fully configurable
improvements:
overall code improvements
a very good set of defaults
The source code and binaries are now in two separate archives. Also the binaries are compiled for Java 5 (last version was compiled for Java 6 and I realize some people might not have it… my bad). I have also included a readme file.
It's supposed to be in jme. Make sure it's there (maybe it was removed very recently). I've tested the demo with the latest release of jme (jars) and it was working.
You can also try to do "Project ->Clean" from the top menu in eclipse. If it the error is still there, just change MouseButtonBinding.RIGHT_BUTTON to 1 in the source code.
^^ This has nothing to do with the thread it is in (I know, that's not very unusual around here, but this time there are no amphibians involved :D), so I answered it elsewhere:
The most likely problem is that you are not setting a cursor. You have to set a cursor every frame to clear any remaining states. This is done so you can change cursors based on picking. Otherwise the cursor would have been set twice: once to restore a previous state and once to apply a new state. And there is a somewhat large overhead when setting a harware cursor (you don't want to do it twice if avoidable) and the harware cursor tends to flicker when changed on linux, so changing it twice would have given too much flickering.
Look how its done in demo it has a big comment section saying "Remember to update your cursor every frame."
If that dosent resolve a problem then something very strange is going on… And to fix it, I need to replicate the problem first. So give me as much details as possible when the problem occurs.
How often does it occur? (Always, Sometimes, Rarely).
Do you have to press anything else for that to occur? (Any keys on keyboard, any mouse buttons)?
Are you following the object, object rotation when that occurs?
Are you using hardware mouse or software mouse when that occurs?
Does the same thing happens when using press CTRL key?
What version of jme you are using (release # or from CVS)?
Does it occur in the included demo or in your own code where you are trying to integrate the handler?
Also you can check if the mouseInput is reporting your button as being pressed using