axis_helper.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. // AxisHelper is the visual representation of the three axes
  12. type AxisHelper struct {
  13. Lines
  14. }
  15. // NewAxisHelper returns a pointer to a new AxisHelper object
  16. func NewAxisHelper(size float32) *AxisHelper {
  17. axis := new(AxisHelper)
  18. // Creates geometry with three orthogonal lines
  19. // starting at the origin
  20. geom := geometry.NewGeometry()
  21. positions := math32.NewArrayF32(0, 18)
  22. positions.Append(
  23. 0, 0, 0, size, 0, 0,
  24. 0, 0, 0, 0, size, 0,
  25. 0, 0, 0, 0, 0, size,
  26. )
  27. colors := math32.NewArrayF32(0, 18)
  28. colors.Append(
  29. 1, 0, 0, 1, 0.6, 0,
  30. 0, 1, 0, 0.6, 1, 0,
  31. 0, 0, 1, 0, 0.6, 1,
  32. )
  33. geom.AddVBO(gls.NewVBO(positions).AddAttrib(gls.VertexPosition, 3))
  34. geom.AddVBO(gls.NewVBO(colors).AddAttrib(gls.VertexColor, 3))
  35. // Creates line material
  36. mat := material.NewBasic()
  37. // Initialize lines with the specified geometry and material
  38. axis.Lines.Init(geom, mat)
  39. return axis
  40. }