Emini Physics Engine 1.3.5a API Documentation

at.emini.physics2D
Class Event

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

public class Event
extends java.lang.Object

The Event class represents a generic event that can be triggered in the world.
The world checks all registered event for its triggers. The event can have filters:

The event has a trigger target (see below): depending on type, the meaning of the targets is different
 - TYPE_BODY_POSITION
   - target1, target2 -> upper left edge of check area 
   - target3, target4 -> lower right edge of check area
 - TYPE_BODY_VELOCITY
   - velocity in pixel per second
   - target1, target2 -> lower upper limit of speed
   - target3, target4 -> irrelevant
 - TYPE_BODY_ROTATION
   - target1, target2 -> lower and upper limit for the rotation (rotation is always [0;360]
   - target3, target4 -> irrelevant 
 - TYPE_BODY_ANGULARVELOCITY
   - target1, target2 -> lower and upper limit for the angular velocity (in degrees per second), can be negative
   - target3, target4 -> irrelevant
 - TYPE_BODY_COLLISION
   -  target1 > 0 -> trigger upon collisions north (negative y)
   -  target2 > 0 -> trigger upon collisions east (positive x)
   -  target3 > 0 -> trigger upon collisions south (position y)
   -  target4 > 0 -> trigger upon collisions west (negative x) 
 - TYPE_BODY_COLLISION_RELATIVE (this event is created using its particular method)
   -  target1, target2 -> the default direction
   -  target3 -> the allowed deviation from the direction
An event can be "trigger once" which causes the event to be raised exactly once as long as the condition is met. When at some time the condition is not met anymore, the event can be raised again for this parameter.
Note: The trigger once functionality uses up memory and computational resources.

Author:
Alexander Adensamer

Field Summary
protected  UserData mUserData
          User data
static int TYPE_BODY_ANGULARVELOCITY
          Event type angular velocity.
static int TYPE_BODY_COLLISION
          Event type collision.
static int TYPE_BODY_COLLISION_RELATIVE
          Event type collision.
static int TYPE_BODY_POSITION
          Event type position.
static int TYPE_BODY_ROTATION
          Event type rotation.
static int TYPE_BODY_SENSOR
          Event type area collision.
static int TYPE_BODY_VELOCITY
          Event type velocity.
static int TYPE_CONSTRAINT_FORCE
          Event type constraint force.
 
Constructor Summary
protected Event(Body bodyFilter, Shape shapeFilter, Constraint constraintFilter, int type, float target1FX, float target2FX, float target3FX, float target4FX, java.lang.Object target)
          Constructor.
protected Event(Event other, Body[] bodyMapping)
          Copy Constructor.
protected Event(int type)
          Empty Constructor.
 
Method Summary
 boolean checkEvent(World world, PhysicsEventListener listener)
          Checks if the event is currently active.
 Event copy(Body[] bodyMapping)
          Copies the event.
static Event createBodyEvent(Body bodyFilter, Shape shapeFilter, int type, int target1, int target2, int target3, int target4)
          Creates a body event.
static Event createBodySensorEvent(Body bodyFilter, Shape shapeFilter, Body sensor)
          Creates an area collide event.
static Event createCollisionRelativeEvent(Body bodyFilter, Shape shapeFilter, int startAngle, int endAngle)
          Creates a relative collision event.
static Event createConstraintEvent(Constraint constraintFilter, int type, int target1, int target2)
          Creates a constraint event.
 Body getBodyFilter()
          Gets the body filter.
 Constraint getConstraintFilter()
          Gets the constraint filter.
 int getIdentifier()
          Gets the event identifier.
 Shape getShapeFilter()
          Gets the shape filter.
 java.lang.Object getTargetObject()
          Return the target object.
 boolean getTriggerOnce()
          Gets the trigger once flag.
 UserData getUserData()
          Get user data.
static Event loadEvent(PhysicsFileReader reader, World world, UserData userData)
          Loads an event from stream.
 void setBodyFilter(Body b)
          Sets the body filter.
protected  void setConstraintFilter(Constraint c)
          Sets the constraint filter.
 void setScript(Script script)
          Sets the execution script.
 void setShapeFilter(Shape s)
          Sets the shape filter.
protected  void setTargetsFX(float target1FX, float target2FX, float target3FX, float target4FX)
          Sets all targets.
 void setTriggerOnce(boolean triggerOnce)
          Flag whether event should be triggered more than once in a row.
 void setUserData(UserData userData)
          Set User data
protected  float targetAFX()
          Gets the targetA
protected  float targetBFX()
          Gets the targetB
protected  float targetCFX()
          Gets the targetC
protected  float targetDFX()
          Gets the targetD
 int type()
          Gets the event type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_BODY_POSITION

public static final int TYPE_BODY_POSITION
Event type position.

See Also:
Constant Field Values

TYPE_BODY_VELOCITY

public static final int TYPE_BODY_VELOCITY
Event type velocity.

See Also:
Constant Field Values

TYPE_BODY_ROTATION

public static final int TYPE_BODY_ROTATION
Event type rotation.

See Also:
Constant Field Values

TYPE_BODY_ANGULARVELOCITY

public static final int TYPE_BODY_ANGULARVELOCITY
Event type angular velocity.

See Also:
Constant Field Values

TYPE_BODY_COLLISION

public static final int TYPE_BODY_COLLISION
Event type collision.

See Also:
Constant Field Values

TYPE_BODY_COLLISION_RELATIVE

public static final int TYPE_BODY_COLLISION_RELATIVE
Event type collision. Used for relative collision.

See Also:
Constant Field Values

TYPE_BODY_SENSOR

public static final int TYPE_BODY_SENSOR
Event type area collision. This event type is triggered when a body enters a region defined by another body.

See Also:
Constant Field Values

TYPE_CONSTRAINT_FORCE

public static final int TYPE_CONSTRAINT_FORCE
Event type constraint force.

See Also:
Constant Field Values

mUserData

protected UserData mUserData
User data

Constructor Detail

Event

protected Event(Body bodyFilter,
                Shape shapeFilter,
                Constraint constraintFilter,
                int type,
                float target1FX,
                float target2FX,
                float target3FX,
                float target4FX,
                java.lang.Object target)
Constructor. Direct constructor for the event

Parameters:
bodyFilter - the body to which this event applies, null if all.
shapeFilter - the shape (=group of bodies) to which this event applies, null if all.
constraintFilter - the constraint to which this event applies, null if all.
type - the type of the event (must be consistent to the used filter).
target1FX - the target 1
target2FX - the target 2
target3FX - the target 3
target4FX - the target 4

Event

protected Event(Event other,
                Body[] bodyMapping)
Copy Constructor.

Parameters:
other - the event to copy.
bodyMapping - the mapping of bodies in the new world (null if not used).

Event

protected Event(int type)
Empty Constructor. This is used for loading the event.

Parameters:
type - type of the event.
Method Detail

createBodyEvent

public static Event createBodyEvent(Body bodyFilter,
                                    Shape shapeFilter,
                                    int type,
                                    int target1,
                                    int target2,
                                    int target3,
                                    int target4)
Creates a body event.

Parameters:
bodyFilter - the body to which this event applies, null if all.
shapeFilter - the shape (=group of bodies) to which this event applies, null if all.
type - the type of the event (can only be a BODY event type).
target1 - the target 1
target2 - the target 2
target3 - the target 3
target4 - the target 4

createCollisionRelativeEvent

public static Event createCollisionRelativeEvent(Body bodyFilter,
                                                 Shape shapeFilter,
                                                 int startAngle,
                                                 int endAngle)
Creates a relative collision event. The event will trigger if a collision happens between the two passed angles.

Parameters:
bodyFilter - the body to which this event applies, null if all.
shapeFilter - the shape (=group of bodies) to which this event applies, null if all.
startAngle - start angle
endAngle - end angle

createBodySensorEvent

public static Event createBodySensorEvent(Body bodyFilter,
                                          Shape shapeFilter,
                                          Body sensor)
Creates an area collide event. Triggers when a body collides with the sensor body.

Parameters:
bodyFilter - the body to which this event applies, null if all.
shapeFilter - the shape (=group of bodies) to which this event applies, null if all.
sensor - The sensor body that is not physically present, but is used only for event checking.

createConstraintEvent

public static Event createConstraintEvent(Constraint constraintFilter,
                                          int type,
                                          int target1,
                                          int target2)
Creates a constraint event.

Parameters:
constraintFilter - the constraint to which this event applies, null if all.
type - the type of the event (can only be a CONSTRAINT event type).
target1 - the target 1
target2 - the target 2

copy

public Event copy(Body[] bodyMapping)
Copies the event. Creates a deep copy of the event. The shape is not copied, but used as reference (see @link Body.Body(Body)).

Parameters:
bodyMapping - the mapping of bodies in the new world (null if not used).
Returns:
a deep copy of the event.

loadEvent

public static Event loadEvent(PhysicsFileReader reader,
                              World world,
                              UserData userData)
Loads an event from stream.

Parameters:
reader - the file reader representing the data stream
world - the world for correct referencing of bodies/constraints used by the event
Returns:
the loaded event

getIdentifier

public int getIdentifier()
Gets the event identifier. This is -1 as long as the event is not registered on the world.

Returns:
the event identifier.

type

public int type()
Gets the event type.

Returns:
the event type.

setScript

public void setScript(Script script)
Sets the execution script. The script is executed whenever the event triggers. This applies only to body events. Note that the script has to be registered on the world to be executed.

Parameters:
script - the script to execute.

setBodyFilter

public void setBodyFilter(Body b)
Sets the body filter.

Parameters:
b - the body for which the event applies to.

getBodyFilter

public Body getBodyFilter()
Gets the body filter.

Returns:
the body filter.

setShapeFilter

public void setShapeFilter(Shape s)
Sets the shape filter.

Parameters:
s - the shape (= group of bodies) for which the event applies to.

getShapeFilter

public Shape getShapeFilter()
Gets the shape filter.

Returns:
the shape filter.

getTargetObject

public java.lang.Object getTargetObject()
Return the target object. The target object is a relevnat object depending on teh event type. For sensor collision events, this is the sensor body.

Returns:
the target object.

setConstraintFilter

protected void setConstraintFilter(Constraint c)
Sets the constraint filter.

Parameters:
c - the constraint filter for event triggering.

getConstraintFilter

public Constraint getConstraintFilter()
Gets the constraint filter.

Returns:
the constraint filter.

targetAFX

protected float targetAFX()
Gets the targetA

Returns:
the target A

targetBFX

protected float targetBFX()
Gets the targetB

Returns:
the target B

targetCFX

protected float targetCFX()
Gets the targetC

Returns:
the target C

targetDFX

protected float targetDFX()
Gets the targetD

Returns:
the target D

setTargetsFX

protected void setTargetsFX(float target1FX,
                            float target2FX,
                            float target3FX,
                            float target4FX)
Sets all targets. The meaning of targets depend on the event type.

Parameters:
target1FX - the target 1
target2FX - the target 2
target3FX - the target 3
target4FX - the target 4

setTriggerOnce

public void setTriggerOnce(boolean triggerOnce)
Flag whether event should be triggered more than once in a row. Turn off is not really required, uses memory and performance

Parameters:
triggerOnce - new value of trigger once

getTriggerOnce

public boolean getTriggerOnce()
Gets the trigger once flag.

Returns:
the trigger once flag.

checkEvent

public boolean checkEvent(World world,
                          PhysicsEventListener listener)
Checks if the event is currently active. Triggers the event on the event listener for each object (constraint or body) that fulfills the condition of the event.

Parameters:
world - the world
listener - the event listener
Returns:
true if the event triggered at least once.

getUserData

public UserData getUserData()
Get user data.

Returns:
the user data.

setUserData

public void setUserData(UserData userData)
Set User data

Parameters:
userData - the user data

Emini Physics Engine 1.3.5a API Documentation

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