Пример #1
0
	void main_3delight(void *arg)
	{
		if( bumpInterp() == 0 )
		{
			normal n = outNormal();
			/* Bump. */
			do_bump_map(
				//bumpValue(),
				//bumpDepth(),
				normalCamera(),
				n );
			outNormal() = n;
		}
		else if( bumpInterp() == 1 )
		{
			///* Tangent Space Normals. */
			//vector udir, vdir;

			//if( stangent != vector(0) )
			//{
			//	vdir = stangent ^ i_normalCamera;
			//}
			//else
			//{
			//	vdir = Du(tt) * dPdu + Dv(tt) * dPdv;
			//	vdir = i_normalCamera ^ (vdir ^ i_normalCamera);
			//}

			//udir = i_normalCamera ^ vdir;
			//vector uorient = Du(ss) * dPdu + Dv(ss) * dPdv;
			//if( udir.uorient < 0 )
			//{
			//	udir = -udir;
			//}

			//vector basisx = normalize(udir);
			//vector basisy = normalize(vdir);
			//vector basisz = normalize(i_normalCamera);

			//outNormal() = normal(
			//	(bumpNormal().x - 0.5f) * basisx +
			//	(bumpNormal().y - 0.5f) * basisy +
			//	(bumpNormal().z - 0.5f) * basisz );

			//outNormal() = normalize(outNormal());
		}
		else
		{
			/* Object Space Normals. This needs some work. */
			//outNormal() = ntransform( "object", "current", bumpNormal() - 0.5f );
			//outNormal() = normalize(outNormal());
			matrix toObject = to_object();
			vector tmp = (bumpNormal() - normal(0.5f,0.5f,0.5f)) * toObject;
			outNormal() = normalize(tmp);
		}
	}
Пример #2
0
	void main_hack(void *arg)
	{
		//outNormal() = normalCamera();
		outNormal() = bumpNormal();
	}
