fisica
Class FContact

java.lang.Object
  extended by fisica.FContact

public class FContact
extends java.lang.Object

Represents a contact between two bodies. Objects of this type are not created by the users. Contacts are passed to the user when they implement the contactStarted(FContact){ }, contactPersisted(FContact){ } and contactEnded(FContact){ } methods in the applet:

 FWorld world;

 void setup() {
   Fisica.init(this);

   world = new FWorld();
   world.setEdges();

   // Create and add bodies to the world here
   // ...
 }

 void draw() {
   world.step();
   world.draw();
 }

 void contactStarted(FContact contact) {
   // Draw in green an ellipse where the contact took place
   fill(0, 170, 0);
   ellipse(contact.getX(), contact.getY(), 20, 20);
 }

 void contactPersisted(FContact contact) {
   // Draw in blue an ellipse where the contact took place
   fill(0, 0, 170);
   ellipse(contact.getX(), contact.getY(), 10, 10);
 }

 void contactStarted(FContact contact) {
   // Draw in red an ellipse where the contact took place
   fill(170, 0, 0);
   ellipse(contact.getX(), result.getY(), 20, 20);
 }


 
To know if the contact is the beggining, the continuation or the end of a contact it is better to use the other method contactResult(FContactResult){ }.

See Also:
FContactResult

Method Summary
 boolean contains(FBody n1)
          Returns true if the contact contains the body.
 boolean contains(FBody n1, FBody n2)
          Returns true if the contact contains the two bodies.
 boolean contains(java.lang.String n1)
          Returns true if the contact contains the body.
 boolean contains(java.lang.String n1, java.lang.String n2)
          Returns true if the contact contains the two bodies.
 FBody getBody1()
          Returns the first body involved in the contact.
 FBody getBody2()
          Returns the second body involved in the contact.
 float getFriction()
          Get the friction coefficient of the contact.
 fisica.FContactID getId()
          Get the identifier of the contact.
 float getNormalX()
          Returns the horizontal component of the contact normal.
 float getNormalY()
          Returns the vertical component of the contact normal.
 float getRestitution()
          Get the restitution coefficient of the contact.
 float getSeparation()
          Get the separation between the bodies.
 float getVelocityX()
          Returns the horizontal component of the contact velocity.
 float getVelocityY()
          Returns the vertical component of the contact velocity.
 float getX()
          Returns the horizontal position of the contact point.
 float getY()
          Returns the vertical position of the contact point.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBody1

public FBody getBody1()
Returns the first body involved in the contact.

Returns:
first of the bodies involved in the contact

getBody2

public FBody getBody2()
Returns the second body involved in the contact.

Returns:
second of the bodies involved in the contact

getX

public float getX()
Returns the horizontal position of the contact point.

Returns:
the horizontal position of the contact point in pixels
See Also:
getY()

getY

public float getY()
Returns the vertical position of the contact point.

Returns:
the vertical position of the contact point in pixels
See Also:
getX()

getVelocityX

public float getVelocityX()
Returns the horizontal component of the contact velocity.

Returns:
the horizontal component of the contact velocity
See Also:
getVelocityY()

getVelocityY

public float getVelocityY()
Returns the vertical component of the contact velocity.

Returns:
the vertical component of the contact velocity
See Also:
getVelocityX()

getNormalX

public float getNormalX()
Returns the horizontal component of the contact normal.

Returns:
the horizontal component of the contact normal
See Also:
getNormalY()

getNormalY

public float getNormalY()
Returns the vertical component of the contact normal.

Returns:
the vertical component of the contact normal
See Also:
getNormalX()

getSeparation

public float getSeparation()
Get the separation between the bodies.

Returns:
a positive value means that the bodies have space between them, negative values means that the bodies have penetrated each other

getFriction

public float getFriction()
Get the friction coefficient of the contact. The friction determines the ratio of the reaction force tangent to a contact that the two bodies will recieve. Basically it can be seen as a coefficient that will control how the bodies get slown down when they slide against each other. This value depends on the friction coefficients of the two bodies involved in the contact.

Returns:
a positive value. A value of 0 means no friction and thus the body will not be slown down if no other forces are applied

getRestitution

public float getRestitution()
Get the restitution coefficient of the contact. The restitution determines the ratio of the reaction force normal to a contact that the two bodies will recieve. Basically it can be seen as a coefficient that will control the strength with which the bodies bounce back from the collision. This value depends on the resititution coefficients of the two bodies involved in the contact.

Returns:
a positive value. A value of 0 means no bounce after a collision, and a value of 1 means bounce with it's full speed from a collision

getId

public fisica.FContactID getId()
Get the identifier of the contact. This value is useful in order to uniquely identify a contact. A new contact ID is created whenever to bodies enter into contact at a given point. If the bodies slide against each other the contact ID is maintained even if the point of contact is modified due to the slide. As soon as the two bodies separate the contact is considered ended.

Returns:
a unique identifier representing the contact

contains

public boolean contains(java.lang.String n1,
                        java.lang.String n2)
Returns true if the contact contains the two bodies. If one of the bodies does not have a name this function returns false.

Parameters:
n1 - the name of one of the bodies
n2 - the name of another one of the bodies
Returns:
true if the contact bodies have the names given by the parameters
See Also:
FBody.setName(java.lang.String)

contains

public boolean contains(FBody n1,
                        FBody n2)
Returns true if the contact contains the two bodies.

Parameters:
n1 - one of the bodies
n2 - another one of the bodies
Returns:
true if the contact bodies are the ones given by the parameters

contains

public boolean contains(java.lang.String n1)
Returns true if the contact contains the body.

Returns:
true if one of the contact bodies has the name given by the parameters
See Also:
FBody.setName(java.lang.String)

contains

public boolean contains(FBody n1)
Returns true if the contact contains the body.

Returns:
true if one of the contact bodies has the name given by the parameters


processing library fisica by Ricard Marxer. (c) 2009-2013