Callback Function Coin (Open Inventor)

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

Post Reply
redwhitered
Posts: 2
Joined: Tue Apr 03, 2007 12:25 pm

Callback Function Coin (Open Inventor)

Post by redwhitered »

How is it possible to write a callback function in Coin for the Space Navigator?

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

jwick
Moderator
Moderator
Posts: 3331
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

Hi redwhitered,

Unfortunately, we have no experience with Coin. If you, or someone else figures it out, please post your results here for others.

Thanks,
Jim
3Dx Software Development
Kant1
Posts: 1
Joined: Sun Jun 17, 2007 5:04 pm
Location: Houston

Post by Kant1 »

Hi redwhitered,

will try to help although I'm OpenInventor developer... You would need to forward events to the viewer : 2 ways to do it

1 call setEventCallback on the viewer : you will get all the events and the first to do is to filter them
or
2 add a SoEventCallback node in your scenegraph

hope it will help you

Kant1
Post Reply