Is it possible to use the files
Inventor/Qt/devices/SoQtSpaceball.h
Inventor/events/SoSpaceballButtonEvent.h
coming with Coin3d?
The following Code shows the implementation of a Keyboard callback function (event handler).
How can a callback for the Space Navigator be added?
Code: Select all
#define SOQT_DLL
#define COIN_DLL
// Headerfiles SoQt
#include <Inventor>
#include <Inventor>
// Headerfiles Coin
#include <Inventor>
#include <Inventor>
#include <Inventor>
#include <Inventor>
#include <Inventor>
#include <Inventor>
#include <Inventor>
#include <Inventor>
#include <Inventor>
#include <Inventor>
#include <Inventor>
#include <Inventor>
#include <Inventor>
#include <Inventor>
#include <Inventor>
// Headerfiles QT
//#include <QtGui>
// Additional Headers
#include <math> // for M_PI
#include <iostream>
using namespace std;
// derived Class for including Callback Handler
class MyExaminerViewer : public SoQtExaminerViewer
{
public:
MyExaminerViewer(QWidget * parent = NULL,
const char * name = NULL,
SbBool embed = TRUE) : SoQtExaminerViewer(parent) {}
protected:
virtual SbBool processSoEvent(const SoEvent *const ev);
};
SbBool MyExaminerViewer::processSoEvent(const SoEvent *const ev) {
// check if the event triggered is a SoKeyboardEvent
if (ev->getTypeId() == SoKeyboardEvent::getClassTypeId()) {
// cast it to a SoKeyboardEvent
SoKeyboardEvent * kbev = (SoKeyboardEvent *) ev;
// check if it is a release event
if (SoKeyboardEvent::isKeyReleaseEvent(ev, kbev->getKey())) {
// evaluate the value of the key which was pressed or released
switch ( kbev->getKey() ) {
case SoKeyboardEvent::F: cout << "foo" << endl; return TRUE;
case SoKeyboardEvent::B: cout << "bar" << endl; return TRUE;
case SoKeyboardEvent::ESCAPE: SoQt::exitMainLoop(); return TRUE;
default:
cout <<kbev>getPrintableCharacter() << " pressed." <<endl>getTypeId() == SoSpaceballButtonEvent::getClassTypeId()) {
// cast it to a SoSpbaceballButtonEvent
SoSpaceballButtonEvent * sbev = (SoSpaceballButtonEvent *) ev;
// FIXME: get pressed Buttons from Space Navigator
cout << "SoSpaceballButtonEvent detected " <<endl>getTypeId() == SoMotion3Event::getClassTypeId()) {
// cast it to a SoMotion3Event
SoMotion3Event * m3ev = (SoMotion3Event *) ev;
// FIXME: get Translation and Rotation from Space Navigator
cout << "SoMotion3Event detected " <<endl>ref(); // increases counter for preventing erasing scene graph
root->addChild(new SoCone);
// initialize an Examiner Viewer
// Note that MyExaminerViewer is derived from SoQtExaminerViewer
MyExaminerViewer *myviewer = new MyExaminerViewer(appWindow);
myviewer->setSceneGraph(root); // set scene into viewer
myviewer->setTitle("Basic Interaction");
myviewer->show();
SoQt::show(appWindow);
SoQt::mainLoop();
delete myviewer;
root->unref();
return 0;
}