-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyApplication.cs
More file actions
60 lines (52 loc) · 1.76 KB
/
Copy pathMyApplication.cs
File metadata and controls
60 lines (52 loc) · 1.76 KB
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
using INFOGRTemplate;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common.Input;
using OpenTK.Windowing.GraphicsLibraryFramework;
using System.Diagnostics;
using System.Globalization;
namespace Template
{
class MyApplication
{
// member variables
public Surface screen;
private readonly Stopwatch timer = new();
public Raytracer raytracer;
public KeyboardState KeyBoardState { get; set; }
public MouseState MouseState { get; set; }
// constructor
public MyApplication(Surface screen)
{
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
this.screen = screen;
}
// initialize
public void Init()
{
raytracer = new Raytracer(screen);
// (optional) example of how you can load a triangle mesh in any file format supported by Assimp
object? mesh = Util.ImportMesh("../../../assets/cube.obj");
}
// tick: renders one frame
private TimeSpan deltaTime = new();
private uint frames = 0;
private string timeString = "---- ms/frame";
public void Tick()
{
timer.Restart();
screen.Clear(0);
raytracer.KeyBoardState = KeyBoardState;
raytracer.MouseState = MouseState;
raytracer.Render(); //render every tick
deltaTime += timer.Elapsed;
frames++;
if (deltaTime.TotalSeconds > 1)
{
timeString = (deltaTime.TotalMilliseconds / frames).ToString("F1") + " ms/frame";
frames = 0;
deltaTime = TimeSpan.Zero;
}
screen.PrintOutlined(timeString, 2, 2, Color4.White);
}
}
}