Esempio n. 1
0
void Reader::readObj(const char* name, Mesh* m){

	ifstream in;

	string buffer;
	vector<string> tokens;
	vector<string> indexes;

	Group* g = new Group();
	m->addGroup(g);
	Vertex v;
	Face* f;
	Texts t;
	string mtl;
	
	in.open(name);
	
	if(!in.is_open()){
		cout<<"Arquivo nao foi aberto com sucesso: "<<name<<endl;
		return;
	}
	
	while(!in.eof()){
		getline(in, buffer);
		
		if(buffer.find('\n') != -1){
			cout<<buffer<<endl;
		}
	
		tokens = split(buffer, ' ', true);
		
		switch(buffer[0]){
			case 'v':
				if(tokens.size() > 3){
					v = Vertex(
								atof(tokens[1].c_str()), 
								atof(tokens[2].c_str()), 
								atof(tokens[3].c_str()));
				}else{
					t = Texts(
								atof(tokens[1].c_str()), 
								atof(tokens[2].c_str()));
				}
				
				switch(buffer[1]){
					case 't':
						m->addTexts(t);
						break;
					case 'n':
						m->addNorms(v);
						break;
					default:
						m->addVerts(v);
						break;
				}
				break;
				
			case 'f':
				f = new Face();
				g->addFace(f);
				for(unsigned int x = 1; x < tokens.size(); ++x){
					indexes = split(tokens[x], '/', false);
					f->addVert(atoi(indexes[0].c_str()) - 1);
					if(indexes.size() > 1)
						if(indexes[1].size() > 0)
							f->addText(atoi(indexes[1].c_str()) - 1);						
					if(indexes.size() > 2) 
						f->addNorm(atoi(indexes[2].c_str()) - 1);
				}
				break;
				
			case 'g':
			
				if(!g->getFaces().empty()){
				
					if(tokens.size() == 1){
						g = new Group();
					}
					else {
						g = new Group(tokens[1]);
					}
					m->addGroup(g);
				}
				break;
				
			case 'm':
				mtl = tokens[1];
				break;
				
			case 'u':
				g->setMtl(tokens[1]);
				break;
		}
	}
	
	in.close();
	
	if(mtl.empty()){
		for(Group* g1 : m->getGroups()){
			g1->setMtl("");
		}
	}else{
		string n(name);
		mtl = n.substr(0, n.rfind('\\')) + '\\' + mtl;
		if(!readMtl(mtl.c_str(), m)){
			for(Group* g1 : m->getGroups()){
				g1->setMtl("");
			}
		}
	}
}
Esempio n. 2
0
void ModuleSceneIntro::Draw()
{
	// All draw functions ------------------------------------------------------
	if (draw)
	{
		//Drawing background
		App->renderer->Blit(background, 0, 0, NULL);

		Texts();

		//Drawing "Save Ball" light
		if (saveBallCounter < SAVE_BALL_TIMER)
		{
			saveBallCounter++;
			SDL_Rect rect;
			rect.x = 310; rect.y = 540; rect.w = 30; rect.h = 40;
			App->renderer->Blit(background_lights, rect.x, rect.y, &rect);
		}

		//Drawing pertinent lights
		p2List_item<lightSwitch*>* currentLight = lights.getFirst();
		while (currentLight)
		{
			p2List_item<SDL_Rect*>* currentRect = currentLight->data->lights.getFirst();
			for (int n = 0; n < currentLight->data->lights_on && n < currentLight->data->lights.count(); n++)
			{
				App->renderer->Blit(background_lights, currentRect->data->x, currentRect->data->y, currentRect->data);
				currentRect = currentRect->next;
			}
			if (currentLight->data->counter < LIGHT_ACTIVATION_SPACING + 1)
			{
				currentLight->data->counter++;
			}
			currentLight = currentLight->next;
		}

		//Drawing circle animation
		App->renderer->Blit(circleTexture, 290, 114, &circle.GetCurrentFrame());
		

		//Drawing balls
		p2List_item<PhysBody*>* c = balls.getFirst();
		while (c != NULL)
		{
			int x, y;
			c->data->GetPosition(x, y);
			App->renderer->Blit(ball, x, y, NULL, 0.0f, 0, 0, 0, c->data->scale);
			c = c->next;
		}

		//Drawing Flippers
		int x; int y;
		rightFlipper->GetPosition(x, y);
		App->renderer->Blit(rFlipper, x - 79, y - 10, NULL, 0.0f, RADTODEG * rightFlipper->body->GetAngle(), 79, 10);

		leftFlipper->GetPosition(x, y);
		App->renderer->Blit(lFlipper, x - 14, y - 9, NULL, 0.0f, RADTODEG * leftFlipper->body->GetAngle(), 14, 9);

		//Background items that go above the ball
		App->renderer->Blit(background_up, 0, 0, NULL);

		App->renderer->Blit(background_lights, 423, 92, &BlackBoxLed.GetCurrentFrame());

		for (int n = 0; n < 3; n++)
		{
			if (bounceCounters[n] < 10)
			{
				bounceCounters[n]++;
				switch (n)
				{
				case 0: {	App->renderer->Blit(orange_bump, 285, 66, NULL); break; }
				case 1: {	App->renderer->Blit(orange_bump, 320, 43, NULL); break; }
				case 2: {	App->renderer->Blit(orange_bump, 354, 66, NULL); break; }
				}
			}
		}

		

	}
	App->renderer->Blit(help, 0, 0, NULL);
}