//-----------------------------------------------------------
// FlareInteraction.
// Adds 1337 lens flares for lights w/ coronas.
// (c) 2002 jasonyu
//-----------------------------------------------------------
class FlareInteraction extends Interaction;
#exec OBJ LOAD FILE=..\Textures\HaloTC_LensFlares.utx
var Actor PlayerOwner;
const HLSMAX = 240;
const RGBMAX = 255;
event Initialized()
{
PlayerOwner = ViewportOwner.Actor;
log("Lensflare interaction initialized.");
}
// adapted from:
// http://plaza27.mbn.or.jp/~satomii/design/win32/hls2rgb.html
final simulated function float HueToRGB(float n1, float n2, float hue)
{
if ( hue < 0 ) hue += HLSMAX;
if ( hue > HLSMAX ) hue -= HLSMAX;
/* return r,g, or b value from this tridrant */
if ( hue < (HLSMAX/6) )
return ( n1 + (((n2-n1)*hue + (HLSMAX/12))/(HLSMAX/6)) );
if ( hue < (HLSMAX/2) )
return n2;
if ( hue < ((HLSMAX*2)/3) )
return ( n1 + (((n2-n1)*(((HLSMAX*2)/3)-hue) + (HLSMAX/12))/(HLSMAX/6)) );
else
return n1;
}
final simulated function Color hls2rgb(byte hue, byte lum, byte sat)
{
local Color C;
local float Magic1, Magic2;
local int R,G,B;
if ( sat==0)
{ /* achromatic case */
C.R = (lum*RGBMAX) / HLSMAX;
C.G = C.R;
C.B = C.R;
}
else
{ /* chromatic case */
/* set up magic numbers */
if (lum <= (HLSMAX/2))
Magic2 = (lum*(HLSMAX+sat)+(HLSMAX/2)) / HLSMAX;
else
Magic2 = lum+sat - ((lum*sat)+(HLSMAX/2)) / HLSMAX;
Magic1 = 2*lum - Magic2;
/* get RGB, change units from HLSMAX to RGBMAX */
R = (HueToRGB(Magic1, Magic2, hue+(HLSMAX/3))
* RGBMAX + (HLSMAX/2)) / HLSMAX;
G = (HueToRGB(Magic1, Magic2, hue)
* RGBMAX + (HLSMAX/2)) / HLSMAX;
B = (HueToRGB(Magic1, Magic2, hue-(HLSMAX/3))
* RGBMAX + (HLSMAX/2)) / HLSMAX;
}
C.R = R;
C.G = G;
C.B = B;
C.A = 255;
return C;
}
// adapted from:
// http://www.gamedev.net/reference/articles/article813.asp
simulated function PostRender( canvas Canvas )
{
local Light Other;
local float Dist;
local Vector X,Y,Z, Dir;
local Vector V, C, L;
local float Length;
local float ScaleX, ScaleY;
if ( ViewportOwner.Actor.Pawn != None ) PlayerOwner = ViewportOwner.Actor.Pawn;
else PlayerOwner = ViewportOwner.Actor;
if ( PlayerOwner != None )
{
ScaleX = Canvas.SizeX / 640.0;
ScaleY = Canvas.SizeY / 480.0;
C.X = Canvas.ClipX/2;
C.Y = Canvas.ClipY/2;
GetAxes(PlayerOwner.Rotation, X,Y,Z);
ForEach PlayerOwner.RadiusActors(class'Light', Other, 2000)
{
Dir = Other.Location - PlayerOwner.Location;
Dist = VSize(Dir);
Dir = Dir/Dist;
// find an appropriate light source (bright, in FOV)
if ( (Dir Dot X) > 0.7 && Other.bCorona &&
(
(PlayerOwner.IsA('Pawn') && Pawn(PlayerOwner).LineOfSightTo(Other) ) ||
(PlayerOwner.IsA('Controller') && Controller(PlayerOwner).LineOfSightTo(Other) )
) &&
Other.LightRadius >= 64 && Other.DrawScale > 0.2 )
{
//Convert 3d location to 2d for display on the Canvas
L = WorldToScreen(Other.location);
V.X = L.X - C.X;
V.Y = L.Y - C.Y;
Length = VSize(V);
V = Normal(V);
Canvas.Style = PlayerOwner.ERenderStyle.STY_Additive;
// tint the corona textures to match the hue of the light
Canvas.DrawColor = hls2rgb(Other.LightHue, 15, 75);
// place flares along directional vector
Canvas.SetPos( (V.X*Length*1.2)-32*ScaleX+C.X, (V.Y*Length*1.2)-32*ScaleY+C.Y );
Canvas.DrawTile(Texture'flares_generic_bitmap_2', 64*ScaleX,64*ScaleY,0.0, 0.0, 32, 32);
Canvas.SetPos( (V.X*Length)-32*ScaleX+C.X, (V.Y*Length)-32*ScaleY+C.Y );
Canvas.DrawTile(Texture'flares_generic_bitmap_3', 64*ScaleX,64*ScaleY,0.0, 0.0, 16, 16);
Canvas.SetPos( (V.X*Length*0.66)-64*ScaleX+C.X, (V.Y*Length*0.66)-64*ScaleY+C.Y );
Canvas.DrawTile(Texture'flares_generic_bitmap_4', 128*ScaleX,128*ScaleY,0.0, 0.0, 32, 32);
Canvas.SetPos( (V.X*Length*0.33)-64*ScaleX+C.X, (V.Y*Length*0.33)-64*ScaleY+C.Y );
Canvas.DrawTile(Texture'flares_generic_bitmap_5', 128*ScaleX,128*ScaleY,0.0, 0.0, 32, 32);
Canvas.SetPos( (V.X*Length*0.125)-64*ScaleX+C.X, (V.Y*Length*0.125)-64*ScaleY+C.Y );
Canvas.DrawTile(Texture'flares_generic_bitmap_6', 128*ScaleX,128*ScaleY,0.0, 0.0, 16, 16);
Canvas.SetPos( (V.X*Length*-0.21)-64*ScaleX+C.X, (V.Y*Length*-0.21)-64*ScaleY+C.Y );
Canvas.DrawTile(Texture'flares_generic_bitmap_7', 128*ScaleX,128*ScaleY,0.0, 0.0, 64, 64);
Canvas.SetPos( (V.X*Length*-0.30)-32*ScaleX+C.X, (V.Y*Length*-0.30)-32*ScaleY+C.Y );
Canvas.DrawTile(Texture'flares_generic_bitmap_3', 64*ScaleX,64*ScaleY,0.0, 0.0, 16, 16);
Canvas.SetPos( (V.X*Length*-0.5)-90*ScaleX+C.X, (V.Y*Length*-0.5)-90*ScaleY+C.Y );
Canvas.DrawTile(Texture'flares_generic_bitmap_3', 180*ScaleX,180*ScaleY,0.0, 0.0, 16, 16);
}
}
}
}
defaultproperties
{
bVisible=true
bActive=true
}