From Philipp Machler, "We have extended the support for Wacom Tablet devices:

- Mac OS X
  - not only pressure, but tilt and z-rotation is supported now
"
This commit is contained in:
Robert Osfield
2008-04-11 13:28:09 +00:00
parent 6fed4022a6
commit 76e0198007
5 changed files with 74 additions and 6 deletions

View File

@@ -89,8 +89,13 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
/** Method for adapting pen pressure events, placing this event on the back of the event queue, with specified time.*/
void penPressure(float pressure, double time);
/** Method for adapting pen orientation events, placing this event on the back of the event queue.*/
void penOrientation(float tiltX, float tiltY, float rotation) { penOrientation(tiltX, tiltY, rotation, getTime()); }
/** Method for adapting pen orientation events, placing this event on the back of the event queue, with specified time.*/
void penOrientation(float tiltX, float tiltY, float rotation, double time);
/** Method for adapting pen proximity events, placing this event on the back of the event queue.*/
void penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering) { penProximity(pt, isEntering, getTime()); }

View File

@@ -15,6 +15,7 @@
#define OSGGA_EVENT 1
#include <osg/Object>
#include <osg/Matrix>
#include <osgGA/Export>
namespace osgGA{
@@ -45,11 +46,12 @@ public:
RESIZE=256,
SCROLL=512,
PEN_PRESSURE=1024,
PEN_PROXIMITY_ENTER=2048,
PEN_PROXIMITY_LEAVE=4096,
CLOSE_WINDOW=8192,
QUIT_APPLICATION=16384,
USER=32768
PEN_ORIENTATION=2048,
PEN_PROXIMITY_ENTER=4096,
PEN_PROXIMITY_LEAVE=8192,
CLOSE_WINDOW=16384,
QUIT_APPLICATION=32768,
USER=65536
};
enum KeySymbol
@@ -360,6 +362,20 @@ public:
float getPenPressure() const { return _pressure; }
/// sets the pressure from a tablet
void setPenPressure(float pressure) { _pressure = pressure; }
/// get the tiltX, from a tablet input device (range -1 - 1)
float getPenTiltX() const { return _tiltX; }
/// sets the tiltX from a tablet
void setPenTiltX(float tiltX) { _tiltX = tiltX; }
/// get the tiltY, from a tablet input device (range -1 - 1)
float getPenTiltY() const { return _tiltY; }
/// sets the tiltY from a tablet
void setPenTiltY(float tiltY) { _tiltY = tiltY; }
/// get the rotation, from a tablet input device (range 0 - 2PI)
float getPenRotation() const { return _rotation; }
/// sets the rotation from a tablet
void setPenRotation(float rotation) { _rotation = rotation; }
/// get the orientation from a tablet input device as a matrix
const osg::Matrix getPenOrientation() const;
/// get the current used tablet pointer type
TabletPointerType getTabletPointerType() const { return _tabletPointerType; }
/// set the current used tablet pointer type
@@ -424,6 +440,9 @@ public:
float _mx;
float _my;
float _pressure;
float _tiltX;
float _tiltY;
float _rotation;
unsigned int _buttonMask;
unsigned int _modKeyMask;
ScrollingMotion _scrollingMotion;

View File

@@ -99,6 +99,18 @@ void EventQueue::penPressure(float pressure, double time)
addEvent(event);
}
void EventQueue::penOrientation(float tiltX, float tiltY, float rotation, double time)
{
GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);
event->setEventType(GUIEventAdapter::PEN_ORIENTATION);
event->setPenTiltX(tiltX);
event->setPenTiltY(tiltY);
event->setPenRotation(rotation);
event->setTime(time);
addEvent(event);
}
void EventQueue::penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering, double time)
{
GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);

View File

@@ -39,6 +39,9 @@ GUIEventAdapter::GUIEventAdapter():
_mx(0.5),
_my(0.5),
_pressure(0.0),
_tiltX(0.0),
_tiltY(0.0),
_rotation(0.0),
_buttonMask(0),
_modKeyMask(0),
_scrollingMotion(SCROLL_NONE),
@@ -66,6 +69,9 @@ GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& c
_mx(rhs._mx),
_my(rhs._my),
_pressure(rhs._pressure),
_tiltX(rhs._tiltX),
_tiltY(rhs._tiltY),
_rotation(rhs._rotation),
_buttonMask(rhs._buttonMask),
_modKeyMask(rhs._modKeyMask),
_scrollingMotion(rhs._scrollingMotion),
@@ -100,3 +106,15 @@ void GUIEventAdapter::setInputRange(float Xmin, float Ymin, float Xmax, float Ym
_Xmax = Xmax;
_Ymax = Ymax;
}
const osg::Matrix GUIEventAdapter::getPenOrientation() const
{
float xRad = osg::DegreesToRadians ( getPenTiltY() );
float yRad = osg::DegreesToRadians ( getPenTiltX() );
float zRad = osg::DegreesToRadians ( getPenRotation() );
osg::Matrix xrot = osg::Matrix::rotate ( xRad, osg::Vec3f(1.0f, 0.0f, 0.0f) );
osg::Matrix yrot = osg::Matrix::rotate ( yRad, osg::Vec3f(0.0f, 0.0f, 1.0f) );
osg::Matrix zrot = osg::Matrix::rotate ( zRad, osg::Vec3f(0.0f, 1.0f, 0.0f) );
return ( zrot * yrot * xrot );
}

View File

@@ -864,6 +864,20 @@ bool GraphicsWindowCarbon::handleMouseEvent(EventRef theEvent)
getEventQueue()->penProximity(pointerType, (theTabletRecord.enterProximity != 0));
}
// get tilt and rotation from the pen
TabletPointRec theTabletPointRecord;
if(noErr == GetEventParameter(theEvent, kEventParamTabletPointRec, typeTabletPointRec, NULL,
sizeof(TabletPointRec), NULL, (void *)&theTabletPointRecord))
{
int penRotation = (int)theTabletPointRecord.rotation * 9 / 575; //to get angle between 0 to 360 grad
penRotation = -(((penRotation + 180) % 360) - 180) ; //for same range on all plattforms we need -180 to 180
getEventQueue()->penOrientation (
theTabletPointRecord.tiltX * 60 / 32767.0f, //multiply with 60 to get angle between -60 to 60 grad
-theTabletPointRecord.tiltY * 60 / 32767.0f, //multiply with 60 to get angle between -60 to 60 grad
penRotation
);
}
switch(GetEventKind(theEvent))
{
case kEventMouseDown: