Add support for targetless spotlights, fix bug with "light" keyvalues (#4)
This commit is contained in:
parent
e7606f6c78
commit
7b553f5b7a
1 changed files with 63 additions and 10 deletions
|
@ -249,7 +249,7 @@ void CreateEntityLights( void ){
|
||||||
const char *_color, *_light_brightness, *_spread;
|
const char *_color, *_light_brightness, *_spread;
|
||||||
float intensity, scale, deviance, filterRadius;
|
float intensity, scale, deviance, filterRadius;
|
||||||
int spawnflags, flags, numSamples;
|
int spawnflags, flags, numSamples;
|
||||||
qboolean junior;
|
qboolean junior, isSpotlightEntity;
|
||||||
|
|
||||||
|
|
||||||
/* go throught entity list and find lights */
|
/* go throught entity list and find lights */
|
||||||
|
@ -468,10 +468,15 @@ void CreateEntityLights( void ){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
} else if ( !Q_stricmp( "light_spot", name ) ) {
|
||||||
|
junior = qfalse;
|
||||||
|
isSpotlightEntity = qtrue;
|
||||||
} else if ( !Q_stricmp( "lightJunior", name ) ) {
|
} else if ( !Q_stricmp( "lightJunior", name ) ) {
|
||||||
junior = qtrue;
|
junior = qtrue;
|
||||||
|
isSpotlightEntity = qfalse;
|
||||||
} else if ( !Q_stricmp( "light", name ) ) {
|
} else if ( !Q_stricmp( "light", name ) ) {
|
||||||
junior = qfalse;
|
junior = qfalse;
|
||||||
|
isSpotlightEntity = qfalse;
|
||||||
} else{
|
} else{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -576,7 +581,7 @@ void CreateEntityLights( void ){
|
||||||
|
|
||||||
/* set light intensity */
|
/* set light intensity */
|
||||||
_color = ValueForKey( e, "_light" );
|
_color = ValueForKey( e, "_light" );
|
||||||
if ( _color && _color[0] ) {
|
if ( _color[ 0 ] ) {
|
||||||
/* Handle Half-Life styled _light values which
|
/* Handle Half-Life styled _light values which
|
||||||
* contain color. Otherwise, fallback to _light
|
* contain color. Otherwise, fallback to _light
|
||||||
* being a single float for intensity
|
* being a single float for intensity
|
||||||
|
@ -694,9 +699,11 @@ void CreateEntityLights( void ){
|
||||||
/* set falloff threshold */
|
/* set falloff threshold */
|
||||||
light->falloffTolerance = falloffTolerance / numSamples;
|
light->falloffTolerance = falloffTolerance / numSamples;
|
||||||
|
|
||||||
/* lights with a target will be spotlights */
|
/* lights with a target will be spotlights
|
||||||
|
* also if they are a light_spot
|
||||||
|
*/
|
||||||
target = ValueForKey( e, "target" );
|
target = ValueForKey( e, "target" );
|
||||||
if ( target[ 0 ] ) {
|
if ( isSpotlightEntity || target[ 0 ] ) {
|
||||||
float radius;
|
float radius;
|
||||||
float dist;
|
float dist;
|
||||||
sun_t sun;
|
sun_t sun;
|
||||||
|
@ -704,10 +711,15 @@ void CreateEntityLights( void ){
|
||||||
|
|
||||||
|
|
||||||
/* get target */
|
/* get target */
|
||||||
e2 = FindTargetEntity( target );
|
if ( isSpotlightEntity ) {
|
||||||
if ( e2 == NULL ) {
|
e2 = NULL;
|
||||||
|
} else {
|
||||||
|
e2 = FindTargetEntity( target );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !isSpotlightEntity && e2 == NULL ) {
|
||||||
Sys_FPrintf( SYS_WRN, "WARNING: light at (%i %i %i) has missing target\n",
|
Sys_FPrintf( SYS_WRN, "WARNING: light at (%i %i %i) has missing target\n",
|
||||||
(int) light->origin[ 0 ], (int) light->origin[ 1 ], (int) light->origin[ 2 ] );
|
(int) light->origin[ 0 ], (int) light->origin[ 1 ], (int) light->origin[ 2 ] );
|
||||||
light->photons *= pointScale;
|
light->photons *= pointScale;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -717,9 +729,50 @@ void CreateEntityLights( void ){
|
||||||
numSpotLights++;
|
numSpotLights++;
|
||||||
|
|
||||||
/* make a spotlight */
|
/* make a spotlight */
|
||||||
GetVectorForKey( e2, "origin", dest );
|
if ( isSpotlightEntity ) {
|
||||||
VectorSubtract( dest, light->origin, light->normal );
|
vec3_t angles;
|
||||||
dist = VectorNormalize( light->normal, light->normal );
|
float value;
|
||||||
|
|
||||||
|
GetVectorForKey( e, "angles", angles );
|
||||||
|
|
||||||
|
/* handle the legacy "angle" key */
|
||||||
|
value = FloatForKey( e, "angle" );
|
||||||
|
if ( value == ANGLE_UP ) {
|
||||||
|
light->normal[ 0 ] = 0.0f;
|
||||||
|
light->normal[ 1 ] = 0.0f;
|
||||||
|
light->normal[ 2 ] = 1.0f;
|
||||||
|
} else if ( value == ANGLE_DOWN ) {
|
||||||
|
light->normal[ 0 ] = 0.0f;
|
||||||
|
light->normal[ 1 ] = 0.0f;
|
||||||
|
light->normal[ 2 ] = -1.0f;
|
||||||
|
} else {
|
||||||
|
if ( !value ) {
|
||||||
|
value = angles[ 1 ];
|
||||||
|
}
|
||||||
|
value *= Q_PI * 2.0f / 360.0f;
|
||||||
|
light->normal[ 2 ] = 0.0f;
|
||||||
|
light->normal[ 0 ] = cosf( value );
|
||||||
|
light->normal[ 1 ] = sinf( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* handle the legacy "pitch" key */
|
||||||
|
value = FloatForKey( e, "pitch" );
|
||||||
|
if ( !value ) {
|
||||||
|
value = -angles[ 0 ];
|
||||||
|
}
|
||||||
|
value *= Q_PI * 2.0f / 360.0f;
|
||||||
|
|
||||||
|
light->normal[ 2 ] = sinf( value );
|
||||||
|
light->normal[ 0 ] *= cosf( value );
|
||||||
|
light->normal[ 1 ] *= cosf( value );
|
||||||
|
|
||||||
|
dist = FloatForKey( e, "dist" );
|
||||||
|
} else {
|
||||||
|
GetVectorForKey( e2, "origin", dest );
|
||||||
|
VectorSubtract( dest, light->origin, light->normal );
|
||||||
|
dist = VectorNormalize( light->normal, light->normal );
|
||||||
|
}
|
||||||
|
|
||||||
radius = FloatForKey( e, "radius" );
|
radius = FloatForKey( e, "radius" );
|
||||||
if ( !radius ) {
|
if ( !radius ) {
|
||||||
radius = 64;
|
radius = 64;
|
||||||
|
|
Loading…
Reference in a new issue