-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flickering lights in the modular dungeon scene
- Loading branch information
Showing
2 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
Samples/03 TerrainSamples/SceneModularDungeon/LightController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Engine; | ||
using SharpDX; | ||
using System; | ||
|
||
namespace TerrainSamples.SceneModularDungeon | ||
{ | ||
/// <summary> | ||
/// Light basic controller | ||
/// </summary> | ||
class LightController | ||
{ | ||
private readonly Random rnd = Helper.NewGenerator(); | ||
private readonly float initialTime = Helper.RandomGenerator.NextFloat(0, 100); | ||
|
||
/// <summary> | ||
/// Spot light | ||
/// </summary> | ||
public ISceneLightPoint Light { get; set; } | ||
/// <summary> | ||
/// Light position function | ||
/// </summary> | ||
public Func<Vector3> PositionFnc { get; set; } | ||
|
||
/// <summary> | ||
/// Updates the light position | ||
/// </summary> | ||
/// <param name="gameTime">Game time</param> | ||
public void Update(IGameTime gameTime) | ||
{ | ||
float r = 0.01f; | ||
float h = 0.005f; | ||
float v = 5f; | ||
|
||
float totalSeconds = gameTime.TotalSeconds + initialTime; | ||
|
||
float cos = MathF.Cos(v * totalSeconds); | ||
float sin = MathF.Sin(v * totalSeconds); | ||
|
||
float x = r * cos * rnd.NextFloat(0.15f, 9f); | ||
float z = r * sin * rnd.NextFloat(0.85f, 9f); | ||
|
||
float y = h * sin * rnd.NextFloat(0.35f, 9f); | ||
|
||
Light.Position = PositionFnc() + new Vector3(x, y, z); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters