void AnimationTexture(SoSeparator * root) { // Generate a julia set to use as a texturemap julia(cr, ci, 2.5, texturewidth, textureheight, 4, bitmap, 64); SoTexture2 * texnode = texture(); // Enable backface culling SoShapeHints * hints = new SoShapeHints; hints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE; hints->shapeType = SoShapeHints::SOLID; // Timer sensor SoTimerSensor * texturetimer = new SoTimerSensor(timersensorcallback, texnode); texturetimer->setInterval(0.05); texturetimer->schedule(); // Scene graph if ( root == NULL ) return; // Shouldn't happen. root->ref(); // prevent from being deleted because of the still running timer sensor // SoSeparator * root = new SoSeparator; // root->ref(); root->addChild(hints); root->addChild(texnode); root->addChild(new SoCube); }
void vpSimulator::mainLoop() { if (mainWindowInitialized==false) { vpERROR_TRACE("main window is not opened ") ; } vpTime::wait(1000) ; // Timer sensor SoTimerSensor * timer = new SoTimerSensor(timerSensorCallback, (void *)this); timer->setInterval(0.01); timer->schedule(); vpViewer::mainLoop() ; }
void GenericIKWindow::setupUI() { UI.setupUi(this); exViewer = new SoQtExaminerViewer(UI.frameViewer, "", TRUE, SoQtExaminerViewer::BUILD_POPUP); // setup exViewer->setBackgroundColor(SbColor(1.0f, 1.0f, 1.0f)); exViewer->setAccumulationBuffer(true); exViewer->setAntialiasing(true, 4); exViewer->setTransparencyType(SoGLRenderAction::BLEND); exViewer->setFeedbackVisibility(true); exViewer->setSceneGraph(sceneSep); exViewer->viewAll(); connect(UI.pushButtonReset, SIGNAL(clicked()), this, SLOT(resetSceneryAll())); connect(UI.pushButtonLoad, SIGNAL(clicked()), this, SLOT(loadRobot())); connect(UI.checkBoxColModel, SIGNAL(clicked()), this, SLOT(collisionModel())); connect(UI.comboBoxKC, SIGNAL(activated(int)), this, SLOT(selectKC(int))); connect(UI.pushButtonBox2TCP, SIGNAL(clicked()), this, SLOT(box2TCP())); connect(UI.pushButtonSolve, SIGNAL(clicked()), this, SLOT(solve())); connect(UI.horizontalSliderX, SIGNAL(sliderReleased()), this, SLOT(sliderReleased())); connect(UI.horizontalSliderY, SIGNAL(sliderReleased()), this, SLOT(sliderReleased())); connect(UI.horizontalSliderZ, SIGNAL(sliderReleased()), this, SLOT(sliderReleased())); connect(UI.horizontalSliderA, SIGNAL(sliderReleased()), this, SLOT(sliderReleased())); connect(UI.horizontalSliderB, SIGNAL(sliderReleased()), this, SLOT(sliderReleased())); connect(UI.horizontalSliderG, SIGNAL(sliderReleased()), this, SLOT(sliderReleased())); // a method, that is called by a timer, is allowed to update the IV models without disturbing the render loop SoTimerSensor* timer = new SoTimerSensor((SoSensorCB*)(&updateCB), this); SbTime interval(1.0 / 30); timer->setInterval(interval); timer->schedule(); }
int main(int argc, char** argv) { // init Inventor HWND w = SoWin::init(argv[0]); SoWinExaminerViewer * v = new SoWinExaminerViewer(w); //Preguntar donde iria SoViewportRegion::initClass(); // Iniciamos la escena SoSeparator *root = new SoSeparator; root->ref(); root->addChild(new SoUnits); Pointers * mypointers= new Pointers(); //De este separador colgará la escena que se carga de //fichero, así como las cámaras y luces encargadas de //mostrarla SoSeparator *ojo_izq= new SoSeparator; //Partimos la pantalla SoViewportRegion *vp1 = new SoViewportRegion(); vp1->height=0.4f; vp1->width=0.2f; vp1->y_pos=0.6f; vp1->x_pos=0.0f; vp1->onTop=TRUE; ojo_izq->addChild(vp1); //Introducimos una nueva cámara. Esta cámara pintará //los draggers siempre en la misma posición SoFrustumCamera *cam = new SoFrustumCamera(); ojo_izq->addChild(cam); SoSeparator * escena = new SoSeparator; LightControl * luces; luces = new LightControl(escena); CheckStick * mystickcontrol; mypointers->lights=luces; mypointers->viewer=v; SoSeparator *habitacion=new SoSeparator; SoTransform * centrar = new SoTransform; //centrar->translation.setValue(60.0f,-60.0f,60.0f); centrar->translation.setValue(0,-1.f,0.5f); //centrar->scaleFactor.setValue(0.0001f,0.0001f,0.0001f);//bateria wena //centrar->scaleFactor.setValue(3.f,3.f,3.f); habitacion->addChild(centrar); //Desplazamiento de la pantalla // model SoFile *model = new SoFile; if (argc > 1) model->name.setValue(argv[1]); else model->name.setValue("drumconparedes.wrl"); habitacion->addChild(model); escena->addChild(habitacion); SoSeparator * esqueleto= new SoSeparator; DrawCoin::CrearEsqueleto(esqueleto); mystickcontrol=new CheckStick(DrawCoin::t_cabeza,DrawCoin::t_mano_izq,DrawCoin::t_mano_der); mypointers->sticks=mystickcontrol; escena->addChild(esqueleto); ojo_izq->addChild (escena); //Colocamos la camara de modo que pueda ver toda la escena cam->viewAll(escena,vp1->getViewportRegion()); //cam->position.setValue(0.0f,10.0f,-10.f); //cam->orientation.setValue(SbVec3f(0.0f,-1.f,1.f),0); //De este separador colgará la escena que se carga de //fichero, así como las cámaras y luces encargadas de //mostrarla SoSeparator *ojo_der= new SoSeparator; root->addChild (ojo_der); root->addChild (ojo_izq); //Partimos la pantalla SoViewportRegion *vp2 = new SoViewportRegion(); vp2->height=1.0f; vp2->width=1.0f; vp2->x_pos=0.0f; vp2->onTop=FALSE; ojo_der->addChild(vp2); //Introducimos una nueva cámara. Esta cámara pintará //los draggers siempre en la misma posición SoFrustumCamera * cam2; cam2 = new SoFrustumCamera(); mypointers->camera2=cam2; //cam2->farDistance = 3.f; ojo_der->addChild(cam2); SoTransform * cabeza; SoRotation * rotacion; cabeza=DrawCoin::Get_Cabeza_Pos(); rotacion=DrawCoin::Get_Cabeza_Rot(); cam2->position.connectFrom(&cabeza->translation); cam2->orientation.connectFrom(&rotacion->rotation); ojo_der->addChild (escena); //Colocamos la camara de modo que pueda ver toda la escena cam2->viewAll(escena,vp2->getViewportRegion()); cam2->viewportMapping = SoCamera::LEAVE_ALONE; cam2->position.setValue(0.0f,0.0f,0.0f); int Data_Of_Thread = 1; HANDLE Handle_Of_Thread; Handle_Of_Thread = CreateThread( NULL, 0, Thread, &Data_Of_Thread, 0, NULL); if ( Handle_Of_Thread == NULL) ExitProcess(Data_Of_Thread); //Creamos un sensor encargado del render SoTimerSensor* rendertimer = new SoTimerSensor(renderCallback,(void *)mypointers); rendertimer->setInterval(FPS); rendertimer->schedule(); SoEventCallback *eventCB = new SoEventCallback; eventCB->addEventCallback(SoKeyboardEvent::getClassTypeId(),handle_keyboard,(void*)mypointers); root->addChild(eventCB); v->setBackgroundColor(SbColor(0.0f, 0.2f, 0.3f)); v->setFeedbackVisibility(TRUE); v->setSceneGraph(root); //v->setViewing(FALSE); v->setTitle("Kinect Tracking"); v->setAutoRedraw(FALSE); ///v->setDecoration(FALSE); SoWin::show(w); SoWin::mainLoop(); root->unref(); delete v; return 0; }
int main(int argc, char** argv) { // verify that argument is given if (argc < 2) { std::cerr << "syntax: chain <XML file>" << std::endl; return -1; } // setup the simulation XMLReader::read(std::string(argv[1])); // get the (only) simulation object boost::shared_ptr<Simulator> s = XMLReader::_sim_objs.front(); // setup the visualization QWidget* mainwin = SoQt::init(argc, argv, argv[0]); SoQtExaminerViewer* viewer = new SoQtExaminerViewer(mainwin); SoSeparator* main_sep = new SoSeparator; main_sep->ref(); // add a camera SoPerspectiveCamera* camera = new SoPerspectiveCamera; camera->position = SbVec3f(0, 0, 150); camera->pointAt(SbVec3f(0,0,1)); main_sep->addChild(camera); // add lights SoDirectionalLight* light = new SoDirectionalLight; light->direction = SbVec3f(0,0,1); SoDirectionalLight* light2 = new SoDirectionalLight; light2->direction = SbVec3f(0,0,-1); SoDirectionalLight* light3 = new SoDirectionalLight; light3->direction = SbVec3f(-10,-5,-1); SoDirectionalLight* light4 = new SoDirectionalLight; light4->direction = SbVec3f(-10,-5,1); SoDirectionalLight* light5 = new SoDirectionalLight; light5->direction = SbVec3f(0,-10,1); main_sep->addChild(light); main_sep->addChild(light2); main_sep->addChild(light3); main_sep->addChild(light4); main_sep->addChild(light5); // setup the simulator visualization viz = boost::shared_ptr<InventorOutput>(new InventorOutput(s)); SoSeparator* sep = viz->get_root(); main_sep->addChild(sep); // start rendering viewer->setSceneGraph(sep); viewer->show(); // add a timer sensor that runs the simulation SoTimerSensor* timer = new SoTimerSensor(&render, &s); SbTime interval(STEP_SIZE); timer->setInterval(interval); timer->schedule(); // popup the main window SoQt::show(mainwin); SoQt::mainLoop(); delete viewer; }
int main(int argc, char * argv[]) { /* Default values of program arguments. */ char * heightmap_name = NULL; int triangle_count = 1000; int tile_size = 33; int pixel_error = 6; int edgeSize = 4096; int xOffset = 0; int yOffset = 0; bool drawWater = false; SbBool is_full_screen = FALSE; SbBool is_frustrum_culling = TRUE; /* Get program arguments. */ int command = 0; while ((command = getopt(argc, argv, "h:x:y:s:S:a:e:r:g:fcW")) != -1) { switch (command) { /* Heightmap. */ case 'h': { heightmap_name = optarg; } break; /* Algorithm. */ case 'a': { if (!strcmp(optarg, "roam")) { algorithm = ID_ALG_ROAM; } else if (!strcmp(optarg, "geomipmapping")) { algorithm = ID_ALG_GEO_MIPMAP; } else if (!strcmp(optarg, "chunkedlod")) { algorithm = ID_ALG_CHUNKED_LOD; } else if (!strcmp(optarg, "brutalforce")) { algorithm = ID_ALG_BRUAL_FORCE; } } break; /* Size of the plot map, in data points a long one edge (map is a square). */ case 's': { sscanf(optarg, "%d", &edgeSize); } /* Scaling factor. */ case 'S': { sscanf(optarg, "%d", &scaleFactor); } break; /* X offset in data points. */ case 'x': { sscanf(optarg, "%d", &xOffset); } break; /* Y offset in data points. */ case 'y': { sscanf(optarg, "%d", &yOffset); } break; /* Pixel error of rendering. */ case 'e': { sscanf(optarg, "%d", &pixel_error); } break; /* Number of triangles in triangulation. */ case 'r': { sscanf(optarg, "%d", &triangle_count); } break; /* Tile side size. */ case 'g': { sscanf(optarg, "%d", &tile_size); } break; /* Fullscreen. */ case 'f': { is_full_screen = TRUE; } break; /* Frustrum culling. */ case 'c': { is_frustrum_culling = FALSE; } break; /* Draw water line. */ case 'W': { drawWater = true; } break; case '?': { std::cout << "Unknown option!" << std::endl; help(); exit(1); } break; } } /* Check obligatory arguments. */ if (heightmap_name == NULL) { std::cout << "Input height map wasn't specified!" << std::endl; help(); exit(1); } /* Load heightmap. */ int height = 0; // SoTerrain only seems to handle size which // are multiples of 1024. The +1 maybe due // to some sloppiness some later in the code // (i.e. "<" vs "<=" or something). int width = edgeSize +1; // 1024 + 1;// 1024 * 4 + 1; height = width; PR_INIT_PROFILER(); /* Set environment variables. */ //putenv("IV_SEPARATOR_MAX_CACHES=0"); putenv((char*)"COIN_SHOW_FPS_COUNTER=1"); //putenv("COIN_AUTO_CACHING=0"); /* Create window. */ QWidget * window; if ((window = SoQt::init(argc, argv, "SoTerrain Test Application")) == NULL) { exit(1); } /* Initialization of custom Inventor classes. */ SoSimpleROAMTerrain::initClass(); SoSimpleGeoMipmapTerrain::initClass(); SoSimpleChunkedLoDTerrain::initClass(); SoProfileGroup::initClass(); /* Create scene graph. */ SoProfileGroup *root = new SoProfileGroup(); SoEventCallback *style_callback = new SoEventCallback(); SoPerspectiveCamera *camera = new SoPerspectiveCamera(); SoDrawStyle *style = new SoDrawStyle(); SoDirectionalLight *light = new SoDirectionalLight(); SoSeparator *separator = new SoSeparator(); SoSeparator *terrainSeparator = new SoSeparator(); SoSeparator *markers = new SoSeparator(); // not sure turning off Culling here is having any effect. terrainSeparator->pickCulling.setValue(SoSeparator::OFF); terrainSeparator->renderCulling.setValue(SoSeparator::OFF); SoEventCallback *terrain_callback = new SoEventCallback(); /* Use the TerrainBuilder class to generating the various components. */ TerrainBuilder terrainBuilder; terrainBuilder.setHeight(height); terrainBuilder.setWidth(width); terrainBuilder.initialize(); terrainBuilder.setScalingFactor(scaleFactor); terrainBuilder.setYOffset(yOffset); terrainBuilder.setXOffset(xOffset); terrainBuilder.loadXYZFile(heightmap_name, 4801 * 4801); SoTexture2 *texture = terrainBuilder.getTexture(); SoTextureCoordinate2 *texture_coords = terrainBuilder.getTextureCoordinates(); SoCoordinate3 *coords = terrainBuilder.getMapCoordinates(); SoNormal *normals = terrainBuilder.getNormals(); SoNormalBinding *normal_binding = new SoNormalBinding(); ref_long = terrainBuilder.getRefLong(); ref_lat = terrainBuilder.getRefLat(); style_callback->addEventCallback(SoKeyboardEvent::getClassTypeId(), styleCallback, style); light->direction.setValue(-0.5f, 0.5f, -1.0f); normal_binding->value.setValue(SoNormalBinding::PER_VERTEX_INDEXED); // Create the push pin marker. marker_lat = 37.753; marker_long = -122.440; SoResetTransform *resetForTerrain = new SoResetTransform(); MarkerPin *marker = new MarkerPin(); marker->setScalingFactor(scaleFactor); marker->setReferencePosition(ref_lat, ref_long); marker->setLabel("San Francisco"); marker->setLocation(marker_lat, marker_long, 0.0); SoEventCallback * marker_callback = new SoEventCallback(); marker_callback->addEventCallback( SoKeyboardEvent::getClassTypeId(), markerCallback, marker); vesselMarker = new MarkerPin(); vesselMarker->setScalingFactor(scaleFactor); vesselMarker->setReferencePosition(ref_lat, ref_long); vesselMarker->setLabel("Farralon"); vesselMarker->setLocation(37.7, -123.0, 0.0); /* Connect scene graph nodes. */ root->ref(); root->addChild(style); root->addChild(separator); separator->addChild(terrain_callback); separator->addChild(style_callback); separator->addChild(marker_callback); separator->addChild(camera); separator->addChild(light); separator->addChild(terrainSeparator); terrainSeparator->addChild(resetForTerrain); terrainSeparator->addChild(texture); terrainSeparator->addChild(texture_coords); terrainSeparator->addChild(coords); terrainSeparator->addChild(normals); terrainSeparator->addChild(normal_binding); separator->addChild(markers); separator->addChild(marker->getSoMarker()); separator->addChild(vesselMarker->getSoMarker()); // Water drawing has performance issues. if (drawWater) { separator->addChild(terrainBuilder.getWater()); } switch (algorithm) { case ID_ALG_ROAM: { SoSimpleROAMTerrain * terrain = new SoSimpleROAMTerrain(); terrain->mapSize.setValue(width); terrain->pixelError.setValue(pixel_error); terrain->triangleCount.setValue(triangle_count); terrain->frustrumCulling.setValue(is_frustrum_culling); terrain_callback->addEventCallback(SoKeyboardEvent::getClassTypeId(), terrainCallback, terrain); terrainSeparator->addChild(terrain); } break; case ID_ALG_GEO_MIPMAP: { SoSimpleGeoMipmapTerrain * terrain = new SoSimpleGeoMipmapTerrain(); terrain->mapSize.setValue(width); terrain->tileSize.setValue(tile_size); terrain->pixelError.setValue(pixel_error); terrain_callback->addEventCallback(SoKeyboardEvent::getClassTypeId(), terrainCallback, terrain); terrainSeparator->addChild(terrain); } break; case ID_ALG_CHUNKED_LOD: { SoSimpleChunkedLoDTerrain * terrain = new SoSimpleChunkedLoDTerrain(); terrain->mapSize.setValue(width); terrain->tileSize.setValue(tile_size); terrain->pixelError.setValue(pixel_error); terrain_callback->addEventCallback(SoKeyboardEvent::getClassTypeId(), terrainCallback, terrain); terrainSeparator->addChild(terrain); } break; case ID_ALG_BRUAL_FORCE: { SoIndexedTriangleStripSet * terrain = new SoIndexedTriangleStripSet(); /* Create terrain heightmap vertices indices. */ terrain->coordIndex.setNum((height - 1) * ((2 * width) + 1)); int * indices = terrain->coordIndex.startEditing(); int I = 0; for (int Y = 0; Y < (height - 1); Y++) { for (int X = 0; X < width; X++) { indices[I++] = (Y * width) + X; indices[I++] = ((Y + 1) * width) + X; } indices[I++] = -1; } terrain->coordIndex.finishEditing(); terrainSeparator->addChild(terrain); } break; } // terrainSeparator->addChild(terrainBuilder.getWater()); /* Setup camera and render area. */ SoQtFreeViewer * render_area = new SoQtFreeViewer(window); SoSceneManager * scene_manager = new SoSceneManager(); render_area->setHeadlight(TRUE /*FALSE*/); render_area->setSceneManager(scene_manager); scene_manager->setRenderCallback(renderCallback, render_area); scene_manager->activate(); camera->viewAll(root, render_area->getViewportRegion()); camera->nearDistance.setValue(0.01f); render_area->setSceneGraph(root); render_area->setTitle("Terrain Viewer Application"); render_area->setSize(SbVec2s(640, 480)); render_area->show(); render_area->setFullScreen(is_full_screen); camera->position.setValue(0 , 0, 1); // Use a SoIdleSensor to update marker position, this is because // we can't add new markers when the tree is still being traversed // (only when idle). SoIdleSensor * positionUpdater = new SoIdleSensor(); positionUpdater->setFunction(updatePositionCallback); positionUpdater->setData(markers); // Use a SoTimeSensor to periodically schedule // the SoIdleSensor to update marker positions. SoTimerSensor * timerSensor = new SoTimerSensor(timerSensorCallback, root); timerSensor->setInterval(0.2f); timerSensor->setData(positionUpdater); timerSensor->schedule(); /* Run application. */ SoQt::show(window); SoQt::mainLoop(); SoQt::done(); // PR_PRINT_RESULTS(profile_name); /* Free memory. */ root->unref(); delete positionUpdater; delete render_area; return EXIT_SUCCESS; }