point.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 material
  5. import (
  6. "github.com/g3n/engine/gls"
  7. "github.com/g3n/engine/math32"
  8. )
  9. // Point material is normally used for single point sprites
  10. type Point struct {
  11. Standard // Embedded standard material
  12. }
  13. // NewPoint creates and returns a pointer to a new point material
  14. func NewPoint(color *math32.Color) *Point {
  15. pm := new(Point)
  16. pm.Standard.Init("point", color)
  17. // Sets uniform's initial values
  18. pm.uni.SetColor(vEmissive, color)
  19. pm.uni.SetPos(pSize, 1.0)
  20. pm.uni.SetPos(pRotationZ, 0)
  21. return pm
  22. }
  23. // SetEmissiveColor sets the material emissive color
  24. // The default is {0,0,0}
  25. func (pm *Point) SetEmissiveColor(color *math32.Color) {
  26. pm.uni.SetColor(vEmissive, color)
  27. }
  28. // SetSize sets the point size
  29. func (pm *Point) SetSize(size float32) {
  30. pm.uni.SetPos(pSize, size)
  31. }
  32. // SetRotationZ sets the point rotation around the Z axis.
  33. func (pm *Point) SetRotationZ(rot float32) {
  34. pm.uni.SetPos(pRotationZ, rot)
  35. }
  36. // RenderSetup is called by the engine before drawing the object
  37. // which uses this material
  38. func (pm *Point) RenderSetup(gs *gls.GLS) {
  39. pm.Material.RenderSetup(gs)
  40. pm.uni.Transfer(gs)
  41. }