Android Programming Press on the image to return to the main documentation page.

ABPhysicsEngine

Written by Alain Bailleul

List of types:

ABForce
ABGroup
ABJoint
ABParticle
ABPhysicsEngine
ABVector

ABForce

For making forces like gravity, pushing, etc...

Events:

None

Members:


  getValue (invmass As Double) As ABVector

  Initialize (useMass As Boolean, vx As Double, vy As Double, counter As Int, name As String)

  Name As String

  UseMass As Boolean [write only]

  vx As Double [write only]

  vy As Double [write only]

Members description:

getValue (invmass As Double) As ABVector
Initialize (useMass As Boolean, vx As Double, vy As Double, counter As Int, name As String)
Name As String
UseMass As Boolean [write only]
if the force uses mass, the mass of the particle is taken into account when calculating the force.
Some forces do not use mass, like gravity
vx As Double [write only]
vy As Double [write only]

ABGroup

A group contains Particles and joints that act as one big particle.

Events:

None

Members:


  AddArrayOfGroupsToCollisionList (array() As ABGroup)

  AddArrayOfJoints (array() As ABJoint)

  AddArrayOfParticles (array() As ABParticle)

  AddCollidable (group As ABGroup)

  AddJoint (obj As ABJoint)

  AddParticle (obj As ABParticle)

  CollideInternal As Boolean

  CollisionList As java.util.List [read only]

  GetGroupHits As java.util.List

  GetJointByName (name As String) As ABJoint

  GetJoints As java.util.List

  GetParticleByName (name As String) As ABParticle

  GetParticles As java.util.List

  Initialize (name As String, collideInternal As Boolean)

  Name As String

  RemoveCollidable (group As ABGroup)

  RemoveJoint (obj As ABJoint)

  RemoveParticle (obj As ABParticle)

Members description:

AddArrayOfGroupsToCollisionList (array() As ABGroup)
AddArrayOfJoints (array() As ABJoint)
Add an array of joints to the group
AddArrayOfParticles (array() As ABParticle)
Add an array of particles to the group
AddCollidable (group As ABGroup)
Adds an Group instance to be checked for collision against this one.
AddJoint (obj As ABJoint)
Add a joint to the group
AddParticle (obj As ABParticle)
Add a particle to the group
CollideInternal As Boolean
Determines if the members of this Group are checked for collision with one
another.
CollisionList As java.util.List [read only]
Returns the array of every Group assigned to collide with this Group instance.
GetGroupHits As java.util.List
GetJointByName (name As String) As ABJoint
returns a joint from the group by name
GetJoints As java.util.List
returns all joints in the group
GetParticleByName (name As String) As ABParticle
Get a particle from the froup by name
GetParticles As java.util.List
returns all particles in the group
Initialize (name As String, collideInternal As Boolean)
Name As String
RemoveCollidable (group As ABGroup)
Removes a Group from the collidable list of this Group.
RemoveJoint (obj As ABJoint)
Remove a joint from the group
RemoveParticle (obj As ABParticle)
remove a particle from the group

ABJoint

A joint is connection between two particles.

Events:

None

Members:


  Angle As Double [read only]

  Center As ABVector [read only]

  CurrLength As Double [read only]

  Fixed As Boolean [read only]

  Initialize (part1 As ABParticle, part2 As ABParticle, name As String, stiffness As Double)

  isConnectedTo (p As ABParticle) As Boolean

  Name As String

  Part1 As ABParticle

  Part2 As ABParticle

  Radian As Double [read only]

  RestLength As Double

  Stiffness As Double

Members description:

Angle As Double [read only]
Center As ABVector [read only]
CurrLength As Double [read only]
Fixed As Boolean [read only]
Initialize (part1 As ABParticle, part2 As ABParticle, name As String, stiffness As Double)
isConnectedTo (p As ABParticle) As Boolean
Name As String
Part1 As ABParticle
Part2 As ABParticle
Radian As Double [read only]
RestLength As Double
Stiffness As Double
The stifness of the joint. 0 = very loose, 1 = very stiff

ABParticle

A particle is the basic element of what things are made of. They are put
together in a group and are joint with each other with joints.

Events:

None

