Exemplo n.º 1
0
/**
 * draw_tetrahedron:
 * @solid: TRUE if the tetrahedron should be solid.
 *
 * Renders a tetrahedron centered at the modeling coordinates
 * origin with a radius of the square root of 3.
 *
 **/
void
draw_tetrahedron (gboolean solid)
{
  if (solid)
    tetrahedron (GL_TRIANGLES);
  else
    tetrahedron (GL_LINE_LOOP);
}
Exemplo n.º 2
0
void display(){
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	mode=0;
	tetrahedron(n);
	mode=1;
	glTranslatef(-2,0,0);
	tetrahedron(n);
	mode=2;
	glTranslatef(4,0,0);
	tetrahedron(n);

	glFlush();
};
Exemplo n.º 3
0
void generateSphere(GLuint program, ShapeData* sphereData)
{
    tetrahedron(N);
    
    // Normals and tangents
    for (int i = 0; i < numSphereVertices; i++) {
        sphereData->normals[i] = vec3(sphereData->points[i].x, sphereData->points[i].y, sphereData->points[i].z);
    }
    
    // TexCoords
    double u, v;
    for (int i = 0; i < numSphereVertices; i++) {
        u = 0.5*(atan2(sphereData->points[i].z, sphereData->points[i].x)/M_PI + 1); //0~1
        v = 1 + asin(sphereData->points[i].y)/M_PI - 0.5; //0~1, and right ways up
        
        // make sure that we have no seam
        if( i % 3 > 0 ) {
            vec2 prev = sphereData->UVs[i-(i%3)];
            if( fabs(u - prev.x) > 0.5 ) {
                float diff = ( u < prev.x ) ? ( u + 1 - prev.x ) : ( u - 1 - prev.x );
                u = prev.x + diff;
            }
        }
        sphereData->UVs[i] = vec2(u,v);
    }
    
    // Create a vertex array object
    sphereData->enableUVArray( true, program );
    sphereData->bind(program);
}
Exemplo n.º 4
0
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
tetrahedron(n);
glFlush();
}
void mydisplay()
{

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	tetrahedron(5);
	glFlush();
}
Exemplo n.º 6
0
void drawSun(){

	glPushAttrib(GL_ENABLE_BIT);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_FOG);
	glEnable(GL_DEPTH_TEST);

	//Draw Sun
	GLfloat yellowMaterial[] = { 1, 1, 0 };
	float zeros[3] = { 0, 0, 0 };

	glMaterialfv(GL_FRONT, GL_SPECULAR, zeros);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, zeros);
	glMaterialfv(GL_FRONT, GL_AMBIENT, zeros);
	glMaterialfv(GL_FRONT, GL_EMISSION, yellowMaterial);

	glPushMatrix();
	glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]);
	glScalef(3, 3, 3);
	tetrahedron(6);
	glPopMatrix();



	glPopAttrib();
}
Exemplo n.º 7
0
void generateSphere(GLuint program, ShapeData* sphereData)
{
    tetrahedron(N);

    sphereData->numVertices = numSphereVertices;

    // Normals
    for (int i = 0; i < numSphereVertices; i++)
    {
        sphereNormals[i] = point3(spherePoints[i].x, spherePoints[i].y, spherePoints[i].z);
    }
    
    // TexCoords
    double u, v;
    for (int i = 0; i < numSphereVertices; i++)
    {
        v = 0.5 - asin(spherePoints[i].y)/M_PI ; //0~1
        u = 0.5*(atan2(spherePoints[i].z,spherePoints[i].x)/M_PI + 1); //0~1
        sphereUVs[i] = point2(u,v);
    }

    // Create a vertex array object
    glGenVertexArrays( 1, &sphereData->vao );
    glBindVertexArray( sphereData->vao );

    // Set vertex attributes
    setVertexAttrib(program,
        (float*)spherePoints,  sizeof(spherePoints),
        (float*)sphereNormals, sizeof(sphereNormals),
        (float*)sphereUVs, sizeof(sphereUVs));
}
Exemplo n.º 8
0
static solid *tesselated_tetrahedron(coord size, int iter, jigglystruct *js) {
    solid *s = tetrahedron(js);
    int i;

    for(i=0; i<iter; i++) {
        solid_tesselate(s);
    }
    return s;
}
void display(void) {

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glLoadIdentity();

    tetrahedron();
    glutSwapBuffers();

}
Exemplo n.º 10
0
Arquivo: base.c Projeto: felx/detritus
/* Displays all three modes, side by side */
void display(void) {
	static float object_angle = 0;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	gluPerspective(45, aspect, 1, -1);
	gluLookAt(eye[0], eye[1], eye[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

	glMaterialf(GL_FRONT, GL_SHININESS, mat_shininess);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);

	if (rotating) {
		object_angle += 5;
	}

	if (rotating == 3) {
		glRotatef(object_angle, 0, 1, 0);

		glLightfv(GL_LIGHT0, GL_POSITION, light_pos);

		tetrahedron(n);
	} else if (rotating == 2) {
		tetrahedron(n);

		glRotatef(object_angle, 0, 1, 0);

		glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
	} else if (rotating == 1) {
		glLightfv(GL_LIGHT0, GL_POSITION, light_pos);

		glRotatef(object_angle, 0, 1, 0);

		tetrahedron(n);
	} else {
		tetrahedron(n);

		glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
	}

	glutSwapBuffers();
}
Exemplo n.º 11
0
void render() {

    sphere();

    teapot();

    cone();

    torus();

    tetrahedron();

}
Exemplo n.º 12
0
void
Planet::generate(int num_subdivisions, shader s)
{
  this->NumTimesToSubdivide = num_subdivisions;
  this->NumTriangles = pow(4, num_subdivisions + 1);
  this->NumVertices = this->NumTriangles*3;

  points = new point4[NumVertices];
  normals = new vec3[NumVertices];

  tetrahedron (this->NumTimesToSubdivide, s);
  this->shade_type = s;
}
Exemplo n.º 13
0
//****************************************
void repaint() {// function called to repaint the window
	GLfloat* pixelColor;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the screen buffer
	if(fracCount<6){
	glBegin(GL_POINTS); // start drawing in single pixel mode
	for(GLfloat y = maxY; y >= minY; y -= stepY){
		for(GLfloat x = minX+juliaSpecial; x <= maxX+juliaSpecial; x += stepX){
			pixelColor=calculateColor(x,y);
			glColor3fv(pixelColor+color); // set color
			glVertex3f(x-juliaSpecial, y, 0.0f); // put pixel on screen (buffer) - [ 1 ]
			//printf("%d\t%d\n",stepX,stepY);
		}
	}
	glEnd(); // end drawing
	}
	else {
		switch(fracCount)
		{
			case 6:
				//glPushMatrix();
				tetrahedron(5);
				//glPopMatrix();
				break;
		}
	}
	if(fracCount==0){
		drawFrontPage();
	}
	else
	{
		glPushMatrix();
		char title[25]="";
		strcpy(title,titleSet[fracCount-1]);
		glColor3f(0.2,0.2,0.2);
		output(-1.1,1.2,0,GLUT_BITMAP_TIMES_ROMAN_24,title);
		printf("%s\n",title);
		glPopMatrix();
	}
	glutSwapBuffers(); // swap the buffers - [ 2 ]
}
Exemplo n.º 14
0
void APIENTRY
glutSolidTetrahedron(void)
{
  tetrahedron(GL_TRIANGLES);
}
Exemplo n.º 15
0
/* CENTRY */
void APIENTRY
glutWireTetrahedron(void)
{
  tetrahedron(GL_LINE_LOOP);
}
Exemplo n.º 16
0
// OpenGL initialization
void
init()
{
    // Subdivide a tetrahedron into a sphere
    tetrahedron( NumTimesToSubdivide );

    // Create a vertex array object
    GLuint vao;
    glGenVertexArrays( 1, &vao );
    glBindVertexArray( vao );

    // Create and initialize a buffer object
    GLuint buffer;
    glGenBuffers( 1, &buffer );
    glBindBuffer( GL_ARRAY_BUFFER, buffer );
    glBufferData( GL_ARRAY_BUFFER, sizeof(points) + sizeof(normals),
		  NULL, GL_STATIC_DRAW );
    glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points), points );
    glBufferSubData( GL_ARRAY_BUFFER, sizeof(points),
		     sizeof(normals), normals );

    // Load shaders and use the resulting shader program
    GLuint program = InitShader( "vshader56.glsl", "fshader56.glsl" );
    glUseProgram( program );
	
    // set up vertex arrays
    GLuint vPosition = glGetAttribLocation( program, "vPosition" );
    glEnableVertexAttribArray( vPosition );
    glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0,
			   BUFFER_OFFSET(0) );

    GLuint vNormal = glGetAttribLocation( program, "vNormal" ); 
    glEnableVertexAttribArray( vNormal );
    glVertexAttribPointer( vNormal, 3, GL_FLOAT, GL_FALSE, 0,
			   BUFFER_OFFSET(sizeof(points)) );

    // Initialize shader lighting parameters
    point4 light_position( 0.0, 0.0, 2.0, 0.0 );
    color4 light_ambient( 0.2, 0.2, 0.2, 1.0 );
    color4 light_diffuse( 1.0, 1.0, 1.0, 1.0 );
    color4 light_specular( 1.0, 1.0, 1.0, 1.0 );

    color4 material_ambient( 1.0, 0.0, 1.0, 1.0 );
    color4 material_diffuse( 1.0, 0.8, 0.0, 1.0 );
    color4 material_specular( 1.0, 0.0, 1.0, 1.0 );
    float  material_shininess = 5.0;

    color4 ambient_product = light_ambient * material_ambient;
    color4 diffuse_product = light_diffuse * material_diffuse;
    color4 specular_product = light_specular * material_specular;

    glUniform4fv( glGetUniformLocation(program, "AmbientProduct"),
		  1, ambient_product );
    glUniform4fv( glGetUniformLocation(program, "DiffuseProduct"),
		  1, diffuse_product );
    glUniform4fv( glGetUniformLocation(program, "SpecularProduct"),
		  1, specular_product );
	
    glUniform4fv( glGetUniformLocation(program, "LightPosition"),
		  1, light_position );

    glUniform1f( glGetUniformLocation(program, "Shininess"),
		 material_shininess );
		 
    // Retrieve transformation uniform variable locations
    ModelView = glGetUniformLocation( program, "ModelView" );
    Projection = glGetUniformLocation( program, "Projection" );
    
    glEnable( GL_DEPTH_TEST );
    
    glClearColor( 1.0, 1.0, 1.0, 1.0 ); /* white background */
}
Exemplo n.º 17
0
void
glutWireTetrahedron(void)
{
  tetrahedron(GL_LINE_LOOP);
}
void init() {


	map.initialize();
	cam_moves[0] = Translate(-0.01, 0, 0);
	cam_moves[1] = Translate(0, 0, -0.01);
	cam_moves[2] = Translate(0.01, 0, 0);
	cam_moves[3] = Translate(0, 0, 0.01);
	int* arr = map.decrypt(Snake_Head);
	int i = arr[0]- Length/2, j= arr[1]-Width/2;
	cam_COF = Translate((i+2)*sphere_width, 0, j*sphere_width) * cam_COF;
	cam_eye = Translate(-(i-2)*sphere_width, 15, j*sphere_width) * cam_eye;

	vec4 a(0, 0, 0, 1);
	vec4 b(sphere_width, 0, 0, 1);
	vec4 c(0, 0, sphere_width, 1);
	vec4 d(sphere_width, 0, sphere_width, 1);

	vec3 normal = vec3(0, 1, 0);

	normals[index] = normal;
	points[index] = a;
	index++;
	normals[index] = normal;
	points[index] = b;
	index++;
	normals[index] = normal;
	points[index] = c;
	index++;

	normals[index] = normal;
	points[index] = b;
	index++;
	normals[index] = normal;
	points[index] = c;
	index++;
	normals[index] = normal;
	points[index] = d;
	index++;

	//generate the sphere
	tetrahedron(NumTimesToSubdivide);

	GLuint vao;
	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);

	GLuint buffer[2];
	glGenBuffers(2, buffer);
	glBindBuffer(GL_ARRAY_BUFFER, buffer[0]);
	glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);

	glBindBuffer(GL_ARRAY_BUFFER, buffer[1]);
	glBufferData(GL_ARRAY_BUFFER, sizeof(normals), normals, GL_STATIC_DRAW);

	program = InitShader("src/vshader.glsl", "src/fshader.glsl");
	glUseProgram(program);

	glBindBuffer(GL_ARRAY_BUFFER, buffer[0]);
	GLuint vPosition = glGetAttribLocation(program, "vPosition");
	glEnableVertexAttribArray(vPosition);
	glVertexAttribPointer(vPosition, 4, GL_FLOAT, GL_FALSE, 0,
			BUFFER_OFFSET(0) );

	glBindBuffer(GL_ARRAY_BUFFER, buffer[1]);
	GLuint vNormal = glGetAttribLocation(program, "vNormal");
	glEnableVertexAttribArray(vNormal);
	glVertexAttribPointer(vNormal, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) );

	vec4 ambient_product = light_ambient * material_ambient;
	vec4 diffuse_product = light_diffuse * material_diffuse;
	vec4 specular_product = light_specular * material_specular;

	glUniform4fv(glGetUniformLocation(program, "AmbientProduct"), 1,
			ambient_product);
	glUniform4fv(glGetUniformLocation(program, "DiffuseProduct"), 1,
			diffuse_product);
	glUniform4fv(glGetUniformLocation(program, "SpecularProduct"), 1,
			specular_product);
	lightPos_loc = glGetUniformLocation(program, "LightPosition");
	glUniform4fv(lightPos_loc, 1, light_position);
	glUniform1f(glGetUniformLocation(program, "Shininess"), material_shininess);

	model_loc = glGetUniformLocation(program, "Model");
	glUniformMatrix4fv(model_loc, 1, GL_TRUE, mat4(1));
	camera_loc = glGetUniformLocation(program, "Camera");
	projection_loc = glGetUniformLocation(program, "Projection");

	glEnable(GL_DEPTH_TEST);
	glClearColor(1.0, 1.0, 1.0, 1.0);

	direction = Periodic;
	step(0);
}
Exemplo n.º 19
0
void
glutSolidTetrahedron(void)
{
  tetrahedron(GL_TRIANGLES);
}
Exemplo n.º 20
0
void APIENTRY auxSolidTetrahedron (GLdouble radius)
{
    GLdouble center[3] = {(GLdouble)0.0, (GLdouble)0.0, (GLdouble)0.0};

    tetrahedron (center, radius, GL_TRIANGLES);
}
Exemplo n.º 21
0
/*  Render wire frame or solid tetrahedra.  If no display list with
 *  the current model size exists, create a new display list.
 */
