1
/*-----------------------------------------------------------------------------
7
-------------------------------------------------------------------------------
9
This tracks and renders the light sources. (Note that they do not really
10
CAST light in the OpenGL sense of the world, these are just simple panels.)
11
These are NOT subclassed to entities because these are dynamic. Some lights
12
blink, and thus they can't go into the fixed render lists managed by
15
-----------------------------------------------------------------------------*/
26
#include "GetTickCount.h"
31
#include "PixelCity.h"
35
static GLvector2 angles[5][360];
37
static bool angles_done;
40
/*-----------------------------------------------------------------------------
42
-----------------------------------------------------------------------------*/
58
/*-----------------------------------------------------------------------------
60
-----------------------------------------------------------------------------*/
70
/*-----------------------------------------------------------------------------
72
-----------------------------------------------------------------------------*/
82
for (int size = 0; size < MAX_SIZE; size++) {
83
for (int i = 0 ;i < 360; i++) {
84
angles[size][i].x = cosf ((float)i * DEGREES_TO_RADIANS) * ((float)size + 0.5f);
85
angles[size][i].y = sinf ((float)i * DEGREES_TO_RADIANS) * ((float)size + 0.5f);
91
glDisable (GL_CULL_FACE);
92
glBlendFunc (GL_ONE, GL_ONE);
93
glBindTexture(GL_TEXTURE_2D, TextureId (TEXTURE_LIGHT));
94
glDisable (GL_CULL_FACE);
96
for (l = head; l; l = l->_next)
103
/*-----------------------------------------------------------------------------
105
-----------------------------------------------------------------------------*/
107
CLight::CLight (GLvector pos, GLrgba color, int size)
112
_size = CLAMP (size, 0, (MAX_SIZE - 1));
113
_vert_size = (float)_size + 0.5f;
114
_flat_size = _vert_size + 0.5f;
116
_cell_x = WORLD_TO_GRID(pos.x);
117
_cell_z = WORLD_TO_GRID(pos.z);
125
/*-----------------------------------------------------------------------------
127
-----------------------------------------------------------------------------*/
129
void CLight::Blink ()
133
//we don't want blinkers to be in sync, so have them blink at
134
//slightly different rates. (Milliseconds)
135
_blink_interval = 1500 + RandomVal (500);
139
/*-----------------------------------------------------------------------------
141
-----------------------------------------------------------------------------*/
143
void CLight::Render ()
149
GLvector camera_position;
152
if (!Visible (_cell_x, _cell_z))
154
camera = CameraAngle ();
155
camera_position = CameraPosition ();
156
if (fabs (camera_position.x - _position.x) > RenderFogDistance ())
158
if (fabs (camera_position.z - _position.z) > RenderFogDistance ())
160
if (_blink && (GetTickCount () % _blink_interval) > 200)
162
angle = (int)MathAngle (camera.y);
163
offset = angles[_size][angle];
165
glColor4fv (&_color.red);
167
glVertex3f (pos.x + offset.x, pos.y - _vert_size, pos.z + offset.y);
169
glVertex3f (pos.x - offset.x, pos.y - _vert_size, pos.z - offset.y);
171
glVertex3f (pos.x - offset.x, pos.y + _vert_size, pos.z - offset.y);
173
glVertex3f (pos.x + offset.x, pos.y + _vert_size, pos.z + offset.y);