Skip to content

Commit

Permalink
fixed up iOS assimp example.
Browse files Browse the repository at this point in the history
there was an issue with the way the model were loaded...
it was based on the number of touches on the screen,
so when you pressed 3 fingers, it would load and destroy 2 models before loading the correct 3rd one.
  • Loading branch information
julapy committed Dec 13, 2012
1 parent 4349c7b commit f79370f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 39 deletions.
4 changes: 4 additions & 0 deletions examples/ios/assimpExample/src/testApp.h
Expand Up @@ -28,8 +28,12 @@ class testApp : public ofxiPhoneApp{
void gotFocus();
void gotMemoryWarning();
void deviceOrientationChanged(int newOrientation);

void loadModel(int modelIndex);

ofxAssimpModelLoader model;
int modelIndex;
int modelsTotal;
ofLight light;
};

91 changes: 52 additions & 39 deletions examples/ios/assimpExample/src/testApp.mm
Expand Up @@ -8,16 +8,57 @@

ofDisableArbTex(); // we need GL_TEXTURE_2D for our models coords.

model.loadModel("astroBoy_walk.dae", true);
model.setPosition(ofGetWidth() * 0.5, (float)ofGetHeight() * 0.75 , 0);
model.setLoopStateForAllAnimations(OF_LOOP_NORMAL);
model.playAllAnimations();

glEnable(GL_DEPTH_TEST);

glShadeModel(GL_SMOOTH); //some model / light stuff
light.enable();
ofEnableSeparateSpecularLight();

modelIndex = 0;
modelsTotal = 4;
loadModel(modelIndex);
}

void testApp::loadModel(int modelIndex) {
ofPoint modelPosition(ofGetWidth() / 2, (float)ofGetHeight() * 0.75 , 0);

switch(modelIndex){
case 0:
model.loadModel("astroBoy_walk.dae");
model.setPosition(modelPosition.x, modelPosition.y, modelPosition.z);
ofEnableSeparateSpecularLight();
break;
case 1:
model.loadModel("TurbochiFromXSI.dae");
model.setPosition(modelPosition.x, modelPosition.y, modelPosition.z);
model.setRotation(0, -180, 1, 0, 0);
model.setScale(1.2, 1.2, 1.2);
ofEnableSeparateSpecularLight();
break;
case 2:
model.loadModel("dwarf.x");
model.setPosition(modelPosition.x, modelPosition.y, modelPosition.z);
model.setScale(1.2, 1.2, 1.2);
ofDisableSeparateSpecularLight();
break;
case 3:
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 4:
model.loadModel("squirrel/NewSquirrel.3ds");
model.setPosition(modelPosition.x, modelPosition.y, modelPosition.z);
model.setRotation(0, -90, 1, 0, 0);
ofDisableSeparateSpecularLight();
break;
default:
break;
}

model.setLoopStateForAllAnimations(OF_LOOP_NORMAL);
model.playAllAnimations();
}

//--------------------------------------------------------------
Expand All @@ -42,8 +83,8 @@
ofPopMatrix();

ofDrawBitmapString("fps: " + ofToString(ofGetFrameRate(), 2), 10, 15);
ofDrawBitmapString("fingers 2-5 load models", 10, 30);
ofDrawBitmapString("num animations for this model: " + ofToString(model.getAnimationCount()), 10, 45);
ofDrawBitmapString("num animations for this model: " + ofToString(model.getAnimationCount()), 10, 30);
ofDrawBitmapString("double tap to change model", 10, 60);
}

//--------------------------------------------------------------
Expand All @@ -53,38 +94,7 @@

//--------------------------------------------------------------
void testApp::touchDown(ofTouchEventArgs & touch){
if(touch.id >= 1){
switch(touch.id){
case 1:
model.loadModel("dwarf.x");
model.setPosition(ofGetWidth() / 2, (float)ofGetHeight() * 0.75 , 0);
model.setScale(1.2, 1.2, 1.2);
ofDisableSeparateSpecularLight();
break;
case 2:
model.loadModel("TurbochiFromXSI.dae");
model.setPosition(ofGetWidth() / 2, (float)ofGetHeight() * 0.75 , 0);
model.setRotation(0,-180,1,0,0);
model.setScale(1.2, 1.2, 1.2);
ofEnableSeparateSpecularLight();
break;
case 3:
model.loadModel("squirrel/NewSquirrel.3ds");
model.setPosition(ofGetWidth() / 2, (float)ofGetHeight() * 0.75 , 0);
ofDisableSeparateSpecularLight();
break;
case 4:
model.loadModel("astroBoy_walk.dae");
model.setPosition(ofGetWidth() / 2, (float)ofGetHeight() * 0.75 , 0);
ofEnableSeparateSpecularLight();
break;
default:
break;
}
}

model.setLoopStateForAllAnimations(OF_LOOP_NORMAL);
model.playAllAnimations();
}

//--------------------------------------------------------------
Expand All @@ -99,7 +109,10 @@

//--------------------------------------------------------------
void testApp::touchDoubleTap(ofTouchEventArgs & touch){

if(++modelIndex > modelsTotal - 1){
modelIndex = 0;
}
loadModel(modelIndex);
}

//--------------------------------------------------------------
Expand Down

0 comments on commit f79370f

Please sign in to comment.