Members:


  addAnimation (bm As android.graphics.Bitmap, State As Int, Direction As Int, Action As Int, NumOfFrames As Int, Delay As Int, AnimationBehaviour As Int)

  AddForce (force As ABForce)

  Angle As Double

  ANIM_ACTION_A As Int

  ANIM_ACTION_B As Int

  ANIM_ACTION_NONE As Int

  ANIM_ACTION_X As Int

  ANIM_ACTION_Y As Int

  ANIM_BEHAVIOUR_CONTINIOUS As Int

  ANIM_BEHAVIOUR_ONCE As Int

  ANIM_DIRECTION_DOWN As Int

  ANIM_DIRECTION_LEFT As Int

  ANIM_DIRECTION_RIGHT As Int

  ANIM_DIRECTION_UP As Int

  ANIM_STATE_MOVE As Int

  ANIM_STATE_STILL As Int

  AnimAction As Int

  AnimDirection As Int

  AnimState As Int

  AutoRotate As Boolean

  CenterX As Double

  CenterY As Double

  CIRCLE As Int

  Elasticity As Double

  Friction As Double

  GetForceByName (name As String) As ABForce

  GetForces As java.util.List

  GetHits As java.util.List

  GiveCurrentAnimBitmap As android.graphics.Bitmap

  Height As Double

  Initialize (type As Int, centerX As Double, centerY As Double, width As Double, height As Double, radius As Double, collidable As Boolean, seeCollisionAsHit As Boolean, rotation As Double, name As String)

  InvMass As Double [read only]

  isAnimated As Boolean [read only]

  isFixed As Boolean

  isSolid As Boolean

  isVisible As Boolean

  Mass As Double

  Name As String

  PauseAnimation

  Radian As Double

  Radius As Double

  RECTANGLE As Int

  RemoveForce (force As ABForce)

  ResumeAnimation

  StartAnimation (State As Int, Direction As Int, Action As Int)

  StopAnimation

  Traction As Double

  Type As Int

  Velocity As ABVector

  Width As Double

Members description:

addAnimation (bm As android.graphics.Bitmap, State As Int, Direction As Int, Action As Int, NumOfFrames As Int, Delay As Int, AnimationBehaviour As Int)
Add an animation. This is a bitmap containing all the frames of an animation.
All frames need to be of the same width.

State:
STATE_STILL
STATE_MOVE

Direction:
DIRECTION_UP
DIRECTION_DOWN
DIRECTION_LEFT
DIRECTION_RIGHT

Action:
ACTION_Y
ACTION_B
ACTION_X
ACTION_A;
ACTION_NONE;

AnimationBehaviour:
ANIMATIONBEHAVIOUR_ONCE
ANIMATIONBEHAVIOUR_CONTINIOUS
AddForce (force As ABForce)
Angle As Double
ANIM_ACTION_A As Int
ANIM_ACTION_B As Int
ANIM_ACTION_NONE As Int
ANIM_ACTION_X As Int
ANIM_ACTION_Y As Int
ANIM_BEHAVIOUR_CONTINIOUS As Int
ANIM_BEHAVIOUR_ONCE As Int
ANIM_DIRECTION_DOWN As Int
ANIM_DIRECTION_LEFT As Int
ANIM_DIRECTION_RIGHT As Int
ANIM_DIRECTION_UP As Int
ANIM_STATE_MOVE As Int
ANIM_STATE_STILL As Int
AnimAction As Int
AnimDirection As Int
AnimState As Int
AutoRotate As Boolean
CenterX As Double
CenterY As Double
CIRCLE As Int
Elasticity As Double
The elasticity of a particle. 0 = not elastic, 1 = very elastic
Friction As Double
The friction of a particle. 0 = like ice, 1 = sticky like glue
GetForceByName (name As String) As ABForce
GetForces As java.util.List
GetHits As java.util.List
GiveCurrentAnimBitmap As android.graphics.Bitmap
Height As Double
Initialize (type As Int, centerX As Double, centerY As Double, width As Double, height As Double, radius As Double, collidable As Boolean, seeCollisionAsHit As Boolean, rotation As Double, name As String)
InvMass As Double [read only]
isAnimated As Boolean [read only]
isFixed As Boolean
If a particle is fixed, no force will interact with it
isSolid As Boolean
isVisible As Boolean
Mass As Double
The mass of a particle. Must always be greater than 0
Name As String
PauseAnimation
Pause an animation
Radian As Double
The rotation of the Particle in radians. For drawing methods you may
want to use the angle property which gives the rotation in
degrees from 0 to 360.


Note that while the Particle can be rotated, it does not have angular
velocity. In otherwords, during collisions, the rotation is not altered,
and the energy of the rotation is not applied to other colliding particles.

Radius As Double
RECTANGLE As Int
RemoveForce (force As ABForce)
ResumeAnimation
Resume an Animation
StartAnimation (State As Int, Direction As Int, Action As Int)
Start an animation

State:
STATE_STILL
STATE_MOVE

Direction:
DIRECTION_UP
DIRECTION_DOWN
DIRECTION_LEFT
DIRECTION_RIGHT

Action:
ACTION_Y
ACTION_B
ACTION_X
ACTION_A;
ACTION_NONE;
StopAnimation
Stop an animation
Traction As Double
The traction of a particle. Can override the friction of another particle
Type As Int
Velocity As ABVector
The speed of the particle. Better use a force to move an object
as this will be more natural.
Width As Double

ABPhysicsEngine

A physics engine for Basic4Android.

Features:
- collision detection (Circle-Circle, Rect-Rect, Circle-Rect and Rect-Circle)
between groups and within groups
- particles with elasticity, friction, traction, sprite animation, etc...
- Joints with stiffness that connects particles
- groups of particles and joints
- self-buildable forces (like gravity, push, ...) on the engine and particles
- vector functions
- ...

