UMSSmoothCamera
Class SmoothCamera

source: e:\games\UnrealTournament\UMSSmoothCamera\Classes\SmoothCamera.uc
|
+--UMSSmoothCamera.SmoothCamera
Direct Known Subclasses:None

class SmoothCamera
extends Core.Object


Variables
 vector SmoothDollyLocChange
 vector SmoothDollyLocStart
 vector SmoothDollyTargetLocation
 float SmoothDollyTime
 float SmoothDollyTotalTime
 float SmoothPanAccelTime
 rotator SmoothPanRotChange
 rotator SmoothPanRotStart
 rotator SmoothPanTargetRotation
 float SmoothPanTime
 float SmoothPanTotalTime
 float SmoothdollyAccelTime
 bool bAcceleratingDolly
 bool bAcceleratingPan
 bool bDeceleratingDolly
 bool bDeceleratingPan
 bool bSmoothDollying
 bool bSmoothPanning


Function Summary
 void DoSmoothDolly(vector NewLocation, Actor NewTarget, float Time, float AccelTime, bool bAccel, bool bDecel)
 void DoSmoothPan(rotator NewRotation, Actor NewTarget, float Time, float AccelTime, bool bAccel, bool bDecel)
 float getSmoothPos(float currentTime, float x, bool bAccel, bool bDecel)



Source Code


