// // ============================================================ // // Light // // ============================================================ // // // Copyright (C) 1997 // // Professor Kenneth I. Joy // Computer Science Department // University of California // Davis, CA 95616 // // Permission is granted to use at your own risk and // distribute this software in source and binary forms // provided the above copyright notice and this paragraph // are preserved on all copies. This software is provided // "as is" with no express or implied warranty. // // // ============================================================ // #include #include #include #include #include #include "Light.h" #define TRUE 1 #define FALSE 0 /* ========================================================== CONSTRUCTORS, DESTRUCTOR ========================================================== */ Light :: Light () {} Light :: Light ( const Point& location, const Color& diffuse ) { _position = location ; _diffuse = diffuse ; } Light :: Light ( const Light& c ) { _position = c._position ; _diffuse = c._diffuse ; } Light :: ~Light () { } /* ========================================================== OPERATOR= ========================================================== */ Light& Light :: operator= ( const Light& c ) { if ( this == &c ) return ( *this ) ; _position = c._position ; _diffuse = c._diffuse ; return ( *this ) ; } /* ========================================================== OUTPUT ========================================================== */ ostream& operator<< ( ostream& co, const Light& c ) { return c.output( co ) ; } /* ========================================================== OUTPUT ========================================================== */ ostream& Light :: output ( ostream& co ) const { co << "Light ( " << _position << ", " << _diffuse << " )" << endl ; return ( co ) ; } /* ========================================================== GL Setup Stuff ========================================================== */ void Light :: GL () const { GLfloat array[4] ; array[0] = 0.0 ; array[1] = 0.0 ; array[2] = 0.0 ; array[3] = 1.0 ; glLightfv ( GL_LIGHT0, GL_AMBIENT, array ) ; array[0] = GLfloat ( _position.x() ) ; array[1] = GLfloat ( _position.y() ) ; array[2] = GLfloat ( _position.z() ) ; array[3] = 1.0 ; glLightfv ( GL_LIGHT0, GL_POSITION, array ) ; array[0] = GLfloat ( _diffuse.red() ) ; array[1] = GLfloat ( _diffuse.green() ) ; array[2] = GLfloat ( _diffuse.blue() ) ; array[3] = 1.0 ; glLightfv ( GL_LIGHT0, GL_DIFFUSE, array ) ; //array[0] = 1.0 ; //array[1] = 1.0 ; //array[2] = 1.0 ; //array[3] = 1.0 ; glLightfv ( GL_LIGHT0, GL_SPECULAR, array ) ; }