line_strip.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 // Embedded graphic object
  14. uniMVP 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(igeom, gls.LINE_STRIP)
  21. l.AddMaterial(l, imat, 0, 0)
  22. l.uniMVP.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. // Transfer mvpm uniform
  33. location := l.uniMVP.Location(gs)
  34. gs.UniformMatrix4fv(location, 1, false, &mvpm[0])
  35. }
  36. // Raycast satisfies the INode interface and checks the intersections
  37. // of this geometry with the specified raycaster
  38. func (l *LineStrip) Raycast(rc *core.Raycaster, intersects *[]core.Intersect) {
  39. lineRaycast(l, rc, intersects, 1)
  40. }