/* * Exam.c * 4-4-2005_Surfaces_and_TestExam * * Created by Simone Portuesi on 02/04/06. * Copyright 2006 __MyCompanyName__. All rights reserved. * */ /* Template file di esame, riempire con lo svolgimento dell'esame */ /* Include GL, GLU & GLUT */ #ifdef WIN32 #include #include #include #include #endif #ifdef __APPLE__ #include #include #include #endif #ifdef linux #include #include #include #endif /* Include some standard stuff */ #include #include #include /* Include my files */ #include "main.h" #include "utility.h" #include "Bezier.h" #include "ProfileRotate.h" /* Disegna un triangolo dello scafo */ void q_scafo() { /* Punti per il triangolo */ GLfloat points[][3] = { { 0, 0, 0.25}, { 1, 0, 0}, { 0, -0.25, 0} }; /* Valori necessari per il calcolo della normale */ GLfloat v1[3],v2[3],normal[3]; GLfloat norm; /* Calcolo Normale */ VECT_OP_VECT(v1,-,points[0],points[1]); VECT_OP_VECT(v2,-,points[2],points[1]); CROSSPROD(normal,v1,v2); norm=NORM_VECT(normal); VECT_OP_SCAL(normal,/,normal,norm); /* Disegna triangolo */ glBegin(GL_TRIANGLES); glNormal3fv(normal); glVertex3fv(points[0]); glVertex3fv(points[1]); glVertex3fv(points[2]); glEnd(); } /* Disegna scafo usando triangolo e simmetria */ void scafo() { glPushMatrix(); q_scafo(); glScalef(1,1,-1); q_scafo(); glScalef(-1,1,1); q_scafo(); glScalef(1,1,-1); q_scafo(); glPopMatrix(); } /* Disegna albero per rotazione polilinea */ void albero() { GLfloat profile[][2] = { {0 , 1 }, {0.01, 0.95 }, {0.01, -0.25 } }; int n_profile=3; rotateprofile(profile,n_profile,8); } /* Disegna vela */ void vela() { GLdouble vela[][4] = { { 0, 1, -0.5, 1 }, { 0.5, 1, 0, 1 }, { 0, 1, 0.5, 1 }, { 0.5, 0.6, -0.5, 1 }, { 1, 0.6, 0, 1 }, { 0.5, 0.6, 0.5, 1 }, { 0, 0.2, -0.5, 1 }, { 0.5, 0.2, 0, 1 }, { 0, 0.2, 0.5, 1 } }; BezierSurface(vela, 3, 3, 16); } /* Materiale simile legno, marrone diffuso e ambient, no specular */ void marrone_legno() { GLfloat mat_specular[] = { 0, 0, 0, 1.0 }; GLfloat mat_ambient_diffuse[] = { 0.4, 0.2, 0, 1.0 }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_ambient_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0); } /* Materiale simile metallo, grigio blue diffuso e specular, griggio scuro di ambient */ void grigio_metallo() { GLfloat mat_ambient[] = { 0.1, 0.1, 0.1, 1.0 }; GLfloat mat_specular_diffuse[] = { 0.3, 0.3, 0.5, 1.0 }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular_diffuse); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50.0); } /* Materiale tipo plastica rosso fiamante, rosso diffuso, bianco speculare, rosso scuro ambient */ void rosso_fiammante() { GLfloat mat_ambient[] = { 0.4, 0, 0, 1.0 }; GLfloat mat_specular[] = { 0.6, 0.6, 0.6, 1.0 }; GLfloat mat_diffuse[] = { 1, 0, 0, 1.0 }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20.0); } void barca() { glPushMatrix(); /* Scafo con colore */ marrone_legno(); scafo(); /* Albero con colore */ grigio_metallo(); albero(); /* Vela ruotate di 30 gradi con colore */ glRotatef(30,0,1,0); rosso_fiammante(); vela(); glPopMatrix(); } void init_model() { /* Set up light */ GLfloat light_position[] = { 1.0, 1.0, 1.0, 0 }; GLfloat light_ambient[] = { 0.8, 0.8, 1.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 1.0, 0.7, 1.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); } void display_model() { /* Fiat lux */ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); /* Draw model */ barca(); /* Disable light */ glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); } void keyboard_model(unsigned char key, int x, int y) { }