void display(void) { #if 0 Matrix m1, m2, m3; Quaternion q1; tball.getRotation().getValue(m3); q1.setValue(m3); m1.setRotate(q1); m2.setTranslate( tball.getPosition() ); m1.mult( m2 ); if(move_obj == true) { scene_trans->editSFMatrix()->setValue( m1 ); } else { cam_trans->editSFMatrix()->setValue( m1 ); } #endif cam_trans->editSFMatrix()->setValue(tball.getFullTrackballMatrix()); #if 0 fprintf(stderr, "%f %f %f\n", cam_trans->getMatrix()[3][0], cam_trans->getMatrix()[3][1], cam_trans->getMatrix()[3][2]); #endif OSG::Real32 t = glutGet(GLUT_ELAPSED_TIME); for(OSG::UInt32 i = 0; i < 6; ++i) { if(pAnimTrs[i] != NULL) { pAnimTrs[i]->editRotation().setValueAsAxisDeg( 0.f, 1.f, 0.f, t / 50.f); } } OSG::commitChanges(); // fprintf(stderr, "Frame start\n"); // fprintf(stderr, "============================================\n"); win->render(rentravact); }
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(); }