The three virtues of a programmer: Laziness, Impatience, and Hubris. – Larry Wall
Difference between revisions of "Unreal Wiki:Scratchpad"
From Unreal Wiki, The Unreal Engine Documentation Site
Line 6: | Line 6: | ||
<uscript> | <uscript> | ||
− | function | + | // if spider mode, update rotation based on floor |
− | { | + | function UpdateRotation(float DeltaTime, float maxPitch) |
− | + | { | |
− | + | local vector X,Y,Z; | |
+ | local rotator ViewRotation; | ||
+ | local vector MyFloor, CrossDir, FwdDir, OldFwdDir, OldX, RealFloor; | ||
− | + | if ( bInterpolating || Pawn.bInterpolating ) | |
− | + | { | |
− | + | ViewShake(deltaTime); | |
− | + | return; | |
− | + | } | |
− | + | GetAxes(Rotation,X,Y,Z); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | TurnTarget = None; | |
− | + | bRotateToDesired = false; | |
− | + | bSetTurnRot = false; | |
− | + | ||
− | + | if (PolarityPawn(Pawn).currentSurfaceNormal == -oldSurfaceNormal) | |
− | + | MyFloor = oldSurfaceNormal Cross X; | |
− | + | else | |
− | } | + | MyFloor = PolarityPawn(Pawn).currentSurfaceNormal; |
+ | |||
+ | if ( MyFloor != oldSurfaceNormal ) | ||
+ | { | ||
+ | // smoothly change floor | ||
+ | RealFloor = MyFloor; | ||
+ | MyFloor = Normal(6*DeltaTime * MyFloor + (1 - 6*DeltaTime) * oldSurfaceNormal); | ||
+ | if ( (RealFloor Dot MyFloor) > 0.9999 ) | ||
+ | MyFloor = RealFloor; | ||
+ | else | ||
+ | { | ||
+ | // translate view direction | ||
+ | CrossDir = Normal(RealFloor Cross oldSurfaceNormal); | ||
+ | FwdDir = CrossDir Cross MyFloor; | ||
+ | OldFwdDir = CrossDir Cross oldSurfaceNormal; | ||
+ | X = MyFloor * (oldSurfaceNormal Dot X) | ||
+ | + CrossDir * (CrossDir Dot X) | ||
+ | + FwdDir * (OldFwdDir Dot X); | ||
+ | X = Normal(X); | ||
+ | |||
+ | Z = MyFloor * (oldSurfaceNormal Dot Z) | ||
+ | + CrossDir * (CrossDir Dot Z) | ||
+ | + FwdDir * (OldFwdDir Dot Z); | ||
+ | Z = Normal(Z); | ||
+ | oldSurfaceNormal = MyFloor; | ||
+ | Y = Normal(MyFloor Cross X); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if ( (aTurn != 0) || (aLookUp != 0) ) | ||
+ | { | ||
+ | // adjust Yaw based on aTurn | ||
+ | if ( aTurn != 0 ) | ||
+ | X = Normal(X + 3 * Y * Sin(0.0005*DeltaTime*aTurn)); | ||
+ | |||
+ | // adjust Pitch based on aLookUp | ||
+ | if ( aLookUp != 0 ) | ||
+ | { | ||
+ | OldX = X; | ||
+ | X = Normal(X + 3 * Z * Sin(0.0005*DeltaTime*aLookUp)); | ||
+ | Z = Normal(X Cross Y); | ||
+ | |||
+ | // bound max pitch | ||
+ | if ( (Z Dot MyFloor) < 0.25 /* was 0.707 */ ) | ||
+ | // TODO FIX CAMERA PITCH EXTREMES | ||
+ | { | ||
+ | ClientMessage("OldX: " $ OldX); | ||
+ | OldX = 0.252*Normal(OldX - MyFloor * (MyFloor Dot OldX)); | ||
+ | // WAS: OldX = Normal(OldX - MyFloor * (MyFloor Dot OldX)); | ||
+ | ClientMessage("New OldX: " $ OldX); | ||
+ | |||
+ | if ( (X Dot MyFloor) > 0) | ||
+ | X = Normal(OldX + MyFloor); | ||
+ | else | ||
+ | X = Normal(OldX - MyFloor); | ||
+ | ClientMessage("FinalX: " $ X); | ||
+ | Z = Normal(X Cross Y); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | // calculate new Y axis | ||
+ | Y = Normal(MyFloor Cross X); | ||
+ | } | ||
+ | ViewRotation = OrthoRotation(X,Y,Z); | ||
+ | SetRotation(ViewRotation); | ||
+ | ViewShake(deltaTime); | ||
+ | ViewFlash(deltaTime); | ||
+ | Pawn.FaceRotation(ViewRotation, deltaTime ); | ||
+ | } | ||
</uscript> | </uscript> |
Revision as of 21:41, 26 April 2008
This page is for pasting code you want to show someone as an example or to get assistance with. This allows you to easily collaborate with someone to solve a problem, and allows easy comparisons of the edits.
You are free to remove any existing code from below, and paste your code between the <uscript> </uscript> tags. If the page hasn't been edited in 24 hours, you can assume it isn't needed anymore and can be removed. A full edit history will be available, so don't worry about losing anything.
// if spider mode, update rotation based on floor function UpdateRotation(float DeltaTime, float maxPitch) { local vector X,Y,Z; local rotator ViewRotation; local vector MyFloor, CrossDir, FwdDir, OldFwdDir, OldX, RealFloor; if ( bInterpolating || Pawn.bInterpolating ) { ViewShake(deltaTime); return; } GetAxes(Rotation,X,Y,Z); TurnTarget = None; bRotateToDesired = false; bSetTurnRot = false; if (PolarityPawn(Pawn).currentSurfaceNormal == -oldSurfaceNormal) MyFloor = oldSurfaceNormal Cross X; else MyFloor = PolarityPawn(Pawn).currentSurfaceNormal; if ( MyFloor != oldSurfaceNormal ) { // smoothly change floor RealFloor = MyFloor; MyFloor = Normal(6*DeltaTime * MyFloor + (1 - 6*DeltaTime) * oldSurfaceNormal); if ( (RealFloor Dot MyFloor) > 0.9999 ) MyFloor = RealFloor; else { // translate view direction CrossDir = Normal(RealFloor Cross oldSurfaceNormal); FwdDir = CrossDir Cross MyFloor; OldFwdDir = CrossDir Cross oldSurfaceNormal; X = MyFloor * (oldSurfaceNormal Dot X) + CrossDir * (CrossDir Dot X) + FwdDir * (OldFwdDir Dot X); X = Normal(X); Z = MyFloor * (oldSurfaceNormal Dot Z) + CrossDir * (CrossDir Dot Z) + FwdDir * (OldFwdDir Dot Z); Z = Normal(Z); oldSurfaceNormal = MyFloor; Y = Normal(MyFloor Cross X); } } if ( (aTurn != 0) || (aLookUp != 0) ) { // adjust Yaw based on aTurn if ( aTurn != 0 ) X = Normal(X + 3 * Y * Sin(0.0005*DeltaTime*aTurn)); // adjust Pitch based on aLookUp if ( aLookUp != 0 ) { OldX = X; X = Normal(X + 3 * Z * Sin(0.0005*DeltaTime*aLookUp)); Z = Normal(X Cross Y); // bound max pitch if ( (Z Dot MyFloor) < 0.25 /* was 0.707 */ ) // TODO FIX CAMERA PITCH EXTREMES { ClientMessage("OldX: " $ OldX); OldX = 0.252*Normal(OldX - MyFloor * (MyFloor Dot OldX)); // WAS: OldX = Normal(OldX - MyFloor * (MyFloor Dot OldX)); ClientMessage("New OldX: " $ OldX); if ( (X Dot MyFloor) > 0) X = Normal(OldX + MyFloor); else X = Normal(OldX - MyFloor); ClientMessage("FinalX: " $ X); Z = Normal(X Cross Y); } } // calculate new Y axis Y = Normal(MyFloor Cross X); } ViewRotation = OrthoRotation(X,Y,Z); SetRotation(ViewRotation); ViewShake(deltaTime); ViewFlash(deltaTime); Pawn.FaceRotation(ViewRotation, deltaTime ); }