Module org.dyn4j

Class Force


  • public class Force
    extends java.lang.Object
    Represents a force.
    Since:
    1.0.0
    Version:
    3.2.0
    Author:
    William Bittle
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Vector2 force
      The force to apply
    • Constructor Summary

      Constructors 
      Constructor Description
      Force()
      Default constructor.
      Force​(double x, double y)
      Creates a new Force using the x and y components.
      Force​(Force force)
      Copy constructor.
      Force​(Vector2 force)
      Creates a new Force using the given Vector2.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Vector2 getForce()
      Returns the force vector.
      boolean isComplete​(double elapsedTime)
      Returns true if this force should be removed.
      void set​(double x, double y)
      Sets this Force to the given components.
      void set​(Force force)
      Sets this Force to the given Force.
      void set​(Vector2 force)
      Sets this Force to the given force Vector2.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • force

        protected Vector2 force
        The force to apply
    • Constructor Detail

      • Force

        public Force()
        Default constructor.
      • Force

        public Force​(double x,
                     double y)
        Creates a new Force using the x and y components.
        Parameters:
        x - the x component
        y - the y component
      • Force

        public Force​(Vector2 force)
        Creates a new Force using the given Vector2.
        Parameters:
        force - the force Vector2
        Throws:
        java.lang.NullPointerException - if force is null
      • Force

        public Force​(Force force)
        Copy constructor.
        Parameters:
        force - the Force to copy
        Throws:
        java.lang.NullPointerException - if force is null
    • Method Detail

      • set

        public void set​(double x,
                        double y)
        Sets this Force to the given components.
        Parameters:
        x - the x component
        y - the y component
      • set

        public void set​(Vector2 force)
        Sets this Force to the given force Vector2.
        Parameters:
        force - the force Vector2
        Throws:
        java.lang.NullPointerException - if force is null
      • set

        public void set​(Force force)
        Sets this Force to the given Force.
        Parameters:
        force - the Force to copy
        Throws:
        java.lang.NullPointerException - if force is null
      • isComplete

        public boolean isComplete​(double elapsedTime)
        Returns true if this force should be removed.

        Implement this method to create Force objects that are not cleared each iteration by the World.

        The default implementation always returns true.

        Parameters:
        elapsedTime - the elapsed time since the last call to this method
        Returns:
        boolean true if this force should be removed
        Since:
        3.1.0
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getForce

        public Vector2 getForce()
        Returns the force vector.
        Returns:
        Vector2