|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object hermes.HObject hermes.Being hermes.physics.MassedBeing
public abstract class MassedBeing
An extension of Being
representing a body with mass and elasticity.
Field Summary | |
---|---|
protected float |
_mass
|
Fields inherited from class hermes.Being |
---|
_position, _shape, _time, _velocity |
Constructor Summary | |
---|---|
MassedBeing(HShape shape,
PVector velocity,
float mass,
float elasticity)
Instantiates a new MassedBeing with given mass and elasticity. |
|
MassedBeing(HShape shape,
PVector velocity,
float mass,
float elasticity,
float sampleLength)
Instantiates a new MassedBeing with given mass and elasticity, and multisampling with a default maximum samples value of 10. |
|
MassedBeing(HShape shape,
PVector velocity,
float mass,
float elasticity,
float sampleLength,
int maxSamples)
Instantiates a new MassedBeing with given mass and elasticity, and multisampling. |
Method Summary | |
---|---|
void |
addDisplacement(PVector displacement)
Adds a displacement to the being, which will be applied at the next step. |
void |
addForce(PVector force)
Adds a force to the being, which will be applied at the next step. |
void |
addImpulse(PVector impulse)
Adds an impulse to the being, which will be applied at the next step. |
protected void |
addImpulseCollision(ImpulseCollision collision)
Adds an impulse collision to the being's collision list. |
static ImpulseCollision |
addImpulseCollision(MassedBeing being1,
MassedBeing being2,
PVector projection)
Sets up a collision between two beings, with elasticity equal to the average of the being's elasticity. |
static ImpulseCollision |
addImpulseCollision(MassedBeing being1,
MassedBeing being2,
PVector projection,
float elasticity)
Sets up a collision between two beings, with custom elasticity. |
void |
addMass(float mass)
adds mass to the being |
void |
addMassSafe(float mass)
Will add a mass to the being, unless this would cause the beings mass to become zero or negative, in which case it has no effect. |
protected void |
applyDisplacement()
Applies the accumulated displacement and clears it. |
protected void |
applyImpulse()
Applies the currently acccumulated impulse and clears it. |
protected void |
clearCollisions()
clears the collision list |
protected void |
clearForce()
clears all forces |
protected void |
EulerIntegrateVelocity(double dt)
Integrates velocity on acceleration using Euler-Cromer. |
PVector |
getDisplacement()
Gets the current displacement on the being (note that this will be non-zero only after displacements have been applied, before updates). |
float |
getElasticity()
the being's elasticity |
PVector |
getForce()
gets the current force on the being (note that this will be non-zero only after forces have been applied, before updates) this is a reference, if you manipulate the returned vector it will change the force |
PVector |
getImpulse()
Gets the current impulse on the being (note that this will be non-zero only after impulses have been applied, before updates). |
ImpulseCollision |
getImpulseCollisionWith(MassedBeing other)
Returns the collision between this being and another, if such a collision has been added. |
float |
getMass()
gets the being's mass |
boolean |
needsMoreSamples()
Used for multisampling -- if true the object needs to be sampled more on the current update. |
void |
setElasticity(float elasticity)
Sets the being's elasticity (bounciness). |
void |
setMass(float mass)
sets the being's mass |
void |
step()
Updates the being's position and velocity based on the forces applied since the last step, using Euler-Cromer integration. |
java.lang.String |
toString()
|
Methods inherited from class hermes.Being |
---|
draw, EulerIntegratePosition, getBoundingBox, getPosition, getShape, getVelocity, getVelocityX, getVelocityY, getX, getY, processUpdate, setDone, setPosition, setPosition, setPosition, setVelocity, setVelocityX, setVelocityY, setX, setY, update, updateTime |
Methods inherited from class hermes.HObject |
---|
addToGroup, delete, getGroups, receive, receive, receive, receive, removeFromGroup |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected float _mass
Constructor Detail |
---|
public MassedBeing(HShape shape, PVector velocity, float mass, float elasticity)
shape
- Shape used to determine Being
's position and collision detectionvelocity
- The Being
's initial velocity. Velocity gets updated automatically every timestep.mass
- the Being
's masselasticity
- the Being
's elasticitypublic MassedBeing(HShape shape, PVector velocity, float mass, float elasticity, float sampleLength, int maxSamples)
Instantiates a new MassedBeing with given mass and elasticity, and multisampling. Elasticity determines bounciness of collisions, a collision between beings of elasticity 1 will be perfectly elastic, and a collision between beings of mass 0 will be perfectly inelastic, ie they will lose all velocity parallel to the collision axis. If elasticity is greater than 1, they will gain speed from collisions, which may produce unrealistic results.
Multisampling causes a Being to be updated and checked for interactions multiple times per update, if
it is moving above a certain speed. This is used to prevent collision detection and other interactions
from failing due to sampling. Multisampling is determined by sampleLength
, the distance the
being must travel before multisampling is applied, and maxSample
, the number of samples
allowed to prevent very long loops if a Being moves too fast.
shape
- Shape used to determine Being
's position and collision detection.velocity
- The Being
's initial velocity. Velocity gets updated automatically every timestep.mass
- the Being
's masselasticity
- the Being
's elasticitysampleLength
- The length of the motion sample, ie how for the being has to travel
before more samples are needed. The being's shortest spanning length
is a reasonable valuemaxSamples
- The maximum number of samples allowed. If the being can reach a very high
speed, this must be very high for motion sampling to work, but this reduces
performance. Increasing the sample length allows lower maxSamples values, but
decreases accuracy.public MassedBeing(HShape shape, PVector velocity, float mass, float elasticity, float sampleLength)
Instantiates a new MassedBeing with given mass and elasticity, and multisampling with a default maximum samples value of 10. Elasticity determines bounciness of collisions, a collision between beings of elasticity 1 will be perfectly elastic, and a collision between beings of mass 0 will be perfectly inelastic, ie they will lose all velocity parallel to the collision axis. If elasticity is greater than 1, they will gain speed from collisions, which may produce unrealistic results.
Multisampling causes a Being to be updated and checked for interactions multiple times per update, if
it is moving above a certain speed. This is used to prevent collision detection and other interactions
from failing due to sampling. Multisampling is determined by sampleLength
, the distance the
being must travel before multisampling is applied, and maxSample
, the number of samples
allowed to prevent very long loops if a Being moves too fast.
shape
- Shape used to determine Being
's position and collision detection.velocity
- The Being
's initial velocity. Velocity gets updated automatically every timestep.mass
- the Being
's masselasticity
- the Being
's elasticitysampleLength
- The length of the motion sample, ie how for the being has to travel
before more samples are needed. The being's shortest spanning length
is a reasonable valueMethod Detail |
---|
public float getMass()
public void setMass(float mass)
mass
- the mass to set (must be positive)public void addMass(float mass)
mass
- the mass of the beingpublic void addMassSafe(float mass)
mass
- the mass to addpublic float getElasticity()
public PVector getImpulse()
public PVector getDisplacement()
public PVector getForce()
public void setElasticity(float elasticity)
elasticity
- the elasticity, should be in the range [0,1]public void addForce(PVector force)
force
- the force the addpublic void addImpulse(PVector impulse)
impulse
- the impulse to addpublic void addDisplacement(PVector displacement)
displacement
- the displacement to addpublic void step()
step
in class Being
public boolean needsMoreSamples()
HObject
needsMoreSamples
in class Being
protected void applyImpulse()
protected void applyDisplacement()
protected void EulerIntegrateVelocity(double dt)
dt
- the time stepprotected void clearCollisions()
protected void clearForce()
public static ImpulseCollision addImpulseCollision(MassedBeing being1, MassedBeing being2, PVector projection)
being1
- the first beingbeing2
- the second beingprojection
- the projection vector from being1 to being2public static ImpulseCollision addImpulseCollision(MassedBeing being1, MassedBeing being2, PVector projection, float elasticity)
being1
- the first beingbeing2
- the second beingprojection
- the projection vector from being1 to being2public ImpulseCollision getImpulseCollisionWith(MassedBeing other)
other
- the being to check for collision with
protected void addImpulseCollision(ImpulseCollision collision)
collision
- the collisionpublic java.lang.String toString()
toString
in class Being
Being
, use for debugging
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |