Implemented support for float x and y mouse positions, and normalization of

mouse coords in osgGA::GUIEventAdapter, and ported osgGA camera manaipulators
to use the new normalized values.

Moved osgProducer across to tracking the window dimensions and ensure that the
internals values in osgProducer::EventAdapter are kept consistent.  Moved
the warp pointer in Viewer across to using KeyboardMouse::positionPointer().
This commit is contained in:
Robert Osfield
2003-04-04 19:10:37 +00:00
parent fb49e5a60f
commit 169bf25f77
13 changed files with 150 additions and 259 deletions

View File

@@ -83,7 +83,7 @@ int main( int argc, char **argv )
// set the keyboard mouse callback to catch the events from the windows.
bool done = false;
osgProducer::KeyboardMouseCallback kbmcb(done);
osgProducer::KeyboardMouseCallback kbmcb(kbm,done);
kbmcb.setStartTick(start_tick);
// register the callback with the keyboard mouse manger.

View File

@@ -75,7 +75,7 @@ public:
to initialise the mouse pointer when mouse position relative to a controls
neutral mouse position is required, i.e when mimicking a aircrafts joystick.
*/
virtual void requestWarpPointer(int x,int y) = 0;
virtual void requestWarpPointer(float x,float y) = 0;
};

View File

@@ -230,24 +230,24 @@ public:
/** button pressed/released, return -1 if inappropriate for this event.*/
virtual int getButton() const = 0;
/** window minimum x. */
virtual int getXmin() const = 0;
/** manimum x mouse position. */
virtual float getXmin() const = 0;
/** window maximum x. */
virtual int getXmax() const = 0;
/** maximum x mouse position. */
virtual float getXmax() const = 0;
/** window minimum y. */
virtual int getYmin() const = 0;
/** minimum y mouse position. */
virtual float getYmin() const = 0;
/** window maximum y. */
virtual int getYmax() const = 0;
/** maximum y mouse position. */
virtual float getYmax() const = 0;
/** current mouse x position.*/
virtual int getX() const = 0;
virtual float getX() const = 0;
/** current mouse y position.*/
virtual int getY() const = 0;
virtual float getY() const = 0;
/** current mouse button state */
virtual unsigned int getButtonMask() const = 0;
@@ -256,6 +256,18 @@ public:
/** time in seconds of event. */
virtual double time() const = 0;
/** return the getX() value normalised to the range of -1 to 1.
* -1 would be the left hand side of the window.
* 0.0 would be the middle of the window.
* +1 would be the right hand side of the window.*/
inline float getXnormalized() const { return 2.0f*(getX()-getXmin())/(getXmax()-getXmin())-1.0f; }
/** return the getY() value normalised to the range of -1 to 1.
* -1 would be the bottom of the window.
* 0.0 would be the middle of the window.
* +1 would be the top of the window.*/
inline float getYnormalized() const { return 2.0f*(getY()-getYmin())/(getYmax()-getYmin())-1.0f; }
protected:

View File

@@ -26,7 +26,7 @@ class ActionAdapter : public osgGA::GUIActionAdapter
void requestContinuousUpdate(bool) {}
void requestWarpPointer(int,int) {}
void requestWarpPointer(float ,float ) {}
};

View File

