Legacy:UnrealTournament Extension Pack/XtMainUtil - Unreal Wiki

# Legacy:UnrealTournament Extension Pack/XtMainUtil

### From Unreal Wiki, The Unreal Engine Documentation Site

< Legacy:UnrealTournament Extension Pack
Object_(UT) >> xtMainUtil (Package: xtCore.u)

## About/Description

The basic Util of the UnrealTournament Extension Pack provides tons of new functions relating many different tasks and topics. All functions are static functions to allow calling them from every class without any reference. Every function that represents a mathematical or physical law is a additionally declared as "final" because it is written as it should be written and should not be modified in subclasses, because it would alter the original meaning. However this page serves as a complete online-reference of all functions the Util contains + detailed and clear description. All functions not enterily written by me are marked and credited with the original author and/or links to his/her source. Some functions are also declared in actor-based root classes due to better implementation into actor classes (like GetPlayer() both in xtMainUtil and xtRootActor). The Util has it's "own version" due to frequently updating, fixing and adding functions.

Class Name | xtMainUtil.uc
Type/Perpose | Global Function providing class
Topics | Maths, Vectors, Rotators, Quaternions, Strings, Conversions..
Superclass | Object_(UT)
Subclasses | xtAIUtil, [[UnrealTournament_Extension_Pack/xtCanvasUtil | xtCanvasUtil]], xtPhysicsUtil, xtThelemaPhysics
Current Version | v1.2
Current Function Count | 128
Author | Shadow

## Constants

const sourcescale
  A simple base value.
const e
  The euler constant, also defined by the Euler Function.
const go
  constant of the golden rule
const sinPI
  Sin(PI) as constant (faster than calculating sin(PI))
const cosPI
  Cos(PI) as constant (faster than calculating cos(PI))
const tanPI
  Tan(PI) as constant (faster than calculating tan(PI))

const version
  Just a simple string-constant used for version related stuff.

## Functions

### General/Other (13 Functions)

static final function playerpawn GetPlayer(actor A)
  A slow function for finding the current player(s). It's recommended to use the Version of xtRootActor.uc!

static final function hud GetHUD(actor A)
  A slow function for finding the current HUD. It's recommended to use the Version of xtRootActor.uc!

static final function levelinfo GetLevel(actor A)
  A slow function for finding the current Levelinfo/Level. It's recommended to use the Version of xtRootActor.uc!

static final function levelinfo GetEntryLevel(actor A)
  A slow function for finding the actual EntryLevel. It's recommended to use the Version of xtRootActor.uc!

static final function gameinfo GetGameinfo(actor A)
  A slow function for finding the actual Gameinfo. It's recommended to use the Version of xtRootActor.uc!

static final function bool Win32(actor A)
  Returns whether current system is any Windows OS (True) or not (False).

static final function string GetGraphicsCard(actor Owner,bool bLog)
  Returns currently used Graphics Card (as string, like "NVIDIA Geforce FX Go5200"). However this is slow, better to use the actor-based version of xtRootActor!

static final function string GetGFXCardConcern(actor Owner,bool bLog)
  Returns currently used Concern the Graphics Card/Chip was build by (as string, like "nVIDIA", "INTEL" or "ATI"). However this is slow, better to use the actor-based version of xtRootActor!

static final function string GetRenderDrv(actor Owner,bool bLog)
  Returns currently used Render Driver (as string, like "OpenGLDrv.OpenGLRenderDevice"). However this is slow, better to use the actor-based version of xtRootActor!

static final function int IsDirectXRender(actor A,bool bLog)
  Returns if the current Render Driver is any DirectX Render Driver. 0 = Standard Direct3D 6/7, 1 = Direct3D8, 3 = xtDirect3D8/9 (Extension Pack Drivers), 4 = Any other Render Driver.

static final function int IsOpenGLRender(actor A,bool bLog)
  Returns if the current Render Driver is any OpenGL Render Driver. 0 = Standard OpenGL, 2 = Advanced OpenGL (UTGLR), 3 = xtOpenGL (Extension Pack Render Driver), 4 = Any other Render Driver.

static final function bool IsGlideRender(actor A,bool bLog)
  Returns whether the current Render Driver is a 3Dfx/Glide Driver (True) or not (False).

static final function bool IsCPURender(actor a,bool bLog)
  Returns whether the current Render Driver is Software Render Driver (True) or not (False).

### Drawing/View/Effects (8 Functions)

static final function bool ActorIsInViewCosine(vector View,vector Dir,float FOV)
  Checks if a object is within your view, where View is a vector facing forward and Dir the vector pointing to the object that is searched. Every other view computing function bases on this on.

static final function bool IsActorInFOV(Pawn P,Actor A,optional float FOVCosine)
  Returns whether pawn P can see A based on FOVCosine.

static final function bool ACanSeeB(Pawn TraceFrom,Actor TraceTo, optional float FOVCos, optional bool bTraceActors)
  Same as IsActorInFOV but more precise (uses tracing) and allows some special trace options. For example it is used for Coronas that are culled by Meshes too.

static function Actor SpecialTrace(Actor A,out vector HitLocation,out vector HitNormal,vector Start,optional bool bTraceActors,optional float TraceInterval,optional vector TraceDirection,optional float TraceLimit,optional vector Extent)
  A special recurvise Trace.

static function FullSceneBlend(bool bRadius,actor Owner,vector VFog,float BlendMult,optional float Radius,optional bool bDist)
  Blends the view of the player depending on the angle and/or radius to the actor Owner.

static function TraceProject(xtprojector P,out vector V,out rotator R)
  Special Tracing function for the Projectors. It's the initial called tracing for the Projector.

static function SetProjectMaterial(xtprojector P,int I,bool bOn)
  A Projection Texture Update/Placing Function used for some effects and turning on/off.

static final function DynamicProject(xtdynamicprojector P,float Delta,bool bOn)
  Detaches - Updates - Attaches updated by Delta. Contains scaling, modifying, placing and special placement/rotation methods for very advanced decals.

### Vectors (13 Functions)

static final function vector Vect2(float X,float Y,float Z)
  Builds up a vector with the custom components x,y,z - pretty useful building up vector matrices, or changing components without refering to a vector component by vector.x for example. Returns a new vector build by the components.

static final function vector Vect2D(float X,float Y)
  Same as Vect2 but ignoring Z-Component.

static final function float VSizeSq(vector V)
  Returns the squared VSize of the given vector V.

static final function float VSize2D(vector V)
  Returns the VSize of V ignoring Z-Component.

static final function float VSizeSq2D(vector V)
  Same as VSizeSq ignoreing Z-Component.

static final function bool VZero(vector V)
  Returns (true/false) whether a given vector V is zero-vector or not.

static final function float VClamp(vector V, float min, float max)
  Clamps a given vector V (VSize of V) between min and max.

static final function VRange(vector v,out float max,out float min)
  Similar to VClamp except for the fact that it can return min AND max and only returns the components (let's say X is the lowest value than min = X, or Z is the highest value than max = Z).

static final function vector VLerp(vector A,vector B,float Alpha)
  Linear interpolation of an equaled vector between A and B scaled by Alpha.

static final function vector VSmerp(vector A,vector B,float Alpha)
  Smoothed non-linear interpolatin of an equaled vector between A and B scaled by Alpha.

static final function bool VInterpolate(vector A,vector B,out vector DeltaV,float DeltaT)
  Time-based custom interpolation of vector DeltaV between vectors A and B updated by DeltaT. Returns whether DeltaV has reached (true) vector B or not (false).

static final function vector Spat(vector A,vector B,vector C)
  Builds up the Spat-Product by given vector a,b, and c. The Spat-Product of three vectors is the volume shaped by three custom vectors.

static final function vector DoubleCross(vector A,vector B,vector C)
  The Double Cross Product of three given vectors a,b and c. The Double Cross Product of three vectors is the planar limited by these three vectors.

### Rotators (7 Functions)

static final function rotator Rot2(int P,int Y,int R)
  Builds up a custom rotator based on free components P (Pitch), Y (Yaw) and R (Roll). Like the Vect2 Function it's also good for building up (rotator) matrices.

static final function float RotSize(rotator R)
  Returns the absolute complete value of a rotator taking into account every component (pitch|yaw|roll)

static final function float RotSizeNRoll(rotator r)
  Same as RotSize ignoring Roll Component.

static function RVector( out vector A, vector B, float Degree )
  Rotates vector A towards B in amount of Degree (in Degrees). Source: RotateVector

static final function rotator RLerp(rotator A,rotator B,float Alpha)
  Linear interpolation of an equaled rotator between A and B scaled by Alpha.

static final function rotator RSmerp(rotator A,rotator B,float Alpha)
  Smoothed non-linear interpolation of an equaled rotator between A and B scaled by Alpha.

static final function bool RInterpolate(rotator RA,rotator RB,out rotator DeltaR,float DeltaT)
  Time-based custom interpolation of rotator DeltaR between rotators RA and RB updated by DeltaT. Returns whether DeltaR has reached rotator RB (true) or not (false).

### Distances (2 Functions)

static function bool DistanceCompare(vector A,vector B,float Compare)
  Compares the distance between vectors A and B with the compare value. Returns true if the compared distance is greater than the compare value and false if not.

static function float GetDistanceBetween(vector A,vector B,optional int Factor,optional bool bStats)
  Returns a Factor-influenced distance between A and B. The greater the Factor the less the "distance" is changing. bStats can be used for debugging, it writes some distance states to the log.

### Body Calculations (5 Functions)

static final function bool GetBoundingBox(vector Pos,vector Center,vector Dimension,out vector Volume)
  Builds up an abstract box by the given vector Dimension. The Location/Center of the box is the vector Center. It returns either true if the vector Pos is within that abstract box or false if the vector Pos is outside of that box. Volume is a random location on the surface of the box based on it's volume.

static final function bool GetBoundingCylinder(vector Pos,vector Center,float Height,float Radius,out vector Volume)
  Builds up an abstract cylinder defined by given Height and Radius and determines whether Pos is within that cylinder (true) or not (false). Volume is a random location on the surface of the cylinder based on it's volume.

static final function bool GetBoundingHCylinder(vector Pos,vector Center,float Height,float InnerRadius,float Thickness,out vector Volume)
  Builds up an abstract hollow cylinder defined by Height, InnerRadius and Thickness. Returns whether Pos is within the cylinder (true) or not (false).Volume is a random location on the surface of the hollow cylinder based on it's volume.

static final function bool GetBoundingCone(vector Pos,vector Center,float Height,float Radius,out vector Volume)
  Builds up an abstract cone defined by Height and Radius. Returns whether Pos is within the cone (true) or not (false). Volume is a random location on the surface of the cone based on it's volume.

static final function bool GetBoundingSphere(vector Pos,vector Center,float Radius,out vector Volume)
  Builds up an abstract sphere defined by Radius. Returns whether Pos is within the sphere (true) or not (false). Volume is a random location on the surface of the sphere based on it's volume.

### Byte (2 Functions)

static final function byte FByte(float F,bool bSign)
  Converts any given float F into a byte and may pay attention on the sign of f by bSign.

static final function float BFloat(byte B,bool bSign)
  Converts any given byte B into a float and may pay attention on the sign of the returned float.

### Integer/Float

#### General (11 Functions)

static final function int Sign(float A)
  Returns the signum of float A. Returns 1 if positive, returns 0 if neutral (0 ..) or -1 if negative.

static final function int Round(float A)
  Rounds float A up.

static final function float FRand2(float Influence,optional float Base)
  Advanced Float Randomizing Function. Returns a random number whose randomness is controlled by Influence. Optionally you can set a basic value Base.

static final function float FRand3(float Min,float Max,optional float Base,optional float Influence)
  Advanced Float Randomizing Function. Returns a random value within the range of Min/Max. Optionally you can set a start or basic value Base and how the final value is randomized by changing Influenced. If Influence = 0 it will be always ranged between Min and Max.

static final function float FWrap(float f)
  Wraps the float F to a limit range of 0/1.

static final function float FWrap2(float f,float min,float max)
  Wraps the float F to a limit range of Min/Max.

static final function int IFactorial(int I)
  Returns the Factorial of I.

static final function int NextPowerOfTwo( coerce int in )
  Source: NextPowerOfTwo

static final function int PrevPowerOfTwo( coerce int in )
  Source: NextPowerOfTwo

static final function float FPrime(float X)
  Returns the number of primes up to X. For example 6 will return 3.348663759 which you can round down to 3. Thus the number 6 has 3 prime numbers: 2,3 and 5. 0 and 1 are not defined as prime numbers however.

static final function int FPrime2(float X)
  Returns the number of primes up to X. For example 6 will return 3. Thus the number 6 has 3 prime numbers: 2,3 and 5. This function works the same as FPrime except for rounding the returned value as integer. 0 and 1 are not defined as prime numbers however.

#### Scaling (4 Functions)

static final function bool Scale(out float F,float T,float Min,float Max,float Decrease,float Increase,bool bGrow,optional float base)
  Calculates a linear scaled float F either from Min/base to Max (scaled by Increase) or Max/Base to Min (scaled by Descrease) updating by time T. Starts by increasing if bGrow = true. Returns the current "final" state of the value - True if Max reached, False if Min reached.

static final function ScalePeriodic(out float F,float T,float Min,float Max,float Decrease,float Increase,bool bGrow,optional float Coefficent)
  Similar to Scale but scales a float F using a loop thus repeating increasing and decreasing the value (like using sin).

static function float ScaleByWave(int Mode,float Amp,float Freq,float L)
  Smoothly scales an equaled float by trigonometric functions like sin, cos, tan and so on. Mode is the indicator for the used trigonometric function (where 0 = sin for example). Amp is the Min/Max (the Amplitude) of the value. Freq is the frequency of the wavy scaled value and L the lifetime/periode.

static final function float ScaleByDistance(float Base,vector A,vector B,int Factor,float Min,float Max,bool bReverse)
  Smoothly scales an equaled float starting with Base depending on the distance between A and B (influenced by Factor) until either Min or Max reached. bReverse swaps the function output: True = the value increases by distance, False = the value decreases by distance.

#### Percentage Calculation (3 Functions)

static final function float BaseValue(float P,float V)
  Returns the base value of a percent term where P is the percantage and V the percent value. Example: you have P (5 %) and V (10) given and want to know what's the basevalue/100 % of that, it's 200, because 5 % of 200 is 10.

static final function float Percentage(float B,float V)
  Returns the percentage of a percent term where B is the base value and V the percent value. Example: you have B (200) and V (10) given and want to know what's the percentage of that, it's 5 %, because 10 of 200 are 5 %.

static final function float PercentValue(float P,float B)
  Returns the percent value of a percent term where P is the percantage and B the base value. Example: you have B (200) and P (5 %) given and want to know what's the percente value of that, it's 10, because 5 % of 200 is 10.

#### Angles/Trigonometry (4 Functions)

static final function float RadToDeg(float rad)
  Converts any given radian Rad into degrees.

static final function float DegToRad(float deg)
  Converts any given degrees Deg into radians.

static final function float dSin(float Angle)
  Returns the Sine of an Angle in degrees. Standard Sin uses radians (for precision reasons).

static final function float dCos(float Angle)
  Returns the Cosine of an Angle in degrees. Standard Cos uses radians (for precision reasons).

#### Advanced Trigonometry (7 Secant and Combined Functions)

static final function float Sec(float X)
  Returns the the Secant of X.

static final function float Csc(float X)
  Returns the the CoSecant of X.

static final function float SinACos(float X)
  Fast way of Sin(ACos(X)), through avoiding nesting.

static final function float SinATan(float X)
  Fast way of Sin(ATan(X)), through avoiding nesting.

static final function float CosATan(float X)
  Fast way of Cos(ATan(X)), through avoiding nesting.

static final function float TanASin(float X)
  Fast way of Tan(ASin(X)), through avoiding nesting.

static final function float TanACos(float X)
  Fast way of Tan(ACos(X)), through avoiding nesting.

#### Advanced Trigonometry (6 Hyperbolic Functions)

static final function float SinH(float X)
  Returns the the Hyperbolic Sine of X.

static final function float CosH(float X)
  Returns the the Hyperbolic Cosine of X.

static final function float TanH(float X)
  Returns the the Hyperbolic Tangent of X.

static final function float CoTanH(float X)
  Returns the the Hyperbolc CoTangent of X.

static final function float SecH(float X)
  Returns the the Hyperbolic Secant of X.

static final function float CscH(float X)
  Returns the the Hyperbolic CoSecant of X.

#### Inverse Trigonometry (8 Functions)

static final function float ASin(float X)
  Returns the the arcSin of X. Source: ASin

static final function float ASin2(float Y,float Rad)
  Returns the arcSin of Y where Y is the opposite leg and Rad is the Hyperthenuse. More precise version of the previous aSin(x). Source: ASin2

static final function float ACos(float A)
  Returns the arcSin of A. Source: ACos

static final function float ACos2(float X,float Rad)
  Returns the arcSin of X where X is the adjecent leg and Rad is the opposite. More precise version of aCos(x). Source: ACos2

static final function float ATan2(float Y,float X)
  Returns the arcTan where X is the adjecent leg and Y the opposite leg. More precise version of ATan(x). Source: ATan2

static final function float ACoTan(float X)
  Computes arcCoTan of X and returns it.

static final function float ASec(float X)
  Computes arcSecant of X and returns it.

static final function float ACsc(float X)
  Computes arcCoSecant of X and returns it.

#### Inverse Trigonometry (6 Inverse Hyperbolic Functions)

static final function float ASinH(float X)
  Returns the inverse Hyperbolic Sine of X.

static final function float ACosH(float X)
  Returns the inverse Hyperbolic Cosine of X.

static final function float ATanH(float X)
  Returns the inverse Hyperbolic Tangent of X.

static final function float ACoTanH(float X)
  Returns the inverse Hyperbolic CoTangent of X.

static final function float ASecH(float X)
  Returns the inverse Hyperbolic Secant of X.

static final function float ACscH(float X)
  Returns the inverse Hyperbolic CoSecant of X.

#### Special Trigonometry (9 Functions)

static final function float SqSin(float X)
  Returns the sin²(x).

static final function float CSin(float X)
  Returns the sin(x).

static final function float nSin(float X,float n)
  Returns the sin^n(x).

static final function float NSinC(float X)
  Returns the Sinus Cardinalis of X (Normalized).

static final function float UnSinC(float X)
  Returns the Sinus Cardinalis of X (Unnormalized).

static final function float SqCos(float X)
  Returns the cos²(x).

static final function float CCos(float X)
  Returns the cos(x).

static final function float SqTan(float X)
  Returns the tan²(x).

static final function float TanC(float X)
  Returns the Tangent Cardinalis of X.

#### Special Math Functions (8 Functions)

static final function float HeronsFormula(vector gA,vector gB,vector gC)
  Computes the triangle area shaped by three vectors gA, gB and gC.

static final function float Langevin(float X)
  Returns the Langevin Function Value of X.

static final function float SemV(float X)
  Returns the Semiversus of X (Spheric Cosine).

static final function float Cat(float X,float A)
  Returns the Catenoide of X scaled by A.

static final function float FLambda(float X,float b)
  This is a special Exp-Function. It returnes X raised to X raised to b-1. The higher b is the more the function approaches 1, as long as x < 1.

static final function float Sigmoid(float X)
  The Sigmoid of X. If it would be used for drawing it would display an S-Curve.

static final function float DSigmoid(float X,float Center,float Steepness)
  A doubled Sigmoid of X. If it would be used for drawing it would display a doubled S-Curve and is based on the Gaussian-Curve where Center is the center of the Graph and Steepness the steepness of it.

static final function float FHermite(float X,float n)
  Returns Hn(x), the Hermetic Polynomial. If n is power of two it returns power-of-two-potencies and vice versa.

#### Advanced Roots (5 Functions)

static final function float nRoot(float X,float n)
  Returns the nth Root of X.

static final function float nDoubleRoot(float X,float m,float n)
  Returns the fast way of the mth Root of the nth Root of X.

static final function float nMultRoot(float n,float A,float B)
  Returns the nth Root of A multiplied with the nth Root of B. You can also write: nRoot(A*B,n).

static final function float nDivRoot(float n,float a,float b)
  Returns the nth Root of A divided by the nth Root of B. You can also write: nRoot(A/B,n).

static final function float nExpRoot(float X,float m,float n)
  Returns the nth Root of X^m.

#### Logarithm/Exponential Functions (5 Functions)

static final function float Exp2(float A,float X)
  Returns A^X. The native Build-in Exp-Function returned e^X.

static final function float LB(float A)
  Returns the binary Logarithm of A. The Logarithm of A to the base 2.

static final function float LG(float A)
  Returns the decadic Logarithm of A. The Logarithm of A to the base 10.

static final function float LC(float A,float B)
  Returns the custom Logarithm of A to the base B.

static final function float Euler(float n)
  Returns the Euler Value of n. If n is too high it will return 1 (around n*10^9).

### Booleans (1 Function)

static final function bool RandBool()
  Randomly returns true/false.

### Strings (1 Function)

static final function string ReplaceBoolValue(bool B,string TrueString,string FalseString)
  The return values (true/false) of bool B will be converted to a string by TrueString for True and FalseString for False.

## Known UnrealScript Subclasses

    xtMainUtil
     +- xtCanvasUtil
     +- xtAIUtil
     +- xtPhysicsUtil
         +- xtThelemaPhysics

Category:Legacy Custom Class (UT) \\

Category: Legacy Custom Class (UT)

##### Views

- Legacy
- Discussion
- Current revision

##### Search