//do Animation-Calculations here void Animate() { static OSG::Real64 t0 = OSG::getSystemTime(); OSG::Real64 t = OSG::getSystemTime() - t0; OSG::Real32 rotb = t * 10.0; if(rotb > 360.0) rotb -= 360.0; OSG::Real32 rotc1 = t * 20.0; if(rotc1 > 360.0) rotc1 -= 360.0; OSG::Real32 rotc2 = t * 40.0; if(rotc2 > 360.0) rotc2 -= 360.0; OSG::Quaternion q; q.setValueAsAxisDeg(0,0,1, rotb); globals->box_trans->editMatrix().setRotate(q); q.setValueAsAxisDeg(0,0,1, rotc1); globals->cylinder1_trans->editMatrix().setRotate(q); q.setValueAsAxisDeg(0,0,1, rotc2); globals->cylinder2_trans->editMatrix().setRotate(q); globals->mgr->redraw(); }
void initFloor(void) { OSG::GeometryUnrecPtr floor = OSG::makePlaneGeo(2000.f, 2000.f, 10, 10); OSG::NodeUnrecPtr floorN = OSG::makeNodeFor(floor); OSG::TransformUnrecPtr xform = OSG::Transform::create(); OSG::NodeUnrecPtr xformN = OSG::makeNodeFor(xform); OSG::ImageUnrecPtr img = OSG::ImageFileHandler::the()->read("sand1Tile.png"); OSG::TextureObjChunkUnrecPtr tex = OSG::TextureObjChunk::create(); tex->setImage(img); OSG::ChunkMaterial *chunkMat = dynamic_cast<OSG::ChunkMaterial *>(floor->getMaterial()); if(chunkMat != NULL) { chunkMat->addChunk(tex); } OSG::Quaternion quat; quat.setValueAsAxisDeg(OSG::Vec3f(1.f, 0.f, 0.f), -90.f); xform->editMatrix().setRotate(quat); xformN->addChild(floorN); g->rootN->addChild(xformN); }
OSG::NodeTransitPtr createScene(OSG::Window *win) { OSG::NodeRecPtr rootN = OSG::makeNodeFor(OSG::Group::create()); // Create ground: OSG::NodeUnrecPtr groundN = OSG::makePlane(25,25,1,1); OSG::Matrix m; OSG::Quaternion q; q.setValueAsAxisDeg(OSG::Vec3f(1,0,0), -90); m.setRotate(q); OSG::TransformUnrecPtr groundTransC = OSG::Transform::create(); groundTransC->setMatrix(m); OSG::NodeUnrecPtr groundTransN = OSG::makeNodeFor(groundTransC); groundTransN->addChild(groundN); rootN->addChild(groundTransN); // Set ground material: OSG::SimpleMaterialUnrecPtr mat = OSG::SimpleMaterial::create(); mat->setDiffuse(OSG::Color3f(0.8,0.8,0.8)); dynamic_cast<OSG::Geometry*>(groundN->getCore())->setMaterial(mat); // // Create figure: // OSG::NodeUnrecPtr figure1N = // OSG::SceneFileHandler::the()->read("../Models/Figure.obj"); // G.figure1TransC = OSG::Transform::create(); // OSG::NodeUnrecPtr trans1N = OSG::makeNodeFor(G.figure1TransC); // trans1N->addChild(figure1N); // rootN->addChild(trans1N); OSG::NodeUnrecPtr figureModelA = OSG::SceneFileHandler::the()->read("../assets/Figure.obj"); BoardGame::Figure* figureA = new BoardGame::Figure(); figureA->setModel(figureModelA); rootN->addChild(figureA->getRoot()); OSG::NodeUnrecPtr figureModelB = OSG::SceneFileHandler::the()->read("../assets/Figure.obj"); BoardGame::Figure* figureB = new BoardGame::Figure(); figureB->setModel(figureModelB); rootN->addChild(figureB->getRoot()); G.selectedNode = figureModelA; return(OSG::NodeTransitPtr(rootN)); }