-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathProjectionData.cs
More file actions
87 lines (77 loc) · 3.11 KB
/
Copy pathProjectionData.cs
File metadata and controls
87 lines (77 loc) · 3.11 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// ProjectionData.cs, 07.11.2019
// Copyright (C) Dominic Beger 07.11.2019
using System;
using System.Drawing;
namespace SharpMath.Geometry
{
/// <summary>
/// Provides configuration data for performing projections in a view frustum.
/// </summary>
[Serializable]
public struct ProjectionData
{
/// <summary>
/// Initializes a new instance of the <see cref="ProjectionData" /> struct.
/// </summary>
/// <param name="canvasSize">The size of the canvas.</param>
/// <param name="aspectRatio">The aspect ratio.</param>
/// <param name="fieldOfView">The field of view.</param>
/// <param name="nearPlane">The near plane.</param>
/// <param name="farPlane">The far plane.</param>
/// <exception cref="ArgumentException">
/// nearPlane must be a value greater than zero.
/// or
/// farPlane must be a value greater than zero.
/// or
/// nearPlane must be a value smaller than farPlane.
/// or
/// FOV must be greater than zero and must not be bigger than 360 degrees (PI).
/// </exception>
public ProjectionData(Size canvasSize, float aspectRatio, float fieldOfView, float nearPlane, float farPlane)
{
if (nearPlane <= 0)
throw new ArgumentException("nearPlane must be a value greater than zero.");
if (farPlane <= 0)
throw new ArgumentException("farPlane must be a value greater than zero.");
if (nearPlane >= farPlane)
throw new ArgumentException("nearPlane must be a value smaller than farPlane.");
if (fieldOfView <= 0 || fieldOfView > Math.PI)
throw new ArgumentException(
"FOV must be greater than zero and must not be bigger than 360 degrees (PI).");
CanvasSize = canvasSize;
AspectRatio = aspectRatio;
FieldOfView = fieldOfView;
NearPlane = nearPlane;
FarPlane = farPlane;
}
/// <summary>
/// Gets or sets the size of the canvas.
/// </summary>
public Size CanvasSize { get; set; }
/// <summary>
/// Gets or sets the aspect ratio.
/// </summary>
public float AspectRatio { get; set; }
/// <summary>
/// Gets or sets the field of view (FOV).
/// </summary>
public float FieldOfView { get; set; }
/// <summary>
/// Gets or sets the near plane.
/// </summary>
public float NearPlane { get; set; }
/// <summary>
/// Gets or sets the far plane.
/// </summary>
public float FarPlane { get; set; }
/// <summary>
/// Gets the depth.
/// </summary>
public float Depth => FarPlane - NearPlane;
/// <summary>
/// Gets the default <see cref="ProjectionData" />.
/// </summary>
public static ProjectionData Default
=> new ProjectionData(new Size(100, 100), 16f / 9f, (float) Math.PI / 3f, 1f, 100f);
}
}