Permalink
Browse files

From Stephan Huber, "attached are some fixes to the osc-plugin and th…

…e touch-implementations for iOS and os x and other small bugfixes. These fixes will normalize the orientation of the touch points, and transmitting the touch points over osc via the TUIO-protocol works now more robustly between two osg-applications.

I added a new tag to p3d called forward_touch_event_to_device and renamed the existing forward_event_to_device to forward_mouse_event_to_device. This new tag will transmit touches to the virtual trackpad as touch events. I added the MultitouchTrackball to the p3d-app so zooming and moving a model remotely should now work, if you use forward_touch_event_to_device. I kept (and fixed) forward_mouse_event_to_device for background compatibility, so old presentations works as in previous versions, without the ability to zoom + scale. of course.

forward_touch_event_to_device needs some more testing, (e.g. with image-streams and keystone, afaik there’s no support for touch-events...) but for a first version it works nice.
"
  • Loading branch information...
1 parent 8904fa1 commit e6f9e65f9185c21be968c230ed20dcfc1526128b @osg-training-guest osg-training-guest committed Jan 23, 2014
@@ -36,6 +36,7 @@
#include <osgGA/TerrainManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/StateSetManipulator>
+#include <osgGA/MultiTouchTrackballManipulator>
#include <osgPresentation/deprecated/SlideEventHandler>
#include <osgPresentation/Cursor>
@@ -50,6 +51,7 @@
#include <fstream>
#include <iostream>
+
#include <string.h>
#ifdef USE_SDL
@@ -174,6 +176,58 @@ class ForwardToDeviceEventHandler : public osgGA::GUIEventHandler {
};
+class DumpEventHandler : public osgGA::GUIEventHandler {
+public:
+ DumpEventHandler() : osgGA::GUIEventHandler() {}
+
+ virtual bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, osg::Object *, osg::NodeVisitor *)
+ {
+ switch (ea.getEventType())
+ {
+ case osgGA::GUIEventAdapter::FRAME:
+ return false;
+ break;
+ case osgGA::GUIEventAdapter::PUSH:
+ std::cout << "PUSH: ";
+ break;
+ case osgGA::GUIEventAdapter::RELEASE:
+ std::cout << "RELEASE: ";
+ break;
+ case osgGA::GUIEventAdapter::MOVE:
+ std::cout << "MOVE: ";
+ break;
+ case osgGA::GUIEventAdapter::DRAG:
+ std::cout << "DRAG: ";
+ break;
+ case osgGA::GUIEventAdapter::SCROLL:
+ std::cout << "SCROLL: ";
+ break;
+ break;
+
+ default:
+ std::cout << ea.getEventType() << " ";
+ break;
+ }
+ std::cout << ea.getX() << "/" << ea.getY() << " " << ea.isMultiTouchEvent() << std::endl;
+ return false;
+ }
+
+
+ bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv)
+ {
+ if (event->asGUIEventAdapter())
+ return osgGA::GUIEventHandler::handle(event, object, nv);
+ else
+ {
+ return false;
+ }
+ }
+
+
+private:
+};
+
+
enum P3DApplicationType
{
@@ -423,7 +477,7 @@ int main( int argc, char **argv )
{
osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
- keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
+ keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::MultiTouchTrackballManipulator() );
keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
@@ -444,6 +498,8 @@ int main( int argc, char **argv )
viewer.setCameraManipulator( keyswitchManipulator.get() );
}
+
+ //viewer.getEventHandlers().push_front(new DumpEventHandler());
// add the state manipulator
osg::ref_ptr<osgGA::StateSetManipulator> ssManipulator = new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet());
@@ -13,6 +13,22 @@
#include <osgViewer/api/IOS/GraphicsWindowIOS>
+@interface MyViewController : UIViewController
+
+- (BOOL)shouldAutorotate;
+
+
+@end
+
+@implementation MyViewController
+
+- (BOOL)shouldAutorotate
+{
+ return YES;
+}
+@end
+
+
@implementation iphoneViewerAppDelegate
@synthesize _window;
@@ -148,7 +164,11 @@ virtual bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &
for(osgGA::GUIEventAdapter::TouchData::iterator i = ea.getTouchData()->begin(); i != ea.getTouchData()->end(); ++i, ++j)
{
const osgGA::GUIEventAdapter::TouchData::TouchPoint& tp = (*i);
- _mats[j]->setMatrix(osg::Matrix::translate(tp.x, ea.getWindowHeight() - tp.y, 0));
+ if (ea.getMouseYOrientation() == osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS)
+ _mats[j]->setMatrix(osg::Matrix::translate(tp.x, ea.getWindowHeight() - tp.y, 0));
+ else
+ _mats[j]->setMatrix(osg::Matrix::translate(tp.x, tp.y, 0));
+
_mats[j]->setNodeMask(0xffff);
std::ostringstream ss;
@@ -227,55 +247,62 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
//get the screen size
CGRect lFrame = [[UIScreen mainScreen] bounds];
- unsigned int w = lFrame.size.width;
- unsigned int h = lFrame.size.height;
+ unsigned int w = lFrame.size.width * [[UIScreen mainScreen] scale];
+ unsigned int h = lFrame.size.height * [[UIScreen mainScreen] scale];
//create the viewer
_viewer = new osgViewer::Viewer();
- /*
+ if(1) {
- // If you want full control over the graphics context / window creation, please uncomment this section
-
- // create the main window at screen size
- self._window = [[UIWindow alloc] initWithFrame: lFrame];
-
- //show window
- [_window makeKeyAndVisible];
-
-
- //create our graphics context directly so we can pass our own window
- osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
-
- // Init the Windata Variable that holds the handle for the Window to display OSG in.
- osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowIOS::WindowData(_window);
-
- // Setup the traits parameters
- traits->x = 0;
- traits->y = 0;
- traits->width = w;
- traits->height = h;
- traits->depth = 16; //keep memory down, default is currently 24
- traits->windowDecoration = false;
- traits->doubleBuffer = true;
- traits->sharedContext = 0;
- traits->setInheritedWindowPixelFormat = true;
- traits->samples = 4;
- traits->sampleBuffers = 1;
-
- traits->inheritedWindowData = windata;
+ // If you want full control over the graphics context / window creation, please uncomment this section
+
+ // create the main window at screen size
+ self._window = [[UIWindow alloc] initWithFrame: lFrame];
+
+ //show window
+ [_window makeKeyAndVisible];
+
+ UIView* parent_view = [[UIView alloc] initWithFrame: CGRectMake(0,0, w, h)];
+ parent_view.backgroundColor = [UIColor redColor];
+ [self._window addSubview: parent_view];
+ MyViewController* view_controller = [[MyViewController alloc] init];
+ view_controller.view = parent_view;
+ self._window.rootViewController = view_controller;
+
+
+ //create our graphics context directly so we can pass our own window
+ osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
+
+ // Init the Windata Variable that holds the handle for the Window to display OSG in.
+ osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowIOS::WindowData(parent_view);
+
+ // Setup the traits parameters
+ traits->x = 50;
+ traits->y = 50;
+ traits->width = w-100;
+ traits->height = h-100;
+ traits->depth = 16; //keep memory down, default is currently 24
+ traits->windowDecoration = false;
+ traits->doubleBuffer = true;
+ traits->sharedContext = 0;
+ traits->setInheritedWindowPixelFormat = true;
+ traits->samples = 4;
+ traits->sampleBuffers = 1;
+
+ traits->inheritedWindowData = windata;
- // Create the Graphics Context
- osg::ref_ptr<osg::GraphicsContext> graphicsContext = osg::GraphicsContext::createGraphicsContext(traits.get());
-
- // if the context was created then attach to our viewer
- if(graphicsContext)
- {
- _viewer->getCamera()->setGraphicsContext(graphicsContext);
- _viewer->getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
+ // Create the Graphics Context
+ osg::ref_ptr<osg::GraphicsContext> graphicsContext = osg::GraphicsContext::createGraphicsContext(traits.get());
+
+ // if the context was created then attach to our viewer
+ if(graphicsContext)
+ {
+ _viewer->getCamera()->setGraphicsContext(graphicsContext);
+ _viewer->getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
+ }
}
- */
//create root
@@ -675,13 +675,14 @@ public:
void addTouchPoint(unsigned int id, TouchPhase phase, float x, float y, unsigned int tapCount = 0);
+ void setTouchData(TouchData* td) { _touchData = td; }
TouchData* getTouchData() const { return _touchData.get(); }
bool isMultiTouchEvent() const { return (_touchData.valid()); }
-
+
inline float getTouchPointNormalizedX(unsigned int ndx) const {
return (getTouchData()->get(ndx).x-_Xmin)/(_Xmax-_Xmin)*2.0f-1.0f;
}
-
+
inline float getTouchPointNormalizedY(unsigned int ndx) const {
if (_mouseYOrientation==Y_INCREASING_UPWARDS)
return (getTouchData()->get(ndx).y-_Ymin)/(_Ymax-_Ymin)*2.0f-1.0f;
@@ -37,7 +37,8 @@ enum Operation
LOAD,
EVENT,
JUMP,
- FORWARD_EVENT
+ FORWARD_MOUSE_EVENT,
+ FORWARD_TOUCH_EVENT
};
struct JumpData
@@ -67,8 +67,11 @@ GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& c
_mouseYOrientation(rhs._mouseYOrientation),
_scrolling(rhs._scrolling),
_tabletPen(rhs._tabletPen),
- _touchData(rhs._touchData)
-{}
+ _touchData(NULL)
+{
+ if(TouchData* td = rhs.getTouchData())
+ setTouchData(osg::clone(td, copyop));
+}
GUIEventAdapter::~GUIEventAdapter()
{
@@ -58,7 +58,7 @@ void MultiTouchTrackballManipulator::handleMultiTouchDrag(const GUIEventAdapter*
osg::Vec2 delta = ((pt_1_last - pt_1_now) + (pt_2_last - pt_2_now)) / 2.0f;
float scale = _distance / 3.0f;
-
+
// osg::notify(osg::ALWAYS) << "drag: " << delta << " scale: " << scale << std::endl;
panModel( delta.x() * scale, delta.y() * scale);
Oops, something went wrong.

0 comments on commit e6f9e65

Please sign in to comment.