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

MojoActions.TsActionShakeView


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
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
class TsActionShakeView extends TsCameraAction;

var() Vector amplitude;
var() Vector frequency;
var() Rotator rotAmplitude;
var() Vector rotFrequency		"X,Y,Z = Pitch, Roll, Yaw";
var() float easeIn				"If easeIn/duration/easeOut are all 0, use attack/sustain/decay. Do not use this and shakeAttack/Sustain/Decay together.";
var() float duration			"If easeIn/duration/easeOut are all 0, use attack/sustain/decay. Do not use this and shakeAttack/Sustain/Decay together.";
var() float easeOut				"If easeIn/duration/easeOut are all 0, use attack/sustain/decay. Do not use this and shakeAttack/Sustain/Decay together.";
var() float shakeAttackTime		"easeIn/duration/easeOut must all be 0. Amount of time spent ramping up the shake amount (can be 0)";
var() float shakeSustainTime	"easeIn/duration/easeOut must all be 0. Amount of time spent holding the shake amount steady (can be 0)";
var() float shakeDecayTime		"easeIn/duration/easeOut must all be 0. Amount of time spent ramping down the shake amount (can be 0)";

var Vector randomOffset;
var Vector randomRotOffset;
var float alpha;
var float totalTime;

function bool OnStart()
{
	randomOffset.X = FRand();
	randomOffset.Y = FRand();
	randomOffset.Z = FRand();
	randomRotOffset.X = FRand();
	randomRotOffset.Y = FRand();
	randomRotOffset.Z = FRand();

	totalTime = 0;

	if (!UsesASD())
	{
		resetInterpolation(easeIn, duration, easeOut);
	}

	return true;
}

function bool UsesASD()
{
	return easeIn == 0 && easeOut == 0 && duration == 0;
}

function bool OnTick(float delta)
{
	local float alpha;
	local Vector offset;
	local Vector rotOffset;
	local Rotator finalRot;
	local float pingPongAlpha;
	local bool bFinished;

	if (!UsesASD())
	{
		bFinished = !tickInterpolation(delta, alpha);

		if (alpha >= 0.5)
			pingPongAlpha = 1 - ((alpha - 0.5) * 2);
		else
			pingPongAlpha = alpha * 2;
	}
	else
	{
		totalTime += delta;
		if (totalTime >= GetDuration())
		{
			return true;
		}

		if (totalTime < shakeAttackTime) // attack
			alpha = totalTime / shakeAttackTime;
		else if (totalTime - shakeAttackTime < shakeSustainTime) // sustain
			alpha = 1;
		else // decay
			alpha = 1 - ((totalTime - shakeAttackTime - shakeSustainTime) / shakeDecayTime);

		pingPongAlpha = alpha * alpha;
		interpTime = totalTime;
	}

	// calculate new offset
	offset.X = Sin((interpTime + randomOffset.X) * frequency.X);
	offset.Y = Sin((interpTime + randomOffset.Y) * frequency.Y);
	offset.Z = Sin((interpTime + randomOffset.Z) * frequency.Z);

	rotOffset.X = Sin((interpTime + randomRotOffset.X) * rotFrequency.X);
	rotOffset.Y = Sin((interpTime + randomRotOffset.Y) * rotFrequency.Y);
	rotOffset.Z = Sin((interpTime + randomRotOffset.Z) * rotFrequency.Z);

	offset *= amplitude * pingPongAlpha;
	rotOffset.X *= rotAmplitude.Pitch * pingPongAlpha;
	rotOffset.Y *= rotAmplitude.Roll * pingPongAlpha;
	rotOffset.Z *= rotAmplitude.Yaw * pingPongAlpha;

	finalRot.Pitch = rotOffset.X;
	finalRot.Roll = rotOffset.Y;
	finalRot.Yaw = rotOffset.Z;

	// calculate new camera offset
	PC.CinematicShakeOffset = offset;
	PC.CinematicShakeRotate = finalRot;

	return !bFinished;
}

function OnFinish()
{
	PC.CinematicShakeOffset = vect(0,0,0);
	PC.CinematicShakeRotate = rot(0,0,0);
}

event bool SetDuration(float _duration)
{
	return false;
}

event float GetDuration()
{
	if (UsesASD())
		return shakeAttackTime + shakeSustainTime + shakeDecayTime;
	else
		return duration;
}

defaultproperties
{
	DName			="Shake View"
	Track			="Effects"
	Help			="Shake camera view"
	UsesDuration	=false

  	easeIn			=0
  	duration		=0
  	easeOut			=0
  	
	shakeAttackTime	=0.01
  	shakeSustainTime=0.5
  	shakeDecayTime	=1
  	
	frequency		=(X=100,Y=100,Z=100)
  	amplitude		=(X=25,Y=25,Z=25)
  	rotFrequency	=(X=100,Y=100,Z=100)
  	rotAmplitude	=(Yaw=1250,Pitch=1250,Roll=0)
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: ne 5.9.2004 15:53:36.000 - Creation time: st 23.5.2018 00:10:49.394 - Created with UnCodeX