UMSPawn
Class MovieHead

source: e:\games\UnrealTournament\UMSPawn\Classes\MovieHead.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Inventory
         |
         +--Engine.Weapon
            |
            +--UMSPawn.MovieHead
Direct Known Subclasses:None

class MovieHead
extends Engine.Weapon

//============================================================================= // MovieHead. // by Hugh Macdonald //=============================================================================
Variables
 rotator RotateChange
 Actor RotateTarget
 float RotateTime
 rotator TargetRotation
 rotator TrackingDirections
 Actor TrackingTarget
 bool bRotating
 bool bTracking


Function Summary
 float DetermineRate(float Time)
 void DoAnimate(name AnimSeq, float Time)
 void DoRotate(rotator NewRotation, Actor NewTarget, float Time)
 void DoTrack(Actor NewTarget, rotator Directions)



Source Code


00001	//=============================================================================
00002	// MovieHead.
00003	// by Hugh Macdonald
00004	//=============================================================================
00005	class MovieHead expands Weapon;
00006	
00007	//The number of units of rotation that make up half a full rotation,
00008	//or one Pi radians.
00009	const RotPiVal = 32768;
00010	
00011	//Panning actually includes tilting and rotating the camera, since 
00012	//all three can be controlled with it -- let me know if you need
00013	//seperate functions for the three kinds of rotation
00014	var bool bRotating;
00015	//The rotation to pan to
00016	var rotator TargetRotation;
00017	//The number of seconds to spend rotating
00018	var float RotateTime;
00019	//The change in Pan per second
00020	var rotator RotateChange;
00021	//The actor the camera is trying to pan to
00022	var actor RotateTarget;
00023	//The camera must stay pointed at the TrackingTarget.
00024	var bool bTracking;
00025	//The actor the camera is tracking
00026	var Actor TrackingTarget;
00027	//The directions that will be tracked.  If the value is greater than
00028	//or equal to zero that kind of rotation will be used to track.  So
00029	//only if you don't want to track in a given direction will you want
00030	//to set one of the values to -1.
00031	var rotator TrackingDirections;
00032	
00033	
00034	event Tick(float DeltaTime)
00035	{
00036		local vector TempVec, X, Y, Z;
00037		local rotator TempRot, TempRot2;
00038		
00039		
00040	    //Check for rotating
00041	 	if(bRotating)
00042		{
00043	        //First, do update for moving target/camera if neccesary.
00044			if(RotateTarget != NONE)
00045			{
00046	            TempRot = rotator(RotateTarget.Location - Location);
00047	            DoRotate(TempRot, RotateTarget, RotateTime);
00048			}
00049			
00050			//We need a check to see if it is done.
00051	        if(RotateTime <= DeltaTime)
00052			{
00053				SetRotation(TargetRotation);
00054	            bRotating = false;
00055			}
00056			else
00057			{
00058	            SetRotation(Rotation + (RotateChange * DeltaTime));
00059	            RotateTime -= DeltaTime;
00060			}
00061		}
00062		
00063		//Check for tracking
00064		if(bTracking)
00065		{
00066			//First, check to see if we have lost our target.
00067			if(TrackingTarget == NONE)
00068				bTracking = false;
00069			else
00070			{
00071				TempVec = (TrackingTarget.Location) - Location;
00072				TempRot = rotator(TempVec);
00073				//Examine TrackingDirections to determine how to track.
00074				if(TrackingDirections.Yaw < 0)
00075					TempRot.Yaw = 0;
00076				if(TrackingDirections.Pitch < 0)
00077					TempRot.Pitch = 0;
00078				if(TrackingDirections.Roll < 0)
00079					TempRot.Roll = 0;
00080				//Flip over the camera if needed.
00081	
00082			}
00083		}
00084	
00085	}
00086	
00087	
00088	function DoRotate(rotator NewRotation, actor NewTarget, float Time)
00089	{
00090		//Check for instant pan.
00091		if(Time == 0)
00092		{
00093			SetRotation(NewRotation);
00094	        bRotating = false;
00095		}		
00096		else
00097		{
00098	        bRotating = true;
00099	        bTracking = false;
00100	        RotateTime = Time;
00101	        RotateTarget = NewTarget;
00102			TargetRotation = NewRotation;
00103	        RotateChange = (TargetRotation - Rotation) / RotateTime;
00104		}
00105	}
00106	
00107	function DoTrack(actor NewTarget, rotator Directions)
00108	{
00109		//Check for no target.
00110		if(NewTarget == NONE)
00111			bTracking = false;
00112		else
00113		{
00114			bTracking = true;
00115	        bRotating = false;
00116			TrackingTarget = NewTarget;
00117			TrackingDirections = Directions;
00118		}
00119	}
00120	
00121	function DoAnimate(name AnimSeq, float Time)
00122	{
00123	    local float Rate;
00124	
00125	    PlayAnim(AnimSeq, 1, 0);
00126	    Rate = DetermineRate(Time);
00127	    PlayAnim(AnimSeq, Rate, 0);
00128	}
00129	
00130	
00131	function float DetermineRate(float Time)
00132	{
00133		local float FramesLeft, CurSecsLeft, Ratio;
00134		FramesLeft = 1 - AnimFrame;
00135		CurSecsLeft = FramesLeft / AnimRate;
00136		Ratio = CurSecsLeft / Time;
00137		return Ratio;
00138	}
00139	
00140	defaultproperties
00141	{
00142	}

End Source Code