-
Notifications
You must be signed in to change notification settings - Fork 0
/
Axis.cs
68 lines (57 loc) · 1.92 KB
/
Axis.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
using System;
using OpenTK;
using OpenTK.Graphics.OpenGL4;
using univ.Engine.Geometry;
namespace univ
{
public class Axis : Component
{
Matrix4 mvp;
Shader shader;
VertexArray geometry;
public Axis(Shader shader)
: base()
{
this.shader = shader;
this.geometry = new VertexArray(PrimitiveType.Lines);
geometry.CreateBuffer("vertex").BufferData<Byte3>(ref vertexData);
geometry.CreateBuffer("colors").BufferData<byte>(ref colorData);
geometry.AddPointer("vertex", new VertexAttribute(shader, "vPosition", VertexAttribPointerType.UnsignedByte, 3, 0, false));
geometry.AddPointer("colors", new VertexAttribute(shader, "vColor", VertexAttribPointerType.UnsignedByte, 4, 0, true));
}
public override void Draw(DrawEventArgs e)
{
/* Calculate Model/View/Projection matrix */
Matrix4.Mult(ref this.modelMatrix, ref e.ModelMatrix, out mvp);
Matrix4.Mult(ref mvp, ref e.Camera.ViewProjection, out mvp);
shader.Use();
shader.SetMatrix("mvp", ref mvp);
GL.LineWidth(2.0f);
geometry.Draw(6);
GL.LineWidth(1.0f);
base.Draw(e);
}
private static Byte3[] vertexData = new Byte3[] {
// X
new Byte3(0,0,0),
new Byte3(100,0,0),
// Y
new Byte3(0,0,0),
new Byte3(0,100,0),
// Z
new Byte3(0,0,0),
new Byte3(0,0,100)
};
private static byte[] colorData = new byte[] {
// X
255,0,0,160,
255,0,0,160,
// Y
0,255,0,160,
0,255,0,160,
// Z
0,0,255,160,
0,0,255,160,
};
}
}