Overview | Package | Class | Source | Class tree | Glossary | Deus Ex 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 00592 00593 00594 00595 00596 00597 00598 00599 00600 00601 00602 00603 00604 00605 00606 00607 00608 00609 00610 00611 00612 00613 00614 00615 00616 00617 00618 00619 00620 00621 00622 00623 00624 00625 00626 00627 00628 00629 00630 00631 00632 00633 00634 00635 00636 00637 00638 00639 00640 00641 00642 00643 00644 00645 00646 00647 00648 00649 00650 00651 00652 00653 00654 00655 00656 00657 00658 00659 00660 00661 00662 00663 00664 00665 00666 00667 00668 00669 00670 00671 00672 00673 00674 00675 00676 00677 00678 00679 00680 00681 00682 00683 00684 00685 00686 00687 00688 00689 00690 00691 00692 00693 00694 00695 00696 00697 00698 00699 00700 00701 00702 00703 00704 00705 00706 00707 00708 00709 00710 00711 00712 00713 00714 00715 00716 00717 00718 00719 00720 00721 00722 00723 00724 00725 00726 00727 00728 00729 00730 00731 00732 00733 00734 00735 00736 00737 00738 00739 00740 00741 00742 00743 00744 00745 00746 00747 00748 00749 00750 00751 00752 00753 00754 00755 00756 00757 00758 00759 00760 00761 00762 00763 00764 00765 00766 00767 00768 00769 00770 00771 00772 00773 00774 00775 00776 00777 00778 00779 00780 00781 00782 00783 00784 00785 00786 00787 00788 00789 00790 00791 00792 00793 00794 00795 00796 00797 00798 00799 00800 00801 00802 00803 00804 00805 00806 00807 00808 00809 00810 00811 00812 00813 00814 00815 00816 00817 00818 00819 00820 00821 00822 00823 00824 00825 00826 00827 00828 00829 00830 00831 00832 00833 00834 00835 00836 00837 00838 00839 00840 00841 00842 00843 00844 00845 00846 00847 00848 00849 00850 00851 00852 00853 00854 00855 00856 00857 00858 00859 00860 00861 00862 00863 00864 00865 00866 00867 00868 00869 00870 00871 00872 00873 00874 00875 00876 00877 00878 00879 00880 00881 00882 00883 00884 00885 00886 00887 00888 00889 00890 00891 00892 00893 00894 00895 00896 00897 00898 00899 00900 00901 00902 00903 00904 00905 00906 00907 00908 00909 00910 00911 00912 00913 00914 00915 00916 00917 00918 00919 00920 00921 00922 00923 00924 00925 00926 00927 00928 00929 00930 00931 00932 00933 00934 00935 00936 00937 00938 00939 00940 00941 00942 00943 00944 00945 00946 00947 00948 00949 00950 00951 00952 00953 00954 00955 00956 00957 00958 00959 00960 00961 00962 00963 00964 00965 00966 00967 00968 00969 00970 00971 00972 00973 00974 00975 00976 00977 00978 00979 00980 00981 00982 00983 00984 00985 00986 00987 00988 00989 00990 00991 00992 00993 00994 00995 00996 00997 00998 00999 01000 01001 01002 01003 01004 01005 01006 01007 01008 01009 01010 01011 01012 01013 01014 01015 01016 01017 01018 01019 01020 01021 01022 01023 01024 01025 01026 01027 01028 01029 01030 01031 01032 01033 01034 01035 01036 01037 01038 01039 01040 01041 01042 01043 01044 01045 01046 01047 01048 01049 01050 01051 01052 01053 01054 01055 01056 01057 01058 01059 01060 01061 01062 01063 01064 01065 01066 01067 01068 01069 01070 01071 01072 01073 01074 01075 01076 01077 01078 01079 01080 01081 01082 01083 01084 01085 01086 01087 01088 01089 01090 01091 01092 01093 01094 01095 01096 01097 01098 01099 01100 01101 01102 01103 01104 01105 01106 01107 01108 01109 01110 01111 01112 01113 01114 01115 01116 01117 01118 01119 01120 01121 01122 01123 01124 01125 01126 01127 01128 01129 01130 01131 01132 01133 01134 01135 01136 01137 01138 01139 01140 01141 01142 01143 01144 01145 01146 01147 01148 01149 01150 01151 01152 01153 01154 01155 01156 01157 01158 01159 01160 01161 01162 01163 01164 |
//============================================================================= // ConCamera //============================================================================= class ConCamera extends ConObject noexport; var Actor cameraActor; // Actor who owns this event var ECameraPositions cameraPosition; // Predefined camera position var ECameraTypes cameraType; // Camera Type var ECameraTypes cameraMode; var ConLight conLightSpeaker; // Used to light actor's faces var ConLight conLightSpeakingTo; // Used to light actor's faces var Vector cameraOffset; var Rotator rotation; var Float cosAngle; var Int firstActorRotation; var Int setActorCount; var bool bCameraLocationSaved; // Camera Fallback Positions (for when camera view obstructed) var ECameraPositions cameraFallbackPositions[9]; var ECameraPositions cameraHeightPositions[9]; var int currentFallback; var bool bUsingFallback; // Used for CT_Speakers mode var float heightModifier; var float centerModifier; var float distanceMultiplier; var float heightFallbackTrigger; // Actors associated with camera placement var Actor firstActor; var Actor secondActor; // These variable are used to prevent camera angle changes when the // actors change. var Actor lastFirstActor; var Actor lastSecondActor; var Bool ignoreSetActors; // Used for Camera debugging var Bool bDebug; var Vector LastLocation; var Rotator LastRotation; var Bool bInteractiveCamera; // ---------------------------------------------------------------------- // SetupCameraFromEvent() // // Sets up the ConCamera structure that will be used to place the // camera in the PlayerCalcView() function of the DeusExPlayer class. // ---------------------------------------------------------------------- function SetupCameraFromEvent( ConEventMoveCamera event ) { ignoreSetActors = False; cameraType = event.cameraType; // Reset our fallback camera ResetFallbackPosition(); // Setup the camera! switch( cameraType ) { // Predefined camera locations case CT_Predefined: cameraPosition = event.cameraPosition; SetCameraValues(); break; // Speakers camera variables case CT_Speakers: SetupSpeakersCamera( event ); break; // Actor camera variables case CT_Actor: SetupActorCamera( event ); break; // Randomly choose from one of the predefined camera locations case CT_Random: SetupRandomCameraPosition(); break; } } // ---------------------------------------------------------------------- // SetupRandomCameraPosition() // // Picks from one of the various predefined camera positions. There is // logic in this routine to track how often we're changing the camera. // We don't want to move the camera each time the actors change, // especially if the camera view (such as a side view) shows both // actors. // ---------------------------------------------------------------------- function SetupRandomCameraPosition() { local Int randomPosition; // 60% chance that the camera position won't change if the same // actors are speaking. if ( Frand() < 0.60 ) { // Check to make sure the same two actors are speaking if ((( firstActor == lastFirstActor ) || ( firstActor == lastSecondActor )) && (( secondActor == lastSecondActor ) || ( secondActor == lastFirstActor ))) { // If we're presently using a side view, then force the camera // to remain focused on the current actor (so we don't switch // 180 degrees, which is kind of annoying) switch( cameraPosition ) { case CP_SideTight: case CP_SideMid: case CP_SideAbove: case CP_SideAbove45: firstActor = lastFirstActor; secondActor = lastSecondActor; ignoreSetActors = True; break; } return; } } // If we got here, then we're setting up a new random camera angle. We want // to save the current actors so we can extend this camera angle over // several lines of dialogue. lastFirstActor = firstActor; lastSecondActor = secondActor; randomPosition = Rand(10); // Hmmm, this sucks, you can't seem to typecast an int as an enumerated // type. bah humbug switch ( randomPosition ) { case 0: cameraPosition = CP_SideTight; break; case 1: cameraPosition = CP_SideMid; break; case 2: cameraPosition = CP_SideAbove; break; case 3: cameraPosition = CP_SideAbove45; break; case 4: cameraPosition = CP_ShoulderLeft; break; case 5: cameraPosition = CP_ShoulderRight; break; case 6: cameraPosition = CP_HeadShotTight; break; case 7: cameraPosition = CP_HeadShotMid; break; case 8: cameraPosition = CP_HeadShotLeft; break; case 9: cameraPosition = CP_HeadShotRight; break; } SetCameraValues(); } // ---------------------------------------------------------------------- // SetupSpeakersCamera() // // Sets up the camera with info contained in the event structure // ---------------------------------------------------------------------- function SetupSpeakersCamera( ConEventMoveCamera event ) { rotation = event.rotation; heightModifier = event.heightModifier; centerModifier = event.centerModifier; distanceMultiplier = event.distanceMultiplier; } // ---------------------------------------------------------------------- // SetupActorCamera() // // Sets up the camera with info contained in the event structure // ---------------------------------------------------------------------- function SetupActorCamera( ConEventMoveCamera event ) { cameraOffset = event.cameraOffset; rotation = event.rotation; } // ---------------------------------------------------------------------- // SetActors() // // Sets the actors to be used for placing the camera // ---------------------------------------------------------------------- function SetActors( Actor newFirstActor, Actor newSecondActor ) { if ( ignoreSetActors ) return; firstActor = newFirstActor; secondActor = newSecondActor; setActorCount++; // hack for now // cameraOffset = newFirstActor.location; } // ---------------------------------------------------------------------- // SetCameraValues() // // Sets up the camera values for each different camera position // ---------------------------------------------------------------------- function SetCameraValues() { switch( cameraPosition ) { case CP_SideTight: cameraMode = CT_Speakers; rotation = rot(0, 16788, 0); heightModifier = 10.8; centerModifier = 0.0; distanceMultiplier = 0.90; break; case CP_SideMid: cameraMode = CT_Speakers; rotation = rot(0, 16788, 0); heightModifier = 10.8; centerModifier = 0.0; distanceMultiplier = 2.20; break; case CP_SideAbove: cameraMode = CT_Speakers; rotation = rot(59636, 17824, 0); heightModifier = 10.5; centerModifier = 0.0; distanceMultiplier = 1.0; break; case CP_SideAbove45: cameraMode = CT_Speakers; rotation = rot(57136, 40868, 0); heightModifier = -19.0; centerModifier = 0.0; distanceMultiplier = 1.80; break; case CP_ShoulderLeft: cameraMode = CT_Speakers; rotation = rot(0, 39056, 0); heightModifier = 10.5; centerModifier = 0.20; distanceMultiplier = 1.0; break; case CP_ShoulderRight: cameraMode = CT_Speakers; rotation = rot(0, 26456, 0); heightModifier = 10.5; centerModifier = 0.20;; distanceMultiplier = 1.0; break; case CP_HeadShotTight: cameraMode = CT_Actor; rotation = rot(0, 32400, 0); cameraOffset = vect(-23, 0, 0); break; case CP_HeadShotMid: cameraMode = CT_Actor; rotation = rot(0, 32400, 0); cameraOffset = vect(-30, 0, 0); break; case CP_HeadShotLeft: cameraMode = CT_Actor; // rotation = rot(0, 42100, 0); rotation = rot(0, 45100, 0); cameraOffset = vect(-16, 17, 0); break; case CP_HeadShotRight: cameraMode = CT_Actor; // rotation = rot(0, 23500, 0); rotation = rot(0, 20500, 0); cameraOffset = vect(-16, -17, 0); break; case CP_HeadShotSlightRight: cameraMode = CT_Actor; rotation = rot(300, 33600, 0); cameraOffset = vect(-27.4, 2.1, 0); break; case CP_HeadShotSlightLeft: cameraMode = CT_Actor; rotation = rot(300, 29800, 0); cameraOffset = vect(-27.4, -5.60, 0); break; case CP_StraightAboveLookingDown: cameraMode = CT_Speakers; rotation = rot(60000, 16588, 0); heightModifier = 22.22; centerModifier = 0.0; distanceMultiplier = 0.90; break; case CP_StraightBelowLookingUp: cameraMode = CT_Speakers; rotation = rot(8500, 16588, 0); heightModifier = 11.4; centerModifier = 0.0; distanceMultiplier = 0.90; break; case CP_BelowLookingUp: cameraMode = CT_Speakers; rotation = rot(16564, 16224, 0); heightModifier = 3.3; centerModifier = -0.3; distanceMultiplier = 0.90; break; } } // ---------------------------------------------------------------------- // InitializeCameraValues() // // Sets up the camera with default values // ---------------------------------------------------------------------- function InitializeCameraValues(Actor cameraOwner) { cameraPosition = CP_SideTight; SetCameraValues(); CreateHighlights(cameraOwner); } // ---------------------------------------------------------------------- // SwitchCameraMode() // // Switches camera modes between CT_Speakers and CT_Actor // ---------------------------------------------------------------------- function SwitchCameraMode() { if ( cameraMode == CT_Speakers ) cameraMode = CT_Actor; else cameraMode = CT_Speakers; } // ---------------------------------------------------------------------- // IncCameraMode() // // There must be a better way to do enum math // ---------------------------------------------------------------------- function IncCameraMode() { switch( cameraPosition ) { case CP_SideTight: cameraPosition = CP_SideMid; break; case CP_SideMid: cameraPosition = CP_SideAbove; break; case CP_SideAbove: cameraPosition = CP_SideAbove45; break; case CP_SideAbove45: cameraPosition = CP_ShoulderLeft; break; case CP_ShoulderLeft: cameraPosition = CP_ShoulderRight; break; case CP_ShoulderRight: cameraPosition = CP_HeadShotTight; break; case CP_HeadShotTight: cameraPosition = CP_HeadShotMid; break; case CP_HeadShotMid: cameraPosition = CP_HeadShotLeft; break; case CP_HeadShotLeft: cameraPosition = CP_HeadShotRight; break; case CP_HeadShotRight: cameraPosition = CP_HeadShotSlightRight; break; case CP_HeadShotSlightRight: cameraPosition = CP_HeadShotSlightLeft; break; case CP_HeadShotSlightLeft: cameraPosition = CP_StraightAboveLookingDown; break; case CP_StraightAboveLookingDown: cameraPosition = CP_StraightBelowLookingUp; break; case CP_StraightBelowLookingUp: cameraPosition = CP_BelowLookingUp; break; case CP_BelowLookingUp: cameraPosition = CP_SideTight; break; } SetCameraValues(); } // ---------------------------------------------------------------------- // DecCameraMode() // // There must be a better way to do enum math // ---------------------------------------------------------------------- function DecCameraMode() { switch( cameraPosition ) { case CP_SideTight: cameraPosition = CP_BelowLookingUp; break; case CP_SideMid: cameraPosition = CP_SideTight; break; case CP_SideAbove: cameraPosition = CP_SideMid; break; case CP_SideAbove45: cameraPosition = CP_SideAbove; break; case CP_ShoulderLeft: cameraPosition = CP_SideAbove45; break; case CP_ShoulderRight: cameraPosition = CP_ShoulderLeft; break; case CP_HeadShotTight: cameraPosition = CP_ShoulderRight; break; case CP_HeadShotMid: cameraPosition = CP_HeadShotTight; break; case CP_HeadShotLeft: cameraPosition = CP_HeadShotMid; break; case CP_HeadShotRight: cameraPosition = CP_HeadShotLeft; break; case CP_HeadShotSlightRight: cameraPosition = CP_HeadShotRight; break; case CP_HeadShotSlightLeft: cameraPosition = CP_HeadShotSlightRight; break; case CP_StraightAboveLookingDown: cameraPosition = CP_HeadShotSlightLeft; break; case CP_StraightBelowLookingUp: cameraPosition = CP_StraightAboveLookingDown; break; case CP_BelowLookingUp: cameraPosition = CP_StraightBelowLookingUp; break; } SetCameraValues(); } // ---------------------------------------------------------------------- // SetDebugMode() // ---------------------------------------------------------------------- function SetDebugMode(bool bNewDebug) { bDebug = bNewDebug; } // ---------------------------------------------------------------------- // CreateHighlight() // // Creates a highlight above the actor or actors talking. This is done // since sometimes it's difficult to see the actors' faces. // ---------------------------------------------------------------------- function CreateHighlights(Actor cameraOwner) { conLightSpeaker = cameraOwner.Spawn(class'ConLight'); conLightSpeakingTo = cameraOwner.Spawn(class'ConLight'); } // ---------------------------------------------------------------------- // DestroyHighlights() // ---------------------------------------------------------------------- function DestroyHighlights() { if (conLightSpeaker != None) { conLightSpeaker.Destroy(); conLightSpeaker = None; } if (conLightSpeakingTo != None) { conLightSpeakingTo.Destroy(); conLightSpeakingTo = None; } } // ---------------------------------------------------------------------- // CalculateCameraPosition() // // Calculates the camera location and rotation. Returns True if // the camera position was calculated, False if we must defer to the // default PlayerCalcView() function // ---------------------------------------------------------------------- function bool CalculateCameraPosition( out actor ViewActor, out vector CameraLocation, out rotator CameraRotation) { local Vector centerPoint, distVector; local Vector center1, center2; local vector View; local Float distance; local bool bTraceSecondActor; local Int workYaw; // Used to make sure the camera isn't behind something. local float ViewDist; // If either of the actors is missing, abort!!! if ((firstActor == None) || (secondActor == None)) return False; if (bDebug) Log("ConCamera::CalculateCameraPosition()------------------------------"); // Check to see which cameraMode we're in. If we're in Speakers mode, then // the camera is based on the position of the two speakers. Otherwise, // the camera is based on an actor. if ( cameraMode == CT_Speakers ) { // Check to see if both actors are the same. If so, we want // to default to an actor-based camera, since CT_Speakers mode // requires two actors to work properly if (firstActor == secondActor) { SetupSameActorFallbackCamera(); return CalculateCameraPosition(ViewActor, CameraLocation, CameraRotation); } else { // Used to determine if we need to trace the second actor // (we always trace the first) bTraceSecondActor = True; // Set the first center point, based on the first actor's location center1 = firstActor.Location; if (Pawn(firstActor) != None) center1.Z += (Pawn(firstActor).BaseEyeHeight / 1.5) + heightModifier; else if (Decoration(firstActor) != None) center1.Z += (Decoration(firstActor).BaseEyeHeight / 1.5) + heightModifier; center2 = secondActor.Location; if (Pawn(secondActor) != None) center2.Z += Pawn(secondActor).BaseEyeHeight; else if (Decoration(secondActor) != None) center2.Z += Decoration(secondActor).BaseEyeHeight; if (bDebug) log(" center1 = " $ center1); if (bDebug) log(" center2 = " $ center2); centerPoint = (center1 + center2) / 2.0; distance = VSize(center2 - center1) * distanceMultiplier; if (bDebug) log(" VSize(center2 - center1) = " $ VSize(center2 - center1)); if (bDebug) log(" distanceMultiplier = " $ distanceMultiplier); if (bDebug) log(" distance = " $ distance); if (bDebug) log(" centerModifier = " $ centerModifier); if (bDebug) log(" centerPoint = " $ centerPoint); if (bDebug) log(" distVector = " $ distVector); // Update the Camera Rotation. If the first actor is // the PlayerPawn, then use ViewRotation. Otherwise we need to // use the Rotation instead (for ScriptedPawns and Decorations, // which are both derived from Actor). CameraRotation = Rotator(secondActor.Location - firstActor.Location) + rotation; // This beautiful chunk of code below performs some hideous magic to make // sure the camera stays in the same 180 degrees throughout the conversation // (this of course only applies to camera events that are based on multiple // actors. Events baesd on individual actors will override this, of course). // // First pass through, calculate the base angle we'll be using for future // reference. Every pass after that we'll check to make sure the camera falls // within a 180 degree range. If the camera falls outside that range, we'll // move the camera to the other side of the actor, while still facing that // actor (basically mirroring the camera's position). if (setActorCount == 1) { // Use this as the baseline firstActorRotation = Rotator(secondActor.Location - firstActor.Location).Yaw % 65536; if (firstActorRotation < 0) firstActorRotation += 65535; workYaw = CameraRotation.Yaw % 65536; if (workYaw < 0) workYaw += 65536; if ((!((workYaw >= firstActorRotation) && (workYaw <= (firstActorRotation + 32768)))) && (rotation.Yaw < 32768)) { firstActorRotation = (CameraRotation.Yaw - rotation.Yaw) % 65536; if (firstActorRotation < 0) firstActorRotation += 65535; } else if (rotation.Yaw >= 32768) { firstActorRotation += 32768; firstActorRotation = firstActorRotation % 65536; } } else if (setActorCount > 1) { workYaw = CameraRotation.Yaw % 65536; if (workYaw < 0) workYaw += 65536; if ((!((workYaw >= firstActorRotation) && (workYaw <= (firstActorRotation + 32768)))) && (!((workYaw >= (firstActorRotation-65536)) && (workYaw <= ((firstActorRotation + 32768)-65536))))) { CameraRotation = Rotator(secondActor.Location - firstActor.Location) - rotation; } } CameraLocation = centerPoint + Vector(CameraRotation) * (distance * -1); // Check to see if the camera location is nearly identical to the last // location. If so, resort to the previous location and rotation. This is done // to prevent"jitter" of the camera that can sometimes occur with the above algorithm. if ((bCameraLocationSaved) && (VSize(lastLocation - CameraLocation) < 20)) { CameraLocation = lastLocation; CameraRotation = lastRotation; } if (bDebug) log(" CameraLocation = " $ CameraLocation); if (bDebug) log(" CameraRotation = " $ CameraRotation); ViewDist = VSize(centerPoint - CameraLocation); if (bDebug) log(" ViewDist = "$ viewdist); } } else { ViewActor = firstActor; CameraLocation = ViewActor.Location; CameraRotation = ViewActor.DesiredRotation; View = vect(1,0,0) >> CameraRotation; CameraLocation -= (CameraOffset.X * View); View = vect(0,1,0) >> CameraRotation; CameraLocation -= (CameraOffset.Y * View); View = vect(0,0,1) >> CameraRotation; if (ViewActor.IsA('Pawn')) CameraLocation.Z = ViewActor.Location.Z + (Pawn(ViewActor).BaseEyeHeight * 0.95); // CameraLocation.Z = ViewActor.Location.Z + (ViewActor.CollisionHeight * 0.92); else if (ViewActor.IsA('Decoration')) CameraLocation.Z = ViewActor.Location.Z + (Decoration(ViewActor).BaseEyeHeight); // CameraLocation -= (CameraOffset.Z * View); CameraRotation -= rotation; ViewDist = VSize(ViewActor.Location - CameraLocation); } if (ActorObstructed(firstActor, secondActor, CameraLocation, CameraRotation, ViewDist)) { SetupFallbackCamera(); CalculateCameraPosition(ViewActor, CameraLocation, CameraRotation); } else if ((bTraceSecondActor) && (ActorObstructed(secondActor, firstActor, CameraLocation, CameraRotation, ViewDist))) { SetupFallbackCamera(); CalculateCameraPosition(ViewActor, CameraLocation, CameraRotation); } else if (cameraMode == CT_Speakers) { // Check if there is a significant Z difference between the two actors. // If so, then we want to use fallback cameras that don't look so bad. // Usually this happens if the player starts a conversation with // someone on stairs. if (Abs(firstActor.Location.Z - secondActor.Location.Z) > heightFallbackTrigger) { if (SetupHeightFallbackCamera()) CalculateCameraPosition(ViewActor, CameraLocation, CameraRotation); } } // Update the light positions conLightSpeaker.UpdateLocation(firstActor); // If no second actor, then turn that light off if (secondActor != None) conLightSpeakingTo.UpdateLocation(secondActor); else conLightSpeakingTo.TurnOff(); // Save the location and rotation so we can display it LastLocation = CameraLocation; LastRotation = CameraRotation; bCameraLocationSaved = True; if (bDebug) Log("------------------------------ConCamera::CalculateCameraPosition()"); bDebug = False; return True; } // ---------------------------------------------------------------------- // ActorObstructed() // // Performs a trace from the actor's location to the camera position // to make sure it's not obstructed by anything. If so, then we try // to move the camera in a bit closer. If that still fails, then // punt and return True and let the caller deal with the problem. // ---------------------------------------------------------------------- function bool ActorObstructed( Actor actorToTrace, Actor ignoreActor, out vector CameraLocation, out rotator CameraRotation, float ViewDist) { local bool bActorObstructed; local vector HitLocation, HitNormal; local Actor HitActor; // Used for texture trace local vector EndTrace, StartTrace; local actor target; local int texFlags; local name texName, texGroup; local bool bInvisibleWall; // Used to test angle between speakers and camera // to make sure both actors onscreen local Vector vector1, vector2; local Float allowableCosAngle; local Float dp; bActorObstructed = True; if (actorToTrace == None) return bActorObstructed; HitActor = actorToTrace.Trace( HitLocation, HitNormal, actorToTrace.Location, CameraLocation, False); if ((HitActor != None) && (bDebug)) log(" HitActor = " $ HitActor); // Only do this if we don't have the interactive camera on // Perform a trace from the camera location to the actors speaking and // (optionally) being spoken to. If something other than the actors // is hit, then first attempt to pull the camera in a little closer. // If that doesn't work, then punt and use a default camera view. if ((HitActor != None) && (HitActor != actorToTrace) && ((ignoreActor != None) && (HitActor != ignoreActor))) { // Pull the camera in a little closer, but only within 25% of the original // desired location if (bDebug) log(" VSize(CameraLocation - HitLocation) = " $ VSize(CameraLocation - HitLocation)); if (bDebug) log(" ViewDist = " $ ViewDist); if (VSize(CameraLocation - HitLocation) < (ViewDist / 3)) { if (bDebug) log(" CameraLocation = " $ CameraRotation); if (bDebug) log(" HitLocation = " $ HitLocation); if (bDebug) log(" CameraRotation = " $ CameraRotation); ViewDist = ViewDist - (VSize(CameraLocation - HitLocation)) - 25; CameraLocation = (HitLocation + (vector(CameraRotation) * 25)); HitActor = actorToTrace.Trace( HitLocation, HitNormal, actorToTrace.Location, CameraLocation, False); if (bDebug) log(" CameraLocation = " $ CameraRotation); if (bDebug) log(" HitLocation = " $ HitLocation); if (bDebug) log(" CameraRotation = " $ CameraRotation); if (bDebug) log(" ViewDist = " $ ViewDist); if (bDebug) log(" HitActor = " $ HitActor); } } // If HitActor is still not None then check to see if we're behind an // invisble wall. If so, then return False, as the invisible wall // won't be drawn and we should be safe with this camera shot. if ((HitActor != None) && (HitActor != actorToTrace) && ((ignoreActor != None) && (HitActor != ignoreActor)) && (!AllFallbackPositionsExhausted())) { bInvisibleWall = True; foreach HitActor.TraceTexture(class'Actor', target, texName, texGroup, texFlags, HitLocation, HitNormal, actorToTrace.Location, CameraLocation) { if ((texFlags & 1) !=0) // 1 = PF_Invisible { bActorObstructed = False; break; } } } else { bActorObstructed = False; } // If this is a Side camera shot, then check to see if both actors are // visible in the scene if (!bActorObstructed) { allowableCosAngle = 0.50; switch(cameraPosition) { case CP_SideTight: case CP_SideMid: case CP_SideAbove: case CP_SideAbove45: vector1 = actorToTrace.Location - CameraLocation; vector2 = ignoreActor.Location - CameraLocation; dp = vector1 dot vector2; cosangle = dp / (VSize(vector1) * VSize(vector2)); if (cosangle < allowableCosAngle) bActorObstructed = True; break; } } return bActorObstructed; } // ---------------------------------------------------------------------- // SetupSameActorFallbackCamera() // ---------------------------------------------------------------------- function SetupSameActorFallbackCamera() { // Just hardcode it, this isn't something that should ever // happen (and when it does it's a bug) cameraPosition = CP_HeadShotSlightRight; SetCameraValues(); // Log this, since we shouldn't be here log("=============================================="); log("WARNING - Conversation Actor speaking to self!"); log(" Speaker = " $ firstActor.bindName); log("=============================================="); } // ---------------------------------------------------------------------- // SetupFallbackCamera() // // Fallback camera, used in case the selected camera position fails // because it is obstructed by terrain or another actor // ---------------------------------------------------------------------- function SetupFallbackCamera() { bUsingFallback = True; cameraPosition = GetNextFallbackPosition(); SetCameraValues(); } // ---------------------------------------------------------------------- // SetupHeightFallbackCamera() // // Sets a suitable fallback camera to be used when there is a signficant // height difference between two acors // ---------------------------------------------------------------------- function bool SetupHeightFallbackCamera() { local int cameraIndex; local ECameraPositions newCameraPosition; bUsingFallback = True; // First check to see if the current camera position is one // of the allowable ones for this type of shot. If so, // then just pass back False. for(cameraIndex=0; cameraIndex<arrayCount(cameraHeightPositions); cameraIndex++) { if (cameraPosition == cameraHeightPositions[cameraIndex]) return False; } // Okay, now just pick one randomly. :) If it's the same one we had // previoiusly, return False (no sense in doing extra work) newCameraPosition = cameraHeightPositions[rand(arrayCount(cameraHeightPositions))]; if (newCameraPosition != cameraPosition) { cameraPosition = newCameraPosition; SetCameraValues(); return True; } else { return False; } } // ---------------------------------------------------------------------- // GetNextFallbackPosition() // ---------------------------------------------------------------------- function ECameraPositions GetNextFallbackPosition() { local ECameraPositions cameraFallback; if (currentFallback == arrayCount(cameraFallbackPositions)) cameraFallback = cameraFallbackPositions[currentFallback-1]; else cameraFallback = cameraFallbackPositions[currentFallback++]; return cameraFallback; } // ---------------------------------------------------------------------- // ResetFallbackPosition() // ---------------------------------------------------------------------- function ResetFallbackPosition() { currentFallback = 0; bUsingFallback = False; } // ---------------------------------------------------------------------- // AllFallbackPositionsExhausted() // ---------------------------------------------------------------------- function bool AllFallbackPositionsExhausted() { return (currentFallback == arrayCount(cameraFallbackPositions)); } // ---------------------------------------------------------------------- // SetInteractiveCamera() // ---------------------------------------------------------------------- function SetInteractiveCamera(bool bNewInteractiveCamera) { bInteractiveCamera = bNewInteractiveCamera; } // ---------------------------------------------------------------------- // UsingFallbackCamera() // // Returns True if we're presently using a fallback camera shot // ---------------------------------------------------------------------- function bool UsingFallbackCamera() { return bUsingFallback; } // ---------------------------------------------------------------------- // UsingHeadshot() // // Returns True if we're presently using a camera trained on a // single actor // ---------------------------------------------------------------------- function bool UsingHeadshot() { local bool bUsingHeadshot; bUsingHeadshot = False; if (cameraType == CT_Predefined) { switch(cameraPosition) { // Intentional Fallthrough case CP_ShoulderLeft: case CP_ShoulderRight: case CP_HeadShotTight: case CP_HeadShotMid: case CP_HeadShotLeft: case CP_HeadShotRight: case CP_HeadShotSlightRight: case CP_HeadShotSlightLeft: bUsingHeadshot = True; break; } } return bUsingHeadshot; } // ---------------------------------------------------------------------- // LogCameraInfo() // // Writes current camera info to the log // ---------------------------------------------------------------------- function LogCameraInfo() { bDebug = True; log(""); log("ConCamera --------------------------------------------------------"); log(" cameraPosition = " $ cameraPosition); log(" cameraMode = " $ cameraMode); log(" rotation = " $ rotation); log(""); log(" LastLocation = " $ LastLocation); log(" LastRotation = " $ LastRotation); log(""); if ( cameraMode == CT_Speakers ) { log(" firstActor = " $ firstActor); log(" Location = " $ firstActor.Location); log(" Rotation = " $ firstActor.Rotation); if (Pawn(firstActor) != None) log(" baseEyeHeight = " $ Pawn(firstActor).baseEyeHeight); log(""); log(" secondActor = " $ secondActor); log(" Location = " $ secondActor.Location); log(" Rotation = " $ secondActor.Rotation); if (Pawn(secondActor) != None) log(" baseEyeHeight = " $ Pawn(secondActor).baseEyeHeight); log(""); log(" heightModifier = " $ heightModifier); log(" centerModifier = " $ centerModifier); log(" distanceMultiplier = " $ distanceMultiplier); } else { log(" actor rotation = " $ firstActor.rotation); log(" cameraOffset = " $ cameraOffset); log(" actor = " $ firstActor); } log("-------------------------------------------------------- ConCamera"); log(""); } // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- defaultproperties { cameraFallbackPositions(1)=CP_ShoulderLeft cameraFallbackPositions(2)=CP_ShoulderRight cameraFallbackPositions(3)=CP_HeadShotSlightRight cameraFallbackPositions(4)=CP_HeadShotSlightLeft cameraFallbackPositions(5)=CP_HeadShotLeft cameraFallbackPositions(6)=CP_HeadShotRight cameraFallbackPositions(7)=CP_HeadShotMid cameraFallbackPositions(8)=CP_HeadShotTight cameraHeightPositions(0)=CP_SideAbove cameraHeightPositions(1)=CP_SideAbove45 cameraHeightPositions(2)=CP_StraightAboveLookingDown cameraHeightPositions(3)=CP_StraightBelowLookingUp cameraHeightPositions(4)=CP_HeadShotLeft cameraHeightPositions(5)=CP_HeadShotRight cameraHeightPositions(6)=CP_HeadShotSlightRight cameraHeightPositions(7)=CP_HeadShotSlightLeft cameraHeightPositions(8)=CP_HeadShotMid heightFallbackTrigger=30.000000 } |
Overview | Package | Class | Source | Class tree | Glossary | Deus Ex UnrealScript Documentation |
previous class next class | frames no frames |