BS Contact J : Java-EAI : Browser Observer
Realizing a HUD
This example illustrates "listening for events" in Java. It shows the implementation of a Head Up Display (HUD). A HUD is a screen which follows the user's movements and always occupies the same position the user's field of view. A HUD behaves like a piece of paper that is stuck to one's glasses.
What is needed to implement the HUD? Of course, geometry which should
represent the HUD, wrapped into a transform node. The transform node will
be provided with the current viewpoint coordinates so that our
To get some user movements, we will implement a kind of navigation bar
as a HUD. If the user clicks on a symbol of the HUD, the user will be
transported and bound to a particular viewpoint. Whenever a TouchSensor
(Note: Although this can be realised with a ProximitySensor and some appropriate routes, we will do this with an extension applet for demonstration purposes)
So how to get notified when a TouchSensor is pressed? To achieve this, the extension applet must register as an observer for the TouchSensor touchTime events of the HUD's symbols by connecting to each TouchSensor's touchTime event first, and then adding the applet (this) as an observer to each event.
// get touch sensor
In this example strings are used as identifier ("red", "green", "blue") but one can think of every java object as an identifying object up to the field itself.
After the applet is registered successfully, all touchTime events of the registered TouchSensors will be sent to the BS Contact J event-handling method of the extension applet:
public boolean onEvent(int type, Object object, Object userData)
In this case two event types must be observed:
To update the HUD, the current camera position and orientation are needed.
These co-ordinates can be received by the following call:
and reading out its coordinates via getValueFloatArray(). After that the value gets set as new coordinate values of the HUD.