simulation.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. type ICollidable interface {
  6. }
  7. // Simulation represents a physics simulation.
  8. type Simulation struct {
  9. forceFields []*ForceField
  10. rigidBodies []*RigidBody
  11. particles []*Particle
  12. }
  13. // NewSimulation creates and returns a pointer to a new physics simulation.
  14. func NewSimulation() *Simulation {
  15. b := new(Simulation)
  16. return b
  17. }
  18. // AddForceField adds a force field to the simulation.
  19. func (s *Simulation) AddForceField(ff *ForceField) {
  20. s.forceFields = append(s.forceFields, ff)
  21. }
  22. // RemoveForceField removes the specified force field from the simulation.
  23. // Returns true if found or false otherwise.
  24. func (s *Simulation) RemoveForceField(ff *ForceField) bool {
  25. for pos, current := range s.forceFields {
  26. if current == ff {
  27. copy(s.forceFields[pos:], s.forceFields[pos+1:])
  28. s.forceFields[len(s.forceFields)-1] = nil
  29. s.forceFields = s.forceFields[:len(s.forceFields)-1]
  30. return true
  31. }
  32. }
  33. return false
  34. }
  35. func (s *Simulation) CollisionBroadphase() {
  36. }
  37. func (s *Simulation) CheckCollisions(collidables []ICollidable) {
  38. }
  39. // Step steps the simulation.
  40. func (s *Simulation) Step() {
  41. // Check for collisions (broad phase)
  42. //s.CollisionBroadphase()
  43. // Check for collisions (narrow phase)
  44. //s.CheckCollisions()
  45. // Apply forces/inertia/impulses
  46. // Update visual representation
  47. }