nfirvine.comwiki

Panda3DXInput2

Filed in: Projects.Panda3DXInput2 · Modified on : Sat, 06 Nov 10

NB: This is an evolving document, and I won't draw attention to any particular updates unless they're exceptionally important. Instead, check out its History instead.

Linkback/Backlink

Corresponding blueprint on Launchpad

Impetus

According to the Panda3D Manual, Panda requires the same ugly hack that pymanymouse/manymouse proper use to get multiple mice to work under Linux. Viz.:

To use raw mouse input under Linux, the panda program needs to open the device files /dev/input/event*. On many Linux distributions, the permission bits are set such that this is not possible. This is a flaw in these distributions.

(I disagree that it's a "flaw in these distributions" since the only reasonable solution is to use (non-root) groups and add users to it (and relogin/reboot), a totally unnecessary hoop for an end user to jump through anyway. So does the linked-to solution.)

Another issue is that in order to use multiple mice, you (or Panda) has to read raw (untransformed by X) values from the mouse, which isn't always what you want. For example, AFAIK, no mouse does pointer acceleration in hardware; that's done by X drivers. You get a pointer in Panda that doesn't abide by the same rules as the regular X pointer. And untransformed input data would mean you'd have to have in-game calibration or something else tedious.

The XInput (XI1) X extension provides this ability, and has done for a while: you can get X events for individual devices. XInput2 (XI2) has been introduced recently, which adds MultiPointer X (MPX): the ability to have multiple "core" devices, now called "masters" (with hardware devices called "slaves"). (I refer to the these two indiscriminately as XInput*/XI*.)

(It should be noted that none of this is an issue in Windows (except perhaps the rawness problem), probably because snooping raw mouse traffic was not perceived to be a security hole. <Insert obligatory MS dig here.>)

Advantages

In summary, advantages of using XInput* over devnodes:

  • No fiddling with groups or udev rules or running as root or mouse-snooping by jerks.
  • Differentiation between "raw" and "multiple". XI2 has a raw (untransformed by X; straight from the driver) events and regular (transformed with clipping, acceleration, etc. by X) events for master and slave devices.

Disadvantages

  • Non-portable obviously.
  • May require real API-breaking changes to Panda.

Potential problems

XInput* have many abilities that would be useful, but I am doubtful that these would be available on a Windows (or perhaps even Mac) platform:

  • Raw events and "unraw" events. In XI, "raw" means the values as returned by the device in its kernel driver. "Unraw" events (I made that term) are what you get from normal events, which may be transformed by X. From the XI2proto.txt: "Transformations include, but are not limited to, axis clipping and acceleration." AFAIK, in order to use multiple mice in Windows, you need to switch to raw mode and read untransformed values. That is, rawness and multiplicity of mice are tightly coupled. Thus, in order to maintain cross-platformedness, we'd have to pander to the lowest common denominator and couple on X, even though we don't have to.

Steps to fruition

  • Learn
    • Panda C++ down and dirty
    • XInput(2) protocol
    • Interfacing
  • Code
    • Start by reimplementing the subpixel precision code (currently a hack done in Xf86dga extension1
    • End with best way to have it in Panda (C++ libs, watcher nodes, etc.)
  • Test
    • Make some unit tests?
  • Demo
    • Write a tutorial module
  • Merge with dev branch?

References

 

1 According to http://www.panda3d.org/phpbb2/viewtopic.php?p=57291#57291this post by rdb on the Panda3D forums.


Powered by PmWiki