Nebula
3D-Studio 3.1 exporter
Articles
Downloads
gMax Exporter
Models
Named Hierarchy Browser
nmax for RL SDK
Quake 2 Interpolator
Wateralgorithms
 
Diverse Jme Mangalore Nebula Project1 Project2 Tabletop

nInputServer

WARNING
This tutorial might be using deprecated functionality. To my knowledge at least the feature of assigning multiple buttons to one action (by using the ampersand) is no longer supported in nebula 2. This tutorial was based on nebula 1 !

Commands:
startlogging stoplogging islogging startrecording stoprecording isrecording startplaying stopplaying isplaying beginmap map endmap getslider getbutton setlongpressedtime getlongpressedtime setdoubleclicktime getdoubleclicktime setmousecallback getmousecallback


Behind the scene:
The input server as it name states handles all actions concerning input operations. The input server can be found in the hierarchy graph at /sys/servers/input. It has an interface to query key states, define keys and key event and key recording/playback. Let's go through this:
The first thing to do is create a key mapping which will decide how your input will be understood by nebula. The mapping is a pair consisting of a button definition which fires the event and an event to be fired when the key is pressed. Take a look at this:

Example of the key mapping from $nebula_home$/bin/observerlib.tcl



        sel /sys/servers/input

        .beginmap

        .map keyb0:shift.pressed    pan

        .map keyb0:ctrl.pressed     orbit

        .map mouse0:btn0.pressed    pan

        .map mouse0:btn1.pressed    orbit

        .map mouse0:btn2.pressed    dolly

        .map keyb0:space.down       "script:orig"

        .map keyb0:j.down           "script:janaview"

        .map keyb0:esc.down         "script:/sys/servers/console.toggle"

        .endmap

      

On the left, starting with .map is the key definition (mouse0:btn2.pressed). On the right you find the events (dolly). The definition of a key consists of a device ID, channel ID and channel modifier (not on axes):
dev:channel[.up|down|pressed|long|double]
There are two types of events for mapping:

  • The first one is called a state event.
  • The state event is defined by a simple string of your own definition (like pan or dolly or _my_wonderfull_key_state_). You can think of a state event being your self definable buttons. You could for example create a state for combo moves or named special game actions (like save game, pause, etc..). Remember: state events are just a definition for your keys. If the keys for your state have been pressed, your state is set to true, but NO action will be executed. In the above example states are
  • The second one is called a script event.
  • The script event is defined by a string starting with "script:" thereafter you place a script function (like "script:/usr/scen/model.setanim("walk")" or "script:_my_tcl_function_"). So everytime your mapped keys are activated your script definition gets fired.

top

Back on top...

?

