line_strip.go 1.6 KB

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