void APIENTRY auxWireTetrahedron (GLdouble radius)
{
    GLdouble center[3] = {(GLdouble)0.0, (GLdouble)0.0, (GLdouble)0.0};

    tetrahedron (center, radius, GL_LINE_LOOP);
}
Exemplo n.º 22
0
TEST(intersection, triangle_tetrahedron) {
    TIntersectionType it;
    double area;

    // create tetrahedron
    TPoint point0(0.00, 0.00, 0.00);
    TPoint point1(3.00, 0.00, 0.00);
    TPoint point2(0.00, 3.00, 0.00);
    TPoint point3(0.00, 0.00, 3.00);
    TTetrahedron tetrahedron(point0, point1, point2, point3);

    // triangle is in tetrahedron
    TPoint pointA(0.50, 0.50, 0.50);
    TPoint pointB(0.50, 1.50, 0.50);
    TPoint pointC(1.50, 0.50, 0.50);
    TTriangle triangle(pointA, pointB, pointC);

    xprintf(Msg, "Test - triangle is in tetrahedron\n");
    GetIntersection(triangle, tetrahedron, it, area);
    EXPECT_FLOAT_EQ(area, 0.5);

    // triangle is greater than tetrahedron, intersection is triangle
    pointA.SetCoord(-3.0, 2.0, 2.0);
    pointB.SetCoord(2.0, -3.0, 2.0);
    pointC.SetCoord(2.0, 2.0, 2.0);
    triangle.SetPoints(pointA, pointB, pointC);

    xprintf(Msg, "Test - triangle is greater than tetrahedron, intersection is triangle\n");
    GetIntersection(triangle, tetrahedron, it, area);
    EXPECT_FLOAT_EQ(area, 0.5);

    // intersection is tetragon
    pointA.SetCoord(-0.50, 0.50, 1.00);
    pointB.SetCoord(2.00, 0.50, 1.00);
    pointC.SetCoord(2.00, 3.00, 1.00);
    triangle.SetPoints(pointA, pointB, pointC);

    xprintf(Msg, "Test - intersection is tetragon\n");
    GetIntersection(triangle, tetrahedron, it, area);
    EXPECT_FLOAT_EQ(area, 0.875);

    // intersection is pentagon
    pointA.SetCoord(-1.0, 2.00, 1.00);
    pointB.SetCoord(1.50, 2.00, 1.00);
    pointC.SetCoord(1.50,-0.5 , 1.00);
    triangle.SetPoints(pointA, pointB, pointC);

    xprintf(Msg, "Test - intersection is pentagon\n");
    GetIntersection(triangle, tetrahedron, it, area);
    EXPECT_FLOAT_EQ(area, 0.5+0.5+0.5*3.0/4.0);

    // intersection is hexagon (plane parallel to x-y)
    pointA.SetCoord(2.00, 2.00, 0.50);
    pointB.SetCoord(2.00, -1.00, 0.50);
    pointC.SetCoord(-1.00, 2.00, 0.50);
    triangle.SetPoints(pointA, pointB, pointC);

    xprintf(Msg, "Test - intersection is hexagon (plane parallel to x-y)\n");
    GetIntersection(triangle, tetrahedron, it, area);
    EXPECT_FLOAT_EQ(area, 2.375);

    // intersection is hexagon
    pointA.SetCoord(0.25, 2.00, 1.00);
    pointB.SetCoord(2.25, 1.00, -1.00);
    pointC.SetCoord(0.25, -1.00, 3.00);
    triangle.SetPoints(pointA, pointB, pointC);

    xprintf(Msg, "Test - intersection is hexagon\n");
    GetIntersection(triangle, tetrahedron, it, area);
    EXPECT_FLOAT_EQ(area, 3.477919);
}
Exemplo n.º 23
0
void render_scene_func(void) {
	GLfloat i,j;
	GLfloat a[] = {0.0,0.0,0.0};
	GLfloat b[] = {0.0,0.0,0.0};
	GLfloat c[] = {0.0,0.0,0.0};
	GLfloat d[] = {0.0,0.0,0.0};

	GLfloat home_shininess[] = { 0.0 };
	GLfloat home_ambient[]={80.0/255.0,30.0/255.0,5.0/255.0,1.0};
	GLfloat home_diffuse[]={139.0/255.0,69.0/255.0,19.0/255.0,1.0};
	GLfloat home_specular[]={.0,.0,.0,.0};

	GLfloat roof_shininess[] = {100.0};
	GLfloat roof_ambient[]={0.1,0.1,0.1,1.0};
	GLfloat roof_diffuse[]={0.9,0.9,0.9,1.0};
	GLfloat roof_specular[]={1.0,1.0,1.0,1.0};

	GLfloat terrain_shininess[] = {0.0};
	GLfloat terrain_ambient[]={0.,0.2,0.0,1.0};
	GLfloat terrain_diffuse[]={0.2,0.8,0.1,1.0};
	GLfloat terrain_specular[]={.0,.0,.0,.0};

	GLfloat sun_shininess[] = {0.0};
	GLfloat sun_ambient[]={1.0,1.0,.0,1.0};
	GLfloat sun_diffuse[]={1.0,1.0,.0,1.0};
	GLfloat sun_specular[]={.0,.0,.0,.0};
	GLfloat sun_emission[]={.0,.1,.1,1.0};

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	gluLookAt(80.0,80.0,0.0,.0,.0,.0,.0,1.0,0.0);
	glRotatef(theta_camera,.0,1.0,0.0);
	glScalef(2.0,2.0,2.0);
	
	//______________________________   main home  ___________________________________//
   glMaterialfv(GL_FRONT, GL_SPECULAR, home_specular);
   glMaterialfv(GL_FRONT, GL_SHININESS, home_shininess);
   glMaterialfv(GL_FRONT, GL_AMBIENT, home_ambient);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, home_diffuse);
    // front
	glBegin(GL_POLYGON); 
		a[0] = 5.0; a[1] = 5.0; a[2] = 10.0; 
		b[0] = -5.0; b[1] = 5.0; b[2] = 10.0;
		c[0] = -5.0; c[1] = -5.0; c[2] = 10.0;
		cross(a,b,c,d);
		glNormal3fv(d);
		glVertex3f(5.0,5.0,10.0);
		glVertex3f(-5.0,5.0,10.0);
		glVertex3f(-5.0,-5.0,10.0);
		glVertex3f(5.0,-5.0,10.0);
    glEnd();

	// bottom
	glBegin(GL_POLYGON);  
		a[0] = 5.0; a[1] = -5.0; a[2] = 10.0; 
		b[0] = 5.0; b[1] = -5.0; b[2] = -10.0;
		c[0] = -5.0; c[1] = -5.0; c[2] = -10.0;
		cross(a,b,c,d);
		glNormal3fv(d);
        glVertex3f(5.0f, -5.0f,10.0f);
		glVertex3f(5.0f, -5.0f,-10.0f);
		glVertex3f(-5.0f, -5.0f,-10.0f);
		glVertex3f(-5.0f, -5.0f,10.0f);
    glEnd(); 

	// up
	glBegin(GL_POLYGON); 
		a[0] = 5.0; a[1] = 5.0; a[2] = 10.0; 
		b[0] = 5.0; b[1] = 5.0; b[2] = -10.0;
		c[0] = -5.0; c[1] = 5.0; c[2] = -10.0;
		cross(a,b,c,d);
		glNormal3fv(d);
        glVertex3f(5.0,5.0,10.0);
		glVertex3f(5.0,5.0,-10.0);
		glVertex3f(-5.0,5.0,-10.0);
		glVertex3f(-5.0,5.0,10.0);
    glEnd();

	// back
	glBegin(GL_POLYGON);
		a[0] = -5.0; a[1] = -5.0; a[2] = -10.0; 
		b[0] = -5.0; b[1] = 5.0; b[2] = -10.0;
		c[0] = 5.0; c[1] = 5.0; c[2] = -10.0;
		cross(a,b,c,d);
		glNormal3fv(d);
		glVertex3f(-5.0,-5.0,-10.0);
		glVertex3f(-5.0,5.0,-10.0);
		glVertex3f(5.0,5.0,-10.0);
		glVertex3f(5.0,-5.0,-10.0);
    glEnd();

	// left
	glBegin(GL_POLYGON);
        a[0] = -5.0; a[1] = -5.0; a[2] = 10.0; 
		b[0] = -5.0; b[1] = 5.0; b[2] = 10.0;
		c[0] = -5.0; c[1] = 5.0; c[2] = -10.0;
		cross(a,b,c,d);
		glNormal3fv(d);
		glVertex3f(-5.0,-5.0,10.0);
		glVertex3f(-5.0,5.0,10.0);
		glVertex3f(-5.0,5.0,-10.0);
		glVertex3f(-5.0,-5.0,-10.0);
    glEnd();

	// right
	glBegin(GL_POLYGON);
		a[0] = 5.0; a[1] = -5.0; a[2] = 10.0; 
		b[0] = 5.0; b[1] = -5.0; b[2] = -10.0;
		c[0] = 5.0; c[1] = 5.0; c[2] = -10.0;
		cross(a,b,c,d);
		glNormal3fv(d);
        glVertex3f(5.0,-5.0,10.0);
		glVertex3f(5.0,-5.0,-10.0);
		glVertex3f(5.0,5.0,-10.0);
		glVertex3f(5.0,5.0,10.0);	
    glEnd();

	//______________________________   roof  ___________________________________//
	glMaterialfv(GL_FRONT, GL_SPECULAR, roof_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, roof_shininess);
	glMaterialfv(GL_FRONT, GL_AMBIENT, roof_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, roof_diffuse);

	// front roof triangle
	glBegin(GL_POLYGON);
		//glNormal3f(0.0,0.0,1.0);
		a[0] = .0;a[1] = 5.0+10.0*(sqrt(3.0)/2.0); a[2] = 10.0; 
		b[0] = -5.0; b[1] = 5.0; b[2] = 10.0;
		c[0] = 5.0; c[1] = 5.0; c[2] = 10.0; 
		cross(a,b,c,d);
		glNormal3fv(d);
		glVertex3f(.0,5.0+10.0*(sqrt(3.0)/2.0),10.0); // 5+a(sqrt(3)/2) = 13.6602540378444	
		glVertex3f(-5.0,5.0,10.0);
        glVertex3f(5.0,5.0,10.0);	
    glEnd();

	// back roof triangle
	glBegin(GL_POLYGON);
		//glNormal3f(0.0,0.0,-1.0);
		a[0] = 5.0; a[1] = 5.0; a[2] = -10.0; 
		b[0] = -5.0; b[1] = 5.0; b[2] = -10.0;
		c[0] = .0; c[1] = 5.0+10.0*(sqrt(3.0)/2.0); c[2] = -10.0;
		cross(a,b,c,d);
		glNormal3fv(d);
        glVertex3f(5.0,5.0,-10.0);
		glVertex3f(-5.0,5.0,-10.0);
		glVertex3f(.0,5.0+10.0*(sqrt(3.0)/2.0),-10.0); // 5+a(sqrt(3)/2) = 13.6602540378444
		
    glEnd();

	// left roof 
	glBegin(GL_POLYGON);  
		//glNormal3fv(calcNormal(.0,5.0+10.0*(sqrt(3.0)/2.0),10.0,.0,5.0+10.0*(sqrt(3.0)/2.0),-10.0));
		a[0] = .0; a[1] = 5.0+10.0*(sqrt(3.0)/2.0); a[2] = 10.0; 
		b[0] = .0; b[1] = 5.0+10.0*(sqrt(3.0)/2.0); b[2] = -10.0;
		c[0] = -5.0; c[1] = 5.0; c[2] = -10.0;
		cross(a,b,c,d);
		glNormal3fv(d);
        glVertex3f(.0,5.0+10.0*(sqrt(3.0)/2.0),10.0);
		glVertex3f(.0,5.0+10.0*(sqrt(3.0)/2.0),-10.0); // 5+a(sqrt(3)/2) = 13.6602540378444
		glVertex3f(-5.0,5.0,-10.0);
		glVertex3f(-5.0,5.0,10.0);
    glEnd();

	// right roof 
	glBegin(GL_POLYGON);  
		//glNormal3fv(calcNormal(.0,5.0+10.0*(sqrt(3.0)/2.0),10.0,5.0,5.0,10.0));
		a[0] = .0; a[1] = 5.0+10.0*(sqrt(3.0)/2.0); a[2] = 10.0;
		b[0] = 5.0; b[1] = 5.0; b[2] = 10.0;
		c[0] = 5.0; c[1] = 5.0; c[2] = -10.0;
		cross(a,b,c,d);
		glNormal3fv(d);
        glVertex3f(.0,5.0+10.0*(sqrt(3.0)/2.0),10.0);
		glVertex3f(5.0,5.0,10.0);
		glVertex3f(5.0,5.0,-10.0);
		glVertex3f(.0,5.0+10.0*(sqrt(3.0)/2.0),-10.0); // 5+a(sqrt(3)/2) = 13.6602540378444
    glEnd();

	//______________________________   terrain  ___________________________________//
	glMaterialfv(GL_FRONT, GL_SPECULAR, terrain_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, terrain_shininess);
	glMaterialfv(GL_FRONT, GL_AMBIENT, terrain_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, terrain_diffuse);
	/*
	glBegin(GL_POLYGON);  
		glNormal3fv(calcNormal(50.0,-5.0,50.0,-50.0,-5.0,50.0));
        glVertex3f(50.0,-5.0,50.0);
		glVertex3f(-50.0,-5.0,50.0);
		glVertex3f(-50.0,-5.0,-50.0);
		glVertex3f(50.0,-5.0,-50.0); 
    glEnd();
	*/
	///*
	i = -50.0;j = -50.0;
	while (i<=0.0){
		j = -50.0;
		while (j<=0.0) {
			glBegin(GL_POLYGON);  
				//glNormal3fv(calcNormal(i,-5.0,j,i+10.0,-5.0,j));
				//glNormal3f(0.0,1.0,0.0);
				c[0] = i; c[1] = -5.0; c[2] = j; 
				b[0] = i+10.0; b[1] = -5.0; b[2] = j;
				a[0] = i+10.0; a[1] = -5.0; a[2] = j+10.0;
				cross(a,b,c,d);
				glNormal3fv(d);
				glVertex3f(i,-5.0,j);
				glVertex3f(i+10.0,-5.0,j);
				glVertex3f(i+10.0,-5.0,j+10.0);
				glVertex3f(i,-5.0,j+10.0); 
			glEnd();
			j += 10.0;
		}
		i += 10.0;
	}
	i = 0.0;j = 0.0;
	while (i<=50.0){
		j = 0.0;
		while (j<=50.0) {
			glBegin(GL_POLYGON);  
				//glNormal3f(0.0,1.0,0.0);
				c[0] = i; c[1] = -5.0; c[2] = j; 
				b[0] = i+10.0; b[1] = -5.0; b[2] = j;
				a[0] = i+10.0; a[1] = -5.0; a[2] = j+10.0;
				cross(a,b,c,d);
				glNormal3fv(d);
				glVertex3f(i,-5.0,j);
				glVertex3f(i+10.0,-5.0,j);
				glVertex3f(i+10.0,-5.0,j+10.0);
				glVertex3f(i,-5.0,j+10.0); 
			glEnd();
			j += 10.0;
		}
		i += 10.0;
	}
	i = 0.0;j = -50.0;
	while (i<=50.0){
		j = -50.0;
		while (j<=0.0) {
			glBegin(GL_POLYGON);  
				//glNormal3f(0.0,1.0,0.0);
				c[0] = i; c[1] = -5.0; c[2] = j; 
				b[0] = i+10.0; b[1] = -5.0; b[2] = j;
				a[0] = i+10.0; a[1] = -5.0; a[2] = j+10.0;
				cross(a,b,c,d);
				glNormal3fv(d);
				glVertex3f(i,-5.0,j);
				glVertex3f(i+10.0,-5.0,j);
				glVertex3f(i+10.0,-5.0,j+10.0);
				glVertex3f(i,-5.0,j+10.0); 
			glEnd();
			j += 10.0;
		}
		i += 10.0;
	}
	i = -50.0;j = 0.0;
	while (i<=0.0){
		j = 0.0;
		while (j<=50.0) {
			glBegin(GL_POLYGON);  
				//glNormal3f(0.0,1.0,0.0);
				c[0] = i; c[1] = -5.0; c[2] = j; 
				b[0] = i+10.0; b[1] = -5.0; b[2] = j;
				a[0] = i+10.0; a[1] = -5.0; a[2] = j+10.0;
				cross(a,b,c,d);
				glNormal3fv(d);
				glVertex3f(i,-5.0,j);
				glVertex3f(i+10.0,-5.0,j);
				glVertex3f(i+10.0,-5.0,j+10.0);
				glVertex3f(i,-5.0,j+10.0); 
			glEnd();
			j += 10.0;
		}
		i += 10.0;
	}
	//______________________________   sun ___________________________________//

	glMaterialfv(GL_FRONT, GL_SPECULAR, sun_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, sun_shininess);
	glMaterialfv(GL_FRONT, GL_AMBIENT, sun_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, sun_diffuse);
	glMaterialfv(GL_FRONT, GL_EMISSION, sun_emission);
		
	// spinning

	// rotate light source
	glRotatef(theta_sun,0.0,0.0,1.0);
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);

	// rotate sun object
	glTranslatef(-50.0,0.0,0.0);
	glScalef(4.0,4.0,4.0);
	tetrahedron(n);

	glutSwapBuffers();
}
Exemplo n.º 24
0
void init()
{
	GLfloat skyboxVertices[] = {
        // Positions          
        -1.0f, 1.0f, -1.0f,
        -1.0f, -1.0f, -1.0f,
        1.0f, -1.0f, -1.0f,
        1.0f, -1.0f, -1.0f,
        1.0f, 1.0f, -1.0f,
        -1.0f, 1.0f, -1.0f,

        -1.0f, -1.0f, 1.0f,
        -1.0f, -1.0f, -1.0f,
        -1.0f, 1.0f, -1.0f,
        -1.0f, 1.0f, -1.0f,
        -1.0f, 1.0f, 1.0f,
        -1.0f, -1.0f, 1.0f,

        1.0f, -1.0f, -1.0f,
        1.0f, -1.0f, 1.0f,
        1.0f, 1.0f, 1.0f,
        1.0f, 1.0f, 1.0f,
        1.0f, 1.0f, -1.0f,
        1.0f, -1.0f, -1.0f,

        -1.0f, -1.0f, 1.0f,
        -1.0f, 1.0f, 1.0f,
        1.0f, 1.0f, 1.0f,
        1.0f, 1.0f, 1.0f,
        1.0f, -1.0f, 1.0f,
        -1.0f, -1.0f, 1.0f,

        -1.0f, 1.0f, -1.0f,
        1.0f, 1.0f, -1.0f,
        1.0f, 1.0f, 1.0f,
        1.0f, 1.0f, 1.0f,
        -1.0f, 1.0f, 1.0f,
        -1.0f, 1.0f, -1.0f,

        -1.0f, -1.0f, -1.0f,
        -1.0f, -1.0f, 1.0f,
        1.0f, -1.0f, -1.0f,
        1.0f, -1.0f, -1.0f,
        -1.0f, -1.0f, 1.0f,
        1.0f, -1.0f, 1.0f
    };  

	planet = tetrahedron(5);
	object = ObjLoadModel("include/obj/torus.obj");

	vec3 tangent[planet.vertexNumber];
	vec3 bitangent[planet.vertexNumber];
	*tangent = *generateTangents(planet.vertexNumber, planet.points, tangent, bitangent);
	
	vec3 vna[planet.vertexNumber];
	*vna = *generateSmoothNormals(planet.vertexNumber, vna, planet.points, planet.normals);
	
	createShader(&skyboxShader, "src/shaders/skybox.vert",
		"src/shaders/skybox.frag");
	createShader(&sunShader, "src/shaders/sun.vert",
		"src/shaders/sun.frag");
	createShader(&planetShader, "src/shaders/planet.vert",
		"src/shaders/planet.frag");
		
	createShader(&atmosphereShader, "src/shaders/atmosphere.vert",
		"src/shaders/atmosphere.frag");
    
    
    glGenFramebuffers(1, &hdrFBO);
    glGenTextures(1, &colorBuffer);
    glBindTexture(GL_TEXTURE_2D, colorBuffer);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, WIDTH, HEIGHT, 0, GL_RGB, GL_FLOAT, NULL);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    
    glGenRenderbuffers(1, &rboDepth);
    glBindRenderbuffer(GL_RENDERBUFFER, rboDepth);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, WIDTH, HEIGHT);
    
    glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorBuffer, 0);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboDepth);
    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
        printf("Framebuffer not complete!\n");
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

	glGenVertexArrays(1, &planetVAO);
	glBindVertexArray(planetVAO);
	glGenBuffers(1, &planetVBO);
	glBindBuffer(GL_ARRAY_BUFFER, planetVBO);
	glBufferData(GL_ARRAY_BUFFER, planet.size + planet.nsize, NULL, GL_STATIC_DRAW);
	glBufferSubData(GL_ARRAY_BUFFER, 0, planet.size, planet.points);
	glBufferSubData(GL_ARRAY_BUFFER, planet.size, planet.nsize, vna);
	
	glBufferSubData(GL_ARRAY_BUFFER, planet.size+planet.nsize, sizeof(tangent), tangent);
	glBufferSubData(GL_ARRAY_BUFFER, planet.size+planet.nsize+sizeof(tangent), sizeof(tangent), tangent);
	
	vPosition = glGetAttribLocation(planetShader, "vPosition");
    glEnableVertexAttribArray(vPosition);
    glVertexAttribPointer(vPosition, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), BUFFER_OFFSET(0));	
    vNormal = glGetAttribLocation(planetShader, "vNormal");
    glEnableVertexAttribArray(vNormal);
    glVertexAttribPointer(vNormal, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), BUFFER_OFFSET(planet.size));
    
    vTangent = glGetAttribLocation(planetShader, "vTangent");
    glEnableVertexAttribArray(vTangent);
    glVertexAttribPointer(vTangent, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), BUFFER_OFFSET(planet.size+planet.nsize));
    
    vBitangent = glGetAttribLocation(planetShader, "vBitangent");
    glEnableVertexAttribArray(vBitangent);
    glVertexAttribPointer(vBitangent, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), BUFFER_OFFSET(planet.size+planet.nsize+sizeof(tangent)));
    
	glBindVertexArray(0);
	
	glGenVertexArrays(1, &skyboxVAO);
	glBindVertexArray(skyboxVAO);
    glGenBuffers(1, &skyboxVBO);
    glBindBuffer(GL_ARRAY_BUFFER, skyboxVBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(skyboxVertices), skyboxVertices, GL_STATIC_DRAW);
    vPosition = glGetAttribLocation(skyboxShader, "vPosition");
    glEnableVertexAttribArray(vPosition);
    glVertexAttribPointer(vPosition, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
    glBindVertexArray(0);
    
    glGenVertexArrays(1, &objectVAO);
	glBindVertexArray(objectVAO);
	glGenBuffers(1, &objectVBO);
	glBindBuffer(GL_ARRAY_BUFFER, objectVBO);
	glBufferData(GL_ARRAY_BUFFER, object.size + object.nsize, NULL, GL_STATIC_DRAW);
	glBufferSubData(GL_ARRAY_BUFFER, 0, object.size, object.points);
	glBufferSubData(GL_ARRAY_BUFFER, object.size, object.nsize, object.normals);
	vPosition = glGetAttribLocation(sunShader, "vPosition");
    glEnableVertexAttribArray(vPosition);
    glVertexAttribPointer(vPosition, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), BUFFER_OFFSET(0));	
    
    vNormal = glGetAttribLocation(sunShader, "vNormal");
    glEnableVertexAttribArray(vNormal);
    glVertexAttribPointer(vNormal, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), BUFFER_OFFSET(object.size));
	glBindVertexArray(0);
	
	glGenVertexArrays(1, &atmosphereVAO);
	glBindVertexArray(atmosphereVAO);
	glGenBuffers(1, &atmosphereVBO);
	glBindBuffer(GL_ARRAY_BUFFER, atmosphereVBO);
	glBufferData(GL_ARRAY_BUFFER, planet.size + planet.nsize, NULL, GL_STATIC_DRAW);
	glBufferSubData(GL_ARRAY_BUFFER, 0, planet.size, planet.points);
	glBufferSubData(GL_ARRAY_BUFFER, planet.size, planet.nsize, planet.normals);
	vPosition = glGetAttribLocation(atmosphereShader, "vPosition");
    glEnableVertexAttribArray(vPosition);
    glVertexAttribPointer(vPosition, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), BUFFER_OFFSET(0));	
    
    vNormal = glGetAttribLocation(atmosphereShader, "vNormal");
    glEnableVertexAttribArray(vNormal);
    glVertexAttribPointer(vNormal, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), BUFFER_OFFSET(planet.size));
	glBindVertexArray(0);
	
    glEnable(GL_DEPTH_TEST);
}
 inline
 Triangle3d
 TetrahedronFaces::operator[](std::size_t index) const {
     return tetrahedron().face(int(index));
 }