-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplane.cs
65 lines (57 loc) · 2.23 KB
/
plane.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK;
namespace Template
{
class plane : @object
{
float d;
Vector3 plane_normal;
public plane(float _d, int _color, Quaternion _rotation, float _absorption = 1, float _refraction = 0)
{
d = -_d;
color = _color;
plane_normal = _rotation * Vector3.UnitZ;
plane_normal.Normalize();
absorption = _absorption;
refraction = _refraction;
}
//Create GLSL functions
public void AddToArray(List<float> array, float[] colors, StringBuilder normal)
{
index = array.Count / 4;
array.Add(plane_normal.X);
array.Add(plane_normal.Y);
array.Add(plane_normal.Z);
array.Add(d);
normal.AppendLine(" if(dot(ray_direction, planes[" + index + "].xyz) > 0){");
normal.AppendLine(" s = -(dot(ray_origin, planes[" + index + "].xyz) + planes[" + index + "].w) / dot(ray_direction, planes[" + index + "].xyz);");
normal.AppendLine(" if(s > 0 && s < t){");
normal.AppendLine(" t = s;");
normal.AppendLine(" col = vec3(" + colors[color * 3] + ", " + colors[color * 3 + 1] + ", " + colors[color * 3 + 2] + "); ");
normal.AppendLine(" normal = -planes[" + index + "].xyz;");
normal.AppendLine(" refraction = "+ refraction + ";");
normal.AppendLine(" absorption = " + absorption + ";");
normal.AppendLine(" }");
normal.AppendLine(" }");
}
//Move plane based on user input
public override void move(Vector3 direction, float[] array)
{
d += Vector3.Dot(plane_normal, direction);
array[index * 4 + 3] = d;
}
//Rotate plane based on user input
public override void rotate(Quaternion rotate, float[] array)
{
plane_normal = rotate * plane_normal;
plane_normal.Normalize();
array[index * 4] = plane_normal.X;
array[index * 4 + 1] = plane_normal.Y;
array[index * 4 + 2] = plane_normal.Z;
}
}
}