Private() : sensorCam1(0), sensorCam2(0) { // left view picksepLeft = new SoSeparator; picksepLeft->ref(); // right view picksepRight = new SoSeparator; picksepRight->ref(); }
int main(int, char **argv) { // Initialize Inventor. This returns a main window to use. // If unsuccessful, exit. HWND myWindow = SoWin::init("A red cone."); // pass the app name if (myWindow == NULL) exit(1); // Make a scene containing a red cone SoSeparator *root = new SoSeparator; SoPerspectiveCamera *myCamera = new SoPerspectiveCamera; SoMaterial *myMaterial = new SoMaterial; root->ref(); root->addChild(myCamera); root->addChild(new SoDirectionalLight); myMaterial->diffuseColor.setValue(1.0, 1.0, 0.0); // Red root->addChild(myMaterial); root->addChild(new SoCone); // Create a renderArea in which to see our scene graph. // The render area will appear within the main window. SoWinExaminerViewer *myRenderArea = new SoWinExaminerViewer(myWindow); // Make myCamera see everything. myCamera->viewAll(root, myRenderArea->getViewportRegion()); // Put our scene in myRenderArea, change the title myRenderArea->setSceneGraph(root); myRenderArea->setTitle("A red cone"); myRenderArea->show(); SoWin::show(myWindow); // Display main window SoWin::mainLoop(); // Main Inventor event loop delete myRenderArea; root->unref(); return 0; }
// the MAIN function int main(int argc, char ** argv) { Widget mainWindow = SoXt::init(argv[0]); if (mainWindow == NULL) exit(1); SoSeparator *root; root = new SoSeparator; root->ref(); player.camera = new SoPerspectiveCamera; root->addChild(player.camera); root->addChild(createScene()) ; //player.camera->viewAll(root, myRenderArea->getViewportRegion()); player.camera->position=SbVec3f(0, 5, 20); player.camera->orientation=SbRotation(-0.1, 0, 0, 1); player.camera->nearDistance=1; player.camera->farDistance=150; player.camera->heightAngle=0.5; //view the whole scene // initialize scenemanager instance SoXtRenderArea *myRenderArea = new SoXtRenderArea(mainWindow); myRenderArea->setSceneGraph(root); myRenderArea->setTitle("Bouncing Ball"); myRenderArea->show(); SoXt::show(mainWindow); SoXt::mainLoop(); return 0; }
SoSeparator *ReadScene(const char *Dir, const char *filename) { FILE *filePtr = NULL; SoSeparator *root; SoInput in; in.addDirectoryLast(Dir); if (!in.openFile(filename)) { cerr << "Error opening file " << filename << " from Directory " << Dir << endl; exit(1); } root = SoDB::readAll(&in); if (root == NULL) cerr << "Error reading file " << filename << " from Directory " << Dir << endl; else { #ifdef DEBUG cerr << "Scene (" << filename << ") read!\n"; #endif root->ref(); } in.closeFile(); return root; }
int QilexDoc::doc_new_kinematic_hand(ct_new_kinematic_chain *data) { int error = 0; int tipus = 0; void * buffer ; //char *buffer; char *buftemp = (char*)malloc(1024); SoOutput out; size_t sizeModel = 0; SoSeparator *kinechain = new SoSeparator; SoSeparator *kinetest = new SoSeparator; Rchain_hand *kineengine = new Rchain_hand(); SoTransform *pos_rot = new SoTransform; SbVec3f joinax; joinax.setValue(SbVec3f(data->x,data->y,data->z)); pos_rot->translation.setValue(joinax); pos_rot->rotation.setValue(SbVec3f(data->axeX, data->axeY, data->axeZ), (float) rad((double) data->angle)); kinechain = readFile(data->QsModelFile.latin1(), tipus); if (kinechain == NULL) // no object read { return 1; } else // ok, there's no object with the same name { error = kineengine->init_dat(data->QsDatFile.latin1()); // if (error == 0) { kinechain->ref(); kinetest = (SoSeparator*)SoNode::getByName(data->QsName.latin1()); if (kinetest==NULL) { //we need to put it in a buffer to write the xml file // if is Ok SoOutput out; out.setBuffer(buftemp, 1024, reallocCB); SoWriteAction wa1(&out); wa1.apply(kinechain); out.getBuffer(buffer, sizeModel); kinechain->insertChild(pos_rot, 0); } error = doc_insert_kinematic_hand(kineengine, kinechain); } } if (error==0) { writeXML_kineelement((char *)buffer, sizeModel, tipus, data, kineengine); } return error; }
int main(int, char **argv) { // Initialize Inventor. This returns a main window to use. // If unsuccessful, exit. HWND myWindow = SoWin::init("A red cone."); // pass the app name if (myWindow == NULL) exit(1); // Make a scene containing a red cone SoSeparator *root = new SoSeparator; root->ref(); SoMaterial *myMaterial = new SoMaterial; myMaterial->diffuseColor.setValue(1.0, 0.0, 0.0); root->addChild(myMaterial); root->addChild(new SoCone); // Set up viewer: SoWinExaminerViewer *myViewer =new SoWinExaminerViewer(myWindow); myViewer->setSceneGraph(root); myViewer->setTitle("Examiner Viewer"); myViewer->show(); SoWin::show(myWindow); // Display main window SoWin::mainLoop(); // Main Inventor event loop root->unref(); return 0; }
bool isVisibleFace(int faceIndex, const SbVec2f& pos, Gui::View3DInventorViewer* viewer) { SoSeparator* root = new SoSeparator; root->ref(); root->addChild(viewer->getSoRenderManager()->getCamera()); root->addChild(vp->getRoot()); SoSearchAction searchAction; searchAction.setType(PartGui::SoBrepFaceSet::getClassTypeId()); searchAction.setInterest(SoSearchAction::FIRST); searchAction.apply(root); SoPath* selectionPath = searchAction.getPath(); SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion()); rp.setNormalizedPoint(pos); rp.apply(selectionPath); root->unref(); SoPickedPoint* pick = rp.getPickedPoint(); if (pick) { const SoDetail* detail = pick->getDetail(); if (detail && detail->isOfType(SoFaceDetail::getClassTypeId())) { int index = static_cast<const SoFaceDetail*>(detail)->getPartIndex(); if (faceIndex != index) return false; SbVec3f dir = viewer->getViewDirection(); const SbVec3f& nor = pick->getNormal(); if (dir.dot(nor) > 0) return false; // bottom side points to user return true; } } return false; }
SoPickedPoint* ViewProvider::getPointOnRay(const SbVec2s& pos, const View3DInventorViewer* viewer) const { //first get the path to this node and calculate the current transformation SoSearchAction sa; sa.setNode(pcRoot); sa.setSearchingAll(true); sa.apply(viewer->getSoRenderManager()->getSceneGraph()); if (!sa.getPath()) return nullptr; SoGetMatrixAction gm(viewer->getSoRenderManager()->getViewportRegion()); gm.apply(sa.getPath()); SoTransform* trans = new SoTransform; trans->setMatrix(gm.getMatrix()); trans->ref(); // build a temporary scenegraph only keeping this viewproviders nodes and the accumulated // transformation SoSeparator* root = new SoSeparator; root->ref(); root->addChild(viewer->getSoRenderManager()->getCamera()); root->addChild(trans); root->addChild(pcRoot); //get the picked point SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion()); rp.setPoint(pos); rp.setRadius(viewer->getPickRadius()); rp.apply(root); root->unref(); trans->unref(); SoPickedPoint* pick = rp.getPickedPoint(); return (pick ? new SoPickedPoint(*pick) : 0); }
void vpSimulator::initSceneGraph() { this->scene = new SoSeparator; this->internalRoot = new SoSeparator; this->externalRoot = new SoSeparator; this->scene->ref(); this->internalRoot->ref(); this->externalRoot->ref(); // define the camera SoPerspectiveCamera this->internalCamera = new SoPerspectiveCamera ; this->externalCamera = new SoPerspectiveCamera ; this->internalCameraPosition = new SoTransform; this->internalCameraObject = createCameraObject(zoomFactor); internalCamera->farDistance.setValue(100); internalCamera->nearDistance.setValue(0.0001f); // link between camera and internal root this->internalRoot->addChild (this->internalCamera); this->internalRoot->addChild (this->scene); this->externalRoot->addChild (this->externalCamera); this->externalRoot->addChild (this->scene); SoSeparator * camera = new SoSeparator; camera->ref(); camera->addChild (this->internalCameraPosition); camera->addChild (this->internalCameraObject); this->externalRoot->addChild (camera); //this->externalRoot->addChild (internalCameraPosition); // this->externalRoot->addChild (internalCameraObject); SoCube *cube = new SoCube ; cube->width=0.01f ; cube->depth=0.01f ; cube->height=0.01f ; this->externalRoot->addChild (cube); if (realtime==NULL) { SoDB::enableRealTimeSensor(FALSE); SoSceneManager::enableRealTimeUpdate(FALSE); realtime = (SbTime *) SoDB::getGlobalField("realTime"); realtime->setValue(0.0); } }
/* Cree une fleche composee d'un cylindre et d'un cone. * La fleche a une hauteur total de <longueur>, dont * <proportionFleche>% pour la fleche. Le rayon du cylindre * est <radius>, et celui de la fleche <radius> * 5. * La fleche est oriente selon l'axe Y. */ static SoSeparator * createArrow (float longueur, float proportionFleche, float radius) { SoSeparator *fleche = new SoSeparator; fleche->ref(); SoTranslation *poseCylindre = new SoTranslation; SoCylinder *line = new SoCylinder; SoTranslation *posePointe = new SoTranslation; SoCone *pointe = new SoCone; float l_cylindre = longueur * ( 1 - proportionFleche); float l_cone = longueur * proportionFleche; float radius_cylindre = radius; float radius_cone = radius * 5; line->radius.setValue (radius_cylindre); line->height.setValue (l_cylindre); poseCylindre->translation.setValue (0, l_cylindre / 2, 0); posePointe->translation.setValue (0.0, l_cylindre / 2 + l_cone / 2, 0); pointe->bottomRadius.setValue (radius_cone); pointe->height.setValue (l_cone); fleche->addChild (poseCylindre); fleche->addChild (line); fleche->addChild (posePointe); fleche->addChild (pointe); return fleche; }
int main(int argc, char** argv) { QWidget* mainwin = SoQt::init(argc, argv, argv[0]); SoSeparator* root = new SoSeparator; root->ref(); InventorRobot robot(root); if (argc == 1){ //robot.parse("../RobotEditorArmar4.dae"); //robot.parse("/media/sf_host/manikin_creo_4.dae"); std::cout << "Usage collada <collada file> [<inventor export>]" <<std::endl; return 1; } else { robot.parse(argv[1]); if (argc==3){ SoWriteAction writeAction; writeAction.getOutput()->openFile(argv[2]); writeAction.apply(root); } } SoQtExaminerViewer* viewer = new SoQtExaminerViewer(mainwin); viewer->setSceneGraph(root); viewer->show(); // Pop up the main window. SoQt::show(mainwin); // Loop until exit. SoQt::mainLoop(); root->unref(); return 1; }
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { #else // UNIX int main(int argc, char ** argv) { #endif // initialize Coin and glut libraries SoDB::init(); #ifdef _WIN32 int argc = 1; char * argv[] = { "glutiv.exe", (char *) NULL }; glutInit(&argc, argv); #else glutInit(&argc, argv); #endif glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); SoSeparator * root; root = new SoSeparator; root->ref(); SoPerspectiveCamera * camera = new SoPerspectiveCamera; root->addChild(camera); root->addChild(new SoDirectionalLight); root->addChild(createScenegraph()); scenemanager = new SoSceneManager; scenemanager->setRenderCallback(redraw_cb, (void *)1); scenemanager->setBackgroundColor(SbColor(0.2f, 0.2f, 0.2f)); scenemanager->activate(); camera->viewAll(root, scenemanager->getViewportRegion()); scenemanager->setSceneGraph(root); glutInitWindowSize(512, 400); SbString title("Offscreen Rendering"); glutwin = glutCreateWindow(title.getString()); glutDisplayFunc(expose_cb); glutReshapeFunc(reshape_cb); // start main loop processing (with an idle callback) glutIdleFunc(idle_cb); glutMainLoop(); root->unref(); delete scenemanager; return 0; }
SoSeparator * createCameraObject (const float zoomFactor = 1.0) { vpDEBUG_TRACE (15, "# Entree."); SoSeparator * cam = new SoSeparator; cam->ref (); SoMaterial *myMaterial = new SoMaterial; myMaterial->diffuseColor.setValue(1.0, 0.0, 0.0); myMaterial->emissiveColor.setValue(0.5, 0.0, 0.0); SoScale *taille = new SoScale; { float zoom = 0.1f * zoomFactor; taille->scaleFactor.setValue (zoom, zoom, zoom); } SoMaterial *couleurBlanc = new SoMaterial; couleurBlanc->diffuseColor.setValue(1.0, 1.0, 1.0); couleurBlanc->emissiveColor.setValue(1.0, 1.0, 1.0); SoDrawStyle * filDeFer = new SoDrawStyle; filDeFer->style.setValue (SoDrawStyle::LINES); filDeFer->lineWidth.setValue (1); SoSeparator * cone = new SoSeparator; cone->ref(); cone->addChild (makePyramide()); cone->addChild (couleurBlanc); cone->addChild (filDeFer); cone->addChild (makePyramide()); cone->unrefNoDelete(); cam->addChild(myMaterial); cam->addChild(taille); cam->addChild(cone); cam->addChild(createFrame(2.0f,0.1f,0.01f)); // cam->unref() ; vpDEBUG_TRACE (15, "# Sortie."); return cam; }
SoSeparator * HandObjectState::copyHandStateIV(){ SoSeparator * graspIVRoot = new SoSeparator(); //FIXME -- is this necesary? graspIVRoot->ref(); SoNode * handIVRoot = mHand->getIVRoot()->copy(1); SoNode * objectIVRoot = mTargetObject->getIVRoot()->copy(1); graspIVRoot->addChild(handIVRoot); graspIVRoot->addChild(objectIVRoot); return graspIVRoot; }
int main() { SoSeparator *root = new SoSeparator; SoPerspectiveCamera *myCamera = new SoPerspectiveCamera; SoMaterial *myMaterial = new SoMaterial; root->ref(); root->addChild(myCamera); root->addChild(new SoDirectionalLight); myMaterial->diffuseColor.setValue(1.0, 0.0, 0.0); root->addChild(myMaterial); root->addChild(new SoCone); }
SoSeparator* IVElement::ivModel(bool tran) { if(tran){ SoSeparator* temp = new SoSeparator; temp->ref(); temp->addChild(color); temp->addChild(trans); temp->addChild(rot); temp->addChild(ivmodel); return temp; }else return ivmodel; }
bool CoinRrtWorkspaceVisualization::addConfiguration( const Eigen::VectorXf &c, CoinRrtWorkspaceVisualization::ColorSet colorSet, float nodeSizeFactor ) { if (c.rows() != robotNodeSet->getSize()) { VR_ERROR << " Dimensions do not match: " << c.rows() <<"!="<< robotNodeSet->getSize() << endl; return false; } if (!TCPNode) return false; float nodeSolutionSize = pathNodeSize*nodeSizeFactor;//15.0;//1.0f SoMaterial *materialNodeSolution = new SoMaterial(); materialNodeSolution->ambientColor.setValue(colors[colorSet].nodeR,colors[colorSet].nodeG,colors[colorSet].nodeB); materialNodeSolution->diffuseColor.setValue(colors[colorSet].nodeR,colors[colorSet].nodeG,colors[colorSet].nodeB); SoSphere *sphereNodeSolution = new SoSphere(); sphereNodeSolution->radius.setValue(nodeSolutionSize); Eigen::VectorXf actConfig; float x,y,z; float x2 = 0.0f,y2 = 0.0f,z2 = 0.0f; SoSeparator *sep = new SoSeparator(); sep->ref(); SoUnits *u = new SoUnits; u->units = SoUnits::MILLIMETERS; sep->addChild(u); // create 3D model for nodes SoSeparator *s = new SoSeparator(); s->addChild(materialNodeSolution); SoTranslation *t = new SoTranslation(); // get tcp coords: robot->setJointValues(robotNodeSet,c); Eigen::Matrix4f m; m = TCPNode->getGlobalPose(); x = m(0,3); y = m(1,3); z = m(2,3); t->translation.setValue(x,y,z); s->addChild(t); // display a solution node different s->addChild(sphereNodeSolution); sep->addChild(s); visualization->addChild(sep); sep->unref(); return true; }
/*! Add the representation of a frame. \param fMo : desired position of the frame \param zoom : Zoom factor. */ void vpSimulator::addFrame (const vpHomogeneousMatrix &fMo, float zoom) { SoScale *taille = new SoScale; taille->scaleFactor.setValue (zoom, zoom, zoom); SoSeparator * frame = new SoSeparator; frame->ref(); frame->addChild(taille); frame->addChild(createFrame (LONGUEUR_FLECHE*zoom, PROPORTION_FLECHE*zoom, RAYON_FLECHE*zoom)); this->addObject(frame, fMo, externalRoot) ; // frame->unref(); }
SoPickedPoint* ViewProvider::getPointOnRay(const SbVec2s& pos, const View3DInventorViewer* viewer) const { // for convenience make a pick ray action to get the (potentially) picked entity in the provider SoSeparator* root = new SoSeparator; root->ref(); root->addChild(viewer->getSoRenderManager()->getCamera()); root->addChild(pcRoot); SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion()); rp.setPoint(pos); rp.apply(root); root->unref(); SoPickedPoint* pick = rp.getPickedPoint(); return (pick ? new SoPickedPoint(*pick) : 0); }
int main(int argc, char ** argv) { QApplication app(argc, argv); // Initializes Quarter (and implicitly also Coin and Qt Quarter::init(); // Make a dead simple scene graph by using the Coin library, only // containing a single yellow cone under the scenegraph root. SoSeparator * root = new SoSeparator; root->ref(); SoBaseColor * col = new SoBaseColor; col->rgb = SbColor(1, 1, 0); root->addChild(col); root->addChild(new SoCone); // Create a QuarterWidget for displaying a Coin scene graph QuarterWidget * viewer = new QuarterWidget; //set default navigation mode file viewer->setNavigationModeFile(); viewer->setSceneGraph(root); // Add some background text SoSeparator * background = create_background(); (void)viewer->getSoRenderManager()->addSuperimposition(background, SoRenderManager::Superimposition::BACKGROUND); // Add some super imposed text SoSeparator * superimposed = create_superimposition(); (void)viewer->getSoRenderManager()->addSuperimposition(superimposed); // Pop up the QuarterWidget viewer->show(); // Loop until exit. app.exec(); // Clean up resources. root->unref(); delete viewer; Quarter::clean(); return 0; }
SoNode* setupHeadUpDisplay(const QString& text) const { SoSeparator* hudRoot = new SoSeparator; hudRoot->ref(); SoOrthographicCamera* hudCam = new SoOrthographicCamera(); hudCam->viewportMapping = SoCamera::LEAVE_ALONE; // Set the position in the window. // [0, 0] is in the center of the screen. // SoTranslation* hudTrans = new SoTranslation; hudTrans->translation.setValue(-0.95f, -0.95f, 0.0f); QFont font = this->font(); font.setPointSize(24); QFontMetrics fm(font); QColor front; front.setRgbF(0.8f, 0.8f, 0.8f); int w = fm.width(text); int h = fm.height(); QImage image(w,h,QImage::Format_ARGB32_Premultiplied); image.fill(0x00000000); QPainter painter(&image); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(front); painter.setFont(font); painter.drawText(0,0,w,h,Qt::AlignLeft,text); painter.end(); SoSFImage sfimage; Gui::BitmapFactory().convert(image, sfimage); SoImage* hudImage = new SoImage(); hudImage->image = sfimage; // Assemble the parts... // hudRoot->addChild(hudCam); hudRoot->addChild(hudTrans); hudRoot->addChild(hudImage); return hudRoot; }
SoPickedPoint* ViewProviderFace::getPickedPoint(const SbVec2s& pos, const SoQtViewer* viewer) const { SoSeparator* root = new SoSeparator; root->ref(); root->addChild(viewer->getHeadlight()); root->addChild(viewer->getCamera()); root->addChild(this->pcMeshPick); SoRayPickAction rp(viewer->getViewportRegion()); rp.setPoint(pos); rp.apply(root); root->unref(); // returns a copy of the point SoPickedPoint* pick = rp.getPickedPoint(); //return (pick ? pick->copy() : 0); // needs the same instance of CRT under MS Windows return (pick ? new SoPickedPoint(*pick) : 0); }
int main(int, char ** argv) { HWND window = SoWin::init("Oil Well"); if (window == NULL) exit(1); SoWinExaminerViewer * viewer = new SoWinExaminerViewer(window); viewer->setDecoration(false); viewer->setSize(SbVec2s(800, 600)); SoSeparator *root = new SoSeparator; root->ref(); SoSeparator *obelisk = new SoSeparator(); // Define the normals used: SoNormal *myNormals = new SoNormal; myNormals->vector.setValues(0, 8, norms); obelisk->addChild(myNormals); SoNormalBinding *myNormalBinding = new SoNormalBinding; myNormalBinding->value = SoNormalBinding::PER_FACE; obelisk->addChild(myNormalBinding); // Define material for obelisk SoMaterial *myMaterial = new SoMaterial; myMaterial->diffuseColor.setValue(.4, .4, .4); obelisk->addChild(myMaterial); // Define coordinates for vertices SoCoordinate3 *myCoords = new SoCoordinate3; myCoords->point.setValues(0, 28, vertices); obelisk->addChild(myCoords); // Define the FaceSet SoFaceSet *myFaceSet = new SoFaceSet; myFaceSet->numVertices.setValues(0, 8, numvertices); obelisk->addChild(myFaceSet); root->addChild(obelisk); viewer->setSceneGraph(root); viewer->setTitle("Oil Well"); viewer->show(); SoWin::show(window); SoWin::mainLoop(); delete viewer; root->unref(); return 0; }
// Routine to create a scene graph representing a dodecahedron SoSeparator * makePyramide() { SoSeparator *result = new SoSeparator; result->ref(); // Define coordinates for vertices SoCoordinate3 *myCoords = new SoCoordinate3; myCoords->point.setValues(0, 5, pyramidVertexes); result->addChild(myCoords); // Define the IndexedFaceSet, with indices into the vertices: SoIndexedFaceSet *myFaceSet = new SoIndexedFaceSet; myFaceSet->coordIndex.setValues (0, 21, (const int32_t*)pyramidFaces); result->addChild (myFaceSet); result->unrefNoDelete(); return result; }
int main(int , char **argv) { // Initialize Inventor. This returns a main window to use. // If unsuccessful, exit. QWidget* myWindow = SoQt::init(argv[0]); // pass the app name if (myWindow == NULL) exit(1); // Make a scene containing a red cone SoSeparator *root = new SoSeparator; SoPerspectiveCamera *myCamera = new SoPerspectiveCamera; SoMaterial *myMaterial = new SoMaterial; root->ref(); root->addChild(myCamera); root->addChild(new SoDirectionalLight); myMaterial->diffuseColor.setValue(1.0, 0.0, 0.0); // Red root->addChild(myMaterial); // GsTL_SoNode::initClass(); GsTL_SoNode* obj = new GsTL_SoNode; obj->addChild(new SoCone); root->addChild( obj ); obj->visible = true; // Create a renderArea in which to see our scene graph. // The render area will appear within the main window. SoQtRenderArea *myRenderArea = new SoQtRenderArea(myWindow); // Make myCamera see everything. myCamera->viewAll(root, myRenderArea->getViewportRegion()); // Put our scene in myRenderArea, change the title myRenderArea->setSceneGraph(root); myRenderArea->setTitle("Hello Cone"); myRenderArea->show(); SoQt::show(myWindow); // Display main window SoQt::mainLoop(); // Main Inventor event loop }
int main(int argc, char ** argv) { QApplication app(argc, argv); // Initializes Quarter library (and implicitly also the Coin and Qt // libraries). Quarter::init(); // Make a dead simple scene graph by using the Coin library, only // containing a single yellow cone under the scenegraph root. SoSeparator * root = new SoSeparator; root->ref(); SoBaseColor * col = new SoBaseColor; col->rgb = SbColor(1, 1, 0); root->addChild(col); root->addChild(new SoCone); // Create a QuarterWidget for displaying a Coin scene graph QuarterWidget * viewer = new QuarterWidget; viewer->setSceneGraph(root); // make the viewer react to input events similar to the good old // ExaminerViewer viewer->setNavigationModeFile(QUrl("coin:///scxml/navigation/examiner.xml")); // Pop up the QuarterWidget viewer->show(); // Loop until exit. app.exec(); // Clean up resources. root->unref(); delete viewer; Quarter::clean(); return 0; }
VirtualRobot::VisualizationNodePtr CoinVisualizationNode::clone(bool deepCopy, float scaling) { THROW_VR_EXCEPTION_IF(scaling<=0,"Scaling must be >0"); SoSeparator* newModel = NULL; if (visualization) { newModel = new SoSeparator; newModel->ref(); if (scaling!=1.0) { SoScale *s = new SoScale; s->scaleFactor.setValue(scaling,scaling,scaling); newModel->addChild(s); } if (deepCopy) { newModel->addChild(visualization->copy(FALSE)); } else newModel->addChild(visualization); } VisualizationNodePtr p(new CoinVisualizationNode(newModel)); if (newModel) newModel->unrefNoDelete(); p->setUpdateVisualization(updateVisualization); p->setGlobalPose(getGlobalPose()); p->setFilename(filename,boundingBox); // clone attached visualizations std::map< std::string, VisualizationNodePtr >::const_iterator i = attachedVisualizations.begin(); while (i!=attachedVisualizations.end()) { VisualizationNodePtr attachedClone = i->second->clone(deepCopy,scaling); p->attachVisualization(i->first, attachedClone); i++; } return p; }
SoPickedPoint* ViewProvider::getPointOnRay(const SbVec3f& pos,const SbVec3f& dir, const View3DInventorViewer* viewer) const { // Note: There seems to be a bug with setRay() which causes SoRayPickAction // to fail to get intersections between the ray and a line //first get the path to this node and calculate the current setTransformation SoSearchAction sa; sa.setNode(pcRoot); sa.setSearchingAll(true); sa.apply(viewer->getSoRenderManager()->getSceneGraph()); SoGetMatrixAction gm(viewer->getSoRenderManager()->getViewportRegion()); gm.apply(sa.getPath()); // build a temporary scenegraph only keeping this viewproviders nodes and the accumulated // transformation SoTransform* trans = new SoTransform; trans->ref(); trans->setMatrix(gm.getMatrix()); SoSeparator* root = new SoSeparator; root->ref(); root->addChild(viewer->getSoRenderManager()->getCamera()); root->addChild(trans); root->addChild(pcRoot); //get the picked point SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion()); rp.setRay(pos,dir); rp.setRadius(viewer->getPickRadius()); rp.apply(root); root->unref(); trans->unref(); // returns a copy of the point SoPickedPoint* pick = rp.getPickedPoint(); //return (pick ? pick->copy() : 0); // needs the same instance of CRT under MS Windows return (pick ? new SoPickedPoint(*pick) : 0); }
SoSeparator * createScenegraph(void) { SoSeparator * texroot = new SoSeparator; texroot->ref(); SoInput in; in.setBuffer(red_cone_iv, strlen(red_cone_iv)); SoSeparator * result = SoDB::readAll(&in); if (result == NULL) { exit(1); } SoPerspectiveCamera *myCamera = new SoPerspectiveCamera; SoRotationXYZ *rot = new SoRotationXYZ; rot->axis = SoRotationXYZ::X; rot->angle = M_PI_2; myCamera->position.setValue(SbVec3f(-0.2, -0.2, 2.0)); myCamera->scaleHeight(0.4); texroot->addChild(myCamera); texroot->addChild(new SoDirectionalLight); texroot->addChild(rot); texroot->addChild(result); myCamera->viewAll(texroot, SbViewportRegion()); // Generate the texture map SoTexture2 *texture = new SoTexture2; texture->ref(); if (generateTextureMap(texroot, texture, 128, 128)) printf ("Successfully generated texture map\n"); else printf ("Could not generate texture map\n"); texroot->unref(); // Make a scene with a cube and apply the texture to it SoSeparator * root = new SoSeparator; root->addChild(texture); root->addChild(new SoCube); return root; }
SoSeparator* IVWorkSpace::calculateBoundingBox(SoSeparator *element){ // set up an engine to calculate the bounding box of the element parameter SoComputeBoundingBox * bboxEngine = new SoComputeBoundingBox; bboxEngine->node = element; // decompose the vectors into separate floating point values SoDecomposeVec3f * dep1 = new SoDecomposeVec3f; SoDecomposeVec3f * dep2 = new SoDecomposeVec3f; dep1->vector.connectFrom(&bboxEngine->min); dep2->vector.connectFrom(&bboxEngine->max); // create engines to compose vectors again. We need eight vectors, // one for each vertex in the bounding box. SoComposeVec3f * comp1 = new SoComposeVec3f; SoComposeVec3f * comp2 = new SoComposeVec3f; SoComposeVec3f * comp3 = new SoComposeVec3f; SoComposeVec3f * comp4 = new SoComposeVec3f; SoComposeVec3f * comp5 = new SoComposeVec3f; SoComposeVec3f * comp6 = new SoComposeVec3f; SoComposeVec3f * comp7 = new SoComposeVec3f; SoComposeVec3f * comp8 = new SoComposeVec3f; // connect the engines so that all corner points are covered comp1->x.connectFrom(&dep1->x); comp1->y.connectFrom(&dep1->y); comp1->z.connectFrom(&dep1->z); comp2->x.connectFrom(&dep2->x); comp2->y.connectFrom(&dep1->y); comp2->z.connectFrom(&dep1->z); comp3->x.connectFrom(&dep2->x); comp3->y.connectFrom(&dep2->y); comp3->z.connectFrom(&dep1->z); comp4->x.connectFrom(&dep1->x); comp4->y.connectFrom(&dep2->y); comp4->z.connectFrom(&dep1->z); comp5->x.connectFrom(&dep1->x); comp5->y.connectFrom(&dep1->y); comp5->z.connectFrom(&dep2->z); comp6->x.connectFrom(&dep2->x); comp6->y.connectFrom(&dep1->y); comp6->z.connectFrom(&dep2->z); comp7->x.connectFrom(&dep2->x); comp7->y.connectFrom(&dep2->y); comp7->z.connectFrom(&dep2->z); comp8->x.connectFrom(&dep1->x); comp8->y.connectFrom(&dep2->y); comp8->z.connectFrom(&dep2->z); // concatenate the eight vectors into a single SoMFVec3f field SoConcatenate * con = new SoConcatenate(SoMFVec3f::getClassTypeId()); con->input[0]->connectFrom(&comp1->vector); con->input[1]->connectFrom(&comp2->vector); con->input[2]->connectFrom(&comp3->vector); con->input[3]->connectFrom(&comp4->vector); con->input[4]->connectFrom(&comp5->vector); con->input[5]->connectFrom(&comp6->vector); con->input[6]->connectFrom(&comp7->vector); con->input[7]->connectFrom(&comp8->vector); // construct a new scene graph, that includes an indexed line to // render the bounding box. SoSeparator* sep = new SoSeparator; SoLightModel* lm = new SoLightModel; lm->model = SoLightModel::BASE_COLOR; SoCoordinate3* coords = new SoCoordinate3; // use the points calculated by our engines coords->point.connectFrom(con->output); SoDrawStyle* ds = new SoDrawStyle; ds->lineWidth = 2; ds->linePattern = 0xf0f0; SoIndexedLineSet* ls = new SoIndexedLineSet; const int32_t idx[] = {0,1,2,3,0,-1,4,5,6,7,4,-1, 1,5,-1,2,6,-1,3,7,-1,0,4,-1}; ls->coordIndex.setNum(24); ls->coordIndex.setValues(0, 24, idx); sep->addChild(lm); sep->addChild(coords); sep->addChild(ds); sep->addChild(ls); sep->ref(); return sep; }