//--------------------------------------------------------------
void Scenario::pushObject(ofxBulletWorldRigid &world, int typeObject, ofVec3f pos){
    
 //   ScenarioObjects.push_back(&m_obstable1);

/*
    ofVec3f pos;
    pos.x = ScenarioXml.getValue("positionX",0.0, 0);
    pos.y = ScenarioXml.getValue("positionY",0.0, 0);
    pos.z = ScenarioXml.getValue("positionZ",0.0, 0);
*/

    switch(typeObject){

        case SimpleObject::ShapeTypeBall:{
            Ball *oBall = new Ball(currentMissions);
            oBall->setup(world, pos);
            oBall->setDefaultZ();
            ScenarioObjects.push_back(oBall);
        }
        break;
            
        case SimpleObject::ShapeTypeHammer:{
            Hammer *oHammer = new Hammer(currentMissions);
            oHammer->setup(world, pos);
            oHammer->setDefaultZ();
            ScenarioObjects.push_back(oHammer);
        }
        break;
            
        case SimpleObject::ShapeTypeLever:{
            Lever *oLever = new Lever(currentMissions);
            int dir = 0;
            oLever->setup(world, pos, "cylinder.stl", ofVec3f(0.05, 0.05, 0.05), dir);
            oLever->setDefaultZ();
            ScenarioObjects.push_back(oLever);
        }
        break;
            
        case SimpleObject::ShapeTypeObstacle:{
            Obstacle *oObstable = new Obstacle(currentMissions);
            oObstable->setup(world, pos, "cylinder.stl", ofVec3f(0.05, 0.05, 0.05));
            oObstable->setDefaultZ();
            ScenarioObjects.push_back(oObstable);
        }
        break;
            
    }
}
void Scenario::loadFromXml(ofxBulletWorldRigid &world){
    ofxXmlSettings ScenarioXml;
    
    if(ScenarioXml.loadFile(PinballChinoManager::projectName+"/scenario.xml")){
        
        ScenarioXml.pushTag("scenario");
        
        int numberOfSavedObjects = ScenarioXml.getNumTags("object");
        
        for(int i = 0; i < numberOfSavedObjects; i++){
            
            ScenarioXml.pushTag("object", i);
            SimpleObject::shapeType Type = (SimpleObject::shapeType)ScenarioXml.getValue("type", 0);
            int objId = ScenarioXml.getValue("id", 0);
            
            
            ofVec3f pos, scale;
			
            pos.x = ScenarioXml.getValue("positionX",0.0, 0);
            pos.y = ScenarioXml.getValue("positionY",0.0, 0);
            pos.z = ScenarioXml.getValue("positionZ",0.0, 0);
            
            scale.x = ScenarioXml.getValue("scaleX",0.0, 0);
            scale.y = ScenarioXml.getValue("scaleY",0.0, 0);
            scale.z = ScenarioXml.getValue("scaleZ",0.0, 0);
			
			ofQuaternion rotation;
            ofVec4f rot;
			
			rot.x = ScenarioXml.getValue("rotationX",0.0,0);
			rot.y = ScenarioXml.getValue("rotationY",0.0,0);
			rot.z = ScenarioXml.getValue("rotationZ",0.0,0);
            rot.w = ScenarioXml.getValue("rotationW",0.0,0);
			rotation.set(rot);
			
            string path;
            path = ScenarioXml.getValue("path","", 0);
            
            //TODO uncomment the line below when the xml is properly configured
            //string strcolor = ScenarioXml.getValue("color", "0xFFFFFF", 0);
			int color = ScenarioXml.getValue("color", 0xFFFFFF, 0);
			
			int pointsCollision = ScenarioXml.getValue("pointsCollision", 0, 0);

			int invisible = 0; // Visible by default event if this value is not implemented in the Xml editor
			invisible = ScenarioXml.getValue("invisible", 0, 0);
			
            switch(Type){
                case SimpleObject::ShapeTypeBall:{
                    Ball *oBall = new Ball(currentMissions);
                    float mass = ScenarioXml.getValue("mass", 0.0);
                    float radius = ScenarioXml.getValue("radius", 0.0);
                    float restitution = ScenarioXml.getValue("restitution", 0.0);
                    float friction = ScenarioXml.getValue("friction", 0.0);
                    oBall->setup(world, pos, mass, radius, restitution, friction);
                    oBall->SetObjectId(objId);
					oBall->setRotation(rotation);
                    oBall->color = color;
					oBall->setVisibility(invisible);
					
                    ScenarioObjects.push_back(oBall);
                }
                break;
                    
                case SimpleObject::ShapeTypeHammer:{
                    Hammer *oHammer = new Hammer(currentMissions);
                    oHammer->setup(world, pos);
                    oHammer->SetObjectId(objId);
					oHammer->setRotation(rotation);
                    oHammer->color = color;
					oHammer->setVisibility(invisible);
                    ScenarioObjects.push_back(oHammer);
					
					oHammer->setupRot();
                }
                break;
                    
                case SimpleObject::ShapeTypeLever:{
                    Lever *oLever = new Lever(currentMissions);
                    int dir = ScenarioXml.getValue("LeverType", 0);
                    oLever->setup(world, pos, path, scale, dir);
                    oLever->SetObjectId(objId);
					oLever->setRotation(rotation);
                    oLever->color = color;
					oLever->setVisibility(invisible);
                    ScenarioObjects.push_back(oLever);

                }
                break;
                    
                case SimpleObject::ShapeTypeObstacle:{
                    Obstacle *oObstable = new Obstacle(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oObstable->setup(world, pos, path, scale);
                    oObstable->SetObjectId(objId);
					oObstable->setRotation(rotation);
                    oObstable->color = color;
					oObstable->setVisibility(invisible);
                    ScenarioObjects.push_back(oObstable);
					oObstable->setPointsCollision(pointsCollision);
					oObstable->setupRot();

                }
                break;
                
                case SimpleObject::ShapeTypeGravity:{
                    Gravity *oGravity = new Gravity(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oGravity->setup(world, pos, path, scale);
                    oGravity->SetObjectId(objId);
					oGravity->setRotation(rotation);
                    oGravity->color = color;
					oGravity->setVisibility(invisible);
                    ScenarioObjects.push_back(oGravity);
					oGravity->setPointsCollision(pointsCollision);
					oGravity->setupRot();
                    
                }
                break;
                   
                case SimpleObject::ShapeTypeTeleporter:{
                    Teleporter *oTeleporter = new Teleporter(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oTeleporter->setup(world, pos, path, scale);
                    oTeleporter->SetObjectId(objId);
					oTeleporter->setRotation(rotation);
                    oTeleporter->color = color;
					oTeleporter->setVisibility(invisible);
                    ScenarioObjects.push_back(oTeleporter);
					oTeleporter->setPointsCollision(pointsCollision);
					oTeleporter->setupRot();
                    
                }
                break;
					
				case SimpleObject::ShapeTypeRamp:{
					Ramp *oRamp = new Ramp(currentMissions);
					//oObstable->setup(world, pos, "3DModels/chino_6.dae");
					oRamp->setup(world, pos, path, scale);
					oRamp->SetObjectId(objId);
					oRamp->setRotation(rotation);
					oRamp->color = color;
					oRamp->setVisibility(invisible);
					ScenarioObjects.push_back(oRamp);
					oRamp->setPointsCollision(pointsCollision);
					oRamp->setupRot();
				}
					break;
					
				case SimpleObject::ShapeTypeObstacleTriShapeMesh:{
					ObstacleTriShapeMesh *oObstacleTriShapeMesh= new ObstacleTriShapeMesh(currentMissions);
					
					oObstacleTriShapeMesh->setup(world, pos, path, scale);
					oObstacleTriShapeMesh->SetObjectId(objId);
					oObstacleTriShapeMesh->setRotation(rotation);
					oObstacleTriShapeMesh->color = color;
					oObstacleTriShapeMesh->setVisibility(invisible);
					ScenarioObjects.push_back(oObstacleTriShapeMesh);
					oObstacleTriShapeMesh->setPointsCollision(pointsCollision);
					oObstacleTriShapeMesh->setupRot();
				}
					break;
					
                case SimpleObject::ShapeTypeAnimatedObject:{
                    AnimatedObject *oAnimatedObject = new AnimatedObject(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oAnimatedObject->setup(world, pos, path, scale);
                    oAnimatedObject->SetObjectId(objId);
					oAnimatedObject->setRotation(rotation);
                    oAnimatedObject->color = color;
					oAnimatedObject->setVisibility(invisible);
                    ScenarioObjects.push_back(oAnimatedObject);
					oAnimatedObject->setPointsCollision(pointsCollision);
					oAnimatedObject->setupRot();
                    
                }
                break;
                
                case SimpleObject::ShapeTypeAnimatedMotionPath:{
                    string pathMotionModel;
                    pathMotionModel = ScenarioXml.getValue("pathMotionModel","", 0);
                    AnimatedMotionPath *oAnimatedMotionPath = new AnimatedMotionPath(currentMissions);
                    oAnimatedMotionPath->setup(world, pos, path, pathMotionModel, scale);
                    oAnimatedMotionPath->SetObjectId(objId);
					oAnimatedMotionPath->setRotation(rotation);
                    oAnimatedMotionPath->color = color;
					oAnimatedMotionPath->setVisibility(invisible);
                    ScenarioObjects.push_back(oAnimatedMotionPath);
					oAnimatedMotionPath->setPointsCollision(pointsCollision);
					oAnimatedMotionPath->setupRot();
                    
                }
                break;
                    
                case SimpleObject::ShapeTypeAnimatedMesh:{
                    AnimatedMesh *oAnimatedMesh = new AnimatedMesh(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oAnimatedMesh->setup(world, pos, path, scale);
                    oAnimatedMesh->SetObjectId(objId);
					oAnimatedMesh->setRotation(rotation);
                    oAnimatedMesh->color = color;
					oAnimatedMesh->setVisibility(invisible);
                    ScenarioObjects.push_back(oAnimatedMesh);
					oAnimatedMesh->setPointsCollision(pointsCollision);
					oAnimatedMesh->setupRot();
                    
                }
                break;
                case SimpleObject::ShapeTypeGeneratedMesh:{
                    GeneratedMesh *oGeneratedMesh = new GeneratedMesh(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oGeneratedMesh->setup(world, pos, path, scale);
                    oGeneratedMesh->SetObjectId(objId);
					oGeneratedMesh->setRotation(rotation);
                    oGeneratedMesh->color = color;
					oGeneratedMesh->setVisibility(invisible);
                    ScenarioObjects.push_back(oGeneratedMesh);
					oGeneratedMesh->setPointsCollision(pointsCollision);
					oGeneratedMesh->setupRot();
                    
                }
                break;
                    
                case SimpleObject::ShapeTypeBounds:{
                    Bounds *oBounds = new Bounds(currentMissions);
                    oBounds->setup(world, pos, path, scale);
                    oBounds->SetObjectId(objId);
					oBounds->setRotation(rotation);
                    oBounds->color = color;
					oBounds->setVisibility(invisible);
                    ScenarioObjects.push_back(oBounds);
					
					oBounds->setupRot();
                }
                break;

            }
            ScenarioXml.popTag();
        }
        
        ScenarioXml.popTag(); //pop position
    }
    
    else{
        
        ofLogError("Scenario file did not load!");
        
    }
    
}
示例#3
0
vector< string >  Tutorial::setup( int _iScaler, int _iThirdOfScreen, bool _bIsLefty ) {
    
    fWriteControls( _bIsLefty );
    
    stringList.clear();
    obstacleList.clear();
    
    iScaler = _iScaler;
    iThirdOfScreen = _iThirdOfScreen;
    
    // Jump!
    float x = iScaler * 40;
    Obstacle tmp;
    tmp.setup( ofVec2f( x, iThirdOfScreen ), iScaler * 4, iScaler * 3, true );
    obstacleList.push_back( tmp );
    
    // Jump off a note to overcome an obstacle.
    float x2 = iScaler * 72;
    addObject( "d3", x2, -1 );
    Obstacle tmp2;
    tmp2.setup( ofVec2f( x2 + iScaler * 8, iThirdOfScreen ), iScaler * 4, iScaler * 6, true );
    obstacleList.push_back( tmp2 );
    
    // Record and replay a note to overcome an obstacle.
    float x3 = iScaler * 92;
    addObject( "d3", x3, -1 );
    addObject( "a3", x3 + iScaler * 29.8, -1 );
    Obstacle tmp3;
    tmp3.setup( ofVec2f( x3 + iScaler * 80, iThirdOfScreen ), iScaler * 4, iScaler * 6, true );
    obstacleList.push_back( tmp3 );
    
    // Spring off notes to get to higher notes and overcome a tall obstacle.
    float x4 = iScaler * 184;
    addObject( "d3", x4, -1 );
    //    addObject( "g4", x4 + iScaler * 8, -1 );
    addObject( "c4", x4 + iScaler * 16, -1 );
    addObject( "g3", x4 + iScaler * 28, -1 );
    
    float x5 = x4 + iScaler * 44;
    addObject( "g3", x5, -1 );
    addObject( "d3", x5 + iScaler * 4, -1 );
    //    addObject( "c5", x5 + iScaler * 8, -1 );
    Obstacle tmp4;
    tmp4.setup( ofVec2f( x5 + iScaler * 16, iThirdOfScreen ), iScaler * 4, iScaler * 12, true );
    obstacleList.push_back( tmp4 );
    
    // Record multiple notes before replaying to overcome a tall obstacle before the notes expire.
    addObject( "b3", x5 + iScaler * 24, -1 );
    addObject( "e3", x5 + iScaler * 28, -1 );
    
    float x6 = iScaler * 300;
    addObject( "b3", x6, -1 );
    addObject( "e3", x6 + iScaler * 8, -1 );
    Obstacle tmp5;
    tmp5.setup( ofVec2f( x6 + iScaler * 58, iThirdOfScreen ), iScaler * 4, iScaler * 12, true );
    obstacleList.push_back( tmp5 );
    
    // Ride a moving note to overcome a tall obstacle.
    Obstacle tmp6;
    tmp6.setup( ofVec2f( x6 + iScaler * 62, iThirdOfScreen ), iScaler * 4, iScaler * 8, true );
    obstacleList.push_back( tmp6 );
    Obstacle tmp7;
    tmp7.setup( ofVec2f( x6 + iScaler * 66, iThirdOfScreen ), iScaler * 4, iScaler * 4, true );
    obstacleList.push_back( tmp7 );
    
    float x7 = iScaler * 370;
    addObject( "b3", x7, -1 );
    //objectList[ objectList.size() - 1 ].vel.set( float( -( iScaler / 8.3333 ) ), 0.0 ); // Moved to testApp.cpp
    Obstacle tmp8;
    tmp8.setup( ofVec2f( x7 + iScaler * 30, iThirdOfScreen ), iScaler * 4, iScaler * 12, true );
    obstacleList.push_back( tmp8 );
    
    return stringList;
}