def RenderFlareTexture(self, tex_ID, r, g, b, a, p, scale): # bleair: Duplicate functions all the same except for the texture to bind to. q = [] q.append(glPoint()) q.append(glPoint()) q.append(glPoint()) q.append(glPoint()) # Basically we are just going to make a 2D box # from four points we don't need a z coord because # we are rotating the camera by the inverse so the # texture mapped quads will always face us. # Set the x coordinate -scale units from the center point. q[0].x = (p.x - scale) # Set the y coordinate -scale units from the center point. q[0].y = (p.y - scale) # Set the x coordinate -scale units from the center point. q[1].x = (p.x - scale) # Set the y coordinate scale units from the center point. q[1].y = (p.y + scale) # Set the x coordinate scale units from the center point. q[2].x = (p.x + scale) # Set the y coordinate -scale units from the center point. q[2].y = (p.y - scale) # Set the x coordinate scale units from the center point. q[3].x = (p.x + scale) # Set the y coordinate scale units from the center point. q[3].y = (p.y + scale) # Save the model view matrix glPushMatrix() # Translate to our point glTranslatef(p.x, p.y, p.z) glRotatef(-self.m_HeadingDegrees, 0.0, 1.0, 0.0) glRotatef(-self.m_PitchDegrees, 1.0, 0.0, 0.0) # Bind to the Big Glow texture glBindTexture(GL_TEXTURE_2D, tex_ID) # Set the color since the texture is a gray scale glColor4f(r, g, b, a) # Draw the Big Glow on a Triangle Strip glBegin(GL_TRIANGLE_STRIP) glTexCoord2f(0.0, 0.0) glVertex2f(q[0].x, q[0].y) glTexCoord2f(0.0, 1.0) glVertex2f(q[1].x, q[1].y) glTexCoord2f(1.0, 0.0) glVertex2f(q[2].x, q[2].y) glTexCoord2f(1.0, 1.0) glVertex2f(q[3].x, q[3].y) glEnd() # Restore the model view matrix glPopMatrix() return
def RenderFlareTexture (self, tex_ID, r, g, b, a, p, scale): # bleair: Duplicate functions all the same except for the texture to bind to. q = [] q.append (glPoint ()) q.append (glPoint ()) q.append (glPoint ()) q.append (glPoint ()) # // Basically we are just going to make a 2D box # // from four points we don't need a z coord because # // we are rotating the camera by the inverse so the # // texture mapped quads will always face us. q[0].x = (p.x - scale); # // Set the x coordinate -scale units from the center point. q[0].y = (p.y - scale); # // Set the y coordinate -scale units from the center point. q[1].x = (p.x - scale); # // Set the x coordinate -scale units from the center point. q[1].y = (p.y + scale); # // Set the y coordinate scale units from the center point. q[2].x = (p.x + scale); # // Set the x coordinate scale units from the center point. q[2].y = (p.y - scale); # // Set the y coordinate -scale units from the center point. q[3].x = (p.x + scale); # // Set the x coordinate scale units from the center point. q[3].y = (p.y + scale); # // Set the y coordinate scale units from the center point. glPushMatrix(); # // Save the model view matrix glTranslatef(p.x, p.y, p.z); # // Translate to our point glRotatef(-self.m_HeadingDegrees, 0.0, 1.0, 0.0); glRotatef(-self.m_PitchDegrees, 1.0, 0.0, 0.0); glBindTexture(GL_TEXTURE_2D, tex_ID); # // Bind to the Big Glow texture glColor4f(r, g, b, a); # // Set the color since the texture is a gray scale glBegin(GL_TRIANGLE_STRIP); # // Draw the Big Glow on a Triangle Strip glTexCoord2f(0.0, 0.0); glVertex2f(q[0].x, q[0].y); glTexCoord2f(0.0, 1.0); glVertex2f(q[1].x, q[1].y); glTexCoord2f(1.0, 0.0); glVertex2f(q[2].x, q[2].y); glTexCoord2f(1.0, 1.0); glVertex2f(q[3].x, q[3].y); glEnd(); glPopMatrix(); # // Restore the model view matrix return
def __init__(self): # Initalize all our member varibles. self.m_MaxPitchRate = 0.0 self.m_MaxHeadingRate = 0.0 self.m_HeadingDegrees = 0.0 self.m_PitchDegrees = 0.0 self.m_MaxForwardVelocity = 0.0 self.m_ForwardVelocity = 0.0 self.m_GlowTexture = None # bleair: NOTE that glCamera.cpp has a bug. m_BigGlowTexture isn't initialized. # Very minor bug because only in the case where we fail to get an earlier # texture will the class potentially read from the uninited memory. Most of # the time the field is assigned to straight away in InitGL (). self.m_BigGlowTexture = None self.m_HaloTexture = None self.m_StreakTexture = None self.m_MaxPointSize = 0.0 self.m_Frustum = zeros((6, 4), 'f') self.m_LightSourcePos = glPoint() self.m_Position = glPoint() self.m_DirectionVector = glVector() self.m_ptIntersect = glPoint()
def __init__ (self): # // Initalize all our member varibles. self.m_MaxPitchRate = 0.0; self.m_MaxHeadingRate = 0.0; self.m_HeadingDegrees = 0.0; self.m_PitchDegrees = 0.0; self.m_MaxForwardVelocity = 0.0; self.m_ForwardVelocity = 0.0; self.m_GlowTexture = None; # bleair: NOTE that glCamera.cpp has a bug. m_BigGlowTexture isn't initialized. # Very minor bug because only in the case where we fail to get an earlier # texture will the class potentially read from the uninited memory. Most of # the time the field is assigned to straight away in InitGL (). self.m_BigGlowTexture = None; self.m_HaloTexture = None; self.m_StreakTexture = None; self.m_MaxPointSize = 0.0; self.m_Frustum = Numeric.zeros ( (6,4), 'f') self.m_LightSourcePos = glPoint () self.m_Position = glPoint () self.m_DirectionVector = glVector () self.m_ptIntersect = glPoint ()
def RenderLensFlare(self): # Draw the flare only If the light source is in our line of sight (inside the Frustum) if (self.SphereInFrustum(self.m_LightSourcePos, 1.0) == True): # Vector pointing from the light's position toward the camera's position (the camera might # be pointing elsewhere, this vector is pointing from the light to the camera) # Lets compute the vector that points to the camera from self.vLightSourceToCamera = self.m_Position - self.m_LightSourcePos # the light source. # Save the length we will need it in a minute Length = self.vLightSourceToCamera.Magnitude() # Move down our look-toward direction vector. Move down the look-toward the same dist. as the # distance between camera and the light. intersect = self.m_DirectionVector * Length self.m_ptIntersect = glPoint(intersect.i, intersect.j, intersect.k) # Now lets find an point along the cameras direction # vector that we can use as an intersection point. # Lets translate down this vector the same distance # that the camera is away from the light source. ptIntersect = self.m_ptIntersect # Did the motion in the correct direction above, now translate the intersection position # relative to our camera location. ptIntersect += self.m_Position # Lets compute the vector that points to the Intersect self.vLightSourceToIntersect = ptIntersect - self.m_LightSourcePos # point from the light source # Save the length we will need it later. Length = self.vLightSourceToIntersect.Magnitude() # Normalize the vector so its unit length self.vLightSourceToIntersect.Normalize() vLightSourceToIntersect = self.vLightSourceToIntersect # You should already know what this does glEnable(GL_BLEND) # You should already know what this does glBlendFunc(GL_SRC_ALPHA, GL_ONE) # You should already know what this does glDisable(GL_DEPTH_TEST) # You should already know what this does glEnable(GL_TEXTURE_2D) # /////////// Differenet Color Glows & Streaks ///////////////////// # //RenderBigGlow(1.0f, 1.0f, 1.0f, 1.0f, m_LightSourcePos, 1.0f); # //RenderStreaks(1.0f, 1.0f, 0.8f, 1.0f, m_LightSourcePos, 0.7f); # // # //RenderBigGlow(1.0f, 0.9f, 1.0f, 1.0f, m_LightSourcePos, 1.0f); # //RenderStreaks(1.0f, 0.9f, 1.0f, 1.0f, m_LightSourcePos, 0.7f); # ////////////////////////////////////////////////////////////////// # //########################## NEW STUFF ################################## # //Check if the center of the flare is occluded if (not self.IsOccluded(self.m_LightSourcePos)): # Render the large hazy glow self.RenderBigGlow(0.60, 0.60, 0.8, 1.0, self.m_LightSourcePos, 16.0) # Render the streaks self.RenderStreaks(0.60, 0.60, 0.8, 1.0, self.m_LightSourcePos, 16.0) # Render the small Glow self.RenderGlow(0.8, 0.8, 1.0, 0.5, self.m_LightSourcePos, 3.5) pt = glPoint(vLightSourceToIntersect * (Length * 0.1) ) # Lets compute a point that is 20% # away from the light source in the pt += self.m_LightSourcePos # direction of the intersection point. # Render the small Glow self.RenderGlow(0.9, 0.6, 0.4, 0.5, pt, 0.6) pt = glPoint(vLightSourceToIntersect * (Length * 0.15) ) # Lets compute a point that is 30% # away from the light source in the pt += self.m_LightSourcePos # direction of the intersection point. # Render the a Halo self.RenderHalo(0.8, 0.5, 0.6, 0.5, pt, 1.7) # Lets compute a point that is 35% pt = glPoint(vLightSourceToIntersect * (Length * 0.175)) # away from the light source in the pt += self.m_LightSourcePos # direction of the intersection point. # Render the a Halo self.RenderHalo(0.9, 0.2, 0.1, 0.5, pt, 0.83) # Lets compute a point that is 57% pt = glPoint(vLightSourceToIntersect * (Length * 0.285)) # away from the light source in the pt += self.m_LightSourcePos # direction of the intersection point. # Render the a Halo self.RenderHalo(0.7, 0.7, 0.4, 0.5, pt, 1.6) # Lets compute a point that is 55.1% pt = glPoint(vLightSourceToIntersect * (Length * 0.2755)) # away from the light source in the pt += self.m_LightSourcePos # direction of the intersection point. # Render the small Glow self.RenderGlow(0.9, 0.9, 0.2, 0.5, pt, 0.8) # Lets compute a point that is 95.5% pt = glPoint(vLightSourceToIntersect * (Length * 0.4775)) # away from the light source in the pt += self.m_LightSourcePos # direction of the intersection point. # Render the small Glow self.RenderGlow(0.93, 0.82, 0.73, 0.5, pt, 1.0) # Lets compute a point that is 98% pt = glPoint(vLightSourceToIntersect * (Length * 0.49)) # away from the light source in the pt += self.m_LightSourcePos # direction of the intersection point. # Render the a Halo self.RenderHalo(0.7, 0.6, 0.5, 0.5, pt, 1.4) # Lets compute a point that is 130% pt = glPoint(vLightSourceToIntersect * (Length * 0.65)) # away from the light source in the pt += self.m_LightSourcePos # direction of the intersection point. # Render the small Glow self.RenderGlow(0.7, 0.8, 0.3, 0.5, pt, 1.8) # Lets compute a point that is 126% pt = glPoint(vLightSourceToIntersect * (Length * 0.63)) # away from the light source in the pt += self.m_LightSourcePos # direction of the intersection point. # Render the small Glow self.RenderGlow(0.4, 0.3, 0.2, 0.5, pt, 1.4) # Lets compute a point that is 160% pt = glPoint(vLightSourceToIntersect * (Length * 0.8)) # away from the light source in the pt += self.m_LightSourcePos # direction of the intersection point. # Render the a Halo self.RenderHalo(0.7, 0.5, 0.5, 0.5, pt, 1.4) # Lets compute a point that is 156.5% pt = glPoint(vLightSourceToIntersect * (Length * 0.7825)) # away from the light source in the pt += self.m_LightSourcePos # direction of the intersection point. # Render the small Glow self.RenderGlow(0.8, 0.5, 0.1, 0.5, pt, 0.6) # Lets compute a point that is 200% pt = glPoint(vLightSourceToIntersect * (Length * 1.0)) # away from the light source in the pt += self.m_LightSourcePos # direction of the intersection point. # Render the a Halo self.RenderHalo(0.5, 0.5, 0.7, 0.5, pt, 1.7) # Lets compute a point that is 195% pt = glPoint(vLightSourceToIntersect * (Length * 0.975)) # away from the light source in the pt += self.m_LightSourcePos # direction of the intersection point. # Render the small Glow self.RenderGlow(0.4, 0.1, 0.9, 0.5, pt, 2.0) # You should already know what this does glDisable(GL_BLEND) # You should already know what this does glEnable(GL_DEPTH_TEST) # You should already know what this does glDisable(GL_TEXTURE_2D) return
def RenderLensFlare(self): # // Draw the flare only If the light source is in our line of sight (inside the Frustum) if (self.SphereInFrustum(self.m_LightSourcePos, 1.0) == True): # Vector pointing from the light's position toward the camera's position (the camera might # be pointing elsewhere, this vector is pointing from the light to the camera) self.vLightSourceToCamera = self.m_Position - self.m_LightSourcePos; # // Lets compute the vector that points to the camera from # // the light source. Length = self.vLightSourceToCamera.Magnitude () # // Save the length we will need it in a minute # Move down our look-toward direction vector. Move down the look-toward the same dist. as the # distance between camera and the light. intersect = self.m_DirectionVector * Length self.m_ptIntersect = glPoint (intersect.i, intersect.j, intersect.k) # // Now lets find an point along the cameras direction # // vector that we can use as an intersection point. # // Lets translate down this vector the same distance # // that the camera is away from the light source. ptIntersect = self.m_ptIntersect # Did the motion in the correct direction above, now translate the intersection position # relative to our camera location. ptIntersect += self.m_Position; self.vLightSourceToIntersect = ptIntersect - self.m_LightSourcePos; # // Lets compute the vector that points to the Intersect # // point from the light source Length = self.vLightSourceToIntersect.Magnitude(); # // Save the length we will need it later. self.vLightSourceToIntersect.Normalize(); # // Normalize the vector so its unit length vLightSourceToIntersect = self.vLightSourceToIntersect glEnable(GL_BLEND); # // You should already know what this does glBlendFunc(GL_SRC_ALPHA, GL_ONE); # // You should already know what this does glDisable(GL_DEPTH_TEST); # // You should already know what this does glEnable(GL_TEXTURE_2D); # // You should already know what this does # /////////// Differenet Color Glows & Streaks ///////////////////// # //RenderBigGlow(1.0f, 1.0f, 1.0f, 1.0f, m_LightSourcePos, 1.0f); # //RenderStreaks(1.0f, 1.0f, 0.8f, 1.0f, m_LightSourcePos, 0.7f); # // # //RenderBigGlow(1.0f, 0.9f, 1.0f, 1.0f, m_LightSourcePos, 1.0f); # //RenderStreaks(1.0f, 0.9f, 1.0f, 1.0f, m_LightSourcePos, 0.7f); # ////////////////////////////////////////////////////////////////// # //########################## NEW STUFF ################################## if (not self.IsOccluded(self.m_LightSourcePos)): # //Check if the center of the flare is occluded # // Render the large hazy glow self.RenderBigGlow(0.60, 0.60, 0.8, 1.0, self.m_LightSourcePos, 16.0); # // Render the streaks self.RenderStreaks(0.60, 0.60, 0.8, 1.0, self.m_LightSourcePos, 16.0); # // Render the small Glow self.RenderGlow(0.8, 0.8, 1.0, 0.5, self.m_LightSourcePos, 3.5); pt = glPoint (vLightSourceToIntersect * (Length * 0.1)); # // Lets compute a point that is 20% pt += self.m_LightSourcePos; # // away from the light source in the # // direction of the intersection point. self.RenderGlow(0.9, 0.6, 0.4, 0.5, pt, 0.6); # // Render the small Glow pt = glPoint (vLightSourceToIntersect * (Length * 0.15)); # // Lets compute a point that is 30% pt += self.m_LightSourcePos; # // away from the light source in the # // direction of the intersection point. self.RenderHalo(0.8, 0.5, 0.6, 0.5, pt, 1.7); # // Render the a Halo pt = glPoint (vLightSourceToIntersect * (Length * 0.175)); # // Lets compute a point that is 35% pt += self.m_LightSourcePos; # // away from the light source in the # // direction of the intersection point. self.RenderHalo(0.9, 0.2, 0.1, 0.5, pt, 0.83); # // Render the a Halo pt = glPoint (vLightSourceToIntersect * (Length * 0.285)); # // Lets compute a point that is 57% pt += self.m_LightSourcePos; # // away from the light source in the # // direction of the intersection point. self.RenderHalo(0.7, 0.7, 0.4, 0.5, pt, 1.6); # // Render the a Halo pt = glPoint (vLightSourceToIntersect * (Length * 0.2755)); # // Lets compute a point that is 55.1% pt += self.m_LightSourcePos; # // away from the light source in the # // direction of the intersection point. self.RenderGlow(0.9, 0.9, 0.2, 0.5, pt, 0.8); # // Render the small Glow pt = glPoint (vLightSourceToIntersect * (Length * 0.4775)); # // Lets compute a point that is 95.5% pt += self.m_LightSourcePos; # // away from the light source in the # // direction of the intersection point. self.RenderGlow(0.93, 0.82, 0.73, 0.5, pt, 1.0); # // Render the small Glow pt = glPoint (vLightSourceToIntersect * (Length * 0.49)); # // Lets compute a point that is 98% pt += self.m_LightSourcePos; # // away from the light source in the # // direction of the intersection point. self.RenderHalo(0.7, 0.6, 0.5, 0.5, pt, 1.4); # // Render the a Halo pt = glPoint (vLightSourceToIntersect * (Length * 0.65)); # // Lets compute a point that is 130% pt += self.m_LightSourcePos; # // away from the light source in the # // direction of the intersection point. self.RenderGlow(0.7, 0.8, 0.3, 0.5, pt, 1.8); # // Render the small Glow pt = glPoint (vLightSourceToIntersect * (Length * 0.63)); # // Lets compute a point that is 126% pt += self.m_LightSourcePos; # // away from the light source in the # // direction of the intersection point. self.RenderGlow(0.4, 0.3, 0.2, 0.5, pt, 1.4); # // Render the small Glow pt = glPoint (vLightSourceToIntersect * (Length * 0.8)); # // Lets compute a point that is 160% pt += self.m_LightSourcePos; # // away from the light source in the # // direction of the intersection point. self.RenderHalo(0.7, 0.5, 0.5, 0.5, pt, 1.4); # // Render the a Halo pt = glPoint (vLightSourceToIntersect * (Length * 0.7825)); # // Lets compute a point that is 156.5% pt += self.m_LightSourcePos; # // away from the light source in the # // direction of the intersection point. self.RenderGlow(0.8, 0.5, 0.1, 0.5, pt, 0.6); # // Render the small Glow pt = glPoint (vLightSourceToIntersect * (Length * 1.0)); # // Lets compute a point that is 200% pt += self.m_LightSourcePos; # // away from the light source in the # // direction of the intersection point. self.RenderHalo(0.5, 0.5, 0.7, 0.5, pt, 1.7); # // Render the a Halo pt = glPoint (vLightSourceToIntersect * (Length * 0.975)); # // Lets compute a point that is 195% pt += self.m_LightSourcePos; # // away from the light source in the # // direction of the intersection point. self.RenderGlow(0.4, 0.1, 0.9, 0.5, pt, 2.0); # // Render the small Glow glDisable(GL_BLEND ); # // You should already know what this does glEnable(GL_DEPTH_TEST); # // You should already know what this does glDisable(GL_TEXTURE_2D); # // You should already know what this does return