Exemple #1
0
//--------------------------------------------------------------
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);
*/
}
Exemple #2
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;
    }



}
Exemple #4
0
//--------------------------------------------------------------
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);
}
Exemple #5
0
//--------------------------------------------------------------
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;
	}


}
Exemple #6
0
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();
}
Exemple #7
0
//--------------------------------------------------------------
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);
    }
}