axis_helper.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2016 The G3N Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package graphic
  5. import (
  6. "github.com/g3n/engine/geometry"
  7. "github.com/g3n/engine/gls"
  8. "github.com/g3n/engine/material"
  9. "github.com/g3n/engine/math32"
  10. )
  11. type AxisHelper struct {
  12. Lines
  13. }
  14. func NewAxisHelper(size float32) *AxisHelper {
  15. axis := new(AxisHelper)
  16. // Creates geometry with three orthogonal lines
  17. // starting at the origin
  18. geom := geometry.NewGeometry()
  19. positions := math32.NewArrayF32(0, 18)
  20. positions.Append(
  21. 0, 0, 0, size, 0, 0,
  22. 0, 0, 0, 0, size, 0,
  23. 0, 0, 0, 0, 0, size,
  24. )
  25. colors := math32.NewArrayF32(0, 18)
  26. colors.Append(
  27. 1, 0, 0, 1, 0.6, 0,
  28. 0, 1, 0, 0.6, 1, 0,
  29. 0, 0, 1, 0, 0.6, 1,
  30. )
  31. geom.AddVBO(gls.NewVBO().AddAttrib("VertexPosition", 3).SetBuffer(positions))
  32. geom.AddVBO(gls.NewVBO().AddAttrib("VertexColor", 3).SetBuffer(colors))
  33. // Creates line material
  34. mat := material.NewBasic()
  35. mat.SetLineWidth(2.0)
  36. // Initialize lines with the specified geometry and material
  37. axis.Lines.Init(geom, mat)
  38. return axis
  39. }