Emini Physics Engine 1.3.5a API Documentation

at.emini.physics2D
Class Contact

java.lang.Object
  extended by at.emini.physics2D.Contact

public class Contact
extends java.lang.Object

The Contact class represents a contact between two bodies.
The contacts are created during the collision detection step. A contact can be a single or double contact of a collision between two bodies. A single contact happens if the contact type is edge-face. In case of two perpendicular bodies the contact type can be face-face. This situation is a single contact object representing the double contact. The extreme points of the face-face intersection line are contacts of the same bodies. To achieve better stacking results, these are treated together (Block solving).

Author:
Alexander Adensamer

Constructor Summary
protected Contact(FXVector normal, Body body1, int index1, Body body2, int index2)
          Constructor.
protected Contact(FXVector contactPosition1, FXVector contactPosition2, Body body1, Body body2)
          Constructor using two absolute points.
 
Method Summary
protected  void applyAccumImpulses()
          Applies the accumulated impulses.
protected  boolean applyMomentum()
          Applies the momentum of the collision.
protected  float applyMomentumPositionCorrectionFX()
          Applies the position correction to the involved bodies.
 Body body1()
          Gets the first body.
 Body body2()
          Gets the second body.
 void clear()
          Sets up the contact for reuse (same bodies).
 void clearAll()
          Sets up the contact for reuse (different bodies).
 boolean concernsBody(Body body)
          Checks is the contact applies to a body.
 FXVector getContactPosition1()
          Gets contact position of the first contact point.
 FXVector getContactPosition2()
          Gets contact position of the second contact point.
 float getDepth1FX()
          Gets the penetration depth first contact point.
 float getDepth2FX()
          Gets the penetration depth second contact point.
 float getImpulseContact1FX()
          Gets the last acting impulse of the contact (position 1).
 float getImpulseContact2FX()
          Gets the last acting impulse of the contact (position 2).
 FXVector getNormal()
          Gets the contact normal.
 boolean isSingle()
          Checks if the contact is a single point.
protected  void precalculate(float invTimestepFX)
          Precalculates values for the constraint iteration.
protected  void precalculatePositionCorrection(float timestepFX, float invTimestepFX)
           
 int segment1()
          Gets the segment index of the first body if it is the landscape or shape index in case of a multi shape.
 int segment2()
          Gets the segment index of the second body if it is the landscape or shape index in case of a multi shape.
 void setContactPosition1(FXVector pos, float depthFX, boolean posAtBody1)
          Sets the first contact position.
 void setContactPosition2(FXVector pos, float depthFX, boolean posAtBody1)
          Sets the second contact position.
 void setNormal(FXVector normal, Body b1, int index1, Body b2, int index2)
          Resets normal and bodies.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Contact

protected Contact(FXVector normal,
                  Body body1,
                  int index1,
                  Body body2,
                  int index2)
Constructor. This sets up the contact, but contact positions are not initialized.

Parameters:
normal - - collision normal
body1 - Body 1
body2 - Body 2

Contact

protected Contact(FXVector contactPosition1,
                  FXVector contactPosition2,
                  Body body1,
                  Body body2)
Constructor using two absolute points. The actual contact position, normal and penetration depth are calculated.

Parameters:
contactPosition1 - contact position on body 1
contactPosition2 - contact position on body 2
body1 - Body 1
body2 - Body 2
Method Detail

setNormal

public final void setNormal(FXVector normal,
                            Body b1,
                            int index1,
                            Body b2,
                            int index2)
Resets normal and bodies. Initializes the contact. This is required for contact reusal.

Parameters:
normal - the contact normal
b1 - Body 1
b2 - Body 2

clear

public final void clear()
Sets up the contact for reuse (same bodies). It is required in order to avoid unnecessary Object instantiations instead of creating a new object.


clearAll

public final void clearAll()
Sets up the contact for reuse (different bodies). This is required in order to avoid unnecessary Object instantiations


setContactPosition1

public final void setContactPosition1(FXVector pos,
                                      float depthFX,
                                      boolean posAtBody1)
Sets the first contact position. Calculates the correct relative position depending on the body positions and orientation

Parameters:
pos - the absolute contact position
depthFX - the penetration depth for this contact
posAtBody1 - flag indicating whether the position lies on body 1

setContactPosition2

public final void setContactPosition2(FXVector pos,
                                      float depthFX,
                                      boolean posAtBody1)
Sets the second contact position. Calculates the correct relative position depending on the body positions and orientation

Parameters:
pos - the absolute contact position
depthFX - the penetration depth for this contact
posAtBody1 - flag indicating whether the position lies on body 1

isSingle

public boolean isSingle()
Checks if the contact is a single point.

Returns:
true if it represents a single contact point.

getContactPosition1

public FXVector getContactPosition1()
Gets contact position of the first contact point.

Returns:
the contact position 1

getContactPosition2

public FXVector getContactPosition2()
Gets contact position of the second contact point.

Returns:
the contact position 2

getNormal

public FXVector getNormal()
Gets the contact normal.

Returns:
the contact normal

body1

public Body body1()
Gets the first body.

Returns:
the first body

segment1

public int segment1()
Gets the segment index of the first body if it is the landscape or shape index in case of a multi shape.

Returns:
the segment/shape index of the first body

body2

public Body body2()
Gets the second body.

Returns:
the second body

segment2

public int segment2()
Gets the segment index of the second body if it is the landscape or shape index in case of a multi shape.

Returns:
the segment/shape index of the second body

getDepth1FX

public float getDepth1FX()
Gets the penetration depth first contact point.

Returns:
the penetration depth of the first contact.

getDepth2FX

public float getDepth2FX()
Gets the penetration depth second contact point.

Returns:
the penetration depth of the second contact (if any).

applyAccumImpulses

protected final void applyAccumImpulses()
Applies the accumulated impulses. Performs the warmstarting of the contact constraint.


precalculate

protected final void precalculate(float invTimestepFX)
Precalculates values for the constraint iteration. The following values are computed:

Parameters:
invTimestepFX - the inverse timestep of the simulation

precalculatePositionCorrection

protected final void precalculatePositionCorrection(float timestepFX,
                                                    float invTimestepFX)
Parameters:
timestepFX - the timestep of the simulation
invTimestepFX - the inverse timestep of the simulation

applyMomentum

protected boolean applyMomentum()
Applies the momentum of the collision. Uses the pre-calculated mass matrices and the current velocities of the bodies to calculate and apply the impulse to satisfy the contact constraint.


applyMomentumPositionCorrectionFX

protected float applyMomentumPositionCorrectionFX()
Applies the position correction to the involved bodies. The concept of virtual velocities is used to correct the positions directly.

Returns:
the amount of correction

concernsBody

public boolean concernsBody(Body body)
Checks is the contact applies to a body.

Parameters:
body - the body for which to check
Returns:
true if this constraint applies to the body.

getImpulseContact1FX

public float getImpulseContact1FX()
Gets the last acting impulse of the contact (position 1).

Returns:
the last acting impulse on the contact at position 1

getImpulseContact2FX

public float getImpulseContact2FX()
Gets the last acting impulse of the contact (position 2). This is only available if the contact is a double contact. If the contact is a single contact, 0 is returned.

Returns:
the last acting impulse on the contact at position 2

Emini Physics Engine 1.3.5a API Documentation

Emini Physics Engine 1.3.5a API Documentation - Copyright 2014 Alexander Adensamer