/
drawen.go
188 lines (148 loc) · 2.81 KB
/
drawen.go
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package physicstest
import (
// "fmt"
"github.com/go-gl/gl"
//"math"
)
func Hello() string{
return "drawengine"
}
func DrawLine(Ln Line){
ax := Ln.Ax
ay := Ln.Ay
bx := Ln.Bx
by := Ln.By
col := Ln.Colour
switch col{
case "grey":
gl.Color3d(0.5,0.5,0.5)
case "red":
gl.Color3d(1, 0, 0)
case "green":
gl.Color3d(0, 1, 0)
case "blue":
gl.Color3d(0, 0, 1)
case "lblue":
gl.Color3d(0.3, 0.3, 1)
case "orange":
gl.Color3d(1, 0.5, 0)
case "yellow":
gl.Color3d(1, 1, 0)
case "purple":
gl.Color3d(1, 0, 1)
default:
gl.Color3d(1, 1, 1)
}
if ay != by{
gl.PushMatrix()
gl.Begin(gl.TRIANGLES)
gl.Vertex3d(ax-0.2, ay, 0)
gl.Vertex3d(ax+0.2, ay, 0)
gl.Vertex3d(ax-0.2, by, 0)
gl.End()
gl.PopMatrix()
gl.PushMatrix()
gl.Begin(gl.TRIANGLES)
gl.Vertex3d(ax+0.2, ay, 0)
gl.Vertex3d(ax+0.2, by, 0)
gl.Vertex3d(ax-0.2, by, 0)
gl.End()
gl.PopMatrix()
}else{
gl.PushMatrix()
gl.Begin(gl.TRIANGLES)
gl.Vertex3d(ax, ay+0.2, 0)
gl.Vertex3d(bx, by+0.2, 0)
gl.Vertex3d(bx, by-0.2, 0)
gl.End()
gl.PopMatrix()
gl.PushMatrix()
gl.Begin(gl.TRIANGLES)
gl.Vertex3d(ax, ay+0.2, 0)
gl.Vertex3d(ax, ay-0.2, 0)
gl.Vertex3d(bx, by-0.2, 0)
gl.End()
gl.PopMatrix()
}
}
func DrawSizeableTri(Tr SizeableTri){
ax := Tr.Ax
bx := Tr.Bx
cx := Tr.Cx
ay := Tr.Ay
by := Tr.By
cy := Tr.Cy
col := Tr.Colour
switch col{
case "grey":
gl.Color3d(0.5,0.5,0.5)
case "red":
gl.Color3d(1, 0, 0)
case "green":
gl.Color3d(0, 1, 0)
case "blue":
gl.Color3d(0, 0, 1)
case "lblue":
gl.Color3d(0.3, 0.3, 1)
case "orange":
gl.Color3d(1, 0.5, 0)
case "yellow":
gl.Color3d(1, 1, 0)
case "purple":
gl.Color3d(1, 0, 1)
default:
gl.Color3d(1, 1, 1)
}
gl.PushMatrix()
// gl.Translated(x, y, 0)
// gl.Scaled(s, s, s)
// gl.Rotated(r, 0, 0, 1)
gl.Begin(gl.TRIANGLES)
gl.Vertex3d(ax, ay, 0)
gl.Vertex3d(bx, by, 0)
gl.Vertex3d(cx, cy, 0)
gl.End()
gl.PopMatrix()
}
func DrawEntity(en Entity){
x := en.Xpos
y := en.Ypos
r := en.Rot
s := en.Size
col := en.Colour
switch col{
case "grey":
gl.Color3d(0.5,0.5,0.5)
case "red":
gl.Color3d(1, 0, 0)
case "green":
gl.Color3d(0, 1, 0)
case "blue":
gl.Color3d(0, 0, 1)
case "lblue":
gl.Color3d(0.3, 0.3, 1)
case "orange":
gl.Color3d(1, 0.5, 0)
case "yellow":
gl.Color3d(1, 1, 0)
case "purple":
gl.Color3d(1, 0, 1)
default:
gl.Color3d(1, 1, 1)
}
gl.PushMatrix()
gl.Translated(x, y, 0)
gl.Scaled(s, s, s)
//gl.Rotated(r*180/math.Pi, 0, 0, 1)
gl.Rotated(r, 0, 0, 1)
enx := [3]float64{-0.8, 0.8, 0}
eny := [3]float64{1, 1, -1}
//in OpenGL 3.2, the vertices below would be stored on the GPU
//so all you would need to do is say DrawShape(A) or something
gl.Begin(gl.TRIANGLES)
gl.Vertex3d(enx[0], eny[0], 0)
gl.Vertex3d(enx[1], eny[1], 0)
gl.Vertex3d(enx[2], eny[2], 0)
gl.End()
gl.PopMatrix()
}