int main (int argc, char* argv[]) { osg::ArgumentParser arguments(&argc, argv); osgViewer::Viewer viewer(arguments); osgGA::TrackballManipulator* manipulator = new osgGA::TrackballManipulator(); viewer.setCameraManipulator(manipulator); osg::Group* root = new osg::Group; root->setInitialBound(osg::BoundingSphere(osg::Vec3(10,0,10), 30)); root->addChild(createAxis()); osg::MatrixTransform* node = setupAnimtkNode(); node->addChild(createAxis()); root->addChild(node); viewer.setSceneData( root ); viewer.realize(); while (!viewer.done()) { viewer.frame(); } }
osg::Node* createModel() { // create the root node which will hold the model. osg::Group *root = new osg::Group(); // add the drawable into a single geode to be shared... osg::Billboard *center = new osg::Billboard(); center->setMode(osg::Billboard::POINT_ROT_EYE); center->addDrawable( createSquare(osg::Vec3(-0.5f, 0.0f, -0.5f), osg::Vec3(1.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 0.0f, 1.0f), osgDB::readImageFile("Images/reflect.rgb")), osg::Vec3(0.0f, 0.0f, 0.0f)); osg::Billboard *x_arrow = new osg::Billboard(); x_arrow->setMode(osg::Billboard::AXIAL_ROT); x_arrow->setAxis(osg::Vec3(1.0f, 0.0f, 0.0f)); x_arrow->setNormal(osg::Vec3(0.0f, -1.0f, 0.0f)); x_arrow->addDrawable( createSquare(osg::Vec3(-0.5f, 0.0f, -0.5f), osg::Vec3(1.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 0.0f, 1.0f), osgDB::readImageFile("Cubemap_axis/posx.png")), osg::Vec3(5.0f, 0.0f, 0.0f)); osg::Billboard *y_arrow = new osg::Billboard(); y_arrow->setMode(osg::Billboard::AXIAL_ROT); y_arrow->setAxis(osg::Vec3(0.0f, 1.0f, 0.0f)); y_arrow->setNormal(osg::Vec3(1.0f, 0.0f, 0.0f)); y_arrow->addDrawable( createSquare(osg::Vec3(0.0f, -0.5f, -0.5f), osg::Vec3(0.0f, 1.0f, 0.0f), osg::Vec3(0.0f, 0.0f, 1.0f), osgDB::readImageFile("Cubemap_axis/posy.png")), osg::Vec3(0.0f, 5.0f, 0.0f)); osg::Billboard *z_arrow = new osg::Billboard(); z_arrow->setMode(osg::Billboard::AXIAL_ROT); z_arrow->setAxis(osg::Vec3(0.0f, 0.0f, 1.0f)); z_arrow->setNormal(osg::Vec3(0.0f, -1.0f, 0.0f)); z_arrow->addDrawable( createSquare(osg::Vec3(-0.5f, 0.0f, -0.5f), osg::Vec3(1.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 0.0f, 1.0f), osgDB::readImageFile("Cubemap_axis/posz.png")), osg::Vec3(0.0f, 0.0f, 5.0f)); osg::Geode *axis = new osg::Geode(); axis->addDrawable(createAxis(osg::Vec3(0.0f, 0.0f, 0.0f), osg::Vec3(5.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 5.0f, 0.0f), osg::Vec3(0.0f, 0.0f, 5.0f))); root->addChild(center); root->addChild(x_arrow); root->addChild(y_arrow); root->addChild(z_arrow); root->addChild(axis); return root; }
SpecialMatrix::MatrixViewer::MatrixViewer( Data::Graph* matrixGraph, QString fileName ) { this->matrixGraph = matrixGraph; this->connections = new SpecialMatrix::NodeConnections(); fileParser = new SpecialMatrix::FileParser( fileName, matrixGraph, connections ); createAxis(); connections->setNodePositionsArrayField( 0, 0, true ); adjustPositions(); //printout nodePositionsArray /*for(size_t i=0; i<connections->getNodePositionsArray().size(); i++) { for(size_t j=0; j<connections->getNodePositionsArray().size(); j++) { if(connections->getNodePositionsArrayField(i, j)) printf("1"); else printf("0"); } printf("\n"); }*/ //printout connectedNodes /*QMapIterator<qlonglong, QList<qlonglong>* > i(*connections->getConnectedNodes()); while ( i.hasNext() ) { i.next(); QList<qlonglong>* list = i.value(); qDebug() << i.key() << "size: " << list->size() << " list has these connected nodes: "; for(int j=0; j<list->size(); j++) { qDebug() << list->at(j); } }*/ }
void apply(osg::Transform& node) { osgAnimation::Bone* bone = dynamic_cast<osgAnimation::Bone*>(&node); if (bone) bone->addChild(createAxis()); traverse(node); }
int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is an example for viewing osgAnimation animations."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","List command line options."); arguments.getApplicationUsage()->addCommandLineOption("--drawbone","draw helps to display bones."); if (arguments.read("-h") || arguments.read("--help")) { arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); return 0; } if (arguments.argc()<=1) { arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); return 1; } bool drawBone = false; if (arguments.read("--drawbone")) drawBone = true; osgViewer::Viewer viewer(arguments); osg::ref_ptr<osg::Group> group = new osg::Group(); osg::Group* node = dynamic_cast<osg::Group*>(osgDB::readNodeFiles(arguments)); //dynamic_cast<osgAnimation::AnimationManager*>(osgDB::readNodeFile(psr[1])); if(!node) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; } // Set our Singleton's model. AnimationManagerFinder finder; node->accept(finder); if (finder._am.valid()) { std::string playModeOpt; if (arguments.read("--play-mode", playModeOpt)) { osgAnimation::Animation::PlayMode playMode = osgAnimation::Animation::LOOP; if (osgDB::equalCaseInsensitive(playModeOpt, "ONCE")) playMode = osgAnimation::Animation::ONCE; else if (osgDB::equalCaseInsensitive(playModeOpt, "STAY")) playMode = osgAnimation::Animation::STAY; else if (osgDB::equalCaseInsensitive(playModeOpt, "LOOP")) playMode = osgAnimation::Animation::LOOP; else if (osgDB::equalCaseInsensitive(playModeOpt, "PPONG")) playMode = osgAnimation::Animation::PPONG; for (osgAnimation::AnimationList::const_iterator animIter = finder._am->getAnimationList().begin(); animIter != finder._am->getAnimationList().end(); ++animIter) { (*animIter)->setPlayMode(playMode); } } node->setUpdateCallback(finder._am.get()); AnimtkViewerModelController::setModel(finder._am.get()); } else { osg::notify(osg::WARN) << "no osgAnimation::AnimationManagerBase found in the subgraph, no animations available" << std::endl; } if (drawBone) { osg::notify(osg::INFO) << "Add Bones Helper" << std::endl; AddHelperBone addHelper; node->accept(addHelper); } node->addChild(createAxis()); AnimtkViewerGUI* gui = new AnimtkViewerGUI(&viewer, WIDTH, HEIGHT, 0x1234); osg::Camera* camera = gui->createParentOrthoCamera(); node->setNodeMask(0x0001); group->addChild(node); group->addChild(camera); viewer.addEventHandler(new AnimtkKeyEventHandler()); viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); viewer.addEventHandler(new osgWidget::MouseHandler(gui)); viewer.addEventHandler(new osgWidget::KeyboardHandler(gui)); viewer.addEventHandler(new osgWidget::ResizeHandler(gui, camera)); viewer.setSceneData(group.get()); viewer.setUpViewInWindow(40, 40, WIDTH, HEIGHT); return viewer.run(); }
int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is an example for viewing osgAnimation animations."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","List command line options."); arguments.getApplicationUsage()->addCommandLineOption("--drawbone","draw helps to display bones."); if (arguments.read("-h") || arguments.read("--help")) { arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); return 0; } //if (arguments.argc()<=1) //{ // arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); // return 1; //} bool drawBone = true; if (arguments.read("--drawbone")) drawBone = true; osgViewer::Viewer viewer(arguments); osg::ref_ptr<osg::Group> group = new osg::Group(); osg::Group* node = dynamic_cast<osg::Group*>(osgDB::readNodeFile("C:/Matej/test_1.osg")); //dynamic_cast<osg::Group*>(osgDB::readNodeFiles(arguments)); //dynamic_cast<osgAnimation::AnimationManager*>(osgDB::readNodeFile(psr[1])); if(!node) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; } cutSimulation(node); // Set our Singleton's model. AnimationManagerFinder finder; node->accept(finder); if (finder._am.valid()) { node->setUpdateCallback(finder._am.get()); AnimtkViewerModelController::setModel(finder._am.get()); osgAnimation::BasicAnimationManager* model = finder._am.get(); const osgAnimation::AnimationList & lstAnimation = model->getAnimationList(); const osg::ref_ptr<osgAnimation::Animation> & canim = *(lstAnimation.begin()); osg::ref_ptr<osgAnimation::Animation> & anim = const_cast<osg::ref_ptr<osgAnimation::Animation> &>(canim); } else { osg::notify(osg::WARN) << "no osgAnimation::AnimationManagerBase found in the subgraph, no animations available" << std::endl; } if (drawBone) { osg::notify(osg::INFO) << "Add Bones Helper" << std::endl; AddHelperBone addHelper; node->accept(addHelper); } node->addChild(createAxis()); AnimtkViewerGUI* gui = new AnimtkViewerGUI(&viewer, WIDTH, HEIGHT, 0x1234); osg::Camera* camera = gui->createParentOrthoCamera(); node->setNodeMask(0x0001); group->addChild(node); group->addChild(camera); viewer.addEventHandler(new AnimtkKeyEventHandler()); viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); viewer.addEventHandler(new osgWidget::MouseHandler(gui)); viewer.addEventHandler(new osgWidget::KeyboardHandler(gui)); viewer.addEventHandler(new osgWidget::ResizeHandler(gui, camera)); //viewer.setSceneData(group.get()); viewer.setUpViewInWindow(40, 40, WIDTH, HEIGHT); // Create the root node Group. osg::ref_ptr<osg::Group> root = new osg::Group; // Read the object //osg::ref_ptr<osg::Node> cow = osgDB::readNodeFile( "D:/Programs64/OSG/Data/OpenSceneGraph-Data-3.0.0/cow.osg" ); // Define a matrix transform osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform; // Set scene graph mt->addChild(group); root->addChild(mt); // Create animation path osg::ref_ptr<osg::AnimationPath> path = new osg::AnimationPath; // Define control points osg::AnimationPath::ControlPoint CP0(osg::Vec3( 0.f, 5.f, 0.f )); osg::AnimationPath::ControlPoint CP1(osg::Vec3( -2.5f, -2.5f, 0.f ),osg::Quat(-osg::PI/4,osg::Vec3( 0.f, 0.f, 1.f )) ); //osg::AnimationPath::ControlPoint CP2 (osg::Vec3( -2.f, -1.f, 0.f ),osg::Quat(-osg::PI*2/6,osg::Vec3( 0.f, 0.f, 1.f )),osg::Vec3( 0.5f, 0.5f, 0.5f )); //osg::AnimationPath::ControlPoint CP3 (osg::Vec3( 2.f, -1.f, 0.f ),osg::Quat(-osg::PI*3/6,osg::Vec3( 0.f, 0.f, 1.f ))); //osg::AnimationPath::ControlPoint CP4 (osg::Vec3( 2.f, 1.f, 0.f )); // Insert them to the path path->insert( 0.0f, CP0 ); // time, point path->insert( 1.0f, CP1 ); //path->insert( 2.0f, CP2 ); //path->insert( 3.0f, CP3 ); //path->insert( 4.0f, CP4 ); //path->setLoopMode(osg::AnimationPath::LoopMode::SWING); // Define animation path callback osg::ref_ptr<osg::AnimationPathCallback> APCallback = new osg::AnimationPathCallback(path.get() ); // Update the matrix transform mt->setUpdateCallback( APCallback.get() ); viewer.setSceneData(root.get()); return viewer.run(); }
MInput::MInput(void) { // ASCII keys char name[2] = {0, 0}; for(int i=65; i<=90; i++) { name[0] = i; createKey(name); } // create touch data for(int i=0; i<10; i++) { m_touches[i] = TouchData(); } // keyboard keys createKey("BACKSPACE"); createKey("TAB"); createKey("ESCAPE"); createKey("SPACE"); createKey("DELETE"); createKey("0"); createKey("1"); createKey("2"); createKey("3"); createKey("4"); createKey("5"); createKey("6"); createKey("7"); createKey("8"); createKey("9"); createKey("ENTER"); createKey("UP"); createKey("DOWN"); createKey("LEFT"); createKey("RIGHT"); createKey("F1"); createKey("F2"); createKey("F3"); createKey("F4"); createKey("F5"); createKey("F6"); createKey("F7"); createKey("F8"); createKey("F9"); createKey("F10"); createKey("F11"); createKey("F12"); createKey("RSHIFT"); createKey("LSHIFT"); createKey("RCONTROL"); createKey("LCONTROL"); createKey("RALT"); createKey("LALT"); // mouse keys createKey("MOUSE_BUTTON1"); createKey("MOUSE_BUTTON2"); createKey("MOUSE_BUTTON3"); // joystick keys createKey("JOY1_BUTTON1"); createKey("JOY1_BUTTON2"); createKey("JOY1_BUTTON3"); createKey("JOY1_BUTTON4"); createKey("JOY1_BUTTON5"); createKey("JOY1_BUTTON6"); createKey("JOY1_BUTTON7"); createKey("JOY1_BUTTON8"); createKey("JOY2_BUTTON1"); createKey("JOY2_BUTTON2"); createKey("JOY2_BUTTON3"); createKey("JOY2_BUTTON4"); createKey("JOY2_BUTTON5"); createKey("JOY2_BUTTON6"); createKey("JOY2_BUTTON7"); createKey("JOY2_BUTTON8"); // axis createAxis("MOUSE_X"); createAxis("MOUSE_Y"); createAxis("MOUSE_WHEEL", 1); createAxis("JOY1_X"); createAxis("JOY1_Y"); createAxis("JOY1_Z"); createAxis("JOY1_R"); createAxis("JOY1_U"); createAxis("JOY1_V"); createAxis("JOY2_X"); createAxis("JOY2_Y"); createAxis("JOY2_Z"); createAxis("JOY2_R"); createAxis("JOY2_U"); createAxis("JOY2_V"); }
void Objdrawaxis (char dir , char tics , double* x , int * nx , double* y , int * ny , char * val[] , int subint , char * format , int font , int textcol, int ticscol, char flag , int seg , int nb_tics_labels) { int iObjUID = 0; int iSubwinUID = 0; int ticksDirection = 0; int ticksStyle = 0; iSubwinUID = getCurrentSubWin(); checkRedrawing(); switch (dir) { default : case 'u' : ticksDirection = 0; break; case 'd' : ticksDirection = 1; break; case 'l' : ticksDirection = 2; break; case 'r' : ticksDirection = 3; break; } switch (tics) { default: case 'v': ticksStyle = 0; break; case 'r': ticksStyle = 1; break; case 'i': ticksStyle = 2; break; } iObjUID = createAxis(iSubwinUID, ticksDirection, ticksStyle, x, *nx, y, *ny, subint, format, font, textcol, ticscol, seg); if (iObjUID == NULL) { Scierror(999, _("%s: No more memory.\n"), "Objdrawaxis"); return; } if (val == NULL) { char **matData; StringMatrix *tics_labels; tics_labels = computeDefaultTicsLabels(iObjUID); if (tics_labels == NULL) { deleteGraphicObject(iObjUID); return; } matData = getStrMatData(tics_labels); /* * The labels vector size must be computed using the matrix's dimensions. * To be modified when the labels computation is moved to the Model. */ setGraphicObjectProperty(iObjUID, __GO_TICKS_LABELS__, matData, jni_string_vector, tics_labels->nbCol * tics_labels->nbRow); deleteMatrix(tics_labels); } else { int i = 0; /* * Labels are set using the str argument; the previous code tested whether each element of the * str array was null and set the corresponding Axis' element to NULL, though there was no * apparent reason to do so. This is still checked, but now aborts building the Axis. */ if (nb_tics_labels == -1) { Scierror(999, _("Impossible case when building axis\n")); deleteGraphicObject(iObjUID); return; } for (i = 0; i < nb_tics_labels; i++) { if (val[i] == NULL) { deleteGraphicObject(iObjUID); return; } } setGraphicObjectProperty(iObjUID, __GO_TICKS_LABELS__, val, jni_string_vector, nb_tics_labels); } setCurrentObject(iObjUID); }