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

Method UpdateStarfield

TombEngine/Game/effects/weather.cpp:233–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231 }
232
233 void EnvironmentController::UpdateStarfield(const ScriptInterfaceLevel& level)
234 {
235 int starCount = level.GetStarfieldStarCount();
236 if (starCount == 0)
237 return;
238
239 if (ResetStarField)
240 {
241 Stars.clear();
242 ResetStarField = false;
243 }
244
245 if (starCount != Stars.size())
246 {
247 // If starCount increased, add new stars to existing list.
248 if (starCount > Stars.size())
249 {
250 // Reserve space for new stars if necessary.
251 Stars.reserve(starCount);
252
253 for (int i = (int)Stars.size(); i < starCount; i++)
254 {
255 auto starDir = Random::GenerateDirectionInCone(-Vector3::UnitY, 70.0f);
256 starDir.Normalize();
257
258 auto star = StarParticle{};
259 star.Direction = starDir;
260 star.Color = Vector3(
261 Random::GenerateFloat(0.6f, 1.0f),
262 Random::GenerateFloat(0.6f, 1.0f),
263 Random::GenerateFloat(0.6f, 1.0f));
264 star.Scale = Random::GenerateFloat(0.5f, 1.5f);
265
266 float cosine = Vector3::UnitY.Dot(starDir);
267 float maxCosine = cos(DEG_TO_RAD(50.0f));
268 float minCosine = cos(DEG_TO_RAD(70.0f));
269
270 if (cosine >= minCosine && cosine <= maxCosine)
271 {
272 star.Extinction = (cosine - minCosine) / (maxCosine - minCosine);
273 }
274 else
275 {
276 star.Extinction = 1.0f;
277 }
278
279 Stars.push_back(star);
280 }
281 }
282 // If starCount decreased, resize vector without reinitializing.
283 else
284 {
285 Stars.resize(starCount);
286 }
287
288 }
289
290 for (auto& star : Stars)

Callers

nothing calls this directly

Calls 15

GenerateDirectionInConeFunction · 0.85
GenerateFloatFunction · 0.85
DEG_TO_RADFunction · 0.85
GetStarfieldStarCountMethod · 0.80
Vector3Function · 0.50
clearMethod · 0.45
sizeMethod · 0.45
reserveMethod · 0.45
NormalizeMethod · 0.45
DotMethod · 0.45

Tested by

no test coverage detected