line_strip.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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/core"
  7. "github.com/g3n/engine/geometry"
  8. "github.com/g3n/engine/gls"
  9. "github.com/g3n/engine/material"
  10. )
  11. // LineStrip is a Graphic which is rendered as a collection of connected lines.
  12. type LineStrip struct {
  13. Graphic // Embedded graphic object
  14. uniMVPm gls.Uniform // Model view projection matrix uniform location cache
  15. }
  16. // NewLineStrip creates and returns a pointer to a new LineStrip graphic
  17. // with the specified geometry and material.
  18. func NewLineStrip(igeom geometry.IGeometry, imat material.IMaterial) *LineStrip {
  19. l := new(LineStrip)
  20. l.Graphic.Init(l, igeom, gls.LINE_STRIP)
  21. l.AddMaterial(l, imat, 0, 0)
  22. l.uniMVPm.Init("MVP")
  23. return l
  24. }
  25. // RenderSetup is called by the engine before drawing this geometry.
  26. func (l *LineStrip) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo) {
  27. // Transfer model view projection matrix uniform
  28. mvpm := l.ModelViewProjectionMatrix()
  29. location := l.uniMVPm.Location(gs)
  30. gs.UniformMatrix4fv(location, 1, false, &mvpm[0])
  31. }
  32. // Raycast satisfies the INode interface and checks the intersections
  33. // of this geometry with the specified raycaster.
  34. func (l *LineStrip) Raycast(rc *core.Raycaster, intersects *[]core.Intersect) {
  35. lineRaycast(l, rc, intersects, 1)
  36. }