debug.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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
  5. import (
  6. "github.com/g3n/engine/core"
  7. "github.com/g3n/engine/experimental/collision"
  8. "github.com/g3n/engine/geometry"
  9. "github.com/g3n/engine/gls"
  10. "github.com/g3n/engine/graphic"
  11. "github.com/g3n/engine/material"
  12. "github.com/g3n/engine/math32"
  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(vertices).AddAttrib(gls.VertexPosition))
  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(vertices).AddAttrib(gls.VertexPosition))
  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 *collision.Contact) {
  58. vertices := math32.NewArrayF32(0, 16)
  59. size := float32(0.0005)
  60. otherPoint := contact.Point.Clone().Add(contact.Normal.Clone().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.Clone())
  68. vertices.AppendVector3(otherPoint)
  69. geom := geometry.NewGeometry()
  70. geom.AddVBO(gls.NewVBO(vertices).AddAttrib(gls.VertexPosition))
  71. mat := material.NewStandard(&math32.Color{0, 0, 1})
  72. faceGraphic := graphic.NewLines(geom, mat)
  73. scene.Add(faceGraphic)
  74. }