bc5575f83a
There was code in the osgViewer/Viewer.cpp and osgViewer/CompositeViewer.cpp that transformed the Y-coordinates of an event. The code in the composite viewer did however miss the touch-data of the event. I thought that it should really be the GUIEventAdapter that should know about this, and hence I added the GUIEventAdapter::setMouseYOrientationAndUpdateCoords which is re-computing the coordinates. First I simply added a boolean to the setMouseYOrientation function: setMouseYOrientation( MouseYOrientation, bool updatecooreds=false ); but then the serializer complained. This function is called from both the Viewer and the CompositeViewer. We have not tested from the viewer, but I cannot see it would not work from visual inspection. The other change is in MultiTouchTrackballManipulator::handleMultiTouchDrag. I have removed the normalisation. The reason for that is that it normalised into screen coordinates from 0,0 to 1,1. The problem with that is that if you have a pinch event and you keep the distance say 300 pixels between your fingers, these 300 pixels represent 0.20 of the screen in the horizontal domain, but 0.3 of the screen in the vertical domain. A rotation of the pinch-fingers will hence result in a zoom in, as the normalised distance is changing between them. A consequence of this is that I have changed the pan-code to use the same algorithm as the middle-mouse-pan. The rest of it is very similar from previous revision, and there has been some fine-tuning here and there. "
152 lines
4.3 KiB
C++
152 lines
4.3 KiB
C++
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
|
*
|
|
* This library is open source and may be redistributed and/or modified under
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* OpenSceneGraph Public License for more details.
|
|
*/
|
|
|
|
#include <osgGA/GUIEventAdapter>
|
|
|
|
using namespace osgGA;
|
|
|
|
|
|
osg::ref_ptr<GUIEventAdapter>& GUIEventAdapter::getAccumulatedEventState()
|
|
{
|
|
static osg::ref_ptr<GUIEventAdapter> s_eventState = new GUIEventAdapter;
|
|
return s_eventState;
|
|
}
|
|
|
|
GUIEventAdapter::GUIEventAdapter():
|
|
_eventType(NONE),
|
|
_windowX(0),
|
|
_windowY(0),
|
|
_windowWidth(1280),
|
|
_windowHeight(1024),
|
|
_key(0),
|
|
_unmodifiedKey(0),
|
|
_button(0),
|
|
_Xmin(-1.0),
|
|
_Xmax(1.0),
|
|
_Ymin(-1.0),
|
|
_Ymax(1.0),
|
|
_mx(0.0),
|
|
_my(0.0),
|
|
_buttonMask(0),
|
|
_modKeyMask(0),
|
|
_mouseYOrientation(Y_INCREASING_DOWNWARDS),
|
|
_scrolling(),
|
|
_tabletPen(),
|
|
_touchData(NULL)
|
|
{}
|
|
|
|
GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop):
|
|
osgGA::Event(rhs,copyop),
|
|
_eventType(rhs._eventType),
|
|
_context(rhs._context),
|
|
_windowX(rhs._windowX),
|
|
_windowY(rhs._windowY),
|
|
_windowWidth(rhs._windowWidth),
|
|
_windowHeight(rhs._windowHeight),
|
|
_key(rhs._key),
|
|
_unmodifiedKey(rhs._unmodifiedKey),
|
|
_button(rhs._button),
|
|
_Xmin(rhs._Xmin),
|
|
_Xmax(rhs._Xmax),
|
|
_Ymin(rhs._Ymin),
|
|
_Ymax(rhs._Ymax),
|
|
_mx(rhs._mx),
|
|
_my(rhs._my),
|
|
_buttonMask(rhs._buttonMask),
|
|
_modKeyMask(rhs._modKeyMask),
|
|
_mouseYOrientation(rhs._mouseYOrientation),
|
|
_scrolling(rhs._scrolling),
|
|
_tabletPen(rhs._tabletPen),
|
|
_touchData(NULL)
|
|
{
|
|
if(TouchData* td = rhs.getTouchData())
|
|
setTouchData(osg::clone(td, copyop));
|
|
}
|
|
|
|
GUIEventAdapter::~GUIEventAdapter()
|
|
{
|
|
}
|
|
|
|
void GUIEventAdapter::setWindowRectangle(int x, int y, int width, int height, bool updateMouseRange)
|
|
{
|
|
_windowX = x;
|
|
_windowY = y;
|
|
_windowWidth = width;
|
|
_windowHeight = height;
|
|
|
|
if (updateMouseRange)
|
|
{
|
|
setInputRange(0, 0, width, height);
|
|
}
|
|
|
|
}
|
|
|
|
void GUIEventAdapter::setInputRange(float Xmin, float Ymin, float Xmax, float Ymax)
|
|
{
|
|
_Xmin = Xmin;
|
|
_Ymin = Ymin;
|
|
_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 );
|
|
}
|
|
|
|
void GUIEventAdapter::addTouchPoint(unsigned int id, TouchPhase phase, float x, float y, unsigned int tapCount)
|
|
{
|
|
if (!_touchData.valid()) {
|
|
_touchData = new TouchData();
|
|
setX(x);
|
|
setY(y);
|
|
}
|
|
|
|
_touchData->addTouchPoint(id, phase, x, y, tapCount);
|
|
}
|
|
|
|
void GUIEventAdapter::copyPointerDataFrom(const osgGA::GUIEventAdapter& sourceEvent)
|
|
{
|
|
setGraphicsContext(const_cast<osg::GraphicsContext*>(sourceEvent.getGraphicsContext()));
|
|
setX(sourceEvent.getX());
|
|
setY(sourceEvent.getY());
|
|
setInputRange(sourceEvent.getXmin(), sourceEvent.getYmin(), sourceEvent.getXmax(), sourceEvent.getYmax());
|
|
setButtonMask(sourceEvent.getButtonMask());
|
|
setMouseYOrientation(sourceEvent.getMouseYOrientation());
|
|
setPointerDataList(sourceEvent.getPointerDataList());
|
|
}
|
|
|
|
|
|
|
|
void GUIEventAdapter::setMouseYOrientationAndUpdateCoords(osgGA::GUIEventAdapter::MouseYOrientation myo)
|
|
{
|
|
if ( myo==_mouseYOrientation )
|
|
return;
|
|
|
|
setMouseYOrientation( myo );
|
|
|
|
_my = _Ymax - _my + _Ymin;
|
|
if( isMultiTouchEvent() )
|
|
{
|
|
for( TouchData::iterator itr = getTouchData()->begin(); itr != getTouchData()->end(); itr++ )
|
|
itr->y = _Ymax - itr->y + _Ymin;
|
|
}
|
|
}
|