void display(void) { Matrix m1, m2, m3; Quaternion q1; tball.getRotation().getValue(m3); q1.setValue(m3); m1.setRotate(q1); // std::cout << "TBROT" << std::endl << tball.getRotation() << std::endl; // std::cout << "M3" << std::endl << m3 << std::endl; // std::cout << "Q1" << std::endl << q1 << std::endl; // std::cout << "M1" << std::endl << m1 << std::endl; // m1.setRotate( tball.getRotation() ); m2.setTranslate( tball.getPosition() ); //std::cout << "Pos: " << tball.getPosition() << ", Rot: " << tball.getRotation() << std::endl; // std::cout << tball.getRotation() << std::endl; m1.mult( m2 ); cam_trans->editSFMatrix()->setValue( m1 ); win->draw( ract ); }
void display(void) { Matrix m1, m2; m1.setRotate( tball.getRotation() ); m2.setTranslate( tball.getPosition() ); m1.mult( m2 ); cam_trans->editSFMatrix()->setValue( m1 ); // move the object float t = glutGet(GLUT_ELAPSED_TIME); Quaternion q; q.setValueAsAxisDeg(0, 1, 0, t / 5000); m1.setTransform(Vec3f(osgsin(t / 500.), 0, osgcos(t / 500)), q); tr->setMatrix(m1); if ( doRender ) win->render( ract ); else win->draw( dact ); }
void display(void) { Matrix m1, m2, m3; Quaternion q1; tball.getRotation().getValue(m3); q1.setValue(m3); m1.setRotate(q1); m2.setTranslate( tball.getPosition() ); m1.mult( m2 ); cam_trans->editSFMatrix()->setValue( m1 ); window->draw( drAct ); }
void display(void) { Matrix m1, m2, m3; m1=trackball.getMatrix(); // m1.transpose(); // m2.setTranslate(0,0,8); // m1.mult(m2); cam_trans->editSFMatrix()->setValue( m1 ); win->draw( ract ); }
void display(void) { Matrix m1, m2; m1.setRotate(tball.getRotation()); m2.setTranslate(tball.getPosition()); m1.mult(m2); cam_trans->editSFMatrix()->setValue(m1); if(doRender) win->render(ract); else win->draw(dact); }
int main(int argc, char** argv) { std::cout << "osgInit()..." << std::endl; osgInit( argc, argv ); std::cout << "glutInit()..." << std::endl; glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); int winID = glutCreateWindow("OpenSG"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(resize); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glClearColor( .3, .3, .8, 1 ); std::cout << "Creating objects..." << std::endl; //BEACON NodePtr beaconNode = Node::create(); GroupPtr beaconCore = Group::create(); beginEditCP( beaconNode ); beaconNode->setCore( beaconCore ); endEditCP( beaconNode ); /* //LIGHT NodePtr dlightNode = Node::create(); DirectionalLightPtr dlightCore = DirectionalLight::create(); beginEditCP(dlightNode); dlightNode->setCore(dlightCore); endEditCP(dlightNode); beginEditCP(dlightCore); dlightCore->setAmbient( .3, .3, .3, 1 ); dlightCore->setDiffuse( .5, .5, .5, 1 ); dlightCore->setDirection( 0, 0 , 1 ); dlightCore->setBeacon( beaconNode ); endEditCP(dlightCore); */ //TRANSFORM NodePtr transNode = Node::create(); TransformPtr transCore = Transform::create(); beginEditCP( transNode ); transNode->setCore( transCore ); transNode->addChild( beaconNode ); endEditCP( transNode ); cam_trans = transCore; //LOD NodePtr lowDetailNode = makeBox( 1,1,1, 1,1,1 ); GeometryPtr boxCore = GeometryPtr::dcast(lowDetailNode->getCore()); SimpleMaterialPtr lowDetailMat = SimpleMaterial::create(); lowDetailMat->setDiffuse( Color3f( 1,0,0 ) ); lowDetailMat->setAmbient( Color3f( 1,0,0 ) ); boxCore->setMaterial( lowDetailMat ); NodePtr medDetailNode = makeSphere( 1, 1 ); GeometryPtr medSphereCore = GeometryPtr::dcast(medDetailNode->getCore()); SimpleMaterialPtr medDetailMat = SimpleMaterial::create(); medDetailMat->setDiffuse( Color3f( 0,1,0 ) ); medDetailMat->setAmbient( Color3f( 0,1,0 ) ); medSphereCore->setMaterial( medDetailMat ); NodePtr highDetailNode = makeSphere( 2, 1 ); GeometryPtr highSphereCore = GeometryPtr::dcast(highDetailNode->getCore()); SimpleMaterialPtr highDetailMat = SimpleMaterial::create(); highDetailMat->setDiffuse( Color3f( 0,0,1 ) ); highDetailMat->setAmbient( Color3f( 0,0,1 ) ); highDetailMat->setSpecular( Color3f(1, 1, 1) ); highDetailMat->setShininess( 10 ); highSphereCore->setMaterial( highDetailMat ); NodePtr lodNode = Node::create(); DistanceLODPtr lodNodeCore = DistanceLOD::create(); beginEditCP(lodNode); lodNode->setCore(lodNodeCore); lodNode->addChild( highDetailNode ); lodNode->addChild( medDetailNode ); lodNode->addChild( lowDetailNode ); endEditCP(lodNode); beginEditCP(lodNodeCore); lodNodeCore->editSFCenter()->setValue( Pnt3f(0, 0, 2) ); lodNodeCore->editMFRange()->push_back( 4.0 ); lodNodeCore->editMFRange()->push_back( 8.0 ); lodNodeCore->editMFRange()->push_back( 11.0 ); endEditCP(lodNodeCore); //TRANSFORM LOD NodePtr transLODNode = Node::create(); TransformPtr transLODCore = Transform::create(); transMat.setTranslate( 1, -1, -1 ); beginEditCP(transLODCore); transLODCore->editSFMatrix()->setValue( transMat ); endEditCP(transLODCore); beginEditCP( transLODNode ); transLODNode->setCore( transLODCore ); transLODNode->addChild( lodNode ); endEditCP( transLODNode ); //ROOT root = Node::create(); GroupPtr rootCore = Group::create(); beginEditCP(root); root->setCore(rootCore); root->addChild(transNode); root->addChild(transLODNode); endEditCP(root); camera = PerspectiveCamera::create(); beginEditCP(camera); camera->setBeacon( beaconNode ); camera->setFov( deg2rad(90) ); camera->setNear( 0.1 ); camera->setFar( 10000 ); endEditCP(camera); SolidBackgroundPtr background = SolidBackground::create(); viewp = Viewport::create(); beginEditCP(viewp); viewp->setCamera( camera ); viewp->setBackground( background ); viewp->setRoot( root ); viewp->setSize( 0,0, 1,1 ); endEditCP(viewp); GLint glVP[4]; glGetIntegerv( GL_VIEWPORT, glVP ); GLUTWindowPtr gwin = GLUTWindow::create(); gwin->setId(winID); gwin->setSize(glVP[2], glVP[3]); window = gwin; beginEditCP(window); window->addPort( viewp ); window->init(); endEditCP(window); drAct = DrawAction::create(); Vec3f pos( 0, 0, 3 ); tball.setMode( Trackball::OSGObject ); tball.setStartPosition( pos, true ); tball.setSum( true ); tball.setTranslationMode( Trackball::OSGFree ); glutMainLoop(); return 0; }