MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / GeneratePointInSpheroid

Function GeneratePointInSpheroid

TombEngine/Math/Random.cpp:157–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155 }
156
157 Vector3 GeneratePointInSpheroid(const Vector3& center, const EulerAngles& orient, const Vector3& semiMajorAxis)
158 {
159 // Use rejection sampling method.
160 auto relPoint = Vector3::Zero;
161 do
162 {
163 relPoint = Vector3(
164 Random::GenerateFloat(-semiMajorAxis.x, semiMajorAxis.x),
165 Random::GenerateFloat(-semiMajorAxis.y, semiMajorAxis.y),
166 Random::GenerateFloat(-semiMajorAxis.z, semiMajorAxis.z));
167 }
168 while ((SQUARE(relPoint.x) / SQUARE(semiMajorAxis.x) +
169 SQUARE(relPoint.y) / SQUARE(semiMajorAxis.y) +
170 SQUARE(relPoint.z) / SQUARE(semiMajorAxis.z)) > 1.0f);
171
172 // Rotate relative point.
173 auto rotMatrix = orient.ToRotationMatrix();
174 relPoint = Vector3::Transform(relPoint, rotMatrix);
175
176 return (center + relPoint);
177 }
178
179 bool TestProbability(float prob)
180 {

Callers 2

GetFishStartPositionFunction · 0.85
UpdateFireflySwarmFunction · 0.85

Calls 3

GenerateFloatFunction · 0.85
Vector3Function · 0.50
ToRotationMatrixMethod · 0.45

Tested by

no test coverage detected