MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / DoObjectLight

Function DoObjectLight

Descent3/object_lighting.cpp:164–455  ·  view source on GitHub ↗

Casts light from an object onto the rooms or terrain

Source from the content-addressed store, hash-verified

162void ReflectRay(vector *, vector *, vector *);
163// Casts light from an object onto the rooms or terrain
164void DoObjectLight(object *obj) {
165 light_info *li;
166 static int first = 1, flare_id = -1, greenflare_id = -1;
167
168 if (obj->flags & OF_DEAD)
169 return;
170
171 if (obj->render_type == RT_NONE)
172 return;
173
174 float negative_light = 1.0f;
175 if (obj->effect_info && obj->effect_info->type_flags & EF_NEGATIVE_LIGHT)
176 negative_light = -1.0f;
177
178 // Temporary hack to make explosions light up
179 if (obj->type == OBJ_FIREBALL) {
180 if (!Detail_settings.Dynamic_lighting)
181 return;
182
183 if (obj->flags & OF_USES_LIFELEFT && Fireballs[obj->id].type == FT_EXPLOSION) {
184 float scalar;
185
186 scalar = (obj->lifetime - obj->lifeleft) / obj->lifetime;
187
188 if (scalar > .5) {
189 scalar -= .5;
190
191 scalar = 1.0 - (scalar / .5);
192 } else {
193 scalar *= 2;
194 }
195
196 if (scalar > .05) {
197 if (OBJECT_OUTSIDE(obj))
198 ApplyLightingToTerrain(&obj->pos, CELLNUM(obj->roomnum), 40 * scalar, negative_light * 1.0f,
199 negative_light * 0.5f, negative_light * 0.0f);
200 else
201 ApplyLightingToRooms(&obj->pos, obj->roomnum, 40 * scalar, negative_light * 1.0f, negative_light * 0.5f,
202 negative_light * 0.0f);
203 }
204 }
205 return;
206 }
207
208 switch (obj->type) {
209 case OBJ_PLAYER: {
210 if ((Players[obj->id].flags) & PLAYER_FLAGS_HEADLIGHT) {
211
212 if (Detail_settings.Fast_headlight_on) {
213 // Do fast headlight
214 fvi_info hit_info;
215 fvi_query fq;
216
217 // shoot a ray from the light position to the current vertex
218 vector end_pos = obj->pos + (obj->orient.fvec * HEADLIGHT_DISTANCE * 2);
219 fq.p0 = &obj->pos;
220 fq.p1 = &end_pos;
221

Callers 1

ObjDoFrameFunction · 0.85

Calls 9

ApplyLightingToTerrainFunction · 0.85
ApplyLightingToRoomsFunction · 0.85
fvi_FindIntersectionFunction · 0.85
IsLightPointVisibleFunction · 0.85
PlayerGetBallPositionFunction · 0.85
FindWeaponNameFunction · 0.85
ObjGetLightInfoFunction · 0.85
ps_randFunction · 0.85
vm_VectorDistanceQuickFunction · 0.50

Tested by

no test coverage detected