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

Engine.DebugCameraController


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
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
// PCF Begin (Debug Camera)
//-----------------------------------------------------------
// Debug Camera Controller
//
// To turn it on, please press Alt+C or both (left and right) analogs on xbox pad
// After turning:
//   WASD  | Left Analog - moving
//   Mouse | Right Analog - rotating
//   Shift | XBOX_KeyB - move faster
//   Q/E   | LT/RT - move Up/Down
//   Enter | XBOX_KeyA - to call "FreezeRendering" console command
//   Alt+C | LeftThumbstick - to toggle debug camera
//
// * Copyright 1998-2011 Epic Games, Inc. All Rights Reserved.
//-----------------------------------------------------------
class DebugCameraController extends PlayerController
	config(Input)
	native(Controller);

/** The key that triggers PrimarySelect(). */
var globalconfig name PrimaryKey;
/** The key that triggers SecondarySelect(). */
var globalconfig name SecondaryKey;
/** The key that triggers Unselect(). */
var globalconfig name UnselectKey;
/** Whether to show information about the selected actor on the debug camera HUD. */
var globalconfig bool bShowSelectedInfo;

var PlayerController        OryginalControllerRef;
var Player                  OryginalPlayer;
var bool                    bIsFrozenRendering;
var	DrawFrustumComponent	DrawFrustum;
var Actor					SelectedActor;
var PrimitiveComponent		SelectedComponent;

/**
 * Called when an actor has been selected with the primary key (e.g. left mouse button).
 *
 * @param HitLoc	World-space position of the selection point.
 * @param HitNormal	World-space normal of the selection point.
 * @param HitInfo	Info struct for the selection point.
 */
native function PrimarySelect( vector HitLoc, vector HitNormal, TraceHitInfo HitInfo );

/**
 * Called when an actor has been selected with the secondary key (e.g. right mouse button).
 *
 * @param HitLoc	World-space position of the selection point.
 * @param HitNormal	World-space normal of the selection point.
 * @param HitInfo	Info struct for the selection point.
 */
native function SecondarySelect( vector HitLoc, vector HitNormal, TraceHitInfo HitInfo );

/**
 * Called when the user pressed the unselect key, just before the selected actor is cleared.
 */
native function Unselect();

simulated event PostBeginPlay()
{
    super.PostBeginPlay();

    // if hud is existing, delete it and create new hud for debug camera
	if ( myHUD != None )
		myHUD.Destroy();
	myHUD = Spawn( class'DebugCameraHUD', self);
}

/*
 *  Function called on activation debug camera controller
 */
function OnActivate( PlayerController PC )
{
    if(DrawFrustum==None) {
        DrawFrustum = new(PC.PlayerCamera) class'DrawFrustumComponent';
    }
    DrawFrustum.SetHidden( false );
    PC.SetHidden(false);
    PC.PlayerCamera.SetHidden(false);

    DrawFrustum.FrustumAngle = PC.PlayerCamera.CameraCache.POV.FOV;
    DrawFrustum.SetAbsolute(true, true, false);
    DrawFrustum.SetTranslation(PC.PlayerCamera.CameraCache.POV.Location);
    DrawFrustum.SetRotation(PC.PlayerCamera.CameraCache.POV.Rotation);

    PC.PlayerCamera.AttachComponent(DrawFrustum);
    ConsoleCommand("show camfrustums"); //called to render camera frustums from oryginal player camera
}

/**
 *  Function called on deactivation debug camera controller
 */
function OnDeactivate( PlayerController PC )
{
    DrawFrustum.SetHidden( true );
    ConsoleCommand("show camfrustums");
    PC.PlayerCamera.DetachComponent(DrawFrustum);
    PC.SetHidden(true);
    PC.PlayerCamera.SetHidden(true);
}

//function called from key bindings command to save information about
// turning on/off FreezeRendering command.
exec function SetFreezeRendering()
{
     ConsoleCommand("FreezeRendering");
     bIsFrozenRendering = !bIsFrozenRendering;
}

//function called from key bindings command
exec function MoreSpeed()
{
    bRun = 2;
}

//function called from key bindings command
exec function NormalSpeed()
{
    bRun = 0;
}