A list of the accepted devices can be found under '/sys/share/input/devs', the list of the channels (keys/buttons)provided by the device can be found in the 'channels' subdirectory of each device. The list of the actual states is under '/sys/share/input/states'. The following table is an extract of devices and channels (keys/buttons)
Device keyDescription
keyb0:bsBackspace key on the standard keyboard
keyb0:tabTabulator key on the standard keyboard
keyb0:returnReturn key on the standard keyboard
keyb0:shiftShift key on the standard keyboard
keyb0:ctrlRight or left control key on the standard keyboard
keyb0:menu??? key on the standard keyboard
keyb0:capitalCaps lock key on the standard keyboard
keyb0:escEscape key on the standard keyboard
keyb0:spaceSpacebar on the standard keyboard
keyb0:prior??? key on the standard keyboard
keyb0:next??? key on the standard keyboard
keyb0:endEnd key on the standard keyboard
keyb0:homeHome key on the standard keyboard
keyb0:leftLeft arrow key on the standard keyboard
keyb0:rightRight arrow key on the standard keyboard
keyb0:upUp arrow key on the standard keyboard
keyb0:downDown arrow key on the standard keyboard
keyb0:select??? key on the standard keyboard
keyb0:printPrint key on the standard keyboard
keyb0:exec??? key on the standard keyboard
keyb0:snap??? key on the standard keyboard
keyb0:insertIns key on the standard keyboard
keyb0:deleteDel key on the standard keyboard
keyb0:help??? key on the standard keyboard
keyb0:[1-0, a-z]The corresponding keys on the standard keyboard
keyb0:lwinLeft windows key on the standard windows keyboard
keyb0:rwinRight windows key on the standard windows keyboard
keyb0:num[0-9]0-9 keys on the standard keyboard num pad
keyb0:multMultiply key on the standard keyboard num pad
keyb0:plusPlus key on the standard keyboard num pad
keyb0:divideDivide key on the standard keyboard num pad
keyb0:minusMinus key on the standard keyboard num pad
keyb0:sep??? key on the standard keyboard
keyb0:decimal??? key on the standard keyboard
keyb0:f[1-24]Corresponding F keys on the standard keyboard (like F1, F2..)
keyb0:numlocNumber lock key on the standard keyboard
keyb0:scrollScroll lock key on the standard keyboard
joy0:btn[0-x]Button 0 to X on your Joystick, depends on how many button your joystick has.
joy0:[+|-][x|y]Axis move on your Joystick. Use getslider if you want to know how far it is pushed. (.getslider "joy0:-x")
joy0:btn[0-x]Button 0 to X, depends on how many button your joystick has.
mouse0:[+|-][x|y]Axis move on your mouse. Same as on Joysticks above
mouse0:btn[0-x]Button 0 to X, same as on Joysticks above

top

Back on top...

?

During the event definition you can combine two input events with an AND, the first input event is then a qualifier event, which must be active with the second event to control the input state. The combination is achieved through a &' sign, the string must contain no spaces.

Example:
.map keyb0:ctrl&keyb0:left.down "sweep_left"
Ctrl-Left on Keyboard 0

So how do you query keys ? Either by mapping an event to the key combination, or by doing the query by yourself in script or code. The interface is the same. You use the two functions getslider getbutton which get the name of the key/state passed. The first one would be used for sliders (for example on joysticks how far they are pushed..) whereas the second just returns true or false.
Example of a tcl script for button and state query



        sel /sys/servers/input

        .getbutton "pan"

        .getbutton "_my_defined_state"

        .getbutton "keyb0:j"

        .getslider "joy0:+x"

      

Example of c++ code for button and state query



    //ref_is is a reference to the input server

    nInputServer *is = this->ref_is.get();



    // query values

    bool  orbit  = is->GetButton("orbit");

    bool  pan    = is->GetButton("pan");

    bool  dolly  = is->GetButton("dolly");

    float mouse_left  = is->GetSlider("mouse0:-x");



    // do what you want....

      

The last thing you might be interrested in is key recording. This is an important feature for demos or replays. The last one is quite often found in racing games, where the moves of the cars are replayed to show the race after the finish. You could also create cutscenes with key recording. You use the logging functions to write the keys to the screen (standard out). The recording functions are used for key recording.


Putting it all together:
Try it yourself, or wait until someone else does it :-):

A key recording demo showing key mapping, querying logging and recording.


top

Back on top...

?

Back to Table of Contents.




Something missing? Mail to cc


2009-06-01
WoW Importer for Max
The World of Warcraft tool for 3D Studio has been updated. It now converts model files from WoW Client version 2.x (upto 2.7) and displays correct animations for multi mesh models. The script can be found here....
2007-03-07
nGUI explained
If you ever wanted some more details on the nebula2 nGUI System you can find it in the nGUI System article.
2006-10-17
Mangalore entity ID's
If you need information about the mangalore entity ID usage have a look here..
2006-08-06
Mangalore Articles
Added a new section about the mangalore game framework from radonlabs. The section contains some articles about my experience with mangalore. Read more here:
2006-03-10
Free models
Finally some free models for the Radonlabs SDK. You can download them here.