forked from g3n/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
axis_helper.go
48 lines (40 loc) · 1.18 KB
/
axis_helper.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
// Copyright 2016 The G3N Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package graphic
import (
"github.com/leapar/engine/geometry"
"github.com/leapar/engine/gls"
"github.com/leapar/engine/material"
"github.com/leapar/engine/math32"
)
// AxisHelper is the visual representation of the three axes
type AxisHelper struct {
Lines
}
// NewAxisHelper returns a pointer to a new AxisHelper object
func NewAxisHelper(size float32) *AxisHelper {
axis := new(AxisHelper)
// Creates geometry with three orthogonal lines
// starting at the origin
geom := geometry.NewGeometry()
positions := math32.NewArrayF32(0, 18)
positions.Append(
0, 0, 0, size, 0, 0,
0, 0, 0, 0, size, 0,
0, 0, 0, 0, 0, size,
)
colors := math32.NewArrayF32(0, 18)
colors.Append(
1, 0, 0, 1, 0.6, 0,
0, 1, 0, 0.6, 1, 0,
0, 0, 1, 0, 0.6, 1,
)
geom.AddVBO(gls.NewVBO(positions).AddAttrib(gls.VertexPosition))
geom.AddVBO(gls.NewVBO(colors).AddAttrib(gls.VertexColor))
// Creates line material
mat := material.NewBasic()
// Initialize lines with the specified geometry and material
axis.Lines.Init(geom, mat)
return axis
}