-
Notifications
You must be signed in to change notification settings - Fork 33
/
HelloPenumbra.cs
78 lines (63 loc) · 2.53 KB
/
HelloPenumbra.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Penumbra;
using System;
namespace HelloPenumbra
{
public class HelloPenumbra : Game
{
GraphicsDeviceManager graphics;
// Store reference to lighting system.
PenumbraComponent penumbra;
// Create sample light source and shadow hull.
Light light = new PointLight
{
Scale = new Vector2(1000f), // Range of the light source (how far the light will travel)
ShadowType = ShadowType.Solid // Will not lit hulls themselves
};
Hull hull = new Hull(new Vector2(1.0f), new Vector2(-1.0f, 1.0f), new Vector2(-1.0f), new Vector2(1.0f, -1.0f))
{
Position = new Vector2(400f, 240f),
Scale = new Vector2(50f)
};
public HelloPenumbra()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
// Create the lighting system and add sample light and hull.
penumbra = new PenumbraComponent(this);
penumbra.Lights.Add(light);
penumbra.Hulls.Add(hull);
}
protected override void Initialize()
{
// Initialize the lighting system.
penumbra.Initialize();
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
// Animate light position and hull rotation.
light.Position =
new Vector2(400f, 240f) + // Offset origin
new Vector2( // Position around origin
(float)Math.Cos(gameTime.TotalGameTime.TotalSeconds),
(float)Math.Sin(gameTime.TotalGameTime.TotalSeconds)) * 240f;
hull.Rotation = MathHelper.WrapAngle(-(float)gameTime.TotalGameTime.TotalSeconds);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
// Everything between penumbra.BeginDraw and penumbra.Draw will be
// lit by the lighting system.
penumbra.BeginDraw();
GraphicsDevice.Clear(Color.CornflowerBlue);
// Draw items affected by lighting here ...
penumbra.Draw(gameTime);
// Draw items NOT affected by lighting here ... (UI, for example)
base.Draw(gameTime);
}
}
}