@@ -40,22 +40,22 @@ class OSGPRODUCER_EXPORT EventAdapter : public osgGA::GUIEventAdapter
virtual int getButton() const { return _button; }
/** window minimum x. */
virtual int getXmin() const { return _Xmin; }
virtual float getXmin() const { return _Xmin; }
/** window maximum x. */
virtual int getXmax() const { return _Xmax; }
virtual float getXmax() const { return _Xmax; }
/** window minimum y. */
virtual int getYmin() const { return _Ymin; }
virtual float getYmin() const { return _Ymin; }
/** window maximum y. */
virtual int getYmax() const { return _Ymax; }
virtual float getYmax() const { return _Ymax; }
/** current mouse x position.*/
virtual int getX() const { return _mx; }
virtual float getX() const { return _mx; }
/** current mouse y position.*/
virtual int getY() const { return _my; }
virtual float getY() const { return _my; }
/** current mouse button state */
virtual unsigned int getButtonMask() const { return _buttonMask; }
@@ -66,14 +66,14 @@ class OSGPRODUCER_EXPORT EventAdapter : public osgGA::GUIEventAdapter
virtual unsigned int getModKeyMask() const { return _modKeyMask; }
/** static method for setting window dimensions.*/
static void setWindowSize(int Xmin, int Ymin, int Xmax, int Ymax);
static void setWindowSize(float Xmin, float Ymin, float Xmax, float Ymax);
/** static method for setting button state.*/
static void setButtonMask(unsigned int buttonMask);
/** method for adapting resize events. */
void adaptResize(double t, int Xmin, int Ymin, int Xmax, int Ymax);
/** method for adapting resize events. */
void adaptResize(double t, float Xmin, float Ymin, float Xmax, float Ymax);
/** method for adapting mouse motion events whilst mouse buttons are pressed.*/
void adaptMouseMotion(double t, float x, float y);
@@ -99,10 +99,10 @@ class OSGPRODUCER_EXPORT EventAdapter : public osgGA::GUIEventAdapter
EventType _eventType;
int _key;
int _button;
int _Xmin,_Xmax;
int _Ymin,_Ymax;
int _mx;
int _my;
float _Xmin,_Xmax;
float _Ymin,_Ymax;
float _mx;
float _my;
unsigned int _buttonMask;
unsigned int _modKeyMask;
double _time;
@@ -119,21 +119,14 @@ class OSGPRODUCER_EXPORT EventAdapter : public osgGA::GUIEventAdapter
static int _s_button;
// used to store window min and max values.
static int _s_Xmin;
static int _s_Xmax;
static int _s_Ymin;
static int _s_Ymax;
static int _s_mx;
static int _s_my;
static float _s_Xmin;
static float _s_Xmax;
static float _s_Ymin;
static float _s_Ymax;
static float _s_mx;
static float _s_my;
static int _s_modKeyMask;
typedef std::map<int,int> KeySymbolMap;
static KeySymbolMap s_keySymbolMap;
static bool s_keySymbolMapInitialized;
bool initKeySymbolMap();
int adaptKeySymbol(Producer::KeySymbol key);
};
}

View File

@@ -30,8 +30,9 @@ namespace osgProducer {
class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseCallback
{
public:
KeyboardMouseCallback(bool &done, bool escapeKeySetsDone=true) :
KeyboardMouseCallback(Producer::KeyboardMouse* keyboardMouse, bool &done, bool escapeKeySetsDone=true) :
Producer::KeyboardMouseCallback(),
_keyboardMouse(keyboardMouse),
_mx(0.0f),_my(0.0f),_mbutton(0),
_done(done),
_escapeKeySetsDone(escapeKeySetsDone)
@@ -72,8 +73,14 @@ class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseC
double getTime() { return _timer.delta_s(_startTick,_timer.tick()); }
Producer::KeyboardMouse* getKeyboardMouse() { return _keyboardMouse; }
const Producer::KeyboardMouse* getKeyboardMouse() const { return _keyboardMouse; }
protected:
EventAdapter* createEventAdapter();
Producer::KeyboardMouse* _keyboardMouse;
float _mx, _my;
unsigned int _mbutton;
bool &_done;

View File

@@ -80,7 +80,7 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction
virtual void requestRedraw() {}
virtual void requestContinuousUpdate(bool) {}
virtual void requestWarpPointer(int x,int y);
virtual void requestWarpPointer(float x,float y);
typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlerList;
EventHandlerList& getEventHandlerList() { return _eventHandlerList; }

View File

@@ -157,7 +157,7 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
us.requestRedraw();
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2,(ea.getYmin()+ea.getYmax())/2);
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f);
flushMouseEventStack();
@@ -258,7 +258,7 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
if (ea.getEventType()!=GUIEventAdapter::RESIZE)
{
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2,(ea.getYmin()+ea.getYmax())/2);
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f);
}
computeLocalDataFromCamera();
@@ -455,9 +455,8 @@ bool DriveManipulator::calcMovement()
{
case(USE_MOUSE_Y_FOR_SPEED):
{
float my = (_ga_t0->getYmin()+_ga_t0->getYmax())/2.0f;
float dy = _ga_t0->getY()-my;
_velocity = -_modelScale*0.0002f*dy;
float dy = _ga_t0->getYnormalized();
_velocity = -_modelScale*0.2f*dy;
break;
}
case(USE_MOUSE_BUTTONS_FOR_SPEED):
@@ -494,11 +493,9 @@ bool DriveManipulator::calcMovement()
osg::Vec3 lv = osg::Vec3(0.0f,0.0f,-1.0f) * rotation_matrix;
// rotate the camera.
float mx = (_ga_t0->getXmin()+_ga_t0->getXmax())/2.0f;
float dx = _ga_t0->getXnormalized();
float dx = _ga_t0->getX()-mx;
float yaw = -inDegrees(dx*0.1f*dt);
float yaw = -inDegrees(dx*50.0f*dt);
osg::Quat yaw_rotation;
yaw_rotation.makeRotate(yaw,up);

View File

@@ -58,7 +58,7 @@ void FlightManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
us.requestRedraw();
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2,(ea.getYmin()+ea.getYmax())/2);
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f);
computeLocalDataFromCamera();
@@ -79,7 +79,7 @@ void FlightManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
if (ea.getEventType()!=GUIEventAdapter::RESIZE)
{
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2,(ea.getYmin()+ea.getYmax())/2);
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f);
}
computeLocalDataFromCamera();
@@ -269,11 +269,8 @@ bool FlightManipulator::calcMovement()
}
float mx = (_ga_t0->getXmin()+_ga_t0->getXmax())/2.0f;
float my = (_ga_t0->getYmin()+_ga_t0->getYmax())/2.0f;
float dx = _ga_t0->getX()-mx;
float dy = _ga_t0->getY()-my;
float dx = _ga_t0->getXnormalized();
float dy = _ga_t0->getYnormalized();
osg::Matrix rotation_matrix;
rotation_matrix.makeRotate(_rotation);
@@ -284,8 +281,8 @@ bool FlightManipulator::calcMovement()
osg::Vec3 sv = lv^up;
sv.normalize();
float pitch = inDegrees(dy*0.15f*dt);
float roll = inDegrees(dx*0.1f*dt);
float pitch = inDegrees(dy*75.0f*dt);
float roll = inDegrees(dx*50.0f*dt);
osg::Quat delta_rotate;

View File

@@ -187,10 +187,10 @@ bool TrackballManipulator::isMouseMoving()
{
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
static const float velocity = 100.0f;
static const float velocity = 0.1f;
float dx = _ga_t0->getX()-_ga_t1->getX();
float dy = _ga_t0->getY()-_ga_t1->getY();
float dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized();
float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized();
float len = sqrtf(dx*dx+dy*dy);
float dt = _ga_t0->time()-_ga_t1->time();
@@ -253,8 +253,8 @@ bool TrackballManipulator::calcMovement()
// return if less then two events have been added.
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
float dx = _ga_t0->getX()-_ga_t1->getX();
float dy = _ga_t0->getY()-_ga_t1->getY();
float dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized();
float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized();
// return if there is no movement.
@@ -306,7 +306,7 @@ bool TrackballManipulator::calcMovement()
// pan model.
float scale = 0.0015f*focalLength;
float scale = 0.5f*focalLength;
osg::Vec3 uv = _camera->getUpVector();
osg::Vec3 sv = _camera->getSideVector();
@@ -325,7 +325,7 @@ bool TrackballManipulator::calcMovement()
// zoom model.
float fd = focalLength;
float scale = 1.0f-dy*0.001f;
float scale = 1.0f-dy;
if (fd*scale>_modelScale*_minimumZoomScale)
{
@@ -339,7 +339,7 @@ bool TrackballManipulator::calcMovement()
// notify(DEBUG_INFO) << "Pushing forward"<<std::endl;
// push the camera forward.
float scale = 0.0015f*fd;
float scale = fd;
osg::Vec3 dv = _camera->getLookVector()*(dy*scale);
_center += dv;

View File

@@ -7,15 +7,12 @@ unsigned int EventAdapter::_s_accumulatedButtonMask = 0;
int EventAdapter::_s_button = 0;
int EventAdapter::_s_modKeyMask = 0;
int EventAdapter::_s_Xmin = 0;
int EventAdapter::_s_Xmax = 1280;
int EventAdapter::_s_Ymin = 0;
int EventAdapter::_s_Ymax = 1024;
int EventAdapter::_s_mx = 0;
int EventAdapter::_s_my = 0;
EventAdapter::KeySymbolMap EventAdapter::s_keySymbolMap;
bool EventAdapter::s_keySymbolMapInitialized = false;
float EventAdapter::_s_Xmin = 0;
float EventAdapter::_s_Xmax = 1280;
float EventAdapter::_s_Ymin = 0;
float EventAdapter::_s_Ymax = 1024;
float EventAdapter::_s_mx = 0;
float EventAdapter::_s_my = 0;
static float s_xOffset=1.0f;
static float s_xScale=0.5f;
@@ -53,7 +50,7 @@ void EventAdapter::copyStaticVariables()
}
void EventAdapter::setWindowSize(int Xmin, int Ymin, int Xmax, int Ymax)
void EventAdapter::setWindowSize(float Xmin, float Ymin, float Xmax, float Ymax)
{
_s_Xmin = Xmin;
_s_Xmax = Xmax;
@@ -68,7 +65,7 @@ void EventAdapter::setButtonMask(unsigned int buttonMask)
}
void EventAdapter::adaptResize(double time, int Xmin, int Ymin, int Xmax, int Ymax)
void EventAdapter::adaptResize(double time, float Xmin, float Ymin, float Xmax, float Ymax)
{
setWindowSize(Xmin,Ymin,Xmax,Ymax);
_eventType = RESIZE;
@@ -102,8 +99,8 @@ void EventAdapter::adaptButtonPress(double time,float x, float y, unsigned int b
break;
}
_s_mx = (int)((x+s_xOffset)*s_xScale*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
_s_my = (int)((y+s_yOffset)*s_yScale*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
_s_mx = (float)((x+s_xOffset)*s_xScale*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
_s_my = (float)((y+s_yOffset)*s_yScale*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
copyStaticVariables();
}
@@ -134,8 +131,8 @@ void EventAdapter::adaptButtonRelease(double time,float x, float y, unsigned int
break;
}
_s_mx = (int)((x+s_xOffset)*s_xScale*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
_s_my = (int)((y+s_yOffset)*s_yScale*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
_s_mx = (float)((x+s_xOffset)*s_xScale*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
_s_my = (float)((y+s_yOffset)*s_yScale*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
copyStaticVariables();
}
@@ -149,8 +146,8 @@ void EventAdapter::adaptMouseMotion(double time, float x, float y)
MOVE;
_time = time;
_s_mx = (int)((x+s_xOffset)*s_xScale*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
_s_my = (int)((y+s_yOffset)*s_yScale*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
_s_mx = (float)((x+s_xOffset)*s_xScale*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
_s_my = (float)((y+s_yOffset)*s_yScale*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
copyStaticVariables();
}
@@ -161,7 +158,7 @@ void EventAdapter::adaptKeyPress( double time, Producer::KeySymbol key)
{
_eventType = KEYDOWN;
_time = time;
_key = adaptKeySymbol(key);
_key = key;
copyStaticVariables();
}
@@ -171,7 +168,7 @@ void EventAdapter::adaptKeyRelease( double time, Producer::KeySymbol key)
// we won't handle this correctly right now.. GUIEventAdapter isn't up to it
_eventType = KEYUP;
_time = time;
_key = adaptKeySymbol(key);
_key = key;
copyStaticVariables();
}
@@ -186,142 +183,3 @@ void EventAdapter::adaptFrame(double time)
copyStaticVariables();
}
bool EventAdapter::initKeySymbolMap()
{
#ifdef WIN32
#if 0
/*
// not mapped yet as I can't see an
// obvious mapping to X11/osgGA::GUIEventAdapter::KeySymbol.
s_keySymbolMap[VK_CAPITAL] = ;
s_keySymbolMap[VK_CONVERT] = ;
s_keySymbolMap[VK_NONCONVERT] = ;
s_keySymbolMap[VK_ACCEPT] = ;
s_keySymbolMap[VK_SNAPSHOT] = ;
s_keySymbolMap[VK_LWIN] = ;
s_keySymbolMap[VK_RWIN] = ;
s_keySymbolMap[VK_APPS] = ;
s_keySymbolMap[VK_ATTN] = ;
s_keySymbolMap[VK_CRSEL] = ;
s_keySymbolMap[VK_EXSEL] = ;
s_keySymbolMap[VK_EREOF] = ;
s_keySymbolMap[VK_PLAY] = ;
s_keySymbolMap[VK_ZOOM] = ;
s_keySymbolMap[VK_NONAME] = ;
s_keySymbolMap[VK_PA1] = ;
*/
// mapped to osgGA::GUIEventAdapter::KeySymbol
s_keySymbolMap[VK_CANCEL] = KEY_Cancel;
s_keySymbolMap[VK_BACK] = KEY_BackSpace;
s_keySymbolMap[VK_TAB] = KEY_Tab;
s_keySymbolMap[VK_CLEAR] = KEY_Clear;
s_keySymbolMap[VK_RETURN] = KEY_Return;
s_keySymbolMap[VK_SHIFT] = KEY_Shift_Lock;
s_keySymbolMap[VK_CONTROL] = KEY_Control_L;
s_keySymbolMap[VK_MENU] = KEY_Menu;
s_keySymbolMap[VK_PAUSE ] = KEY_Pause;
s_keySymbolMap[VK_ESCAPE] = KEY_Escape;
s_keySymbolMap[VK_MODECHANGE] = KEY_Mode_switch;
s_keySymbolMap[VK_SPACE] = KEY_Space;
s_keySymbolMap[VK_PRIOR] = KEY_Prior;
s_keySymbolMap[VK_NEXT] = KEY_Next;
s_keySymbolMap[VK_END] = KEY_End;
s_keySymbolMap[VK_HOME] = KEY_Home;
s_keySymbolMap[VK_LEFT] = KEY_Left;
s_keySymbolMap[VK_UP] = KEY_Up;
s_keySymbolMap[VK_RIGHT] = KEY_Right;
s_keySymbolMap[VK_DOWN] = KEY_Down;
s_keySymbolMap[VK_SELECT] = KEY_Select;
s_keySymbolMap[VK_PRINT] = KEY_Print;
s_keySymbolMap[VK_EXECUTE] = KEY_Execute;
s_keySymbolMap[VK_INSERT] = KEY_Insert;
s_keySymbolMap[VK_DELETE] = KEY_Delete;
s_keySymbolMap[VK_HELP] = KEY_Help;
s_keySymbolMap[VK_NUMPAD0] = KEY_KP_0;
s_keySymbolMap[VK_NUMPAD1] = KEY_KP_1;
s_keySymbolMap[VK_NUMPAD2] = KEY_KP_2;
s_keySymbolMap[VK_NUMPAD3] = KEY_KP_3;
s_keySymbolMap[VK_NUMPAD4] = KEY_KP_4;
s_keySymbolMap[VK_NUMPAD5] = KEY_KP_5;
s_keySymbolMap[VK_NUMPAD6] = KEY_KP_6;
s_keySymbolMap[VK_NUMPAD7] = KEY_KP_7;
s_keySymbolMap[VK_NUMPAD8] = KEY_KP_8;
s_keySymbolMap[VK_NUMPAD9] = KEY_KP_9;
s_keySymbolMap[VK_MULTIPLY] = KEY_KP_Multiply;
s_keySymbolMap[VK_ADD] = KEY_KP_Add;
s_keySymbolMap[VK_SEPARATOR] = KEY_KP_Separator;
s_keySymbolMap[VK_SUBTRACT] = KEY_KP_Subtract;
s_keySymbolMap[VK_DECIMAL] = KEY_KP_Decimal;
s_keySymbolMap[VK_DIVIDE] = KEY_KP_Divide;
s_keySymbolMap[VK_F1] = KEY_F1;
s_keySymbolMap[VK_F2] = KEY_F2;
s_keySymbolMap[VK_F3] = KEY_F3;
s_keySymbolMap[VK_F4] = KEY_F4;
s_keySymbolMap[VK_F5] = KEY_F5;
s_keySymbolMap[VK_F6] = KEY_F6;
s_keySymbolMap[VK_F7] = KEY_F7;
s_keySymbolMap[VK_F8] = KEY_F8;
s_keySymbolMap[VK_F9] = KEY_F9;
s_keySymbolMap[VK_F10] = KEY_F10;
s_keySymbolMap[VK_F11] = KEY_F11;
s_keySymbolMap[VK_F12] = KEY_F12;
s_keySymbolMap[VK_F13] = KEY_F13;
s_keySymbolMap[VK_F14] = KEY_F14;
s_keySymbolMap[VK_F15] = KEY_F15;
s_keySymbolMap[VK_F16] = KEY_F16;
s_keySymbolMap[VK_F17] = KEY_F17;
s_keySymbolMap[VK_F18] = KEY_F18;
s_keySymbolMap[VK_F19] = KEY_F19;
s_keySymbolMap[VK_F20] = KEY_F20;
s_keySymbolMap[VK_F21] = KEY_F21;
s_keySymbolMap[VK_F22] = KEY_F22;
s_keySymbolMap[VK_F23] = KEY_F23;
s_keySymbolMap[VK_F24] = KEY_F24;
s_keySymbolMap[VK_NUMLOCK] = KEY_Num_Lock;
s_keySymbolMap[VK_SCROLL] = KEY_Scroll_Lock;
s_keySymbolMap[VK_LSHIFT] = KEY_Shift_L;
s_keySymbolMap[VK_RSHIFT] = KEY_Shift_R;
s_keySymbolMap[VK_LCONTROL] = KEY_Control_L;
s_keySymbolMap[VK_RCONTROL] = KEY_Control_R;
s_keySymbolMap[VK_LMENU] = KEY_Menu;
s_keySymbolMap[VK_RMENU] = KEY_Menu;
s_keySymbolMap[VK_OEM_CLEAR] = KEY_Clear;
#endif
#else
// no mapping required for non windows (i.e. X11 based)
// since the osgGA::GUIEventAdapter::KeySybol values are
// take from X11/keysymdef.h
#endif
return true;
}
int EventAdapter::adaptKeySymbol(Producer::KeySymbol key)
{
if (!s_keySymbolMapInitialized) s_keySymbolMapInitialized = initKeySymbolMap();
KeySymbolMap::iterator itr = s_keySymbolMap.find(key);
if (itr!=s_keySymbolMap.end()) return itr->second;
else return key;
}

View File

@@ -1,11 +1,7 @@
#include <osg/Math>
#include <osgProducer/KeyboardMouseCallback>
#ifdef WIN32
#include <windows.h>
#else
#include <X11/keysym.h>
#endif
#include <float.h>
using namespace osgProducer;
@@ -15,8 +11,7 @@ void KeyboardMouseCallback::buttonPress( float mx, float my, unsigned int mbutto
_my = my;
_mbutton |= (1<<(mbutton-1));
osg::ref_ptr<EventAdapter> event = new EventAdapter;
osg::ref_ptr<EventAdapter> event = createEventAdapter();
event->adaptButtonPress(getTime(),mx,my,mbutton);
_eventQueueMutex.lock();
@@ -30,8 +25,7 @@ void KeyboardMouseCallback::buttonRelease( float mx, float my, unsigned int mbut
_my = my;
_mbutton &= ~(1<<(mbutton-1));
osg::ref_ptr<EventAdapter> event = new EventAdapter;
osg::ref_ptr<EventAdapter> event = createEventAdapter();
event->adaptButtonRelease(getTime(),mx,my,mbutton);
_eventQueueMutex.lock();
@@ -45,8 +39,7 @@ void KeyboardMouseCallback::doubleButtonPress( float mx, float my, unsigned int
_my = my;
_mbutton |= (1<<(mbutton-1));
osg::ref_ptr<EventAdapter> event = new EventAdapter;
osg::ref_ptr<EventAdapter> event = createEventAdapter();
event->adaptButtonPress(getTime(),mx,my,mbutton);
_eventQueueMutex.lock();
@@ -57,16 +50,9 @@ void KeyboardMouseCallback::doubleButtonPress( float mx, float my, unsigned int
void KeyboardMouseCallback::keyPress( Producer::KeyCharacter key )
{
osg::ref_ptr<EventAdapter> event = new EventAdapter;
osg::ref_ptr<EventAdapter> event = createEventAdapter();
event->adaptKeyPress(getTime(),key);
//
// #ifdef WIN32
// if (_escapeKeySetsDone &&
// event->getKey()==VK_ESCAPE) _done = true;
// #endif
// check against adapted key symbol.
if (_escapeKeySetsDone &&
event->getKey()==osgGA::GUIEventAdapter::KEY_Escape) _done = true;
@@ -80,7 +66,7 @@ void KeyboardMouseCallback::keyPress( Producer::KeyCharacter key )
void KeyboardMouseCallback::keyRelease( Producer::KeyCharacter key )
{
osg::ref_ptr<EventAdapter> event = new EventAdapter;
osg::ref_ptr<EventAdapter> event = createEventAdapter();
event->adaptKeyRelease(getTime(),key);
_eventQueueMutex.lock();
@@ -92,15 +78,9 @@ void KeyboardMouseCallback::specialKeyPress( Producer::KeyCharacter key )
{
osg::ref_ptr<EventAdapter> event = new EventAdapter;
osg::ref_ptr<EventAdapter> event = createEventAdapter();
event->adaptKeyPress(getTime(),key);
// #ifdef WIN32
// if (_escapeKeySetsDone &&
// event->getKey()==VK_ESCAPE) _done = true;
// #endif
// check against adapted key symbol.
if (_escapeKeySetsDone &&
event->getKey()==osgGA::GUIEventAdapter::KEY_Escape) _done = true;
@@ -114,7 +94,7 @@ void KeyboardMouseCallback::specialKeyPress( Producer::KeyCharacter key )
void KeyboardMouseCallback::specialKeyRelease( Producer::KeyCharacter key )
{
osg::ref_ptr<EventAdapter> event = new EventAdapter;
osg::ref_ptr<EventAdapter> event = createEventAdapter();
event->adaptKeyRelease(getTime(),key);
_eventQueueMutex.lock();
@@ -127,7 +107,7 @@ void KeyboardMouseCallback::mouseMotion( float mx, float my)
_mx = mx;
_my = my;
osg::ref_ptr<EventAdapter> event = new EventAdapter;
osg::ref_ptr<EventAdapter> event = createEventAdapter();
event->adaptMouseMotion(getTime(),mx,my);
_eventQueueMutex.lock();
@@ -141,7 +121,7 @@ void KeyboardMouseCallback::passiveMouseMotion( float mx, float my)
_mx = mx;
_my = my;
osg::ref_ptr<EventAdapter> event = new EventAdapter;
osg::ref_ptr<EventAdapter> event = createEventAdapter();
event->adaptMouseMotion(getTime(),mx,my);
_eventQueueMutex.lock();
@@ -158,3 +138,44 @@ void KeyboardMouseCallback::getEventQueue(EventQueue& queue)
_eventQueueMutex.unlock();
}
EventAdapter* KeyboardMouseCallback::createEventAdapter()
{
EventAdapter* ea = new EventAdapter;
Producer::InputArea* ia = _keyboardMouse->getInputArea();
Producer::RenderSurface* rs = _keyboardMouse->getRenderSurface();
if (ia)
{
float minX = FLT_MAX;
float minY = FLT_MAX;
float maxX = -FLT_MAX;
float maxY = -FLT_MAX;
int numInputRectangle = ia->getNumInputRectangle();
for (int i=0;i<numInputRectangle;++i)
{
Producer::InputRectangle* ir = ia->getInputRectangle(i);
minX = osg::minimum(minX,ir->left());
minX = osg::minimum(minX,ir->left()+ir->width());
minY = osg::minimum(minY,ir->bottom());
minY = osg::minimum(minY,ir->bottom()+ir->height());
maxX = osg::maximum(maxX,ir->left());
maxX = osg::maximum(maxX,ir->left()+ir->width());
maxY = osg::maximum(maxY,ir->bottom());
maxY = osg::maximum(maxY,ir->bottom()+ir->height());
}
ea->setWindowSize(minX,minY,maxX,maxY);
}
else if (rs)
{
float xMin,yMin,xMax,yMax;
rs->getWindowRect(xMin,xMax,yMin,yMax);
ea->setWindowSize(xMin,yMin,xMax,yMax);
}
return ea;
}

View File

@@ -84,7 +84,7 @@ void Viewer::setUpViewer(unsigned int options)
_start_tick = _timer.tick();
// set the keyboard mouse callback to catch the events from the windows.
_kbmcb = new osgProducer::KeyboardMouseCallback( _done, (options & ESCAPE_SETS_DONE)!=0 );
_kbmcb = new osgProducer::KeyboardMouseCallback( kbm, _done, (options & ESCAPE_SETS_DONE)!=0 );
_kbmcb->setStartTick(_start_tick);
// register the callback with the keyboard mouse manger.
@@ -263,9 +263,15 @@ void Viewer::selectCameraManipulator(unsigned int no)
if (_keyswitchManipulator.valid()) _keyswitchManipulator->selectCameraManipulator(no);
}
void Viewer::requestWarpPointer(int x,int y)
void Viewer::requestWarpPointer(float x,float y)
{
if (_kbmcb)
{
_kbmcb->getKeyboardMouse()->positionPointer(x,y);
return;
}
Producer::RenderSurface* rs = 0;
// here we need to search for which render surface contains the pointer,