void key(unsigned char key, int x, int y) { switch ( key ) { case 27: win = NULL; cam_trans = NULL; pPoly = NULL; pCOver = NULL; pAlgo = NULL; rentravact = NULL; OSG::osgExit(); exit(0); case 'v': rentravact->setVolumeDrawing(!rentravact->getVolumeDrawing()); break; case 'z': pPoly->setFrontMode(GL_POINT); pPoly->setBackMode(GL_POINT); std::cerr << "PolygonMode: Point." << std::endl; break; case 'x': pPoly->setFrontMode(GL_LINE); pPoly->setBackMode(GL_LINE); std::cerr << "PolygonMode: Line." << std::endl; break; case 'c': pPoly->setFrontMode(GL_FILL); pPoly->setBackMode(GL_FILL); std::cerr << "PolygonMode: Fill." << std::endl; break; case 'p': { if(bPolyActive == true) { OSG_ASSERT(pCOver->subChunk(pPoly) == true); bPolyActive = false; } else { OSG_ASSERT(pCOver->addChunk(pPoly) == true); bPolyActive = true; } break; } case 'w': pAlgo->setStepsize(pAlgo->getStepsize() + (1.0/2048.0)); if(pAlgo->getStepsize() > 0.25) pAlgo->setStepsize(0.25); break; case 'e': pAlgo->setStepsize(pAlgo->getStepsize() - (1.0/2048.0)); if(pAlgo->getStepsize() <= 1.0/200.0) pAlgo->setStepsize(1.0/200.0); break; case 'd': pAlgo->setToggleVisuals(!pAlgo->getToggleVisuals()); break; default: break; } }
void key(unsigned char key, int x, int y) { switch ( key ) { case 27: root = NULL; file = NULL; cam = NULL; vp = NULL; win = NULL; cam_trans = NULL; scene_trans = NULL; pPoly = NULL; pCOver = NULL; gwin = NULL; tx1o = NULL; tx1e = NULL; vpFBO = NULL; vpFBO_RB = NULL; pTexBuffer = NULL; pRenBuffer = NULL; pImg = NULL; delete rentravact; OSG::osgExit(); exit(0); case 'f': vpFBO->setTravMask(~vpFBO->getTravMask()); break; case 'd': oldTravMask = vpFBO->getTravMask(); if(oldTravMask == 0x0000) { vpFBO->setTravMask(~vpFBO->getTravMask()); } dumpImg = true; pTexBuffer ->setReadBack (true); vpFBO->getFrameBufferObject()->setPostProcessOnDeactivate(true); break; case 'r': { // OSG::FieldContainerFactory::the()->dump(); //RenderBuffer Readback // Background OSG::SolidBackgroundUnrecPtr bkgndFBO_RB = OSG::SolidBackground::create(); bkgndFBO_RB->setColor(OSG::Color3f(0.5,1.0,0.5)); // Viewport vpFBO_RB = OSG::FBOViewport::create(); vpFBO_RB->setCamera (cam ); vpFBO_RB->setBackground(bkgndFBO_RB); vpFBO_RB->setRoot (root ); vpFBO_RB->setSize (0, 0, 1, 1 ); OSG::FrameBufferObjectUnrecPtr pFBO_RB = OSG::FrameBufferObject::create(); pRenBuffer = OSG::RenderBuffer::create(); OSG::RenderBufferUnrecPtr pDepthBuffer_RB = OSG::RenderBuffer::create(); pDepthBuffer_RB->setInternalFormat(GL_DEPTH_COMPONENT24 ); pRenBuffer->setInternalFormat(GL_RGBA); OSG::ImageUnrecPtr pImg_RB = OSG::Image::create(); OSG::UInt32 uiImgSize = 4096; pImg_RB->set(OSG::Image::OSG_RGB_PF, uiImgSize, uiImgSize); fprintf(stderr, "Image data : %p\n", pImg_RB->getData()); pRenBuffer->setImage(pImg_RB); pFBO_RB->setSize(uiImgSize, uiImgSize); pFBO_RB->setColorAttachment(pRenBuffer, 0); pFBO_RB->setDepthAttachment(pDepthBuffer_RB ); pFBO_RB->editMFDrawBuffers()->clear(); pFBO_RB->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT); vpFBO_RB->setFrameBufferObject(pFBO_RB); pRenBuffer ->setReadBack (true); vpFBO_RB->getFrameBufferObject()->setPostProcessOnDeactivate(true); win->addPort(vpFBO_RB); dumpImg_RB = true; } break; case 'v': rentravact->setVolumeDrawing(!rentravact->getVolumeDrawing()); break; case 'a': glDisable( GL_LIGHTING ); std::cerr << "Lighting disabled." << std::endl; break; case 's': glEnable( GL_LIGHTING ); std::cerr << "Lighting enabled." << std::endl; break; case 'z': pPoly->setFrontMode(GL_POINT); pPoly->setBackMode(GL_POINT); std::cerr << "PolygonMode: Point." << std::endl; break; case 'x': pPoly->setFrontMode(GL_LINE); pPoly->setBackMode(GL_LINE); std::cerr << "PolygonMode: Line." << std::endl; break; case 'c': pPoly->setFrontMode(GL_FILL); pPoly->setBackMode(GL_FILL); std::cerr << "PolygonMode: Fill." << std::endl; break; case 'p': { if(bPolyActive == true) { OSG_ASSERT(pCOver->subChunk(pPoly) == true); bPolyActive = false; } else { OSG_ASSERT(pCOver->addChunk(pPoly) == true); bPolyActive = true; } break; } case ' ': { OSG::Matrix m; OSG::Quaternion q; OSG::Vec3f v; q = oldq; v = oldv; oldq = tball.getRotation(); oldv = tball.getPosition(); move_obj = ! move_obj; if ( move_obj ) { puts("moving object"); // m = scene_trans->getSFMatrix()->getValue(); tball.setMode( OSG::Trackball::OSGCamera ); } else { puts("moving camera"); // m = cam_trans->getSFMatrix()->getValue(); tball.setMode( OSG::Trackball::OSGObject ); } // q.setValue(m); tball.setStartPosition( v, true ); tball.setStartRotation( q, true ); // std::cout << q << std::endl; // std::cout << v << std::endl; // std::cout << " " << m[3][0] << " " << m[3][1] << " " << m[3][2] << std::endl; } break; } }
void key(unsigned char key, int /*x*/, int /*y*/) { switch ( key ) { case 'l': { loadAnim(); break; } case 'c': { FILE *file=fopen(animName.c_str(),"w"); fclose(file); animOri.clear(); animPos.clear(); frameCount = 0; animTime = 0; break; } case 's': { FILE *file=fopen(animName.c_str(),"a"); OSG::Matrix m=cam_trans->getMatrix(); OSG::Quaternion q(m); OSG::Real32 ax,ay,az,r; animPos.push_back(OSG::Vec3f(m[3][0], m[3][1], m[3][2])); animOri.push_back(q); q.getValueAsAxisRad(ax,ay,az,r); fprintf(file,"%f %f %f %f,%f %f %f\n",ax,ay,az,r, m[3][0], m[3][1], m[3][2]); fclose(file); frameCount = 0; animTime = 0; break; } case 'S': { FILE *file=fopen((animName+".wrl").c_str(),"w"); std::vector<OSG::Quaternion>::iterator qit; fprintf(file,"DEF OriInter OrientationInterpolator {\n\tkey ["); for(size_t i = 0; i < animOri.size(); ++i) { fprintf(file, "%f", i / OSG::Real32(animOri.size() - 1) ); if(i < animOri.size() - 1) fprintf(file,", "); } fprintf(file,"]\n\tkeyValue ["); for(qit = animOri.begin(); qit != animOri.end(); ++qit) { OSG::Real32 ax,ay,az,r; (*qit).getValueAsAxisRad(ax,ay,az,r); fprintf(file, "%f %f %f %f", ax, ay, az, r ); if(qit < animOri.end() - 1) fprintf(file,", "); } fprintf(file,"]\n}\n\n"); std::vector<OSG::Vec3f>::iterator vit; fprintf(file,"DEF PosInter PositionInterpolator {\n\tkey ["); for(size_t i = 0; i < animPos.size(); ++i) { fprintf(file, "%f", i / OSG::Real32(animPos.size() - 1) ); if(i < animPos.size() - 1) fprintf(file,", "); } fprintf(file,"]\n\tkeyValue ["); for(vit = animPos.begin(); vit != animPos.end(); ++vit) { OSG::Vec3f v = *vit; fprintf(file, "%f %f %f, ", v[0], v[1], v[2] ); } fprintf(file,"]\n}\n\n"); fclose(file); break; } case 'j': if(sortfirst!=NULL) { sortfirst->setCompression("JPEG"); } break; case 'r': if(sortfirst!=NULL) { sortfirst->setCompression("RLE"); } break; case 'n': if(sortfirst!=NULL) { sortfirst->editCompression().erase(); } break; case 'i': showInfo = !showInfo; break; case 'w': if(polygonChunk->getFrontMode() == GL_FILL) polygonChunk->setFrontMode(GL_LINE); else polygonChunk->setFrontMode(GL_FILL); if(polygonChunk->getBackMode() == GL_FILL) polygonChunk->setBackMode(GL_LINE); else polygonChunk->setBackMode(GL_FILL); break; case 'a': if(animate) { glutIdleFunc(NULL); animate=false; } else { glutIdleFunc(display); animate=true; } frameCount = 0; animTime = 0; break; case 'd': // remove tree while(root->getNChildren()) { root->subChild(0u); } break; case '+': _dsFactor += 0.01f; if(_dsFactor > 1.0f) _dsFactor = 1.0f; setHEyeWallParameter(_dsFactor, _enablecc); break; case '-': _dsFactor -= 0.01f; if(_dsFactor <= 0.0f) _dsFactor = 0.01f; setHEyeWallParameter(_dsFactor, _enablecc); break; case 'f': if(_enablecc) _enablecc = false; else _enablecc = true; setHEyeWallParameter(_dsFactor, _enablecc); break; case 'B': if(bkgnd->getColor()[0] == 0.0) bkgnd->setColor( OSG::Color3f(1,1,1) ); else bkgnd->setColor( OSG::Color3f(0,0,0) ); break; case 27: // should kill the clients here // exit cleanup(); OSG::osgExit(); exit(0); } glutPostRedisplay(); }