debug.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 physics implements a basic physics engine.
  5. package physics
  6. import (
  7. "github.com/g3n/engine/core"
  8. "github.com/g3n/engine/math32"
  9. "github.com/g3n/engine/geometry"
  10. "github.com/g3n/engine/gls"
  11. "github.com/g3n/engine/graphic"
  12. "github.com/g3n/engine/material"
  13. )
  14. // This file contains helpful infrastructure for debugging physics
  15. type DebugHelper struct {
  16. }
  17. func ShowWorldFace(scene *core.Node, face []math32.Vector3, color *math32.Color) {
  18. if len(face) == 0 {
  19. return
  20. }
  21. vertices := math32.NewArrayF32(0, 16)
  22. for i := range face {
  23. vertices.AppendVector3(&face[i])
  24. }
  25. vertices.AppendVector3(&face[0])
  26. geom := geometry.NewGeometry()
  27. geom.AddVBO(gls.NewVBO().AddAttrib("VertexPosition", 3).SetBuffer(vertices))
  28. mat := material.NewStandard(color)
  29. faceGraphic := graphic.NewLineStrip(geom, mat)
  30. scene.Add(faceGraphic)
  31. }
  32. func ShowPenAxis(scene *core.Node, axis *math32.Vector3) {//}, min, max float32) {
  33. vertices := math32.NewArrayF32(0, 16)
  34. size := float32(100)
  35. minPoint := axis.Clone().MultiplyScalar(size)
  36. maxPoint := axis.Clone().MultiplyScalar(-size)
  37. //vertices.AppendVector3(minPoint.Clone().SetX(minPoint.X - size))
  38. //vertices.AppendVector3(minPoint.Clone().SetX(minPoint.X + size))
  39. //vertices.AppendVector3(minPoint.Clone().SetY(minPoint.Y - size))
  40. //vertices.AppendVector3(minPoint.Clone().SetY(minPoint.Y + size))
  41. //vertices.AppendVector3(minPoint.Clone().SetZ(minPoint.Z - size))
  42. //vertices.AppendVector3(minPoint.Clone().SetZ(minPoint.Z + size))
  43. vertices.AppendVector3(minPoint)
  44. //vertices.AppendVector3(maxPoint.Clone().SetX(maxPoint.X - size))
  45. //vertices.AppendVector3(maxPoint.Clone().SetX(maxPoint.X + size))
  46. //vertices.AppendVector3(maxPoint.Clone().SetY(maxPoint.Y - size))
  47. //vertices.AppendVector3(maxPoint.Clone().SetY(maxPoint.Y + size))
  48. //vertices.AppendVector3(maxPoint.Clone().SetZ(maxPoint.Z - size))
  49. //vertices.AppendVector3(maxPoint.Clone().SetZ(maxPoint.Z + size))
  50. vertices.AppendVector3(maxPoint)
  51. geom := geometry.NewGeometry()
  52. geom.AddVBO(gls.NewVBO().AddAttrib("VertexPosition", 3).SetBuffer(vertices))
  53. mat := material.NewStandard(&math32.Color{1,1,1})
  54. faceGraphic := graphic.NewLines(geom, mat)
  55. scene.Add(faceGraphic)
  56. }
  57. func ShowContact(scene *core.Node, contact *Contact) {
  58. vertices := math32.NewArrayF32(0, 16)
  59. size := float32(0.0005)
  60. otherPoint := contact.Point.Clone().Add(contact.Normal.MultiplyScalar(-contact.Depth))
  61. vertices.AppendVector3(contact.Point.Clone().SetX(contact.Point.X - size))
  62. vertices.AppendVector3(contact.Point.Clone().SetX(contact.Point.X + size))
  63. vertices.AppendVector3(contact.Point.Clone().SetY(contact.Point.Y - size))
  64. vertices.AppendVector3(contact.Point.Clone().SetY(contact.Point.Y + size))
  65. vertices.AppendVector3(contact.Point.Clone().SetZ(contact.Point.Z - size))
  66. vertices.AppendVector3(contact.Point.Clone().SetZ(contact.Point.Z + size))
  67. vertices.AppendVector3(&contact.Point)
  68. vertices.AppendVector3(otherPoint)
  69. geom := geometry.NewGeometry()
  70. geom.AddVBO(gls.NewVBO().AddAttrib("VertexPosition", 3).SetBuffer(vertices))
  71. mat := material.NewStandard(&math32.Color{0,0,1})
  72. faceGraphic := graphic.NewLines(geom, mat)
  73. scene.Add(faceGraphic)
  74. }