Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Graphics > Inventor API > TROUBLE PICKING...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 491 of 501
Post > Topic >>

TROUBLE PICKING OBJECTS

by Anatoli <anatoli.barski@[EMAIL PROTECTED] > Mar 8, 2008 at 10:19 AM

Hallo! I'm trying to select a node by clicking with left mouse button
on them with the following piece of code:

When I run this code, the objects highlighted are mostly near my mouse
click. But they are weirdly picked(not a simple translation from where
I've clicked).

myViewer::myViewer( QWidget *parent, const char *name)
  :myQglViewer(parent,name)
{
  myViewer::selection = new SoSelection; // myQglViewer parent class
created a scene
                                                             // ->
make myViewer::selection new root for that scene

  myViewer::selection->ref();

  myViewer::selection->addChild(scene);

  sm->setSceneGraph(myViewer::selection);

  myViewer::selection->policy = SoSelection::****FT;

  myViewer::selection->addSelectionCallback(&myViewer::madeSelection,
(void*)1L);
  myViewer::selection-
>addDeselectionCallback(&myViewer::madeSelection, (void*)0L);

  modelGeometry = new SoGroup;

  scene->addChild(modelGeometry);

  //fill scene with objects
  modelGeometry->addChild(...)
  modelGeometry->addChild(...)
  ...
}

this calls myQglViewer(parent, name) to create a QGLWidget with
members: scene, scenemanager, camera and headlight which looks as
follows:

myQglViewer::myQglViewer(QWidget *parent, const char *name)
    : QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer |
QGL::AlphaChannel | QGL::DirectRendering) , parent, name),
{
  SoDB::init();

  vpr = new SbView****tRegion(400, 400);
  sm = new SoSceneManager();
  scene = new SoSeparator();
  scene->ref();
  camera = new SoPerspectiveCamera;
  scene->addChild(camera);

  headlight   = new SoPointLight;
  scene->addChild(headlight);

  sm->setSceneGraph(scene);


  SoGLRenderAction *ra = new SoBoxHighlightRenderAction(*vpr);
  sm->setGLRenderAction(ra);
}

Now because I'm not using SoQtRenderArea or similar cl***** I have to
translate QEvent to SoEvent manually
I do it this way:

void myViewer::mousePressEvent(QMouseEvent *e)
{
  myQglViewer::mousePressEvent(e); //allows parent viewer to keep
rotating view on mouse interaction

  if(e->button() == e->LeftButton)
  {
    SoMouseButtonEvent *mbev = new SoMouseButtonEvent;

    mbev->setButton(SoMouseButtonEvent::BUTTON1);
    mbev->setState(SoButtonEvent::DOWN);
    mbev->setPosition(SbVec2s(e->x(), vpr->getWindowSize()[1] - e->y()
- 1));
    mbev->setAltDown((e->state()&e->AltButton));
    mbev->setCtrlDown((e->state()&e->ControlButton));
    mbev->set****ftDown((e->state()&e->****ftButton));
    mbev->setTime(SbTime::getTimeOfDay());

    cout << "MOUSE POS x = " << e->x() << "; y = " << e->y() << endl;

    SoHandleEventAction *heva = new SoHandleEventAction(*vpr);
    heva->setEvent(mbev);
    heva->apply(myViewer::selection);
  }
}

I do the same for mouseReleaseEvent and mouseMoveEvent. mouseMoveEvent
I translate to Location2Event


Your help is very appreciated=) Didn't sleep the whole night to fix
this, but no luck!
 




 1 Posts in Topic:
TROUBLE PICKING OBJECTS
Anatoli <anatoli.barsk  2008-03-08 10:19:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Aug 29 12:52:20 CDT 2008.