Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

WVPersesMAS.PersesArtilleryTrajectory


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
/**
WVPersesMAS.PersesArtilleryTrajectory

Creation date: 2013-12-16 09:26
Last change: $Id$
Copyright (c) 2013, Wormbo
*/

class PersesArtilleryTrajectory extends Emitter;


var vector GoodColor, BadColor;


/**
Spawn the initial trajectory beam particle.
*/
function PostBeginPlay()
{
	Emitters[0].SpawnParticle(1);
	Emitters[1].SpawnParticle(1);
}


/**
Update the trajectory arc according to the given parameters.
*/
function UpdateTrajectory(bool bVisible, optional vector StartLocation, optional vector StartVelocity, optional float Gravity, optional float MinZ, optional bool bCanHitTarget)
{
	local float tMax, tDelta, t;
	local BeamEmitter Arc;
	local int i;
	
	Emitters[0].Disabled = !bVisible;
	
	// check if we need the bounding box hack
	if (bVisible && Normal(StartVelocity).Z > 0)
	{
		// need to calculate apex point (actually only apex height)
		Emitters[1].Disabled = False;
		Emitters[1].Particles[0].Location = StartLocation;
		Emitters[1].Particles[0].Location.Z -= 0.5 * Square(StartVelocity.Z) / Gravity;
	}
	else
	{
		// horizontal or downward initial velocity, so no hack required
		Emitters[1].Disabled = True;
	}
	
	if (!bVisible)
		return;
	
	if (bCanHitTarget)
		Emitters[0].Particles[0].ColorMultiplier = GoodColor;
	else
		Emitters[0].Particles[0].ColorMultiplier = BadColor;
	
	Arc = BeamEmitter(Emitters[0]);
	
	tMax = (StartVelocity.Z + Sqrt(Square(StartVelocity.Z) + 2 * Gravity * (StartLocation.Z - MinZ))) / Gravity;
	tDelta = tMax / (Arc.HighFrequencyPoints - 1);
	
	Arc.HFPoints[0].Location = StartLocation;
	for (i = 1; i < Arc.HighFrequencyPoints; ++i)
	{
		t += tDelta;
		Arc.HFPoints[i].Location = StartLocation + StartVelocity * t - vect(0,0,0.5) * Gravity * Square(t);
	}
}


//=============================================================================
// Default values
//=============================================================================

defaultproperties
{
	GoodColor = (X=0.0,Y=1.0,Z=0.0)
	BadColor = (X=1.0,Y=0.0,Z=0.0)
	
	// the trajectory arc
	Begin Object Class=BeamEmitter Name=Trajectory
		MaxParticles              = 1
		AutomaticInitialSpawning  = False
		LifetimeRange             = (Min=999999.0,Max=999999.0)
		StartSizeRange            = (X=(Min=5.0,Max=5.0))
		HighFrequencyPoints       = 50
		CoordinateSystem          = PTCS_Absolute
		DetermineEndPointBy       = PTEP_Offset
		Texture                   = Texture'EpicParticles.Beams.DanGradient'
		AlphaTest                 = False // DanGradient has an alpha value of 0 and would otherwise be invisible
		Opacity                   = 0.75
	End Object
	Emitters(0) = Trajectory
	
	// invisible particle placed at the trajectory apex to extend the rendering bounding box
	Begin Object Class=SpriteEmitter Name=BoundingBoxHack
		MaxParticles              = 1
		AutomaticInitialSpawning  = False
		LifetimeRange             = (Min=999999.0,Max=999999.0)
		StartSizeRange            = (X=(Min=0.0,Max=0.0)) // so it's not actually visible
		CoordinateSystem          = PTCS_Absolute
	End Object
	Emitters(1) = BoundingBoxHack
	
	bNoDelete = False
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Mi 18.12.2013 12:28:58.000 - Creation time: Do 14.8.2014 09:58:48.206 - Created with UnCodeX