plane.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 shape
  5. import "github.com/g3n/engine/math32"
  6. // Plane is an analytical collision Plane.
  7. // A plane, facing in the +Z direction. The plane has its surface at z=0 and everything below z=0 is assumed to be solid.
  8. type Plane struct {
  9. normal math32.Vector3
  10. }
  11. // NewPlane creates and returns a pointer to a new analytical collision plane.
  12. func NewPlane() *Plane {
  13. p := new(Plane)
  14. p.normal = *math32.NewVector3(0, 0, 1) //*normal
  15. return p
  16. }
  17. // SetRadius sets the radius of the analytical collision sphere.
  18. //func (p *Plane) SetNormal(normal *math32.Vector3) {
  19. //
  20. // p.normal = *normal
  21. //}
  22. // Normal returns the normal of the analytical collision plane.
  23. func (p *Plane) Normal() math32.Vector3 {
  24. return p.normal
  25. }
  26. // IShape =============================================================
  27. // BoundingBox computes and returns the bounding box of the analytical collision plane.
  28. func (p *Plane) BoundingBox() math32.Box3 {
  29. //return math32.Box3{math32.Vector3{math32.Inf(-1), math32.Inf(-1), math32.Inf(-1)}, math32.Vector3{math32.Inf(1), 0, math32.Inf(1)}}
  30. return math32.Box3{math32.Vector3{-1000, -1000, -1000}, math32.Vector3{1000, 1000, 0}}
  31. }
  32. // BoundingSphere computes and returns the bounding sphere of the analytical collision plane.
  33. func (p *Plane) BoundingSphere() math32.Sphere {
  34. return *math32.NewSphere(math32.NewVec3(), math32.Inf(1))
  35. }
  36. // Area returns the surface area of the analytical collision plane.
  37. func (p *Plane) Area() float32 {
  38. return math32.Inf(1)
  39. }
  40. // Volume returns the volume of the analytical collision sphere.
  41. func (p *Plane) Volume() float32 {
  42. return math32.Inf(1)
  43. }
  44. // RotationalInertia computes and returns the rotational inertia of the analytical collision plane.
  45. func (p *Plane) RotationalInertia(mass float32) math32.Matrix3 {
  46. return *math32.NewMatrix3().Zero()
  47. }
  48. // ProjectOntoAxis returns the minimum and maximum distances of the analytical collision plane projected onto the specified local axis.
  49. func (p *Plane) ProjectOntoAxis(localAxis *math32.Vector3) (float32, float32) {
  50. if localAxis.Equals(&p.normal) {
  51. return math32.Inf(-1), 0
  52. } else {
  53. return math32.Inf(-1), math32.Inf(1)
  54. }
  55. }