This repository has been archived by the owner on Sep 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
lensflare.cpp
197 lines (174 loc) · 5.14 KB
/
lensflare.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//-----------------------------------------------------------------------------
//
// $Logfile:: /Quake 2 Engine/Sin/code/game/lensflare.cpp $
// $Revision:: 17 $
// $Author:: Jimdose $
// $Date:: 10/19/98 12:07a $
//
// Copyright (C) 1998 by Ritual Entertainment, Inc.
// All rights reserved.
//
// This source is may not be distributed and/or modified without
// expressly written permission by Ritual Entertainment, Inc.
//
// $Log:: /Quake 2 Engine/Sin/code/game/lensflare.cpp $
//
// 17 10/19/98 12:07a Jimdose
// made all code use fast checks for inheritance (no text lookups when
// possible)
// isSubclassOf no longer requires ::_classinfo()
//
// 16 10/09/98 8:58p Aldie
// Lightstyle on lensflare from Lights
//
// 15 10/09/98 5:23p Aldie
// Added some commands for lightstyle.
//
// 14 9/25/98 2:59p Aldie
// More lensflare stuff. Added lightstyles
//
// 13 5/03/98 4:34p Jimdose
// Changed Vector class
//
// 12 3/30/98 11:39p Markd
// Added modelIndex stuff
//
// 11 3/23/98 1:31p Jimdose
// Revamped event and command system
//
// 10 3/18/98 2:05p Aldie
// Changed the filename of the sprite model extension to .spr
//
// 9 3/14/98 4:40p Aldie
// Added scale to lensflare.
//
// 8 3/13/98 7:25p Aldie
// Expanded lensflare to have color, dlights, and radius.
//
// 7 3/12/98 5:37p Markd
// Changed model file for lensflare from sp3 file to def file
//
// 6 3/12/98 3:02p Aldie
// Cleaned up lensflare.
//
// 5 3/12/98 2:42p Aldie
// Random starting positions for lensflare rotation offset.
//
// 4 3/10/98 7:45p Aldie
//
// 3 3/07/98 5:16p Aldie
// Added new sprite.
//
// 2 3/06/98 7:16p Aldie
// First try at lensflare.
//
// DESCRIPTION:LensFlare effect
//
#include "g_local.h"
#include "entity.h"
#include "lensflare.h"
#include "light.h"
CLASS_DECLARATION( Trigger, LensFlare, "lensflare" );
/*****************************************************************************/
/*SINED lensflare (0 1 0) (-8 -8 -8) (8 8 8)
"color" (r g b) 3 values between 0 and 1.0 (Default is 1.0 1.0 1.0)
"light" If set,make the flare emit a dynamic light. (Default is not set)
"radius" Radius of the dynamic light (Default is 200)
"scale" Factor to scale the lensflare (Default is 0.5)
"sprite" Sprite model to use for the flare (Default is sprites/glow.spr")
"lightstyle" Lightstyle of the lensflare (Default is none)
/*****************************************************************************/
Event EV_LensFlare_Activate( "activate" );
Event EV_LensFlare_Deactivate( "deactivate" );
Event EV_LensFlare_Lightstyle( "lightstyle" );
Event EV_LensFlare_SetLightstyle( "setlightstyle" );
ResponseDef LensFlare::Responses[] =
{
{ &EV_LensFlare_Activate, ( Response )LensFlare::Activate },
{ &EV_LensFlare_Deactivate, ( Response )LensFlare::Deactivate },
{ &EV_LensFlare_Lightstyle, ( Response )LensFlare::Lightstyle },
{ &EV_LensFlare_SetLightstyle, ( Response )LensFlare::SetLightstyle },
{ NULL, NULL }
};
LensFlare::LensFlare( void )
{
Vector color;
Vector def;
int dlight,radius;
float scale;
int lightstyle;
color = G_GetVectorArg("color",Vector(1,1,1));
dlight = G_GetIntArg("light",0);
radius = G_GetIntArg("radius",0);
scale = G_GetFloatArg("scale", 0.5f);
model = G_GetSpawnArg("sprite", "sprites/glow.spr" );
lightstyle = G_GetIntArg("lightstyle", 255 );
setModel( model );
setMoveType( MOVETYPE_NONE );
setSolidType( SOLID_NOT );
edict->s.renderfx |= (RF_LENSFLARE);
if (dlight)
edict->s.renderfx |= (RF_DLIGHT);
edict->s.angles[ROLL] = rand() % 360;
edict->s.alpha = 1.0f;
edict->s.color_r = color.x;
edict->s.color_g = color.y;
edict->s.color_b = color.z;
edict->s.radius = radius;
edict->s.scale = scale;
edict->s.skinnum = lightstyle;
PostEvent( EV_LensFlare_SetLightstyle, 0 );
}
void LensFlare::SetLightstyle
(
Event *ev
)
{
int num;
const char *name;
Entity *ent;
name = Target();
if ( name && strcmp( name, "" ) )
{
num = 0;
do
{
num = G_FindTarget( num, name );
if ( !num )
{
break;
}
ent = G_GetEntity( num );
assert( ent );
if ( ent->isSubclassOf( Light ) )
{
Light *light;
light = ( Light * )ent;
edict->s.skinnum = light->GetStyle();
}
}
while ( 1 );
}
}
void LensFlare::Activate
(
Event *ev
)
{
setSolidType( SOLID_BSP );
showModel();
}
void LensFlare::Deactivate
(
Event *ev
)
{
hideModel();
}
void LensFlare::Lightstyle
(
Event *ev
)
{
edict->s.skinnum = ev->GetInteger( 1 );
}