debug.go 3.3 KB

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