示例#1
0
void Vara::newelliza() {
    for (int i=0; i<numeroCaras; i++) {
		int v0=cara[i]->getIndiceVertice(0);
        int v1=cara[i]->getIndiceVertice(1);
        int v2=cara[i]->getIndiceVertice(2);
        int v3=cara[i]->getIndiceVertice(3);
        PuntoVector3D* v=newell(v0, v1, v2, v3);
        int iN=cara[i]->getIndiceNormal();
        normal[iN]=v;
    }
}
示例#2
0
文件: cara.cpp 项目: ereslibre/igr
Cara::Cara(const QList<PV3f> &vertices)
    : m_vertices(vertices)
{
    newell();
}
示例#3
0
文件: cara.cpp 项目: ereslibre/igr
Cara::Cara(const QList<PV3f> &vertices, int textura)
    : m_vertices(vertices)
    , m_textura(textura)
{
    newell();
}
示例#4
0
void processNode(Object* object){

	//Transformacoes
	glPushMatrix();
	glMultMatrixf(object->m_object);

	//Material
	if(object->material->id == "null"){
		if(materials.empty())
			cout << "Erro! Não há materiais na stack!" << endl;
		else{
			Material* mat = materials.top();
			mat->setMaterial();
		}
	} else{
		object->material->setMaterial();
		materials.push(object->material);
	}
	
	if(object->type == "simple"){ //Desenhar os poligonos
		Simple* simple = (Simple*)object;
		
		//Texturas
		if(object->texture->id != "null")
			textures.push(object->texture);
		if((object->texture->id != "clear") && (textures.top()->id != "clear")){
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, textures.top()->number);
		}
		
		//Triangulo
		if(simple->polygon->type == "triangle"){
			Triangle* triangle = (Triangle*)simple->polygon;
			float* n = newell(triangle);
			
			float length_A = sqrt((triangle->x2-triangle->x1)*(triangle->x2-triangle->x1) + (triangle->y2-triangle->y1)*(triangle->y2-triangle->y1) + (triangle->z2-triangle->z1)*(triangle->z2-triangle->z1));
			float length_B = sqrt((triangle->x3-triangle->x1)*(triangle->x3-triangle->x1) + (triangle->y3-triangle->y1)*(triangle->y3-triangle->y1) + (triangle->z3-triangle->z1)*(triangle->z3-triangle->z1));
			float length_N = sqrt(n[0]*n[0] + n[1]*n[1] + n[2]*n[2]);

			double height = length_N / length_A;

			double width = sqrt(length_B*length_B - height*height);
	
			glBegin(GL_POLYGON);
				glNormal3f(n[0],n[1],n[2]);
				glTexCoord2d(triangle->x1/textures.top()->length_s, triangle->y1/textures.top()->length_t); glVertex3d(triangle->x1, triangle->y1, triangle->z1);
				glTexCoord2d((triangle->x1 + length_A)/textures.top()->length_s, triangle->y1/textures.top()->length_t); glVertex3d(triangle->x2, triangle->y2, triangle->z2);
				glTexCoord2d((triangle->x1 + width)/textures.top()->length_s, (triangle->y1 + height)/textures.top()->length_t);glVertex3d(triangle->x3, triangle->y3, triangle->z3);
			glEnd();
		}
		//Rectangulo
		if(simple->polygon->type == "rectangle"){
			Rectangle* rect = (Rectangle*)simple->polygon;
			float s = mapText(rect->x1, rect->x2, textures.top()->length_s);
			float t = mapText(rect->y1, rect->y2, textures.top()->length_t);
			glBegin(GL_POLYGON);
				glNormal3d(0.0,0.0,1.0);
				glTexCoord2f(0.0,0.0);glVertex2d(rect->x1, rect->y1);
				glTexCoord2f(s  ,0.0);glVertex2d(rect->x2, rect->y1);
				glTexCoord2f(s  ,t  );glVertex2d(rect->x2, rect->y2);
				glTexCoord2f(0.0,t  );glVertex2d(rect->x1, rect->y2);
			glEnd();
		}

		if(simple->polygon->type == "cylinder"){
			Cylinder* cyl = (Cylinder*)simple->polygon;
			gluCylinder(glQ, cyl->base, cyl->top, cyl->height, cyl->slices, cyl->stacks);
		}
		if(simple->polygon->type == "sphere"){
			Sphere* sphere = (Sphere*)simple->polygon;
			gluSphere(glQ, sphere->radius, sphere->slices, sphere->stacks);
		}
		if(simple->polygon->type == "disk"){
			Disk* disk = (Disk*)simple->polygon;
			gluDisk(glQ, disk->inner, disk->outer, disk->slices, disk->loops);
		}
		glDisable(GL_TEXTURE_2D);
		
	}else if(object->type == "compound"){
		if(object->texture->id != "null"){
			textures.push(object->texture);
		}
		Compound* compound = (Compound*)object;
		vector<Object*>::iterator it = compound->childrenObj.begin();
		for( ; it != compound->childrenObj.end(); it++){
			processNode(*it);
		}
	}
	if(object->material->id != "null") materials.pop();
	if(object->texture->id != "null") textures.pop(); 
	glPopMatrix();	
}