//-------------------------------------------------------------- void ofApp::setup(){ ofBackground(50, 0); bAnimate = false; bAnimateMouse = false; animationPosition = 0; currentModel = 0; model.loadModel("astroBoy_walk.dae", true); model.setPosition(ofGetWidth() * 0.5, (float)ofGetHeight() * 0.75 , 0); model.setLoopStateForAllAnimations(OF_LOOP_NORMAL); model.playAllAnimations(); if(!bAnimate) { model.setPausedForAllAnimations(true); } ofEnableBlendMode(OF_BLENDMODE_ALPHA); ofDisableAlphaBlending(); ofEnableDepthTest(); glShadeModel(GL_SMOOTH); //some model / light stuff light.enable(); ofEnableSeparateSpecularLight(); }
//-------------------------------------------------------------- void testApp::keyPressed(int key){ switch (key) { case '1': model.loadModel("astroBoy_walk.dae"); model.setPosition(ofGetWidth()/2, (float)ofGetHeight() * 0.75 , 0); ofEnableSeparateSpecularLight(); break; case '2': model.loadModel("TurbochiFromXSI.dae"); model.setPosition(ofGetWidth()/2, (float)ofGetHeight() * 0.75 , 0); model.setRotation(0,90,1,0,0); ofEnableSeparateSpecularLight(); break; case '3': model.loadModel("dwarf.x"); model.setPosition(ofGetWidth()/2, (float)ofGetHeight() * 0.75 , 0); ofDisableSeparateSpecularLight(); break; case '4': model.loadModel("monster-animated-character-X.X"); model.setPosition(ofGetWidth()/2, (float)ofGetHeight() * 0.75 , 0); ofDisableSeparateSpecularLight(); break; case '5': model.loadModel("squirrel/NewSquirrel.3ds"); model.setPosition(ofGetWidth()/2, (float)ofGetHeight() * 0.75 , 0); model.setRotation(0,-90,1,0,0); ofDisableSeparateSpecularLight(); break; case ' ': bAnimate = !bAnimate; break; default: break; } /* mesh = model.getMesh(0); position = model.getPosition(); normScale = model.getNormalizedScale(); scale = model.getScale(); sceneCenter = model.getSceneCenter(); material = model.getMaterialForMesh(0); tex = model.getTextureForMesh(0); */ }
//-------------------------------------------------------------- void ofApp::keyPressed(int key){ ofPoint modelPosition(ofGetWidth() * 0.5, (float)ofGetHeight() * 0.75); switch (key) { case '1': model.loadModel("astroBoy_walk.dae"); model.setPosition(modelPosition.x, modelPosition.y, modelPosition.z); ofEnableSeparateSpecularLight(); break; case '2': model.loadModel("TurbochiFromXSI.dae"); model.setPosition(modelPosition.x, modelPosition.y, modelPosition.z); model.setRotation(0, -180, 1, 0, 0); ofEnableSeparateSpecularLight(); break; case '3': model.loadModel("dwarf.x"); model.setPosition(modelPosition.x, modelPosition.y, modelPosition.z); ofDisableSeparateSpecularLight(); break; case '4': model.loadModel("monster-animated-character-X.X"); model.setPosition(modelPosition.x, modelPosition.y, modelPosition.z); model.setRotation(0, -90, 0, 0, 1); ofDisableSeparateSpecularLight(); break; case '5': model.loadModel("squirrel/NewSquirrel.3ds"); model.setPosition(modelPosition.x, modelPosition.y, modelPosition.z); ofDisableSeparateSpecularLight(); break; case ' ': bAnimate = !bAnimate; break; default: break; } mesh = model.getMesh(0); model.setLoopStateForAllAnimations(OF_LOOP_NORMAL); model.playAllAnimations(); if(!bAnimate) { model.setPausedForAllAnimations(true); } }
//-------------------------------------------------------------- void testApp::keyPressed(int key) { switch (key) { case '0': model.loadModel("body.obj"); break; case '1': model.loadModel("koala.obj"); ofEnableSeparateSpecularLight(); model.setRotation(1, 180, 1, 0, 0); break; case '2': model.loadModel("TurbochiFromXSI.dae"); // model.setRotation(0,90,1,0,0); // ofEnableSeparateSpecularLight(); break; case '3': model.loadModel("dwarf.x"); ofDisableSeparateSpecularLight(); break; case '4': model.loadModel("monster-animated-character-X.X"); ofDisableSeparateSpecularLight(); break; case '5': model.loadModel("squirrel/NewSquirrel.3ds"); // model.setRotation(0,-90,1,0,0); ofDisableSeparateSpecularLight(); break; case '6': model.loadModel("astroBoy_walk.dae"); ofEnableSeparateSpecularLight(); model.setRotation(1, 180, 1, 0, 0); model.setPosition(0, -(float)ofGetHeight() * 0.5 , 0); break; case ' ': bAnimate = !bAnimate; break; default: break; } }
//-------------------------------------------------------------- void testApp::setup(){ ofSetLogLevel(OF_LOG_WARNING); //NOTICE ofSetOrientation(OF_ORIENTATION_90_LEFT); //zoom in effect zoom = -500; zoomTarget = 350; zoomSpeed = 0.4; grabber.initGrabber(800, 600); // we need GL_TEXTURE_2D for our models coords. ofDisableArbTex(); if (model.loadModel("astroBoy_walk.dae", true)) { model.setAnimation(0); model.setPosition(ofGetWidth()/2, (float)ofGetHeight() * 0.75 , 0); //model.createLightsFromAiModel(); model.disableTextures(); model.disableMaterials(); /* mesh = model.getMesh(0); position = model.getPosition(); normScale = model.getNormalizedScale(); scale = model.getScale(); sceneCenter = model.getSceneCenter(); material = model.getMaterialForMesh(0); tex = model.getTextureForMesh(0); */ } ofEnableBlendMode(OF_BLENDMODE_ALPHA); glEnable(GL_DEPTH_TEST); //some model / light stuff glShadeModel(GL_SMOOTH); light.setup(); ofEnableSeparateSpecularLight(); bAnimate = false; animationTime = 0.0; tcpConnected = tcp.setup(HOST_IP, PORT, false); //nonblocking if (tcpConnected) tcp.sendRaw("Phew!\n"); drawCamera = false; debugMessage = "Bupkes..."; }
//-------------------------------------------------------------- void ofApp::draw(){ ofSetColor(255); ofEnableBlendMode(OF_BLENDMODE_ALPHA); ofEnableDepthTest(); glShadeModel(GL_SMOOTH); //some model / light stuff light.enable(); ofEnableSeparateSpecularLight(); ofPushMatrix(); ofTranslate(model.getPosition().x+100, model.getPosition().y, 0); ofRotate(-mouseX, 0, 1, 0); ofTranslate(-model.getPosition().x, -model.getPosition().y, 0); model.drawFaces(); ofPopMatrix(); glEnable(GL_NORMALIZE); ofPushMatrix(); ofTranslate(model.getPosition().x-300, model.getPosition().y, 0); ofRotate(-mouseX, 0, 1, 0); ofTranslate(-model.getPosition().x, -model.getPosition().y, 0); ofxAssimpMeshHelper & meshHelper = model.getMeshHelper(0); ofMultMatrix(model.getModelMatrix()); ofMultMatrix(meshHelper.matrix); ofMaterial & material = meshHelper.material; if(meshHelper.hasTexture()){ meshHelper.getTextureRef().bind(); } material.begin(); mesh.drawWireframe(); material.end(); if(meshHelper.hasTexture()){ meshHelper.getTextureRef().unbind(); } ofPopMatrix(); ofDisableDepthTest(); light.disable(); ofDisableLighting(); ofDisableSeparateSpecularLight(); ofSetColor(255, 255, 255 ); ofDrawBitmapString("fps: "+ofToString(ofGetFrameRate(), 2), 10, 15); ofDrawBitmapString("keys 1-5 load models, spacebar to trigger animation", 10, 30); ofDrawBitmapString("drag to control animation with mouseY", 10, 45); ofDrawBitmapString("num animations for this model: " + ofToString(model.getAnimationCount()), 10, 60); }
//-------------------------------------------------------------- void ofApp::draw(){ /*mEasyAR.augmenter_.drawVideoBackground();*/ mVideoFrame.draw(0, 0); ofSetColor(255, 255, 255); ofDrawBitmapString("fps: " + ofToString(ofGetFrameRate(), 2), 10, 15); EasyAR::Frame _frame = mEasyAR.augmenter_.newFrame(mEasyAR.tracker_); EasyAR::AugmentedTarget::Status status = _frame.targets()[0].status(); if (status == EasyAR::AugmentedTarget::kTargetStatusTracked) { EasyAR::Matrix44F projectionMatrix = EasyAR::getProjectionGL(mEasyAR.camera_.cameraCalibration(), 0.2f, 500.f); EasyAR::Matrix44F cameraview = EasyAR::getPoseGL(_frame.targets()[0].pose()); EasyAR::ImageTarget target = _frame.targets()[0].target().cast_dynamic<EasyAR::ImageTarget>(); ofEnableBlendMode(OF_BLENDMODE_ALPHA); ofEnableDepthTest(); #ifndef TARGET_PROGRAMMABLE_GL glShadeModel(GL_SMOOTH); //some model / light stuff #endif mLight.enable(); ofEnableSeparateSpecularLight(); ofPushMatrix(); glViewport(0, 0, 640, 480); glMatrixMode(GL_PROJECTION); glLoadMatrixf(&projectionMatrix.data[0]); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(&cameraview.data[0]); //mBox.setScale(0.02f); //mBox.draw(); mModel.drawFaces(); ofPopMatrix(); ofDisableDepthTest(); mLight.disable(); ofDisableLighting(); ofDisableSeparateSpecularLight(); //ofLog() << "marker detected" << std::endl; } }
//-------------------------------------------------------------- void testApp::setup(){ light.enable(); ofEnableSeparateSpecularLight(); shader.load("cheen"); lut.loadImage("LUTs/cheen-lut_blueGreen2.png"); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_RECTANGLE_ARB); ofEnableAlphaBlending(); ofEnableNormalizedTexCoords(); }
void testApp::setup() { //ofSetLogLevel(OF_LOG_VERBOSE); string configpath = ofToDataPath("config.xml"); config.loadFile(configpath); string modelName = config.getValue("model", "seymour.dae"); // we need GL_TEXTURE_2D for our models coords. ofDisableArbTex(); if (model.load(modelName)) { model.setAnimation(0); /* setupBone("r_ulna", 0, 0, 0); setupBone("r_humerus", 0, 1, 0); setupBone("l_ulna", 180, 0, 0); setupBone("l_humerus", 0, -1, 0); setupBone("pelvis", 90, 0, 90); setupBone("spine", -90, 0, 90); */ setupBone("root", 0, 0, 0); /* setupBone("neck", 90, 0, 90); setupBone("l_hip", 180, 0, -90); setupBone("l_knee", -90, 0, -90); setupBone("r_hip", -90, 0, 90); setupBone("r_knee", -90, 0, 90); */ } glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); light.enable(); ofEnableSeparateSpecularLight(); boneID = 0; setupGui(); }
//-------------------------------------------------------------- void testApp::setup(){ //ofSetFrameRate(60); gui.setAutoSave(false); // not working because the rotation matrix resets the translation matrix // gui.addTitle("Translate (not working)"); // gui.addSlider("translate X", translateX, -2, 2); // gui.addSlider("translate Y", translateY, -3, 3); // gui.addSlider("translate Z", translateZ, -5, 5); gui.addSlider("Rotation", rotationView, -360, 360); gui.addToggle("Auto rotate", autoRotate); //ofSetLogLevel(OF_LOG_VERBOSE); // we need GL_TEXTURE_2D for our models coords. ofDisableArbTex(); if (model.setup("Seymour_triangulate.dae")) { gui.addComboBox("Select Joint", selectedJointIndex, model.nrOfJoints, model.jointsLabels); } gui.addTitle("Rotate bones"); gui.addSlider("X", rotX,-5, 5); gui.addSlider("Y", rotY, -5, 5); gui.addSlider("Z", rotZ, -5, 5); gui.loadFromXML(); gui.show(); ofEnableBlendMode(OF_BLENDMODE_ALPHA); glEnable(GL_DEPTH_TEST); //some model / light stuff glShadeModel(GL_SMOOTH); light.enable(); ofEnableSeparateSpecularLight(); }
//-------------------------------------------------------------- void testApp::setup(){ // we need GL_TEXTURE_2D for our models coords. ofDisableArbTex(); if(model.loadModel("WoodenBox/Wooden Box.obj",true)){ model.setAnimation(0); model.setPosition(ofGetWidth()/2, (float)ofGetHeight() * 0.75 , 0); //model.createLightsFromAiModel(); //model.disableTextures(); //model.disableMaterials(); mesh = model.getMesh(0); position = model.getPosition(); normScale = model.getNormalizedScale(); scale = model.getScale(); sceneCenter = model.getSceneCenter(); material = model.getMaterialForMesh(0); tex = model.getTextureForMesh(0); } ofEnableBlendMode(OF_BLENDMODE_ALPHA); glEnable(GL_DEPTH_TEST); //some model / light stuff glShadeModel(GL_SMOOTH); light.enable(); ofEnableSeparateSpecularLight(); //cam.setDistance(100); udpConnection.Create(); udpConnection.Bind(12002); udpConnection.SetNonBlocking(true); modelInitialPosition.x=-model.getPosition().x; modelInitialPosition.y=-model.getPosition().y/2; model.setRotation(0,180,1,0,0); }
//-------------------------------------------------------------- void testApp::setup(){ ofSetLogLevel(OF_LOG_VERBOSE); // we need GL_TEXTURE_2D for our models coords. ofDisableArbTex(); if(model.loadModel("astroBoy_walk.dae",true)){ model.setAnimation(0); model.setPosition(ofGetWidth()/2, (float)ofGetHeight() * 0.75 , 0); //model.createLightsFromAiModel(); //model.disableTextures(); //model.disableMaterials(); mesh = model.getMesh(0); position = model.getPosition(); normScale = model.getNormalizedScale(); scale = model.getScale(); sceneCenter = model.getSceneCenter(); material = model.getMaterialForMesh(0); tex = model.getTextureForMesh(0); } ofEnableBlendMode(OF_BLENDMODE_ALPHA); glEnable(GL_DEPTH_TEST); //some model / light stuff glShadeModel(GL_SMOOTH); light.enable(); ofEnableSeparateSpecularLight(); bAnimate = false; bAnimateMouse = false; animationTime = 0.0; }
void TankClass::setup(){ tankParam.add(xPos.set("xPos",0.0,-1000000.0,1000000.0)); tankParam.add(yPos.set("yPos",0.0,-1000000.0,1000000.0)); tankParam.add(zPos.set("zPos",0.0,-1000000.0,1000000.0)); tankParam.add(xSpeed.set("xSpeed",0.0,-1000000.0,1000000.0)); tankParam.add(ySpeed.set("ySpeed",0.0,-1000000.0,1000000.0)); tankParam.add(zSpeed.set("zSpeed",0.0,-1000000.0,1000000.0)); tankParam.add(rSpeed.set("rSpeed",1.8,-1000000.0,1000000.0)); tankParam.add(rotation.set("rotation",0.0,-1000000.0,1000000.0)); tankParam.add(up.set("up",false)); tankParam.add(down.set("down",false)); tankParam.add(left.set("left",false)); tankParam.add(right.set("right",false)); tankParam.add(upk.set("upk",0,0,1000)); tankParam.add(downk.set("downk",0,0,1000)); tankParam.add(leftk.set("leftk",0,0,1000)); tankParam.add(rightk.set("rightk",0,0,1000)); tankParam.add(red.set("red",0,0,255)); tankParam.add(green.set("green",0,0,255)); tankParam.add(blue.set("blue",0,0,255)); Tank.loadModel("Tank.3ds"); Tank.setScale(.15,.15,.15); ofEnableLighting(); //== glEnable(GL_LIGHTING); glShadeModel(GL_SMOOTH); ofEnableSeparateSpecularLight(); ofEnableNormalizedTexCoords(); ofDisableArbTex(); light.setSpotlight(); light.setSpotConcentration(64); light.setSpotlightCutOff(30); }
void ofApp::drawModels() { ofSetColor(255); ofEnableBlendMode(OF_BLENDMODE_ALPHA); ofEnableDepthTest(); glShadeModel(GL_SMOOTH); //some model / light stuff light.enable(); ofEnableSeparateSpecularLight(); for (int i = 0; i < models.size(); i++) { ofPushMatrix(); models[i]->drawFaces(); ofPopMatrix(); } //model.setScale(.3, .3, .3); //model.drawFaces(); if(ofGetGLProgrammableRenderer()){ glPushAttrib(GL_ALL_ATTRIB_BITS); glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); } glEnable(GL_NORMALIZE); if(ofGetGLProgrammableRenderer()){ glPopAttrib(); } ofDisableDepthTest(); light.disable(); ofDisableLighting(); ofDisableSeparateSpecularLight(); }
//-------------------------------------------------------------- void testApp::setup() { // Set default OF settings. ofSetVerticalSync( true ); ofSetFrameRate( 60 ); ofSetWindowShape( 1280, 720 ); ofSetWindowTitle( "ofxAssimpNISyncExample" ); ofBackground( 0, 0, 0 ); ofSetLogLevel( OF_LOG_VERBOSE ); // First setup hardware if we are on mac. #if defined (TARGET_OSX) niHardwareDriver.setup(); #endif // Init OpenNI Objects. niContext.setup(); niDepthGenerator.setup( &niContext ); niImageGenerator.setup( &niContext ); niUserGenerator.setup( &niContext ); // Init ofxAssimpNISync. // Set required environment settings and load the model. ofDisableArbTex(); ofEnableBlendMode( OF_BLENDMODE_ALPHA ); modelLoader.loadModel( MODEL_FILE_PATH ); light.enable(); glEnable( GL_DEPTH_TEST ); ofEnableSeparateSpecularLight(); // Setup AssimpNISync. assimpNISync.setup( &modelLoader, &niUserGenerator); /* List Bone Names. Use these names to apply syncs below.*/ assimpNISync.listBoneNames(); // Apply syncs. /* Tip : Available OpenNI Joints XN_SKEL_HEAD XN_SKEL_NECK XN_SKEL_TORSO XN_SKEL_WAIST XN_SKEL_LEFT_COLLAR XN_SKEL_LEFT_SHOULDER XN_SKEL_LEFT_ELBOW XN_SKEL_LEFT_WRIST XN_SKEL_LEFT_HAND XN_SKEL_LEFT_FINGERTIP XN_SKEL_RIGHT_COLLAR XN_SKEL_RIGHT_SHOULDER XN_SKEL_RIGHT_ELBOW XN_SKEL_RIGHT_WRIST XN_SKEL_RIGHT_HAND XN_SKEL_RIGHT_FINGERTIP XN_SKEL_LEFT_HIP XN_SKEL_LEFT_KNEE XN_SKEL_LEFT_ANKLE XN_SKEL_LEFT_FOOT XN_SKEL_RIGHT_HIP XN_SKEL_RIGHT_KNEE XN_SKEL_RIGHT_ANKLE XN_SKEL_RIGHT_FOOT */ // All head bones assimpNISync.syncBoneAndOpenNIJoint( 0, "head", 1, XN_SKEL_HEAD ); assimpNISync.syncBoneAndOpenNIJoint( 1, "head", 1, XN_SKEL_HEAD ); assimpNISync.syncBoneAndOpenNIJoint( 2, "head", 1, XN_SKEL_HEAD ); assimpNISync.syncBoneAndOpenNIJoint( 3, "head", 1, XN_SKEL_HEAD ); // All neck bones assimpNISync.syncBoneAndOpenNIJoint( 0, "neck01", 1, XN_SKEL_NECK ); assimpNISync.syncBoneAndOpenNIJoint( 2, "neck01", 1, XN_SKEL_NECK ); assimpNISync.syncBoneAndOpenNIJoint( 3, "neck01", 1, XN_SKEL_NECK ); // All Shoulder bones assimpNISync.syncBoneAndOpenNIJoint( 3, "L_shoulder", 1, XN_SKEL_LEFT_SHOULDER ); assimpNISync.syncBoneAndOpenNIJoint( 3, "R_shoulder", 1, XN_SKEL_RIGHT_SHOULDER ); // All Elbow bones assimpNISync.syncBoneAndOpenNIJoint( 3, "L_elbow", 1, XN_SKEL_LEFT_ELBOW ); assimpNISync.syncBoneAndOpenNIJoint( 3, "R_elbow", 1, XN_SKEL_RIGHT_ELBOW ); // All Wrist bones assimpNISync.syncBoneAndOpenNIJoint( 2, "L_wrist", 1, XN_SKEL_LEFT_WRIST ); assimpNISync.syncBoneAndOpenNIJoint( 2, "R_wrist", 1, XN_SKEL_RIGHT_WRIST ); // All Hip bones assimpNISync.syncBoneAndOpenNIJoint( 3, "L_hip", 1, XN_SKEL_LEFT_HIP ); assimpNISync.syncBoneAndOpenNIJoint( 3, "R_hip", 1, XN_SKEL_RIGHT_HIP ); // init Kinect tilt Angle #if defined (TARGET_OSX) tiltAngle = niHardwareDriver.getTiltAngle(); #endif }
//-------------------------------------------------------------- void testApp::draw(){ ofEnableAlphaBlending(); if (state == 0) { pm.post.begin(cm.cam); if (useLights) lm.begin(); ofFloatColor bgColor = cs.colorScheme[0][0]; float complementHue = bgColor.getHue() + 0.5; if (complementHue > 1.0) complementHue-=1.0; bgColor.setHue(complementHue); bgColor.setSaturation(bgColor.getSaturation() - 0.2); ofBackground(bgColor); tm.draw(); if (useLights) lm.end(); pm.post.end(); } else if (state == 1) { cs.draw(); } else if (state == 2) { aa.drawAnalytics(); } else if (state == 3) { glShadeModel(GL_SMOOTH); glProvokingVertex(GL_LAST_VERTEX_CONVENTION); ofFloatColor gradientStart = cs.colorScheme[0][0]; float complementHue = gradientStart.getHue() + 0.5; if (complementHue > 1.0) complementHue-=1.0; ofFloatColor gradientEnd; gradientEnd.setHue(complementHue); gradientEnd.setSaturation(gradientStart.getSaturation() - 0.2); ofBackgroundGradient(gradientEnd, gradientStart); cm.cam.begin(); // mCamMainCam.begin(); ofEnableLighting(); // mLigDirectional.setAmbientColor( cs.colorScheme[0][2]); // mLigDirectional.setDiffuseColor( cs.colorScheme[0][1]); mLigDirectional.setSpecularColor(gradientStart); mLigDirectional.setGlobalPosition(1000, 1000, 1000); mLigDirectional.lookAt(ofVec3f(0,0,0)); ofEnableSeparateSpecularLight(); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); mLigDirectional.enable(); ofSetColor(mLigDirectional.getDiffuseColor()); mMatMainMaterial.begin(); mShdPhong->begin(); if (shouldRenderNormals){ mShdPhong->setUniform1f("shouldRenderNormals", 1.0); } else { mShdPhong->setUniform1f("shouldRenderNormals", 0.0); } glPushAttrib(GL_SHADE_MODEL); if (shouldUseFlatShading){ mShdPhong->setUniform1f("shouldUseFlatShading", 1.0); glShadeModel(GL_FLAT); glProvokingVertex(GL_FIRST_VERTEX_CONVENTION); // OpenGL default is GL_LAST_VERTEX_CONVENTION } else { mShdPhong->setUniform1f("shouldUseFlatShading", 0.0); glShadeModel(GL_SMOOTH); glProvokingVertex(GL_LAST_VERTEX_CONVENTION); } tm.draw(); // restores shade model glPopAttrib(); // restores vertex convention defaults. glProvokingVertex(GL_LAST_VERTEX_CONVENTION); mShdPhong->end(); // we revert to default values, to not end up mMatMainMaterial.end(); mLigDirectional.disable(); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); ofDisableLighting(); cm.cam.end(); // mCamMainCam.end(); } ofDisableAlphaBlending(); }
//-------------------------------------------------------------- void testApp::draw(){ glShadeModel(GL_SMOOTH); glProvokingVertex(GL_LAST_VERTEX_CONVENTION); ofBackgroundGradient(ofColor::fromHsb(0, 0, 120), ofColor::fromHsb(0, 0, 0)); mCamMainCam.begin(); ofEnableLighting(); mLigDirectional.setGlobalPosition(1000, 1000, 1000); mLigDirectional.lookAt(ofVec3f(0,0,0)); ofEnableSeparateSpecularLight(); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); mLigDirectional.enable(); ofSetColor(mLigDirectional.getDiffuseColor()); mMatMainMaterial.begin(); mShdPhong->begin(); if (shouldRenderNormals){ mShdPhong->setUniform1f("shouldRenderNormals", 1.0); } else { mShdPhong->setUniform1f("shouldRenderNormals", 0.0); } glPushAttrib(GL_SHADE_MODEL); if (shouldUseFlatShading){ mShdPhong->setUniform1f("shouldUseFlatShading", 1.0); glShadeModel(GL_FLAT); glProvokingVertex(GL_FIRST_VERTEX_CONVENTION); // OpenGL default is GL_LAST_VERTEX_CONVENTION } else { mShdPhong->setUniform1f("shouldUseFlatShading", 0.0); glShadeModel(GL_SMOOTH); glProvokingVertex(GL_LAST_VERTEX_CONVENTION); } if (shouldDrawBuiltinBox) { ofBox(0, 0, 0, 100); } else { ofPushMatrix(); ofScale(50, 50,50); mMshCube.draw(); ofPopMatrix(); } // restores shade model glPopAttrib(); // restores vertex convention defaults. glProvokingVertex(GL_LAST_VERTEX_CONVENTION); mShdPhong->end(); // we revert to default values, to not end up mMatMainMaterial.end(); mLigDirectional.disable(); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); ofDisableLighting(); ofSetColor(255); for (int i=0; i<8; i++){ // we do a manual scale by scaling the mesh vertex coord by 50.f to render the point at the vertex position ofDrawBitmapString(ofToString(i), mMshCube.getVertex(i) * 50.0f); } mCamMainCam.end(); // draw HUD items outside of camera. string builtInIndicator = ((shouldDrawBuiltinBox) ? "built-in" : "mesh-based"); ofDrawBitmapStringHighlight( "Rendering " + builtInIndicator + " box. Press 'b' to toggle." , ofVec3f(10,20), ofColor(255), ofColor(0)); string normalsIndicator = ((shouldRenderNormals) ? "normals" : "faces"); ofDrawBitmapStringHighlight( "Showing " + normalsIndicator + ". Press 'n' to toggle." , ofVec3f(10,40), ofColor(255), ofColor(0)); string flatShadingIndicator = ((shouldUseFlatShading) ? "on" : "off"); ofDrawBitmapStringHighlight( "Flat Shading is " + flatShadingIndicator + ". Press 'f' to toggle." , ofVec3f(10,60), ofColor(255), ofColor(0)); ofDrawBitmapStringHighlight( "Press SPACEBAR to reload shader." , ofVec3f(10,80), ofColor(0), ofColor(255)); }
//-------------------------------------------------------------- void ofApp::draw(){ // draw mesh ofEnableDepthTest();{ // ofPushMatrix();{ camera.begin();{ // ofTranslate(-rawDepthPixels.getWidth()/2.0, -rawDepthPixels.getHeight()/2.0, 0); ofSetLineWidth(1.f); if(enableDrawDebug) world.drawDebug(); // light light.draw(); ofEnableLighting();{ light.enable();{ if (enableSeparateSpecularLight) { ofEnableSeparateSpecularLight(); } glDisable(GL_COLOR_MATERIAL); material.begin();{ // kinect mesh if (!hideKinectMesh) { kinectMesh.setMode(OF_PRIMITIVE_TRIANGLES); glLineWidth(int(1)); enableDrawKinectWireFrame ? kinectMesh.drawWireframe() : kinectMesh.drawFaces(); } // spheres for( int i = 0; i < spheres.size(); i++ ) { spheres[i]->draw(); } // assimp models for (int i = 0; i < assimpModelBulletShapes.size(); i++) { int assimpModelId = modelSetVector[assimpModelBulletShapes[i]->getSetId()][assimpModelBulletShapes[i]->getIndex()]; ofPoint scale = assimpModelLoaders[assimpModelId].getScale(); ofxAssimpMeshHelper & meshHelper = assimpModelLoaders[assimpModelId].getMeshHelper(0); // ofMaterial & assimpModelMaterial = meshHelper.material; meshHelper.getTextureRef().bind();{ // assimpModelMaterial.begin();{ assimpModelBulletShapes[i]->transformGL();{ ofScale(scale.x, scale.y, scale.z); enableDrawAssimpModelWireFrame ? assimpModelLoaders[assimpModelId].getCurrentAnimatedMesh(0).drawWireframe() : assimpModelLoaders[assimpModelId].getCurrentAnimatedMesh(0).drawFaces(); } assimpModelBulletShapes[i]->restoreTransformGL(); // }assimpModelMaterial.end(); }meshHelper.getTextureRef().unbind(); } // debug // - camera target debugSphereCameraTarget.draw(); // - debugSpheres if (enableDrawDebugSpheres) { for (int i = 0; i < (int)debugSpheres.size(); i++) { debugSpheres[i].draw(); } } }material.end(); if (enableSeparateSpecularLight) { ofDisableSeparateSpecularLight(); } }light.disable(); }ofDisableLighting(); if(enableDrawDebug) ofDrawAxis(10000); // }ofPopMatrix(); }camera.end(); }ofDisableDepthTest(); // gui if (showPanel) { panel.draw(); } // debug ofSetColor(255); // - fps ofSetWindowTitle(ofToString(ofGetFrameRate(), 0)+" assimpModelBulletShapes:"+ofToString((int)assimpModelBulletShapes.size(), 0)); // - center guide line if (enableDrawGuideLine) { ofSetColor(ofColor::lightBlue); ofLine(ofGetWidth()/2.0, 0, ofGetWidth()/2.0, ofGetHeight()); ofLine(0, ofGetHeight()/2.0, ofGetWidth(), ofGetHeight()/2.0); ofSetColor(255); } // - depth data ofVec2f debugImageSize(1920/10.0, 1080/10.0); if (showPanel){ // draw below the gui panel // ofRect(panel.getPosition().x, panel.getHeight()+4, debugImageSize.x+2, debugImageSize.y+2); // texDepth.draw(panel.getPosition().x+1, panel.getHeight()+5, debugImageSize.x, debugImageSize.y); // draw upper right corner ofRect(ofGetWidth()-debugImageSize.x-3, 1, debugImageSize.x+2, debugImageSize.y+2); texDepth.draw(ofGetWidth()-debugImageSize.x-2, 2, debugImageSize.x, debugImageSize.y); } // - RGB data if (showPanel) { // draw below the gui panel // ofRect(panel.getPosition().x, panel.getHeight()+5+debugImageSize.y+2, debugImageSize.x+2, debugImageSize.y+2); //texRGB.draw(panel.getPosition().x+1, panel.getHeight()+5+debugImageSize.y+3, debugImageSize.x, debugImageSize.y); // draw upper right corner ofRect(ofGetWidth()-debugImageSize.x-3, debugImageSize.y+4, debugImageSize.x+2, debugImageSize.y+2); texRGB.draw(ofGetWidth()-debugImageSize.x-2, debugImageSize.y+5, debugImageSize.x, debugImageSize.y); } // - saved reference depth pixels if (showPanel) { // draw upper right corner ofRect(ofGetWidth()-debugImageSize.x-3, debugImageSize.y*2+7, debugImageSize.x+2, debugImageSize.y+2); savedReferenceDepthTexture.draw(ofGetWidth()-debugImageSize.x-2, debugImageSize.y*2+8, debugImageSize.x, debugImageSize.y); } // - diff depth if (showPanel) { // draw upper right corner ofRect(ofGetWidth()-debugImageSize.x-3, debugImageSize.y*3+10, debugImageSize.x+2, debugImageSize.y+2); diffDepthTexture.draw(ofGetWidth()-debugImageSize.x-2, debugImageSize.y*3+11, debugImageSize.x, debugImageSize.y); } // - info about ofxKinectV2 // ofDrawBitmapString("ofxKinectV2: Work in progress addon.\nBased on the excellent work by the OpenKinect libfreenect2 team\n\n-Only supports one Kinect v2 at a time. \n-Requires USB 3.0 port ( superspeed )\n-Requires patched libusb. If you have the libusb from ofxKinect ( v1 ) linked to your project it will prevent superspeed on Kinect V2", 10, 14); // info about shortcut keys if (showPanel) { ofDrawBitmapStringHighlight("press f: toggle full screen ", ofGetWidth()-300, ofGetHeight()-130, ofColor::white, ofColor::black); ofDrawBitmapStringHighlight("press h: hide/show GUI ", ofGetWidth()-300, ofGetHeight()-110, ofColor::white, ofColor::black); ofDrawBitmapStringHighlight("press 0: load sakura model ", ofGetWidth()-300, ofGetHeight()-90, ofColor::white, ofColor::black); ofDrawBitmapStringHighlight("press 1: load bitcoin & dgcoin model", ofGetWidth()-300, ofGetHeight()-70, ofColor::white, ofColor::black); ofDrawBitmapStringHighlight("press 2: load DNA model ", ofGetWidth()-300, ofGetHeight()-50, ofColor::white, ofColor::black); ofDrawBitmapStringHighlight("press 3: load maple model ", ofGetWidth()-300, ofGetHeight()-30, ofColor::white, ofColor::black); ofDrawBitmapStringHighlight("press w: apply force ", ofGetWidth()-300, ofGetHeight()-10, ofColor::white, ofColor::black); } }