MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / GetUnitVector

Function GetUnitVector

Source/Engine/Core/RandomStream.h:132–144  ·  view source on GitHub ↗

Returns a random vector of unit size.

Source from the content-addressed store, hash-verified

130 /// Returns a random vector of unit size.
131 /// </summary>
132 Float3 GetUnitVector() const
133 {
134 Float3 result;
135 float l;
136 do
137 {
138 result.X = GetFraction() * 2.0f - 1.0f;
139 result.Y = GetFraction() * 2.0f - 1.0f;
140 result.Z = GetFraction() * 2.0f - 1.0f;
141 l = result.LengthSquared();
142 } while (l > 1.0f || l < ZeroTolerance);
143 return Float3::Normalize(result);
144 }
145
146 /// <summary>
147 /// Gets a random <see cref="Vector3"/> with components in a range between [0;1].

Callers

nothing calls this directly

Calls 3

GetFractionFunction · 0.85
NormalizeFunction · 0.50
LengthSquaredMethod · 0.45

Tested by

no test coverage detected