// // Computergraphik II // Prof. Dr. Juergen Doellner // Wintersemester 2001/02 // // Rahmenprogramm zu Aufgabenzettel 5 // #include "cgwave.h" #include "vector.h" #include #include #ifndef PI const double PI = 3.14159265358979323846; #endif CGWave::CGWave() { run_ = false; culling_ = false; showNormals_ = false; periodAnim_ = false; lightAnim_ = false; zoom_ = 1.5; periode_=0; list_ = NULL; rot_ = 180.0; buildPatch(40); } CGWave::~CGWave() { } static GLfloat light_position1[] = {0.0, 1.0, 0.0, 1.0}; /* Point light location. */ void CGWave::drawScene() { glPushMatrix(); glRotatef(60,1,0,0); glScaled(zoom_, zoom_, zoom_); glLightfv(GL_LIGHT1, GL_POSITION, light_position1); drawObject(); // Positionieren bzw. Animieren der Lichtquelle 1 // draw light source (yellow !) glPushMatrix(); glDisable(GL_LIGHTING); // draw vector from light source glColor4f(1, 1, 0, 0.5); glBegin(GL_LINES); glVertex3f(light_position1[0], light_position1[1], light_position1[2]); glVertex3f(light_position1[0], 0, light_position1[2]); glEnd(); // translate sphere that represents our light source glTranslatef(light_position1[0], light_position1[1], light_position1[2]); glutSolidSphere(0.03,10,10); glEnable(GL_LIGHTING); glPopMatrix(); glPopMatrix(); } Vector CGWave::WavedNormal(const Vector& v) const { // get distance, stretch wave length double distance = abs(v)*20; // add periode shift distance += periode_; // normalize to [0,2*PI[ // while (distance >= 2*PI) // distance -= 2*PI; // normalize point vector const Vector v_norm = v.normalized(); const double cos_dist = cos(distance); const double nx = v_norm[0]*cos_dist; const double ny = 1; // alternative: sin(distance); const double nz = v_norm[2]*cos_dist; return Vector(nx, ny, nz).normalized(); } void CGWave::handleVertex(const Vector& v) const { // compute normal according to wave functions glNormal3dv(WavedNormal(v).rep()); // send vertex glVertex3dv(v.rep()); } void CGWave::drawObject() { // draw geometry int c=0; for(int j=0; j