Beispiel #1
0
void myTable::draw() {
	myUnitCube p1, p2, p3, p4, t;
	tableAppearance *texture = new tableAppearance();
	// Coefficients for material of feets
	float amb1[3] = { 0.11875, 0.11875, 0.11875 };
	float dif1[3] = { 0.11875, 0.11875, 0.11875 };
	float spec1[3] = { 0.93, 0.93, 0.93 };
	float shininess1 = 12.f;
	CGFappearance *materialF = new CGFappearance(amb1, dif1, spec1, shininess1);
	materialF->apply();
	glPushMatrix();
	glPushMatrix();
	glTranslated(-2, 1.75, -1);
	glScaled(0.3, 3.5, 0.3);
	p1.draw();
	glPopMatrix();

	glPushMatrix();
	glTranslated(-2, 1.75, 1);
	glScaled(0.3, 3.5, 0.3);
	p2.draw();
	glPopMatrix();

	glPushMatrix();
	glTranslated(2, 1.75, 1);
	glScaled(0.3, 3.5, 0.3);
	p3.draw();
	glPopMatrix();

	glPushMatrix();
	glTranslated(2, 1.75, -1);
	glScaled(0.3, 3.5, 0.3);
	p4.draw();
	glPopMatrix();
	glPopMatrix();

	glPushMatrix();
	texture->apply();
	glPushMatrix();
	glTranslated(0, 3.5, 0);
	glScaled(5, 0.3, 3);
	t.draw();
	glPopMatrix();

	glPopMatrix();

}
Beispiel #2
0
void CylinderSlice::drawBase(float yAxis) {
    float angle = 360.0f / _slices;
    
    float last_angle = 0.0f;
    
    glPushMatrix();
    
    if (_isClockBase) {
        float amb[3] = {1, 1, 1};
        float dif[3] = {1, 1, 1};
        float spec[3] = {1, 1, 1};
        float shininess = 10.0f;
        
        CGFappearance *clockAppearance = new CGFappearance(amb, dif, spec, shininess);
        clockAppearance->setTexture("clock.png");
        
        clockAppearance->apply();
    }
    
    if (yAxis) {
        glTranslated(0, yAxis, 0);
        
        glRotated(180, 0.0f, 0.0f, 1.0f);
        
        if (_smooth)
            glNormal3f(0, 1, 0);
    } else if (_smooth)
        glNormal3f(0, -1, 0);
    
    /*glBegin(GL_POLYGON);
    
    crd first_crd;
    
    first_crd.x = -0.5f / _slices;
    first_crd.y = 0.0f;
    first_crd.z = 0.5f / _slices;
    
	glTexCoord2d((cos(_slices-1 * deg2rad) +1) / 2,
		(sin(_slices-1 * deg2rad) +1) / 2);
    
    glVertex3f(first_crd.x, first_crd.y, first_crd.z);
    
    _vertices.push_back(first_crd);
    
    crd second_crd;
    
    second_crd.x = 0.5f / _slices;
    second_crd.y = 0.0f;
    second_crd.z = 0.5f / _slices;
    
	glTexCoord2d((cos(_slices-2 * deg2rad) +1) / 2,
		(sin(_slices-2 * deg2rad) +1) / 2);
    
    glVertex3f(second_crd.x, second_crd.y, second_crd.z);
    
    _vertices.push_back(second_crd);
    
    crd last_crd;
    
    last_crd.x = 0.5f / _slices;
    last_crd.y = 0.0f;
    last_crd.z = 0.5f / _slices;
    
    for (int i = 0; i < _slices - 2; i++) {
        last_crd.x += cosf(deg2rad * (angle + last_angle)) / _slices;
        last_crd.z += sinf(deg2rad * (angle + last_angle)) / _slices;
        
        last_angle += angle;
        
        _vertices.push_back(last_crd);
        
       // glTexCoord2d(last_crd.x, last_crd.z);
		 glTexCoord2d((cos(i * deg2rad) +1) / 2,
				(sin(i * deg2rad) +1) / 2);
        glVertex3f(last_crd.x, last_crd.y, last_crd.z);
    }
    
    glEnd();*/
	glBegin(GL_TRIANGLE_FAN);
	glNormal3f(0, 1, 0);
	glTexCoord2f(0.5, 0.5);
	glVertex3f(0, 0, 0);
	for (int i =0; i<=_slices;i++) {	
		glTexCoord2f((cos(angle*i)+1)/2,(sin(angle*i)+1)/2);
		glVertex3f(cos(angle*i), 0, sin(angle*i));
	}
	glEnd();

	glBegin(GL_TRIANGLE_FAN);
	glNormal3f(0, -1, 0);
	glVertex3f(0, 1, 0);
	for (int i =0; i<=_slices;i++) {
		glVertex3f(cos(-angle*i), 1, sin(-angle*i));
	}
	glEnd();

    
    glPopMatrix();
}
Beispiel #3
0
void LightingScene::display() {

	// ---- BEGIN Background, camera and axis setup

	// Clear image and depth buffer everytime we update the scene
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Initialize Model-View matrix as identity (no transformation
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// Apply transformations corresponding to the camera position relative to the origin
	CGFscene::activeCamera->applyView();

	// Draw axis
	axis.draw();
	light0->draw();
	light1->draw();

	// ---- END Background, camera and axis setup

	// ---- BEGIN Primitive drawing section
	// ---- BEGIN Primitive drawing section

	//First Table
	glPushMatrix();
	glTranslated(5, 0, 8);
	table->draw();
	glPopMatrix();

	//Second Table
	glPushMatrix();
	glTranslated(12, 0, 8);
	table->draw();
	glPopMatrix();

	//Floor
	// Coefficients for material
	float amb[3] = { 0, 0, 0.3984 };
	float dif[3] = { 0, 0, 0.3984 };
	float spec[3] = { 0, 0, 0.1 };
	float shininess = 12.f;
	CGFappearance *materialF = new CGFappearance(amb, dif, spec, shininess);
	glPushMatrix();
	materialF->apply();
	glTranslated(7.5, 0, 7.5);
	glScaled(15, 0.2, 15);
	wall->draw();
	glPopMatrix();

	//LeftWall
	float amb1[3] = { 0.3984, 0, 0 };
	float dif1[3] = { 0.3984, 0, 0 };
	float spec1[3] = { 0.20, 0, 0 };
	float shininess1 = 12.f;
	CGFappearance *materialLw = new CGFappearance(amb1, dif1, spec1,
			shininess1);

	glPushMatrix();
	materialLw->apply();
	glTranslated(0, 4, 7.5);
	glRotated(-90.0, 0, 0, 1);

	glScaled(8, 0.2, 15);
	wall->draw();
	glPopMatrix();

	//PlaneWall
	glPushMatrix();
	glTranslated(7.5, 4, 0);
	glRotated(90.0, 1, 0, 0);
	glScaled(15, 0.2, 8);
	wall->draw();
	glPopMatrix();

	// Board A
	glPushMatrix();
	glTranslated(4, 4, 0.2);
	glScaled(BOARD_WIDTH, BOARD_HEIGHT, 1);
	glRotated(90.0, 1, 0, 0);
	slidesTexture->apply();
	boardA->draw();
	glPopMatrix();

	//PlaneB
	glPushMatrix();
	glTranslated(10.5, 4, 0.2);
	glScaled(BOARD_WIDTH, BOARD_HEIGHT, 1);
	glRotated(90.0, 1, 0, 0);
	boardTexture->apply();
	boardB->draw();
	glPopMatrix();

	//roof
	glPushMatrix();
	glTranslated(0, 8, 0);
	glNormal3f(0,-1,0);
	glBegin(GL_QUADS);
		glVertex3f(0,0,0);
		glVertex3f(15,0,0);
		glVertex3f(15,0,15);
		glVertex3f(0,0,15);
	glEnd();
	glPopMatrix();

	// lamp in the roof
	glRotated(180,1,0,0);
	glTranslated(7.5, -8, -7.5);
	myLamp *lamp = new myLamp(20, 1);

	lamp->draw();
	// ---- END Primitive drawing section

	// We have been drawing in a memory area that is not visible - the back buffer, 
	// while the graphics card is showing the contents of another buffer - the front buffer
	// glutSwapBuffers() will swap pointers so that the back buffer becomes the front buffer and vice-versa
	glutSwapBuffers();
}
void MyTable::draw(){ 
	float ambWood[3] ={0.38, 0.2, 0.0196};
	float difWood[3] = {0.38, 0.2, 0.0196};
	float specWood[3] = {0.05, 0.05, 0.05};
	float shininessWood = 10.f;
	CGFappearance * wood = new CGFappearance(ambWood,difWood,specWood,shininessWood);

	float ambMetal[3] = {0.3, 0.3, 0.3};
	float difMetal[3] = {0.4, 0.4, 0.4};
	float specMetal[3] = {0.6, 0.6, 0.6};
	float shininessMetal = 500.f;
	CGFappearance * metal = new CGFappearance(ambMetal,difMetal,specMetal,shininessMetal);



	MyUnitCube myUnitCube = MyUnitCube();
	
	glPushMatrix();
		glRotated(rPN*zTrans*30,0,1,0);
		glTranslatef(xTrans,0,zTrans);
		glPushMatrix();  // top
			glTranslatef(0, 0.15 + 3.5,0);
			glScalef(5,0.3,3);
			wood->apply();

			myUnitCube.draw();
		glPopMatrix();

	metal->apply();
	
	glPushMatrix(); // legs
		glTranslatef(0, 1.75,0);

		glPushMatrix();
			glTranslatef(-2.5 + 0.15, 0, -1.5 + 0.15);
			glScalef(0.3,3.5,0.3);
			myUnitCube.draw();
		glPopMatrix();

		glPushMatrix();
			glTranslatef(2.5 - 0.15, 0, -1.5 + 0.15);
			glScalef(0.3,3.5,0.3);
			myUnitCube.draw();
		glPopMatrix();

		glPushMatrix();
			glTranslatef(-2.5 + 0.15, 0, 1.5 - 0.15);
			glScalef(0.3,3.5,0.3);
			myUnitCube.draw();
		glPopMatrix();

		glPushMatrix();
			glTranslatef(2.5 - 0.15, 0, 1.5 - 0.15);
			glScalef(0.3,3.5,0.3);
			myUnitCube.draw();
		glPopMatrix();

	glPopMatrix();

	glPopMatrix();
}