""" pygl/Light.py: CCP4MG Molecular Graphics Program Copyright (C) 2001-2008 University of York, CCLRC Copyright (C) 2009-2010 University of York Copyright (C) 2012 STFC This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3, modified in accordance with the provisions of the license to address the requirements of UK law. You should have received a copy of the modified GNU Lesser General Public License along with this library. If not, copies may be downloaded from http://www.ccp4.ac.uk/ccp4license.php This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. """ class Light: def __init__(self,id,position=(0.0, 0.0, 0.0),ambient=(0.1, 0.1, 0.1),specular=(0.4, 0.4, 0.4),diffuse=(1.0, 1.0, 1.0)): self.position = position self.ambient = ambient self.specular = specular self.diffuse = diffuse self.id = id; self.on = 0 def __str__(self): return "" def turn_on(self): self.on = 1 def turn_off(self): self.on = 0 def apply(self): import opengl opengl.glEnable(opengl.GL_LIGHTING); opengl.glEnable(self.id); light_position = opengl.newfv4(self.position[0], self.position[1], self.position[2], 0.0) light_ambient = opengl.newfv4(self.ambient[0], self.ambient[1], self.ambient[2], 1.0) light_diffuse = opengl.newfv4(self.diffuse[0], self.diffuse[1], self.diffuse[2], 1.0) light_specular = opengl.newfv4(self.specular[0], self.specular[1], self.specular[2], 1.0) opengl.glLightfv(self.id, opengl.GL_POSITION, light_position); opengl.glLightfv(self.id, opengl.GL_AMBIENT, light_ambient); opengl.glLightfv(self.id, opengl.GL_DIFFUSE, light_diffuse); opengl.glLightfv(self.id, opengl.GL_SPECULAR, light_specular); opengl.delcGLfp(light_position) opengl.delcGLfp(light_ambient) opengl.delcGLfp(light_diffuse) opengl.delcGLfp(light_specular) if self.on == 0: opengl.glDisable(self.id); def copy(self): light = Light() light.position[0] = self.position[0] light.position[1] = self.position[1] light.position[2] = self.position[2] light.ambient[0] = self.ambient[0] light.ambient[1] = self.ambient[1] light.ambient[2] = self.ambient[2] light.diffuse[0] = self.diffuse[0] light.diffuse[1] = self.diffuse[1] light.diffuse[2] = self.diffuse[2] light.specular[0] = self.specular[0] light.specular[1] = self.specular[1] light.specular[2] = self.specular[2] return light