line_strip.go 1.4 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/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. type LineStrip struct {
  13. Graphic
  14. mvpm gls.UniformMatrix4f // Model view projection matrix uniform
  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(igeom, gls.LINE_STRIP)
  21. l.AddMaterial(l, imat, 0, 0)
  22. l.mvpm.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. // Calculates model view projection matrix and updates uniform
  28. mw := l.MatrixWorld()
  29. var mvpm math32.Matrix4
  30. mvpm.MultiplyMatrices(&rinfo.ViewMatrix, &mw)
  31. mvpm.MultiplyMatrices(&rinfo.ProjMatrix, &mvpm)
  32. l.mvpm.SetMatrix4(&mvpm)
  33. l.mvpm.Transfer(gs)
  34. }
  35. // Raycast satisfies the INode interface and checks the intersections
  36. // of this geometry with the specified raycaster
  37. func (l *LineStrip) Raycast(rc *core.Raycaster, intersects *[]core.Intersect) {
  38. lineRaycast(l, rc, intersects, 1)
  39. }