/*
 * Switch from debug camera controller to local player controller
 */
function DisableDebugCamera()
{
    if( OryginalControllerRef != none )
    {
        // restore FreezeRendering command state before quite
        if( bIsFrozenRendering==true ) {
            ConsoleCommand("FreezeRendering");
            bIsFrozenRendering = false;
        }
        if( OryginalPlayer != none )
        {
            OnDeactivate( OryginalControllerRef );
            OryginalPlayer.SwitchController( OryginalControllerRef );
            OryginalControllerRef = none;
        }
    }
}

auto state PlayerWaiting
{
	function PlayerMove(float DeltaTime)
	{
		local float UndilatedDeltaTime;
		
		UndilatedDeltaTime = DeltaTime / WorldInfo.TimeDilation;

		super.PlayerMove(UndilatedDeltaTime);

		if (WorldInfo.Pauser != None)
		{
			PlayerCamera.UpdateCamera(DeltaTime);
		}
	}
};

/**
 * Called from DebugCameraInput
 * Process an input key event routed through unrealscript from another object. This method is assigned as the value for the
 * OnRecievedNativeInputKey delegate so that native input events are routed to this unrealscript function.
 *
 * @param	ControllerId	the controller that generated this input key event
 * @param	Key				the name of the key which an event occured for (KEY_Up, KEY_Down, etc.)
 * @param	EventType		the type of event which occured (pressed, released, etc.)
 * @param	AmountDepressed	for analog keys, the depression percent.
 *
 * @return	true to consume the key event, false to pass it on.
 */
function bool NativeInputKey( int ControllerId, name Key, EInputEvent Event, float AmountDepressed = 1.f, bool bGamepad = FALSE )
{
    local vector		CamLoc, ZeroVec;
    local rotator		CamRot;
   	local TraceHitInfo	HitInfo;
	local Actor			HitActor;
	local vector		HitLoc, HitNormal;

	CamLoc = PlayerCamera.CameraCache.POV.Location;
    CamRot = PlayerCamera.CameraCache.POV.Rotation;

	if ( Event == IE_Pressed )
	{
		if ( Key == UnselectKey )
		{
			Unselect();
			SelectedActor = None;
			SelectedComponent = None;
			return true;
		}
		if ( Key == PrimaryKey )
		{
			HitActor = Trace(HitLoc, HitNormal, vector(camRot) * 5000 * 20 + CamLoc, CamLoc, true, ZeroVec, HitInfo);
			if( HitActor != None)
			{
				SelectedActor = HitActor;
				SelectedComponent = HitInfo.HitComponent;
				PrimarySelect( HitLoc, HitNormal, HitInfo );
			}
			return true;
		}
		if ( Key == SecondaryKey )
		{
			HitActor = Trace(HitLoc, HitNormal, vector(camRot) * 5000 * 20 + CamLoc, CamLoc, true, ZeroVec, HitInfo);
			if( HitActor != None)
			{
				SelectedActor = HitActor;
				SelectedComponent = HitInfo.HitComponent;
				SecondarySelect( HitLoc, HitNormal, HitInfo );
			}
			return true;
		}
	}
	return false;
}

exec function ShowDebugSelectedInfo()
{
	bShowSelectedInfo = !bShowSelectedInfo;
}

/** Overridden to potentially pipe commands to regular PlayerController */
native function string ConsoleCommand(string Command, optional bool bWriteToLog = true);

cpptext
{
	/**
	 * Builds a list of components that are hidden based upon gameplay
	 *
	 * @param ViewLocation the view point to hide/unhide from
	 * @param HiddenComponents the list to add to/remove from
	 */
	virtual void UpdateHiddenComponents(const FVector& ViewLocation,TSet<UPrimitiveComponent*>& HiddenComponents);
}

defaultproperties
{
 	InputClass=class'Engine.DebugCameraInput'
    OryginalControllerRef=None
    OryginalPlayer=None
    bIsFrozenRendering=false

    DrawFrustum=none
	bHidden=FALSE
	bHiddenEd=FALSE

	bAlwaysTick=TRUE
}
// PCF End

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: to 6-1-2011 07:10:36.000 - Creation time: ti 22-3-2011 19:57:05.109 - Created with UnCodeX