Please give credit to me if you use this library in your software as it took a lot
of research to get the physics right, but still very simple to use.

Events:

Error (Number as int, Message as String)

Members:


  AddGlobalForce (force As ABForce)

  AddGroup (group As ABGroup)

  AddListOfGroups (list As java.util.List)

  Damping As Double

  GetGlobalForceByName (name As String) As ABForce

  GetGlobalForces As java.util.List

  GetGroupByName (name As String) As ABGroup

  GetGroups As java.util.List

  Initialize (dt As Double)

  JointCollisionCycles As Int

  JointCycles As Int

  RemoveGlobalForce (force As ABForce)

  RemoveGroup (group As ABGroup)

  Step

Members description:

AddGlobalForce (force As ABForce)
Add a force to the engine. It will have impact on all groups
AddGroup (group As ABGroup)
Add a group to the egnine
AddListOfGroups (list As java.util.List)
Add a list of groups to the engine
Damping As Double
The global damping. Values should be between 0 and 1. Higher numbers result
in less damping. A value of 1 is no damping. A value of 0 won't allow any
particles to move. The default is 1.


Damping will slow down your simulation and make it more stable. If you find
that your sim is "blowing up', try applying more damping.

GetGlobalForceByName (name As String) As ABForce
Returns a force from the engine by name
GetGlobalForces As java.util.List
Returns all global forces
GetGroupByName (name As String) As ABGroup
Get a group by name
GetGroups As java.util.List
returns all the groups in the engine
Initialize (dt As Double)
Initializes the engine. You must call this method prior to adding any
particles or joints.
dt: The delta time value for the engine. This parameter can be used --
in conjunction with speed at which ABPhysicsEngine.Step() is called --
to change the speed of the simulation. Typical values are 1/3 or 1/4. Lower
values result in slower, but more accurate simulations, and higher ones
result in faster, less accurate ones. Note that this only applies to the
forces added to particles. If you do not add any forces, the dt
value won't matter.
JointCollisionCycles As Int
Determines the number of times in a single ABPhysicsEngine.Step() cycle that
the joints have their positions corrected and particles in collision have their
positions corrected. This can greatly increase stability and prevent breakthroughs,
especially with large complex arrangements of joints and particles. The larger
this number, the more stable the simulation, at an expense of performance.


This setting differs from the jointCycles property in that it
resolves both joints and collisions during a ABPhysicsEngine.Step(),
as opposed to just the joints. The default value is 1.

JointCycles As Int
Determines the number of times in a single APEngine.step() cycle that
the joints have their positions corrected. Increasing this number can result in
stiffer, more stable configurations of joints, especially when they are in large
complex arrangements. The trade off is that the higher you set this number the more
performance will suffer.


This setting differs from the jointCollisionCycles property in that it
only resolves joints during a ABPhysicsEngine.Step(). The default value
is 0. Because this property doesn't correct for collisions, you should only use it when
the collisions of an arrangement of particles and joints are not an issue. If you
do set this value higher than the default of 0, then jointCollisionCycles
should at least be 1, in order to check collisions one time during the
ABPhysicsEngine.Step() cycle.

RemoveGlobalForce (force As ABForce)
Remove a force from the engine
RemoveGroup (group As ABGroup)
Removes a group from the engine
Step
Update all groups in the engine. Must be used in your timer loop

ABVector

A vector is a point into the coordination system.

Events:

None

Members:


  copy (v As ABVector)

  cross (v As ABVector) As Double

  distance (v As ABVector) As Double

  distanceSigned (v As ABVector) As Double

  divEquals (s As Double) As ABVector

  dot (v As ABVector) As Double

  Initialize (px As Double, py As Double)

  magnitude As Double

  minus (v As ABVector) As ABVector

  minusEquals (v As ABVector) As ABVector

  mult (s As Double) As ABVector

  multEquals (s As Double) As ABVector

  normalize As ABVector

  plus (v As ABVector) As ABVector

  plusEquals (v As ABVector) As ABVector

  setTo (px As Double, py As Double)

  times (v As ABVector) As ABVector

  toString As String

  x As Double

  yle="color: #000000; ">y As Double

Members description:

copy (v As ABVector)
cross (v As ABVector) As Double
distance (v As ABVector) As Double
distanceSigned (v As ABVector) As Double
divEquals (s As Double) As ABVector
dot (v As ABVector) As Double
Initialize (px As Double, py As Double)
magnitude As Double
minus (v As ABVector) As ABVector
minusEquals (v As ABVector) As ABVector
mult (s As Double) As ABVector
multEquals (s As Double) As ABVector
normalize As ABVector
plus (v As ABVector) As ABVector
plusEquals (v As ABVector) As ABVector
setTo (px As Double, py As Double)
times (v As ABVector) As ABVector
toString As String
x As Double
y As Double

Top