/
arena.go
55 lines (45 loc) · 1.37 KB
/
arena.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
package main
import (
"image"
"golang.org/x/mobile/gl"
"github.com/shazow/linerage3d/collision"
)
func NewArenaNode(bounds image.Rectangle, shader Shader) *arena {
shape := NewStaticShape()
shape.vertices = []float32{
float32(bounds.Min.X), 0, float32(bounds.Min.Y),
float32(bounds.Max.X), 0, float32(bounds.Min.Y),
float32(bounds.Max.X), 0, float32(bounds.Max.Y),
float32(bounds.Max.X), 0, float32(bounds.Max.Y),
float32(bounds.Min.X), 0, float32(bounds.Min.Y),
float32(bounds.Min.X), 0, float32(bounds.Max.Y),
}
shape.Buffer()
return newArena(bounds, &Node{
Shape: shape,
shader: shader,
})
}
func newArena(bounds image.Rectangle, node *Node) *arena {
arena := &arena{
Node: node,
Collider: collision.LinearCollider(bounds),
}
arena.Reset()
return arena
}
type arena struct {
*Node
collision.Collider
}
func (shape *arena) Draw(camera Camera) {
shader := shape.shader
gl.Uniform3fv(shader.Uniform("material.ambient"), []float32{0.05, 0.0, 0.02})
gl.Uniform3fv(shader.Uniform("lights[0].color"), []float32{0.2, 0.1, 0.1})
gl.Uniform1f(shader.Uniform("lights[0].intensity"), 0.3)
// TODO: Move this into a texture
gl.Uniform1f(shader.Uniform("lights[1].intensity"), 25.0)
gl.Uniform3fv(shader.Uniform("lights[1].position"), []float32{0, 20, 0})
gl.Uniform3fv(shader.Uniform("lights[1].color"), []float32{0.05, 0.0, 0.1})
shape.Node.Draw(camera)
}