00001	class SmoothCamera expands MovieCamera;
00002	
00003	var bool bAcceleratingPan;
00004	var bool bDeceleratingPan;
00005	
00006	var bool bSmoothPanning;
00007	
00008	var float SmoothPanTime;
00009	var float SmoothPanTotalTime;
00010	var float SmoothPanAccelTime;
00011	var rotator SmoothPanTargetRotation;
00012	var rotator SmoothPanRotStart;
00013	var rotator SmoothPanRotChange;
00014	
00015	
00016	var bool bAcceleratingDolly;
00017	var bool bDeceleratingDolly;
00018	
00019	var bool bSmoothDollying;
00020	
00021	var float SmoothDollyTime;
00022	var float SmoothDollyTotalTime;
00023	var float SmoothdollyAccelTime;
00024	var vector SmoothDollyTargetLocation;
00025	var vector SmoothDollyLocStart;
00026	var vector SmoothDollyLocChange;
00027	
00028	function DoSmoothPan(rotator NewRotation, actor NewTarget, float Time, float AccelTime, bool bAccel, bool bDecel)
00029	{
00030		if((!bDecel && !bAccel) || (AccelTime == 0) || (Time == 0))
00031		{
00032			bSmoothPanning = false;
00033			DoPan(NewRotation, NewTarget, Time);
00034			return;
00035		}
00036		
00037		bSmoothPanning = true;
00038		bChaseCam = false;
00039		bTracking = false;
00040		
00041		SmoothPanTargetRotation = NewRotation;
00042		
00043		while((SmoothPanTargetRotation.yaw - Rotation.yaw) > 32768)
00044		{
00045		    SmoothPanTargetRotation.yaw -= 65536;
00046		}
00047		while((SmoothPanTargetRotation.pitch - Rotation.pitch) > 32768)
00048		{                  
00049		    SmoothPanTargetRotation.pitch -= 65536;
00050		}
00051		while((SmoothPanTargetRotation.roll - Rotation.roll) > 32768)
00052		{
00053		    SmoothPanTargetRotation.roll -= 65536;
00054		}
00055		while((SmoothPanTargetRotation.yaw - Rotation.yaw) < -32768)
00056		{
00057		    SmoothPanTargetRotation.yaw += 65536;
00058		}
00059		while((SmoothPanTargetRotation.pitch - Rotation.pitch) < -32768)
00060		{                  
00061		    SmoothPanTargetRotation.pitch += 65536;
00062		}
00063		while((SmoothPanTargetRotation.roll - Rotation.roll) < -32768)
00064		{
00065		    SmoothPanTargetRotation.roll += 65536;
00066		}
00067	
00068		SmoothPanRotChange = SmoothPanTargetRotation - Rotation;
00069		SmoothPanRotStart = Rotation;
00070		bAcceleratingPan = bAccel;
00071		bDeceleratingPan = bDecel;
00072		SmoothPanAccelTime = AccelTime;
00073		SmoothPanTotalTime = Time;
00074		SmoothPanTime = 0;
00075		
00076		if((bAccel && bDecel) && (SmoothPanAccelTime > (SmoothPanTotalTime / 2)))
00077			SmoothPanAccelTime = SmoothPanTotalTime / 2;
00078		else if(((bAccel && !bDecel) || (bDecel && !bAccel)) && (SmoothPanAccelTime > SmoothPanTotalTime))
00079			SmoothPanAccelTime = SmoothPanTotalTime;
00080	}
00081	
00082	function DoSmoothDolly(vector NewLocation, actor NewTarget, float Time, float AccelTime, bool bAccel, bool bDecel)
00083	{
00084		if((!bDecel && !bAccel) || (AccelTime == 0) || (Time == 0))
00085		{
00086			bSmoothDollying = false;
00087			DoDolly(NewLocation, NewTarget, Time);
00088			return;
00089		}
00090		
00091		bSmoothDollying = true;
00092		bChaseCam = false;
00093		bCircling = false;
00094		bInterpolating = false;
00095		
00096		SmoothDollyTargetLocation = NewLocation;
00097		SmoothDollyLocChange = NewLocation - Location;
00098		SmoothDollyLocStart = Location;
00099		bAcceleratingDolly = bAccel;
00100		bDeceleratingDolly = bDecel;
00101		SmoothDollyAccelTime = AccelTime;
00102		SmoothDollyTotalTime = Time;
00103		SmoothDollyTime = 0;
00104		
00105		if((bAccel && bDecel) && (SmoothDollyAccelTime > (SmoothDollyTotalTime / 2)))
00106			SmoothDollyAccelTime = SmoothDollyTotalTime / 2;
00107		else if(((bAccel && !bDecel) || (bDecel && !bAccel)) && (SmoothDollyAccelTime > SmoothDollyTotalTime))
00108			SmoothDollyAccelTime = SmoothDollyTotalTime;
00109	}
00110	
00111	event Tick(float DeltaTime)
00112	{
00113		local float tempFloat;
00114		local float tempFloat2;
00115		local float tempFloat3;
00116		
00117		if(bSmoothPanning)
00118		{
00119			if(SmoothPanTime >= SmoothPanTotalTime)
00120			{
00121				SetRotation(SmoothPanTargetRotation);
00122				bSmoothPanning = false;
00123			}
00124			else
00125			{
00126				tempFloat = SmoothPanAccelTime / SmoothPanTotalTime;
00127				tempFloat2 = SmoothPanTime / SmoothPanTotalTime;
00128				tempFloat3 = getSmoothPos(tempFloat2, tempfloat, bAcceleratingPan, bDeceleratingPan);
00129				
00130				SetRotation(SmoothPanRotStart + (SmoothPanRotChange * tempFloat3));
00131				
00132				SmoothPanTime += DeltaTime;
00133			}
00134		}
00135	
00136		if(bSmoothDollying)
00137		{
00138			if(SmoothDollyTime >= SmoothDollyTotalTime)
00139			{
00140				SetLocation(SmoothDollyTargetLocation);
00141				bSmoothDollying = false;
00142			}
00143			else
00144			{
00145				tempFloat = SmoothDollyAccelTime / SmoothDollyTotalTime;
00146				tempFloat2 = SmoothDollyTime / SmoothDollyTotalTime;
00147				tempFloat3 = getSmoothPos(tempFloat2, tempfloat, bAcceleratingDolly, bDeceleratingDolly);
00148				
00149				SetLocation(SmoothDollyLocStart + (SmoothDollyLocChange * tempFloat3));
00150				
00151				SmoothDollyTime += DeltaTime;
00152			}
00153		}
00154		
00155		super.Tick(DeltaTime);
00156	}
00157	
00158	function float getSmoothPos(float currentTime, float x, bool bAccel, bool bDecel)
00159	{
00160		local float A;
00161		local float grad;
00162		local float temp;
00163		
00164		
00165		if(bAccel && bDecel)
00166		{
00167			A = -0.5 / ((2 * x**3) - (1.5 * x**2));
00168			
00169			if(currentTime <= x)
00170			{
00171				temp = (A * currentTime**3);
00172				return temp;
00173			}
00174	
00175			if(currentTime >= (1 - x))
00176			{
00177				temp = ((A * (currentTime-1)**3) + 1);
00178				return temp;
00179			}
00180	
00181			grad = 3 * A * x**2;
00182			
00183			temp = ((grad * (currentTime - 0.5)) + 0.5);
00184			return temp;
00185		}
00186		
00187		A = -1 / ((2 * x**3) - (3 * x**2));
00188		
00189		if(bAccel && (currentTime <= x))
00190			return (A * currentTime*currentTime*currentTime);
00191		
00192		if(bDecel && (currentTime >= (1 - x)))
00193			return ((A * (currentTime-1)**3) + 1);
00194		
00195		grad = 3 * A * x**2;
00196		
00197		if(bAccel)
00198			return ((grad * (currentTime - 1)) + 1);
00199		
00200		if(bDecel)
00201			return (grad * currentTime);
00202	}
00203	
00204	defaultproperties
00205	{
00206	}

End Source Code