from math import *
from util import *
from constants import *

texWidth = SWIDTH * 1.0/maxTexSize
texHeight = SHEIGHT * 1.0/maxTexSize

class PointLight:
    def __init__(self, origin, size=100, color=[1,1,1,1]):
        self.origin = origin
        self.size = size
        self.color = color
        if len(self.color) != 4:
            self.color.append(1)
            
        self.verts = [ [self.origin[0] - self.size, self.origin[1]], 
                  [self.origin[0] - self.size, self.origin[1] + self.size], 
                  [self.origin[0], self.origin[1] + self.size], 
                  [self.origin[0], self.origin[1]]]
        self.texts = []
        for x,y in self.verts:
             self.texts.append( ( 1.0 * x / SWIDTH*texWidth, (1.0 - 1.0 * y / SHEIGHT)*texHeight ) )
             
        # Holy hack batman.
        self.colors = []
        for i in range(4):
            tmp = []
            for v in self.color:
               tmp.append(v)
            self.colors.append(tmp)

        self.colors[0][3] = 0
        self.colors[1][3] = 0
        self.colors[2][3] = 1
	self.colors[3][3] = 0

        print self.verts
        #print self.texts
        #print self.colors

    def drawQuad(self, verts, texts, colors):
	glBegin(GL_QUADS)
	glColor4fv(colors[0]);
	glTexCoord2f(texts[0][0], texts[0][1] ); glVertex2f(verts[0][0], verts[0][1])    # Bottom Left Of The Texture and Quad
	glColor4fv(colors[1]);
	glTexCoord2f(texts[1][0], texts[1][1] ); glVertex2f(verts[1][0], verts[1][1])    # Bottom Right Of The Texture and Quad
	glColor4fv(colors[2]);
	glTexCoord2f(texts[2][0], texts[2][1] ); glVertex2f(verts[2][0], verts[2][1])    # Top Right Of The Texture and Quad
	glColor4fv(colors[3]);
	glTexCoord2f(texts[3][0], texts[3][1] ); glVertex2f(verts[3][0], verts[3][1])    # Top Left Of The Texture and Quad
        glEnd()
            
    def draw(self, bgtex):

        setTex(bgtex)    
        glLoadIdentity()
        
        self.drawQuad(self.verts, self.texts, self.colors)
        
