Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
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 00252 00253 00254 00255 00256 00257 00258 00259 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 00313 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337 00338 00339 00340 00341 00342 00343 00344 00345 00346 00347 00348 00349 00350 00351 00352 00353 00354 00355 00356 00357 00358 00359 00360 00361 00362 00363 00364 00365 00366 00367 00368 00369 00370 00371 00372 00373 00374 00375 00376 00377 00378 00379 00380 00381 00382 00383 00384 00385 00386 00387 00388 00389 00390 00391 00392 00393 00394 00395 00396 00397 00398 00399 00400 00401 00402 00403 00404 00405 00406 00407 00408 00409 00410 00411 00412 00413 00414 00415 00416 00417 00418 00419 00420 00421 00422 00423 00424 00425 00426 00427 00428 00429 00430 00431 00432 00433 00434 00435 00436 00437 00438 00439 00440 00441 00442 00443 00444 00445 00446 00447 00448 00449 00450 00451 00452 00453 00454 00455 00456 00457 00458 00459 00460 00461 00462 00463 00464 00465 00466 00467 00468 00469 00470 00471 00472 00473 00474 00475 00476 00477 00478 00479 00480 00481 00482 00483 00484 00485 00486 00487 00488 00489 00490 00491 00492 00493 00494 00495 00496 00497 00498 00499 00500 00501 00502 00503 00504 00505 00506 00507 00508 00509 00510 00511 00512 00513 00514 00515 00516 00517 00518 00519 00520 00521 00522 00523 00524 00525 00526 00527 00528 00529 00530 00531 00532 00533 00534 00535 00536 00537 00538 00539 00540 00541 00542 00543 00544 00545 00546 00547 00548 00549 00550 00551 00552 00553 00554 00555 00556 00557 00558 00559 00560 00561 00562 00563 00564 00565 00566 00567 00568 00569 00570 00571 00572 00573 00574 00575 00576 00577 00578 00579 00580 00581 00582 00583 00584 00585 00586 00587 00588 00589 00590 00591 |
/** * Camera: defines the Point of View of a player in world space. * Copyright 1998-2008 Epic Games, Inc. All Rights Reserved. */ class Camera extends Actor notplaceable native; /** PlayerController Owning this Camera Actor */ var PlayerController PCOwner; /** Camera Mode */ var Name CameraStyle; /** default FOV */ var float DefaultFOV; /** true if FOV is locked to a constant value*/ var bool bLockedFOV; /** value FOV is locked at */ var float LockedFOV; /** If we should insert black areas when rendering the scene to ensure an aspect ratio of ConstrainedAspectRatio */ var bool bConstrainAspectRatio; /** If bConstrainAspectRatio is true, add black regions to ensure aspect ratio is this. Ratio is horizontal/vertical. */ var float ConstrainedAspectRatio; /** Default aspect ratio */ var float DefaultAspectRatio; /** If we should apply FadeColor/FadeAmount to the screen. */ var bool bEnableFading; /** Color to fade to. */ var color FadeColor; /** Amount of fading to apply. */ var float FadeAmount; /** Indicates if CamPostProcessSettings should be used when using this Camera to view through. */ var bool bCamOverridePostProcess; /** Post-process settings to use if bCamOverridePostProcess is TRUE. */ var PostProcessSettings CamPostProcessSettings; /** Turn on scaling of color channels in final image using ColorScale property. */ var bool bEnableColorScaling; /** Allows control over scaling individual color channels in the final image. */ var vector ColorScale; /** Should interpolate color scale values */ var bool bEnableColorScaleInterp; /** Desired color scale which ColorScale will interpolate to */ var vector DesiredColorScale; /** Color scale value at start of interpolation */ var vector OriginalColorScale; /** Total time for color scale interpolation to complete */ var float ColorScaleInterpDuration; /** Time at which interpolation started */ var float ColorScaleInterpStartTime; /** The actors which the camera shouldn't see. Used to hide actors which the camera penetrates. */ //var array<Actor> HiddenActors; /* Caching Camera, for optimization */ struct native TCameraCache { /** Cached Time Stamp */ var float TimeStamp; /** cached Point of View */ var TPOV POV; }; var TCameraCache CameraCache; /** * View Target definition * A View Target is responsible for providing the Camera with an ideal Point of View (POV) */ struct native TViewTarget { /** Target Actor used to compute ideal POV */ var() Actor Target; /** Controller of Target (only for non Locally controlled Pawns) */ var() Controller Controller; /** Point of View */ var() TPOV POV; /** Aspect ratio */ var() float AspectRatio; /** PlayerReplicationInfo (used to follow same player through pawn transitions, etc., when spectating) */ var() PlayerReplicationInfo PRI; }; /** Current ViewTarget */ var TViewTarget ViewTarget; /** Pending view target for blending */ var TViewTarget PendingViewTarget; /** Time left when blending to pending view target */ var float BlendTimeToGo; enum EViewTargetBlendFunction { /** Camera does a simple linear interpolation. */ VTBlend_Linear, /** Camera has a slight ease in and ease out, but amount of ease cannot be tweaked. */ VTBlend_Cubic, /** Camera immediately accelerates, but smoothly decelerates into the target. Ease amount controlled by BlendExp. */ VTBlend_EaseIn, /** Camera smoothly accelerates, but does not decelerate into the target. Ease amount controlled by BlendExp. */ VTBlend_EaseOut, /** Camera smoothly accelerates and decelerates. Ease amount controlled by BlendExp. */ VTBlend_EaseInOut, }; /** A set of parameters to describe how to transition between viewtargets. */ struct native ViewTargetTransitionParams { /** Total duration of blend to pending view target. 0 means no blending. */ var() float BlendTime; /** Function to apply to the blend parameter */ var() EViewTargetBlendFunction BlendFunction; /** Exponent, used by certain blend functions to control the shape of the curve. */ var() float BlendExp; structdefaultproperties { BlendFunction=VTBlend_Cubic BlendExp=2.f } // providing the constructor by hand here, because we pass this as an optional parameter // and when the parameter isn't there, the default contructor is called. structcpptext { FViewTargetTransitionParams() { BlendTime = 0.f; BlendFunction = VTBlend_Cubic; BlendExp = 2.f; } } }; var ViewTargetTransitionParams BlendParams; /** List of camera modifiers to apply during update of camera position/ rotation */ var Array<CameraModifier> ModifierList; /** Distance to place free camera from view target */ var float FreeCamDistance; /** Offset to Z free camera position */ var vector FreeCamOffset; // (cpptext) // (cpptext) // (cpptext) // (cpptext) // (cpptext) // (cpptext) // (cpptext) /** * Initialize Camera for associated PlayerController * @param PC PlayerController attached to this Camera. */ function InitializeFor(PlayerController PC) { CameraCache.POV.FOV = DefaultFOV; PCOwner = PC; SetViewTarget(PC.ViewTarget); // set the level default scale SetDesiredColorScale(WorldInfo.DefaultColorScale, 5.f); // Force camera update so it doesn't sit at (0,0,0) for a full tick. // This can have side effects with streaming. UpdateCamera(0.f); } /** * returns camera's current FOV angle */ function float GetFOVAngle() { if( bLockedFOV ) { return LockedFOV; } return CameraCache.POV.FOV; } /** * Lock FOV to a specific value. * A value of 0 to beyond 170 will unlock the FOV setting. */ function SetFOV(float NewFOV) { if( NewFOV < 1 || NewFOV > 170 ) { bLockedFOV = FALSE; return; } bLockedFOV = TRUE; LockedFOV = NewFOV; } /** * Master function to retrieve Camera's actual view point. * do not call this directly, call PlayerController::GetPlayerViewPoint() instead. * * @param OutCamLoc Camera Location * @param OutCamRot Camera Rotation */ final function GetCameraViewPoint(out vector OutCamLoc, out rotator OutCamRot) { // @debug: find out which calls are being made before the camera has been ticked // and have therefore one frame of lag. /* if( CameraCache.TimeStamp != WorldInfo.TimeSeconds ) { `Log(WorldInfo.TimeSeconds @ GetFuncName() @ "one frame of lag"); ScriptTrace(); } */ OutCamLoc = CameraCache.POV.Location; OutCamRot = CameraCache.POV.Rotation; } /** * Sets the new desired color scale and enables interpolation. */ simulated function SetDesiredColorScale(vector NewColorScale, float InterpTime) { // if color scaling is not enabled if (!bEnableColorScaling) { // set the default color scale bEnableColorScaling = TRUE; ColorScale.X = 1.f; ColorScale.Y = 1.f; ColorScale.Z = 1.f; } // Don't bother interpolating if we're already scaling at the desired color if( NewColorScale != ColorScale ) { // save the current as original OriginalColorScale = ColorScale; // set the new desired scale DesiredColorScale = NewColorScale; // set the interpolation duration/time ColorScaleInterpStartTime = WorldInfo.TimeSeconds; ColorScaleInterpDuration = InterpTime; // and enable color scale interpolation bEnableColorScaleInterp = TRUE; } } /** * Performs camera update. * Called once per frame after all actors have been ticked. */ simulated event UpdateCamera(float DeltaTime) { local TPOV NewPOV; local float DurationPct, BlendPct; // update color scale interpolation if (bEnableColorScaleInterp) { BlendPct = FClamp(TimeSince(ColorScaleInterpStartTime)/ColorScaleInterpDuration,0.f,1.f); ColorScale = VLerp(OriginalColorScale,DesiredColorScale,BlendPct); // if we've maxed if (BlendPct == 1.f) { // disable further interpolation bEnableColorScaleInterp = FALSE; } } // Reset aspect ratio and postprocess override associated with CameraActor. bConstrainAspectRatio = FALSE; bCamOverridePostProcess = FALSE; // Update main view target CheckViewTarget(ViewTarget); UpdateViewTarget(ViewTarget, DeltaTime); // our camera is now viewing there NewPOV = ViewTarget.POV; ConstrainedAspectRatio = ViewTarget.AspectRatio; // if we have a pending view target, perform transition from one to another. if( PendingViewTarget.Target != None ) { BlendTimeToGo -= DeltaTime; // Update pending view target CheckViewTarget(PendingViewTarget); UpdateViewTarget(PendingViewTarget, DeltaTime); // blend.... if( BlendTimeToGo > 0 ) { DurationPct = 1.f - BlendTimeToGo / BlendParams.BlendTime; switch (BlendParams.BlendFunction) { case VTBlend_Linear: BlendPct = Lerp(0.f, 1.f, DurationPct); break; case VTBlend_Cubic: BlendPct = FCubicInterp(0.f, 0.f, 1.f, 0.f, DurationPct); break; case VTBlend_EaseIn: BlendPct = FInterpEaseIn(0.f, 1.f, DurationPct, BlendParams.BlendExp); break; case VTBlend_EaseOut: BlendPct = FInterpEaseOut(0.f, 1.f, DurationPct, BlendParams.BlendExp); break; case VTBlend_EaseInOut: BlendPct = FInterpEaseInOut(0.f, 1.f, DurationPct, BlendParams.BlendExp); break; } //BlendPct = FCubicInterp(0.f, class'DialogueManager'.default.OutTan, 1.f, class'DialogueManager'.default.InTan, 1.f - DurationPct); // Update pending view target blend NewPOV = BlendViewTargets(ViewTarget, PendingViewTarget, BlendPct); ConstrainedAspectRatio = Lerp(ViewTarget.AspectRatio, PendingViewTarget.AspectRatio, BlendPct); } else { // we're done blending, set new view target ViewTarget = PendingViewTarget; // clear pending view target PendingViewTarget.Target = None; PendingViewTarget.Controller = None; BlendTimeToGo = 0; // our camera is now viewing there NewPOV = PendingViewTarget.POV; ConstrainedAspectRatio = PendingViewTarget.AspectRatio; } } // Cache results FillCameraCache(NewPOV); } /** * Blend 2 viewtargets. * * @param A Source view target * @paramn B destination view target * @param Alpha Alpha, % of blend from A to B. */ final function TPOV BlendViewTargets(const out TViewTarget A,const out TViewTarget B, float Alpha) { local TPOV POV; POV.Location = VLerp(A.POV.Location, B.POV.Location, Alpha); POV.FOV = Lerp(A.POV.FOV, B.POV.FOV, Alpha); POV.Rotation = RLerp(A.POV.Rotation, B.POV.Rotation, Alpha, TRUE); return POV; } /** * Cache update results */ final function FillCameraCache(const out TPOV NewPOV) { CameraCache.TimeStamp = WorldInfo.TimeSeconds; CameraCache.POV = NewPOV; } /** * Make sure ViewTarget is valid */ native function CheckViewTarget(out TViewTarget VT); /** * Query ViewTarget and outputs Point Of View. * * @param OutVT ViewTarget to use. * @param DeltaTime Delta Time since last camera update (in seconds). */ function UpdateViewTarget(out TViewTarget OutVT, float DeltaTime) { local vector Loc, Pos, HitLocation, HitNormal; local rotator Rot; local Actor HitActor; local CameraActor CamActor; local bool bDoNotApplyModifiers; local TPOV OrigPOV; // store previous POV, in case we need it later OrigPOV = OutVT.POV; // Default FOV on viewtarget OutVT.POV.FOV = DefaultFOV; // Viewing through a camera actor. CamActor = CameraActor(OutVT.Target); if( CamActor != None ) { CamActor.GetCameraView(DeltaTime, OutVT.POV); // Grab aspect ratio from the CameraActor. bConstrainAspectRatio = bConstrainAspectRatio || CamActor.bConstrainAspectRatio; OutVT.AspectRatio = CamActor.AspectRatio; // See if the CameraActor wants to override the PostProcess settings used. bCamOverridePostProcess = CamActor.bCamOverridePostProcess; CamPostProcessSettings = CamActor.CamOverridePostProcess; } else { // Give Pawn Viewtarget a chance to dictate the camera position. // If Pawn doesn't override the camera view, then we proceed with our own defaults if( Pawn(OutVT.Target) == None || !Pawn(OutVT.Target).CalcCamera(DeltaTime, OutVT.POV.Location, OutVT.POV.Rotation, OutVT.POV.FOV) ) { // don't apply modifiers when using these debug camera modes. bDoNotApplyModifiers = TRUE; switch( CameraStyle ) { case 'Fixed' : // do not update, keep previous camera position by restoring // saved POV, in case CalcCamera changes it but still returns false OutVT.POV = OrigPOV; break; case 'ThirdPerson' : // Simple third person view implementation case 'FreeCam' : Loc = OutVT.Target.Location; Rot = OutVT.Target.Rotation; //OutVT.Target.GetActorEyesViewPoint(Loc, Rot); if( CameraStyle == 'FreeCam' ) { Rot = PCOwner.Rotation; } Loc += FreeCamOffset >> Rot; Pos = Loc - Vector(Rot) * FreeCamDistance; HitActor = Trace(HitLocation, HitNormal, Pos, Loc, FALSE, vect(12,12,12)); OutVT.POV.Location = (HitActor == None) ? Pos : HitLocation; OutVT.POV.Rotation = Rot; break; case 'FirstPerson' : // Simple first person, view through viewtarget's 'eyes' default : OutVT.Target.GetActorEyesViewPoint(OutVT.POV.Location, OutVT.POV.Rotation); break; } } } if( !bDoNotApplyModifiers ) { // Apply camera modifiers at the end (view shakes for example) ApplyCameraModifiers(DeltaTime, OutVT.POV); } //`log( WorldInfo.TimeSeconds @ GetFuncName() @ OutVT.Target @ OutVT.POV.Location @ OutVT.POV.Rotation @ OutVT.POV.FOV ); } /** * Set a new ViewTarget with optional BlendTime */ native final function SetViewTarget(Actor NewViewTarget, optional ViewTargetTransitionParams TransitionParams); /** * Give each modifier a chance to change view rotation/deltarot */ function ProcessViewRotation(float DeltaTime, out rotator OutViewRotation, out Rotator OutDeltaRot) { local int ModifierIdx; for( ModifierIdx = 0; ModifierIdx < ModifierList.Length; ModifierIdx++ ) { if( ModifierList[ModifierIdx] != None ) { if( ModifierList[ModifierIdx].ProcessViewRotation(ViewTarget.Target, DeltaTime, OutViewRotation, OutDeltaRot) ) { break; } } } } /** * Apply modifiers on Camera. * @param DeltaTime Time is seconds since last update * @param OutPOV Point of View */ event ApplyCameraModifiers(float DeltaTime, out TPOV OutPOV) { local int ModifierIdx; // Loop through each camera modifier for( ModifierIdx = 0; ModifierIdx < ModifierList.Length; ModifierIdx++ ) { // Apply camera modification and output into DesiredCameraOffset/DesiredCameraRotation if( ModifierList[ModifierIdx] != None && !ModifierList[ModifierIdx].IsDisabled() ) { // If ModifyCamera returns true, exit loop // Allows high priority things to dictate if they are // the last modifier to be applied if( ModifierList[ModifierIdx].ModifyCamera(Self, DeltaTime, OutPOV) ) { break; } } } } function bool AllowPawnRotation() { return TRUE; } /** * list important Camera variables on canvas. HUD will call DisplayDebug() on the current ViewTarget when * the ShowDebug exec is used * * @param HUD - HUD with canvas to draw on * @input out_YL - Height of the current font * @input out_YPos - Y position on Canvas. out_YPos += out_YL, gives position to draw text for next debug line. */ simulated function DisplayDebug(HUD HUD, out float out_YL, out float out_YPos) { local Vector EyesLoc; local Rotator EyesRot; local Canvas Canvas; Canvas = HUD.Canvas; Canvas.SetDrawColor(255,255,255); Canvas.DrawText(" Camera Style:" $ CameraStyle @ "main ViewTarget:" $ ViewTarget.Target); out_YPos += out_YL; Canvas.SetPos(4,out_YPos); Canvas.DrawText(" CamLoc:" $ CameraCache.POV.Location @ "CamRot:" $ CameraCache.POV.Rotation @ "FOV:" $ CameraCache.POV.FOV); out_YPos += out_YL; Canvas.SetPos(4,out_YPos); Canvas.DrawText(" AspectRatio:" $ ConstrainedAspectRatio); out_YPos += out_YL; Canvas.SetPos(4,out_YPos); if( ViewTarget.Target != None ) { ViewTarget.Target.GetActorEyesViewPoint(EyesLoc, EyesRot); Canvas.DrawText(" EyesLoc:" $ EyesLoc @ "EyesRot:" $ EyesRot); out_YPos += out_YL; Canvas.SetPos(4,out_YPos); } } defaultproperties { DefaultFOV=90.000000 DefaultAspectRatio=1.333333 CamPostProcessSettings=(bEnableBloom=True,bEnableSceneEffect=True,Bloom_Scale=1.000000,Bloom_InterpolationDuration=1.000000,DOF_FalloffExponent=4.000000,DOF_BlurKernelSize=16.000000,DOF_MaxNearBlurAmount=1.000000,DOF_MaxFarBlurAmount=1.000000,DOF_ModulateBlurColor=(B=255,G=255,R=255,A=255),DOF_FocusInnerRadius=2000.000000,DOF_InterpolationDuration=1.000000,MotionBlur_MaxVelocity=1.000000,MotionBlur_Amount=0.500000,MotionBlur_FullMotionBlur=True,MotionBlur_CameraRotationThreshold=45.000000,MotionBlur_CameraTranslationThreshold=10000.000000,MotionBlur_InterpolationDuration=1.000000,Scene_HighLights=(X=1.000000,Y=1.000000,Z=1.000000),Scene_MidTones=(X=1.000000,Y=1.000000,Z=1.000000),Scene_InterpolationDuration=1.000000) CameraCache=(POV=(FOV=90.000000)) ViewTarget=(POV=(FOV=90.000000)) PendingViewTarget=(POV=(FOV=90.000000)) BlendParams=(BlendFunction=VTBlend_Cubic,BlendExp=2.000000) FreeCamDistance=256.000000 bHidden=True CollisionType=COLLIDE_CustomDefault Name="Default__Camera" ObjectArchetype=Actor'Engine.Default__Actor' } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |