Open 3D Engine EMotionFX Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
MCore::Random Class Reference

#include <Random.h>

Static Public Member Functions

static MCORE_INLINE float RandF ()
 
static MCORE_INLINE float RandF (float minVal, float maxVal)
 
static AZ::Vector3 RandDirVecF ()
 
static MCORE_INLINE AZ::Vector3 RandomVecF ()
 
static AZ::Vector3 RandomDirVec (const AZ::Vector3 &dir, float coneAngle)
 
static AZ::Vector3 RandomDirVec (const AZ::Vector3 &dir, float coneAngle, uint32 gridSizeX, uint32 gridSizeY, uint32 xGridPos, uint32 yGridPos)
 
static AZ::Vector3 RandomDirVec (const AZ::Vector3 &dir, float startPhi, float endPhi, float startTheta, float endTheta, bool midPoint=false)
 
static AZ::Vector3 UVToVector (const AZ::Vector3 &dir, float coneAngle, float u, float v)
 
static AZStd::vector< AZ::Vector3 > RandomDirVectorsStratisfied (const AZ::Vector3 &dir, float coneAngle, uint32 numVectors)
 
static AZStd::vector< AZ::Vector3 > RandomDirVectorsHammersley (const AZ::Vector3 &dir, float coneAngle, uint32 numVectors)
 
static AZStd::vector< AZ::Vector3 > RandomDirVectorsHammersley2 (const AZ::Vector3 &dir, float coneAngle, uint32 numVectors, uint32 base)
 
static AZStd::vector< AZ::Vector3 > RandomDirVectorsHalton (const AZ::Vector3 &dir, float coneAngle, size_t numVectors, uint32 p2=3)
 
static AZStd::vector< AZ::Vector3 > RandomDirVectorsHalton2 (const AZ::Vector3 &dir, float coneAngle, size_t numVectors, uint32 baseA=2, uint32 baseB=3)
 
static void PlaneHalton (float *result, uint32 num, uint32 p2=3)
 
static void PlaneHalton2 (float *result, uint32 num, uint32 baseA=2, uint32 baseB=3)
 
static void PlaneHammersley (float *result, uint32 num)
 
static void PlaneHammersley2 (float *result, uint32 num, uint32 base)
 

Detailed Description

A random number generation class. This class can generate both random numbers and vectors using several different algorithms.

Member Function Documentation

◆ PlaneHalton()

static void MCore::Random::PlaneHalton ( float *  result,
uint32  num,
uint32  p2 = 3 
)
static

Generates a set of Halton numbers, which are pseudo random numbers.

Parameters
resultThe array to store the resulting numbers in (this needs to be twice as large as the 'num' parameter, since it are two dimensions!)
numThe number of pointSETS to generate (one set is 2 points).
p2The base number of the set, which must be a prime value.

◆ PlaneHalton2()

static void MCore::Random::PlaneHalton2 ( float *  result,
uint32  num,
uint32  baseA = 2,
uint32  baseB = 3 
)
static

Generates a set of Halton numbers, which are pseudo random numbers.

Parameters
resultThe array to store the resulting numbers in (this needs to be twice as large as the 'num' parameter, since it are two dimensions!)
numThe number of pointSETS to generate (one set is 2 points).
baseAThe first base number of the set, which must be a prime value.
baseBThe second base number of the set, which must be a prime value.

◆ PlaneHammersley()

static void MCore::Random::PlaneHammersley ( float *  result,
uint32  num 
)
static

Generates a set of Hammersley numbers, which are pseudo random numbers.

Parameters
resultThe array to store the resulting numbers in (this needs to be twice as large as the 'num' parameter, since it are two dimensions!)
numThe number of pointSETS to generate (one set is 2 points).

◆ PlaneHammersley2()

static void MCore::Random::PlaneHammersley2 ( float *  result,
uint32  num,
uint32  base 
)
static

Generates a set of Hammersley numbers, which are pseudo random numbers.

Parameters
resultThe array to store the resulting numbers in (this needs to be twice as large as the 'num' parameter, since it are two dimensions!)
numThe number of pointSETS to generate (one set is 2 points).
baseThe base number of the set, which must be a prime value (3 would be a good value).

◆ RandDirVecF()

static AZ::Vector3 MCore::Random::RandDirVecF ( )
static

Generates a uniform random normalized direction vector, using floats.

Returns
A uniform random direction vector with a length of 1.

◆ RandF() [1/2]

static MCORE_INLINE float MCore::Random::RandF ( )
inlinestatic

Generate a uniform random float in range of [0..1].

Returns
A uniform random floating point number in range of [0..1].

◆ RandF() [2/2]

static MCORE_INLINE float MCore::Random::RandF ( float  minVal,
float  maxVal 
)
inlinestatic

Generate a uniform random float in a range of a given minimum and maximum.

Parameters
minValThe minimum value of the range.
maxValThe maximum value of the range.
Returns
A uniform random floating point number in range of [min..max].

◆ RandomDirVec() [1/3]

static AZ::Vector3 MCore::Random::RandomDirVec ( const AZ::Vector3 &  dir,
float  coneAngle 
)
static

Generates a uniform random direction vector from a given direction and cone angle. This means that if you specify pi as cone angle, with a direction vector of (0,1,0) you will get a random vector on the upper hemisphere above the XZ plane.

Parameters
dirThe base direction.
coneAngleThe maximum spread angle in radians, which together with the base direction creates a cone, in which a random vector is generated and returned.
Returns
A random vector in the cone defined by the direction and cone angle.

◆ RandomDirVec() [2/3]