Пример #3
0
void display(void)
{
    glDisable(GL_LIGHTING);


    ofstream outTexture( "smokeSphereSmall/smokeSphereSmall_TEX.cpp" );
    ofstream outNormal(  "smokeSphereSmall/smokeSphereSmall_NORM.cpp");
    ofstream outVertices("smokeSphereSmall/smokeSphereSmall_VERT.cpp");
    int j;
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // This clear the background color to dark blue
    glMatrixMode(GL_MODELVIEW); // Modeling transformation
    glLoadIdentity(); // Initialize the model matrix as identity
    glTranslatef(0.0,0.0,-5); // We move the object forward (the model matrix is multiplied by the translation matrix)
    rotation_x = rotation_x + rotation_x_increment;
    rotation_y = rotation_y + rotation_y_increment;
    rotation_z = rotation_z + rotation_z_increment;
    if (rotation_x > 359) rotation_x = 0;
    if (rotation_y > 359) rotation_y = 0;
    if (rotation_z > 359) rotation_z = 0;
    glRotatef(rotation_x,1.0,0.0,0.0); // Rotations of the object (the model matrix is multiplied by the rotation matrices)
    glRotatef(rotation_y,0.0,1.0,0.0);
    glRotatef(rotation_z,0.0,0.0,1.0);

    if (object.id_texture!=-1)
    {
        glBindTexture(GL_TEXTURE_2D, object.id_texture); // We set the active texture
        glEnable(GL_TEXTURE_2D); // Texture mapping ON
    }
    else
        glDisable(GL_TEXTURE_2D); // Texture mapping OFF

    outTexture  << "GLfloat smokeSphereSmall_TEX[]   = \n" << "{\n"    << "  //number of vertices = " << object.polygons_qty*3 << "\n\n";
    outNormal   << "GLfloat smokeSphereSmall_NORM[]  = \n" << "{\n"    << "  //number of vertices = " << object.polygons_qty*3 << "\n\n";
    outVertices << "GLfloat smokeSphereSmall_VERT[]  = \n" << "{\n"    << "  //number of vertices = " << object.polygons_qty*3 << "\n\n";

    glBegin(GL_TRIANGLES); // glBegin and glEnd delimit the vertices that define a primitive (in our case triangles)
    for (j=0; j<object.polygons_qty; j++)
    {
        glTexCoord2f( object.mapcoord[ object.polygon[j].a ].u, object.mapcoord[ object.polygon[j].a ].v);
        outTexture << "" << object.mapcoord[ object.polygon[j].a ].u << ", ";
        outTexture << object.mapcoord[ object.polygon[j].a ].v << ", 1.0,\n";

        glNormal3f( object.normal[ object.polygon[j].a ].x, object.normal[ object.polygon[j].a ].y, object.normal[ object.polygon[j].a ].z);
        outNormal << "" << object.normal[ object.polygon[j].a ].x << ", ";
        outNormal << object.normal[ object.polygon[j].a ].y << ", ";
        outNormal << object.normal[ object.polygon[j].a ].z <<  ",\n";

        glVertex3f( object.vertex[ object.polygon[j].a ].x, object.vertex[ object.polygon[j].a ].y, object.vertex[ object.polygon[j].a ].z);

        outVertices << "" << object.vertex[ object.polygon[j].a ].x << ", ";
        outVertices << object.vertex[ object.polygon[j].a ].y << ", ";
        outVertices << object.vertex[ object.polygon[j].a ].z << ",\n";


        glTexCoord2f( object.mapcoord[ object.polygon[j].b ].u, object.mapcoord[ object.polygon[j].b ].v);
        outTexture << "" << object.mapcoord[ object.polygon[j].b ].u << ", ";
        outTexture << object.mapcoord[ object.polygon[j].b ].v << ", 1.0,\n";

        glNormal3f( object.normal[ object.polygon[j].b ].x, object.normal[ object.polygon[j].b ].y, object.normal[ object.polygon[j].b ].z);

        outNormal << "" << object.normal[ object.polygon[j].b ].x << ", ";
        outNormal << object.normal[ object.polygon[j].b ].y << ", ";
        outNormal << object.normal[ object.polygon[j].b ].z << ",\n";

        glVertex3f( object.vertex[ object.polygon[j].b ].x, object.vertex[ object.polygon[j].b ].y, object.vertex[ object.polygon[j].b ].z);

        outVertices << "" << object.vertex[ object.polygon[j].b ].x << ", ";
        outVertices << object.vertex[ object.polygon[j].b ].y << ", ";
        outVertices << object.vertex[ object.polygon[j].b ].z << ",\n";



        glTexCoord2f( object.mapcoord[ object.polygon[j].c ].u, object.mapcoord[ object.polygon[j].c ].v);
        outTexture << "" << object.mapcoord[ object.polygon[j].c ].u << ", ";
        outTexture << object.mapcoord[ object.polygon[j].c ].v << ", 1.0,\n\n";

        //Normal coordinates of the third vertex
        glNormal3f( object.normal[ object.polygon[j].c ].x, object.normal[ object.polygon[j].c ].y, object.normal[ object.polygon[j].c ].z);

        outNormal << "" << object.normal[ object.polygon[j].c ].x << ", ";
        outNormal << object.normal[ object.polygon[j].c ].y << ", ";
        outNormal << object.normal[ object.polygon[j].c ].z << ",\n\n";


        glVertex3f( object.vertex[ object.polygon[j].c ].x, object.vertex[ object.polygon[j].c ].y, object.vertex[ object.polygon[j].c ].z);

        outVertices << "" << object.vertex[ object.polygon[j].c ].x << ", ";
        outVertices << object.vertex[ object.polygon[j].c ].y << ", ";
        outVertices << object.vertex[ object.polygon[j].c ].z << ",\n\n";

    }

    outTexture << "};\n";
    outNormal << "};\n";
    outVertices << "};\n";

    glEnd();



    //glmDraw(couch, GLM_NONE);


    glFlush(); // This force the execution of OpenGL commands
    glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer
}