1 / 9

Open Inventor (parte progetto)

Open Inventor (parte progetto). Aggiungere alla classe base (delfino.h, Ufo.h, Veicolo.h, …) le inclusioni di open inventor: #include <Inventor/Xt/SoXt.h> #include <Inventor/Xt/viewers/SoXtExaminerViewer.h> #include <Inventor/nodes/SoDirectionalLight.h> #include <Inventor/nodes/SoMaterial.h>

matana
Télécharger la présentation

Open Inventor (parte progetto)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Open Inventor (parte progetto) • Aggiungere alla classe base (delfino.h, Ufo.h, Veicolo.h, …) • le inclusioni di open inventor: • #include <Inventor/Xt/SoXt.h> • #include <Inventor/Xt/viewers/SoXtExaminerViewer.h> • #include <Inventor/nodes/SoDirectionalLight.h> • #include <Inventor/nodes/SoMaterial.h> • #include <Inventor/nodes/SoPerspectiveCamera.h> • #include <Inventor/nodes/SoSeparator.h> • #include <Inventor/nodes/SoTransform.h> • #include <Inventor/nodes/SoCube.h> • #include <Inventor/nodes/SoTexture2.h> • #include <Inventor/nodes/SoPointLight.h> • #include <Inventor/nodes/SoEventCallback.h> • #include <Inventor/events/SoKeyboardEvent.h> • N.B.: Se si utilizzano altre classi occorre includere i file “.h” corrispondenti che possono essere trovati sul Reference Manual di Open Inventor

  2. Open Inventor (parte progetto) 2) Aggiungere nella parte privata di delfino.h: SoTransform *moto; SoPerspectiveCamera *myCamera; 3) In delfino.h aggiungere al costruttore i parametri SoTransform e SoPerspectiveCamera : Delfino (…….SoTransform *m, SoPerspectiveCamera *myC);

  3. Open Inventor (parte progetto) 4) Aggiungere al costruttore a più argomenti di delfino.cpp Delfino (…….SoTransform *m, SoPerspectiveCamera *myC) { … moto = m; myCamera=myC; … }

  4. Open Inventor (parte progetto) 5) Modificare le funzioni muoviti(), giraSinistra(), ecc.. Ad. Esempio in muoviti potreste aggiungere alla fine: //modificare il movimento SbRotation rot = moto->rotation.getValue(); SbVec3f spost(moto->posizione.getX(), moto->posizione.getY(), moto->posizione.getZ()); SbVec3f spostRel; rot.multVec(spost, spostRel); moto->translation.setValue(moto->translation.getValue() + spost ); myCamera->position.setValue(myCamera->position.getValue() + spost ); N.B.: il vettore spost è fornito rispetto alla posizione iniziale della moto, spostRel tiene invece conto dell’effettiva direzione della moto.

  5. Open Inventor (parte progetto) 6) Creare un file (ad. Esempio testInventor.cpp) con un main che gestisca la creazione degli oggetti di base in Open Inventor (vedi file testInventor.cpp). 7) A tale file aggiungere i metodi readFile, timerCallBack, myKeyPressCB, analoghi a quelli dei lucidi seguenti ed opportunamente modificati secondo il proprio progetto.

  6. Caricare i modelli 3D da file SoSeparator *readFile(const char *filename){ SoInput mySceneInput; if (!mySceneInput.openFile(filename)) { fprintf(stderr, "Cannot open file %s\n", filename); return NULL; } SoSeparator *myGraph = SoDB::readAll(&mySceneInput); if (myGraph == NULL) { fprintf(stderr, "Problem reading file\n"); return NULL; } mySceneInput.closeFile(); return myGraph;}

  7. Il Timer Sensor void timerCallback (void *data, SoSensor *) { Veicolo *mioVeicolo = (Veicolo*) data; // conversione esplicita mioVeicolo->muovi(0.04);} …. Veicolo mioVeicolo;…SoTimerSensor *myTimerSensor = new SoTimerSensor(timerCallback, &mioVeicolo);timerSensor->setInterval(0.04f); // 1/25 sec = 0.04timerSensor->schedule();

  8. Catturare gli eventi da tastiera void myKeyPressCB(void *data, SoEventCallback *eventCB){ Veicolo *veicolo = (Veicolo*) data; const SoEvent *event = eventCB->getEvent(); if (SO_KEY_PRESS_EVENT(event, UP_ARROW )) { veicolo->accelera(); } eventCB->setHandled();} …SoEventCallback *myEventCB = new SoEventCallback;myEventCB->addEventCallback( SoKeyboardEvent::getClassTypeId(), myKeyPressCB, veicolo);root->addChild(myEventCB);…

  9. testInventor.cpp

More Related