Exemplo n.º 1
0
void World::LoadScene(const char * scene_path)
{
	// Using case-insensitive strings and streams for easier parsing
	ci_ifstream input;
	input.open(scene_path, ios::in);

	// Invalid file
	if(input.fail() )
	{	 
		fprintf(stderr, "Error loading file: %s\n", scene_path);
		getchar();
		exit(-1);
	}

	ci_string item;
	while( std::getline( input, item, '[' ) )   
	{
        ci_istringstream iss( item );

		ci_string result;
		if( std::getline( iss, result, ']') )
		{
			if( result == "cube" )
			{
				// Box attributes
				CubeModel* cube = new CubeModel();
				cube->Load(iss);
				mModel.push_back(cube);
			}
            else if( result == "sphere" )
            {
                SphereModel* sphere = new SphereModel();
                sphere->Load(iss);
                mModel.push_back(sphere);
            }
            else if( result == "path" )
			{
				Path* path = new Path();
				path->Load(iss);
                mPath.push_back(path);
			}
            else if( result == "spline" )
			{
				BSpline* path = new BSpline();
				path->Load(iss);
                mSpline.push_back(path);
			}
		
			else if ( result.empty() == false && result[0] == '#')
			{
				// this is a comment line
			}
			else
			{
				fprintf(stderr, "Error loading scene file... !");
				getchar();
				exit(-1);
			}
	    }
	}
	input.close();

	// Set PATH vertex buffers
	for (vector<Path*>::iterator it = mPath.begin(); it < mPath.end(); ++it)
	{
		// Draw model
		(*it)->CreateVertexBuffer();
	}

    // Set B-SPLINE vertex buffers
    for (vector<BSpline*>::iterator it = mSpline.begin(); it < mSpline.end(); ++it)
	{
		// Draw model
		(*it)->CreateVertexBuffer();
	}

	//LOAD DAT OBJ MODEL YO
	vector<OBJModel*> pokemon = PokemonGenerator::GeneratePokemon();
	for (int i = 0; i < pokemon.size(); i++)
		mModel.push_back(pokemon[i]);
	srand(20);

	OBJModel* grass = new OBJModel("../Models/Grass_02.obj");
	for (int i = 0; i < 50; i++){

		OBJModel* newgrass = new OBJModel(*grass);
		newgrass->SetPosition(vec3(rand() % 150 - 75, 0, rand() % 150 - 75));
		newgrass->SetScaling(vec3(1, 1, 1));
		mModel.push_back(newgrass);
	}

	// DAYTIME - default
	groundDay = new SkyboxModel("../Models/cube.obj");
	groundDay->SetSwitch(true);
	groundDay->SetPosition(vec3(0, -2.5, 0));
	groundDay->SetScaling(vec3(150, 5, 150));
	mModel.push_back(groundDay);

	skyboxDay = new SkyboxModel("../Models/ds.obj");
	skyboxDay->SetSwitch(true);
	skyboxDay->SetPosition(vec3(0, 60, 0));
	skyboxDay->SetScaling(vec3(80, 80, 80));
	mModel.push_back(skyboxDay);
	
	// NIGHTTIME
	groundNight = new SkyboxModel("../Models/cube2.obj");
	groundNight->SetSwitch(false);
	groundNight->SetPosition(vec3(0, -2.5, 0));
	groundNight->SetScaling(vec3(150, 5, 150));
	mModel.push_back(groundNight);

	skyboxNight = new SkyboxModel("../Models/ns.obj");
	skyboxNight->SetSwitch(false);
	skyboxNight->SetPosition(vec3(0, 60, 0));
	skyboxNight->SetScaling(vec3(80, 80, 80));
	mModel.push_back(skyboxNight);

	
    LoadCameras();
}
Exemplo n.º 2
0
void World::LoadScene(const char * scene_path)
{
	// Using case-insensitive strings and streams for easier parsing
	ci_ifstream input;
	input.open(scene_path, ios::in);

	// Invalid file
	if(input.fail() )
	{	 
		fprintf(stderr, "Error loading file: %s\n", scene_path);
		getchar();
		exit(-1);
	}

	ci_string item;
	while( std::getline( input, item, '[' ) )   
	{
        ci_istringstream iss( item );

		ci_string result;
		if( std::getline( iss, result, ']') )
		{
			if( result == "cube" )
			{
				// Box attributes
				CubeModel* cube = new CubeModel();
				cube->Load(iss);
				mModel.push_back(cube);
			}
			else if( result == "tank" )
			{
				// Box attributes
				tank = new TankModel();
				tank->Load(iss);
				mModel.push_back(tank);
				mCamera.at(0)->setTarget(tank);
				mCamera.at(1)->setTarget(tank);
			}
			else if (result == "alien")
			{
				// Box attributes
				AlienModel* alien = new AlienModel();
				Missile* mis = new Missile(tank);
				AlienCubeModel* pos = new AlienCubeModel();
				pos->SetMissile(mis);
				pos->Load(iss);
				alien->Load(iss);
				mModel.push_back(mis);
				mModel.push_back(pos);
				mModel.push_back(alien);
			}
			else if( result == "vehicle" )
			{
				// Box attributes
				VehicleModel* vehicle = new VehicleModel();
				vehicle->Load(iss);
				mModel.push_back(vehicle);
			}
            else if( result == "sphere" )
            {
                SphereModel* sphere = new SphereModel();
                sphere->Load(iss);
                mModel.push_back(sphere);
            }
            else if( result == "light" )
            {
                LightModel* light = new LightModel();
                light->Load(iss);
                mLightModels.push_back(light);
            }
			else if( result == "sun" )
            {
                SunModel* sun = new SunModel();
                sun->Load(iss);
                mModel.push_back(sun);
				LightModel* light = new LightModel(sun);
                light->Load(iss);
                mLightModels.push_back(light);
            }
			else if( result == "moon" )
            {
                MoonModel* moon = new MoonModel();
                moon->Load(iss);
                mModel.push_back(moon);
            }
            else if( result == "bspline" )
            {
                BSpline* bSpline = new BSpline();
                bSpline->Load(iss);
                mBSplineModels.push_back(bSpline);
            }
			else if (result == "textured_cube")
			{
				TexturedCube* texturedCube = new TexturedCube();
				texturedCube->Load(iss);
				mModel.push_back(texturedCube);
			}
            else if (result == "triangle")
            {
                TriangleModel* triangle = new TriangleModel();
                triangle->Load(iss);
                mModel.push_back(triangle);
            }
            else if (result == "particleEmitter")
            {
                ParticleEmitter* particleEmitter = new ParticleEmitter(vec4(1.0f, 0.0f, 0.0f, 0.0f), vec4(1.0f, 0.0f, 0.0f, 0.0f));
                particleEmitter->Load(iss);
                mModel.push_back(particleEmitter);
                mParticleEmitterModels.push_back(particleEmitter);
                particleEmitter->SetLightSource(mLightModels.back());
                particleEmitter->GenerateParticles();
            }
            else if (result == "cubesm")
            {
                CubeModelSM* cubesm = new CubeModelSM();
                cubesm->Load(iss);
                mModel.push_back(cubesm);
            }
			else if ( result.empty() == false && result[0] == '#')
			{
				// this is a comment line
			}
			else
			{
				fprintf(stderr, "Error loading scene file... !");
				getchar();
				exit(-1);
			}
	    }
	}
	input.close();

    for (vector<Model*>::iterator it = mModel.begin(); it < mModel.end(); ++it)
	{
        // Temporary for single light source
		(*it)->SetLightSource(mLightModels.back());
	}
}
Exemplo n.º 3
0
void World::LoadScene(const char * scene_path)
{
	// Using case-insensitive strings and streams for easier parsing
	ci_ifstream input;
	input.open(scene_path, ios::in);

	// Invalid file
	if (input.fail())
	{
		fprintf(stderr, "Error loading file: %s\n", scene_path);
		getchar();
		exit(-1);
	}

	ci_string item;
	while (std::getline(input, item, '['))
	{
		ci_istringstream iss(item);

		ci_string result;
		if (std::getline(iss, result, ']'))
		{
			if (result == "cube")
			{
				CubeModel* cube = new CubeModel();
				cube->Load(iss);
				mModel.push_back(cube);
			}
			else if (result == "sphere")
			{
#if defined(PLATFORM_OSX)
				int sphereTextureID = TextureLoader::LoadTexture("Textures/moonTexture.jpg");
#else
				int sphereTextureID = TextureLoader::LoadTexture("../Assets/Textures/moonTexture.jpg");
#endif

				SphereModel* moon = new SphereModel(sphereTextureID, vec3(10.0f, 10.0f, 10.0f));
				moon->Load(iss);
				mModel.push_back(moon);
			}
			else if (result == "animationkey")
			{
				AnimationKey* key = new AnimationKey();
				key->Load(iss);
				mAnimationKey.push_back(key);
			}
			else if (result == "animation")
			{
				Animation* anim = new Animation();
				anim->Load(iss);
				mAnimation.push_back(anim);
			}
			else if (result.empty() == false && result[0] == '#')
			{
				// this is a comment line
			}
			else
			{
				fprintf(stderr, "Error loading scene file... !");
				getchar();
				exit(-1);
			}
		}
	}
	input.close();

	// Set Animation vertex buffers
	for (vector<Animation*>::iterator it = mAnimation.begin(); it < mAnimation.end(); ++it)
	{
		// Draw model
		(*it)->CreateVertexBuffer();
	}
}
Exemplo n.º 4
0
void World::LoadScene(const char * scene_path)
{
	// Using case-insensitive strings and streams for easier parsing
	ci_ifstream input;
	input.open(scene_path, ios::in);

	// Invalid file
	if (input.fail())
	{
		fprintf(stderr, "Error loading file: %s\n", scene_path);
		getchar();
		exit(-1);
	}

	ci_string item;
	while (std::getline(input, item, '['))
	{
		ci_istringstream iss(item);

		ci_string result;
		if (std::getline(iss, result, ']'))
		{
			if (result == "player")
			{
				// Box attributes
				PlayerModel* player = new PlayerModel();
				player->Load(iss);
				mModel.push_back(player);

				mPlayerModel = player;
			}
			else if (result == "discoball")
			{
				// Box attributes
				Discoball* discoBallz = new Discoball();
				discoBallz->Load(iss);
				mModel.push_back(discoBallz);
			}
			else if (result == "bunnny")
			{
				// Box attributes
				BunnyModel* bunny = new BunnyModel();
				bunny->Load(iss);
				mModel.push_back(bunny);
			}
			else if (result == "barrel")
			{
				// Box attributes
				BarrelModel* barrel = new BarrelModel();
				barrel->Load(iss);
				mModel.push_back(barrel);
			}
			else if (result == "cube")
			{
				// Box attributes
				CubeModel* cube = new CubeModel();
				cube->Load(iss);
				mModel.push_back(cube);
			}
			else if (result == "sphere")
			{
				SphereModel* sphere = new SphereModel();
				sphere->Load(iss);
				mModel.push_back(sphere);
			}
			else if (result == "animationkey")
			{
				AnimationKey* key = new AnimationKey();
				key->Load(iss);
				mAnimationKey.push_back(key);
			}
			else if (result == "animation")
			{
				Animation* anim = new Animation();
				anim->Load(iss);
				mAnimation.push_back(anim);
			}
			else if (result.empty() == false && result[0] == '#')
			{
				// this is a comment line
			}
			else
			{
				fprintf(stderr, "Error loading scene file... !");
				getchar();
				exit(-1);
			}
		}
	}
	input.close();

	if (DRAW_ANIM_PATH) {
		for (vector<Animation*>::iterator it = mAnimation.begin(); it < mAnimation.end(); ++it)
		{
			(*it)->CreateVertexBuffer();
		}
	}
}
Exemplo n.º 5
0
void World::LoadScene(const char * scene_path){
	// Using case-insensitive strings and streams for easier parsing
	ci_ifstream input;
	input.open(scene_path, ios::in);

	// Invalid file
	if(input.fail() ){	 
		fprintf(stderr, "Error loading file: %s\n", scene_path);
		getchar();
		exit(-1);
	}

	ci_string item;
	while( std::getline( input, item, '[' ) ){
        ci_istringstream iss( item );

		ci_string result;
		if( std::getline( iss, result, ']') ){
			if( result == "cube" ){
				// Box attributes
				//CubeModel* cube = new CubeModel();
				ourGuy->Load(iss);
				mModel.push_back(ourGuy);
			}
			else if( result == "ground" ){
				// Box attributes
				CubeModel* cube = new CubeModel();
				cube->Load(iss);
				mModel.push_back(cube);
			}
            else if( result == "sphere" ){
                //SphereModel* sphere = new SphereModel();
                ourSphere->Load(iss);
                mModel.push_back(ourSphere);
            }
			else if ( result == "animationkey" ){
				AnimationKey* key = new AnimationKey();
				key->Load(iss);
				mAnimationKey.push_back(key);
			}
			else if (result == "animation"){
				Animation* anim = new Animation();
				anim->Load(iss);
				mAnimation.push_back(anim);
			}//*/
			else if (result == "bspline"){
				BSpline* spline = new BSpline();
				spline->Load(iss);
				mBSpline.push_back(spline);
			}//*/
			else if ( result.empty() == false && result[0] == '#'){
				// this is a comment line
			}
			else{
				fprintf(stderr, "Error loading scene file... !");
				getchar();
				exit(-1);
			}
	    }
	}
	input.close();

	// Set Animation vertex buffers
	for (vector<Animation*>::iterator it = mAnimation.begin(); it < mAnimation.end(); ++it)
		// Draw model
		(*it)->CreateVertexBuffer();
}