-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reader.cs
35 lines (34 loc) · 1.19 KB
/
Reader.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
using RayTracer;
using System.IO;
using System.Text;
namespace shangzhel.RayTracer.Debug
{
/// <summary>
/// Implements a function to interpret dumped rays.
/// </summary>
class Reader
{
/// <summary>
/// Deserializes collected rays from a <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The stream to read from.</param>
/// <returns>Rays collected previously.</returns>
public static DebugRay[] ReadFromStream(Stream stream)
{
using var reader = new BinaryReader(stream, Encoding.UTF8, true);
var arr = new DebugRay[reader.ReadInt32()];
for (int i = 0; i < arr.Length; ++i)
{
var id = new int[reader.ReadByte()];
for (int j = 0; j < id.Length; ++j)
{
id[j] = reader.ReadInt32();
}
var from = new Vector3(reader.ReadDouble(), reader.ReadDouble(), reader.ReadDouble());
var to = new Vector3(reader.ReadDouble(), reader.ReadDouble(), reader.ReadDouble());
arr[i] = new DebugRay(id, from, to);
}
return arr;
}
}
}