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

@@ -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; }