Improved the handling of Producer's no dimensional mouse coords.
This commit is contained in:
@@ -203,7 +203,8 @@ public:
|
||||
};
|
||||
|
||||
|
||||
enum ModKeyMask {
|
||||
enum ModKeyMask
|
||||
{
|
||||
MODKEY_LEFT_SHIFT = 0x0001,
|
||||
MODKEY_RIGHT_SHIFT = 0x0002,
|
||||
MODKEY_LEFT_CTRL = 0x0040,
|
||||
@@ -220,7 +221,6 @@ public:
|
||||
MODKEY_META = (MODKEY_LEFT_META|MODKEY_RIGHT_META)
|
||||
};
|
||||
|
||||
|
||||
/** Get the EventType of the GUI event.*/
|
||||
virtual EventType getEventType() const = 0;
|
||||
|
||||
@@ -230,6 +230,16 @@ public:
|
||||
/** button pressed/released, return -1 if inappropriate for this event.*/
|
||||
virtual int getButton() const = 0;
|
||||
|
||||
|
||||
enum MouseYOrientation
|
||||
{
|
||||
Y_INCREASING_UPWARDS,
|
||||
Y_INCREASING_DOWNWARDS
|
||||
};
|
||||
|
||||
void setMouseYOrientation(MouseYOrientation myo) { _mouseYOrientation = myo; }
|
||||
MouseYOrientation getMouseYOrientation() const { return _mouseYOrientation; }
|
||||
|
||||
/** manimum x mouse position. */
|
||||
virtual float getXmin() const = 0;
|
||||
|
||||
@@ -267,15 +277,21 @@ public:
|
||||
* -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; }
|
||||
inline float getYnormalized() const
|
||||
{
|
||||
if (_mouseYOrientation==Y_INCREASING_UPWARDS) return 2.0f*(getY()-getYmin())/(getYmax()-getYmin())-1.0f;
|
||||
else return -(2.0f*(getY()-getYmin())/(getYmax()-getYmin())-1.0f);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
GUIEventAdapter() {}
|
||||
GUIEventAdapter(MouseYOrientation myo=Y_INCREASING_DOWNWARDS):_mouseYOrientation(myo) {}
|
||||
|
||||
/** Force users to create on heap, so that multiple referencing is safe.*/
|
||||
virtual ~GUIEventAdapter() {}
|
||||
|
||||
MouseYOrientation _mouseYOrientation;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -459,7 +459,7 @@ bool DriveManipulator::calcMovement()
|
||||
case(USE_MOUSE_Y_FOR_SPEED):
|
||||
{
|
||||
float dy = _ga_t0->getYnormalized();
|
||||
_velocity = -_modelScale*0.2f*dy;
|
||||
_velocity = _modelScale*0.2f*dy;
|
||||
break;
|
||||
}
|
||||
case(USE_MOUSE_BUTTONS_FOR_SPEED):
|
||||
|
||||
@@ -272,6 +272,7 @@ bool FlightManipulator::calcMovement()
|
||||
float dx = _ga_t0->getXnormalized();
|
||||
float dy = _ga_t0->getYnormalized();
|
||||
|
||||
|
||||
osg::Matrix rotation_matrix;
|
||||
rotation_matrix.makeRotate(_rotation);
|
||||
|
||||
@@ -281,7 +282,7 @@ bool FlightManipulator::calcMovement()
|
||||
osg::Vec3 sv = lv^up;
|
||||
sv.normalize();
|
||||
|
||||
float pitch = inDegrees(dy*75.0f*dt);
|
||||
float pitch = -inDegrees(dy*75.0f*dt);
|
||||
float roll = inDegrees(dx*50.0f*dt);
|
||||
|
||||
osg::Quat delta_rotate;
|
||||
|
||||
@@ -270,23 +270,12 @@ bool TrackballManipulator::calcMovement()
|
||||
osg::Vec3 axis;
|
||||
float angle;
|
||||
|
||||
float mx0 = (_ga_t0->getXmin()+_ga_t0->getXmax())/2.0f;
|
||||
float rx0 = (_ga_t0->getXmax()-_ga_t0->getXmin())/2.0f;
|
||||
|
||||
float my0 = (_ga_t0->getYmin()+_ga_t0->getYmax())/2.0f;
|
||||
float ry0 = (_ga_t0->getYmax()-_ga_t0->getYmin())/2.0f;
|
||||
|
||||
float mx1 = (_ga_t0->getXmin()+_ga_t1->getXmax())/2.0f;
|
||||
float rx1 = (_ga_t0->getXmax()-_ga_t1->getXmin())/2.0f;
|
||||
|
||||
float my1 = (_ga_t1->getYmin()+_ga_t1->getYmax())/2.0f;
|
||||
float ry1 = (_ga_t1->getYmax()-_ga_t1->getYmin())/2.0f;
|
||||
|
||||
float px0 = (_ga_t0->getX()-mx0)/rx0;
|
||||
float py0 = (my0-_ga_t0->getY())/ry0;
|
||||
|
||||
float px1 = (_ga_t1->getX()-mx1)/rx1;
|
||||
float py1 = (my1-_ga_t1->getY())/ry1;
|
||||
float px0 = _ga_t0->getXnormalized();
|
||||
float py0 = _ga_t0->getYnormalized();
|
||||
|
||||
float px1 = _ga_t1->getXnormalized();
|
||||
float py1 = _ga_t1->getYnormalized();
|
||||
|
||||
|
||||
trackball(axis,angle,px1,py1,px0,py0);
|
||||
|
||||
|
||||
@@ -14,13 +14,8 @@ 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;
|
||||
static float s_yOffset=1.0f;
|
||||
static float s_yScale=0.5f;
|
||||
|
||||
|
||||
EventAdapter::EventAdapter()
|
||||
EventAdapter::EventAdapter():
|
||||
osgGA::GUIEventAdapter(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS)
|
||||
{
|
||||
_eventType = NONE; // adaptor does not encapsulate any events.
|
||||
_key = -1; // set to 'invalid' key value.
|
||||
@@ -99,8 +94,8 @@ void EventAdapter::adaptButtonPress(double time,float x, float y, unsigned int b
|
||||
break;
|
||||
}
|
||||
|
||||
_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;
|
||||
_s_mx = x;
|
||||
_s_my = y;
|
||||
|
||||
copyStaticVariables();
|
||||
}
|
||||
@@ -131,8 +126,8 @@ void EventAdapter::adaptButtonRelease(double time,float x, float y, unsigned int
|
||||
break;
|
||||
}
|
||||
|
||||
_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;
|
||||
_s_mx = x;
|
||||
_s_my = y;
|
||||
|
||||
copyStaticVariables();
|
||||
}
|
||||
@@ -146,8 +141,8 @@ void EventAdapter::adaptMouseMotion(double time, float x, float y)
|
||||
MOVE;
|
||||
|
||||
_time = time;
|
||||
_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;
|
||||
_s_mx = x;
|
||||
_s_my = y;
|
||||
copyStaticVariables();
|
||||
|
||||
}
|
||||
|
||||
@@ -147,6 +147,7 @@ EventAdapter* KeyboardMouseCallback::createEventAdapter()
|
||||
Producer::RenderSurface* rs = _keyboardMouse->getRenderSurface();
|
||||
if (ia)
|
||||
{
|
||||
|
||||
float minX = FLT_MAX;
|
||||
float minY = FLT_MAX;
|
||||
float maxX = -FLT_MAX;
|
||||
@@ -172,9 +173,7 @@ EventAdapter* KeyboardMouseCallback::createEventAdapter()
|
||||
}
|
||||
else if (rs)
|
||||
{
|
||||
float xMin,yMin,xMax,yMax;
|
||||
rs->getWindowRect(xMin,xMax,yMin,yMax);
|
||||
ea->setWindowSize(xMin,yMin,xMax,yMax);
|
||||
ea->setWindowSize(-1.0f,-1.0f,1.0f,1.0f);
|
||||
}
|
||||
|
||||
return ea;
|
||||
|
||||
Reference in New Issue
Block a user