static AZ::Vector3 MCore::Random::RandomDirVec ( const AZ::Vector3 &  dir,
float  coneAngle,
uint32  gridSizeX,
uint32  gridSizeY,
uint32  xGridPos,
uint32  yGridPos 
)
static

Generates a uniform random direction vector inside a patch on a cone. This can be used for stratisfied sampling, where you divide for example a hemisphere into equally sized sections (grid cells/patches) and you generate a random sample inside the given grid cells.

Parameters
dirThe base direction.
coneAngleThe cone angle, in radians, where pi is a hemisphere.
gridSizeXThe number of grid cells for x (phi).
gridSizeYThe number of grid cells for y (theta).
xGridPosThe x (phi) grid number to create a sample in.
yGridPosThe y (theta) grid number to create a sample in.
Returns
A random vector on the defined cone, which is split up into <gridSizeX * gridSizeY> grid cells, and where the random vector is a random vector within grid cell number (xGridPos, yGridPos].

◆ RandomDirVec() [3/3]

static AZ::Vector3 MCore::Random::RandomDirVec ( const AZ::Vector3 &  dir,
float  startPhi,
float  endPhi,
float  startTheta,
float  endTheta,
bool  midPoint = false 
)
static

Generates a uniform random vector inside a given area on a cone.

Parameters
dirThe base direction.
startPhiThe start Phi value of the area to create a random sample in.
endPhiThe end Phi value of the area to create a random sample in.
startThetaThe start theta value of the area to create a random sample in.
endThetaThe end theta value of the area to create a random sample in.
midPointIf set to true, the generated random direction will be made exactly in the center of the defined area, so not really random. If set to true, a random sample will be taken inside the specified area.
Returns
A random vector pointing towards a random (or the center) position in the specified area on the cone.

◆ RandomDirVectorsHalton()

static AZStd::vector< AZ::Vector3 > MCore::Random::RandomDirVectorsHalton ( const AZ::Vector3 &  dir,
float  coneAngle,
size_t  numVectors,
uint32  p2 = 3 
)
static

Generate a given amount of uniform direction vectors using Halton sequences.

Parameters
dirThe base direction.
coneAngleThe cone angle in radians, where pi would be a hemisphere.
numVectorsThe number of vectors to generate.
p2The base of the halton sequence (must be a prime value).
Returns
An array containing the generated vectors.

◆ RandomDirVectorsHalton2()

static AZStd::vector< AZ::Vector3 > MCore::Random::RandomDirVectorsHalton2 ( const AZ::Vector3 &  dir,
float  coneAngle,
size_t  numVectors,
uint32  baseA = 2,
uint32  baseB = 3 
)
static

Generate a given amount of uniform direction vectors using hammersley sets.

Parameters
dirThe base direction.
coneAngleThe cone angle in radians, where pi would be a hemisphere.
numVectorsThe number of vectors to generate.
baseAThe first base value (must be a prime value).
baseBThe second base value (must be a prime value).
Returns
An array containing the generated vectors.

◆ RandomDirVectorsHammersley()

static AZStd::vector< AZ::Vector3 > MCore::Random::RandomDirVectorsHammersley ( const AZ::Vector3 &  dir,
float  coneAngle,
uint32  numVectors 
)
static

Generate a given amount of uniform direction vectors using Hammersley sets.

Parameters
dirThe base direction.
coneAngleThe cone angle in radians, where pi would be a hemisphere.
numVectorsThe number of vectors to generate.
Returns
An array containing the generated vectors.

◆ RandomDirVectorsHammersley2()

static AZStd::vector< AZ::Vector3 > MCore::Random::RandomDirVectorsHammersley2 ( const AZ::Vector3 &  dir,
float  coneAngle,
uint32  numVectors,
uint32  base 
)
static

Generate a given amount of uniform direction vectors using Hammersley sets.

Parameters
dirThe base direction.
coneAngleThe cone angle in radians, where pi would be a hemisphere.
numVectorsThe number of vectors to generate.
baseThe base number of the sequence (values of 2 or 3 are nice (must be ap rime value))
Returns
An array containing the generated vectors.

◆ RandomDirVectorsStratisfied()

static AZStd::vector< AZ::Vector3 > MCore::Random::RandomDirVectorsStratisfied ( const AZ::Vector3 &  dir,
float  coneAngle,
uint32  numVectors 
)
static

Generate a given number of stratisfied uniform random samples on a cone.

Parameters
dirThe base direction.
coneAngleThe angle of the cone in radians, where pi would be a hemisphere.
numVectorsThe number of direction vectors to generate. This might not be the number of vectors returned by this method!
Returns
The array containing the random vectors. The length of the array will be equal to (Sqrt(numVectors) * Sqrt(numVectors)).

◆ RandomVecF()

static MCORE_INLINE AZ::Vector3 MCore::Random::RandomVecF ( )
inlinestatic

Generates a uniform random vector where (x,y,z) are in range of [-1..+1] using floats.

Returns
A uniform random vector in range of [-1..+1].

◆ UVToVector()

static AZ::Vector3 MCore::Random::UVToVector ( const AZ::Vector3 &  dir,
float  coneAngle,
float  u,
float  v 
)
static

Convert an u, v [0..1] to a uniform (so area corrected) direction vector on a specified cone.

Parameters
dirThe base direction.
coneAngleThe angle of the cone in radians, so pi would be a hemisphere.
uThe value for phi, in range of [0..1].
vThe value for theta, in range of [0..1].
Returns
The direction vector.

The documentation for this class was generated from the following file: