|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Observable | +--fi.utu.cs.physics.Universe
A universe comprising a collection of Body
objects.
The type of the universe can be infinite, finite or toroid.
Classes implementing the Observer
interface can
observe the universe for detecting collisions between the corporeal bodies;
an instance of the CollisionPair
inner class is
submitted to the observers.
Body
Inner Class Summary | |
class |
Universe.CollisionNotification
Comprises two Body objects that have been
counterparts in a collision. |
Field Summary | |
static int |
FINITE
A finite universe which limits the position of the bodies. |
static int |
INFINITE
An infinite universe which does not impose any limits to the position of the bodies. |
static int |
TOROID
An infinite universe of finite size where the opposite vertical and horizontal edges are connected to form a torus. |
Constructor Summary | |
Universe()
Creates an infinite universe. |
|
Universe(int t,
Point2 min,
Point2 max)
Creates a universe. |
Method Summary | |
void |
addBody(Body b)
Adds the body b to the universe, which is also set
to be the owner of the body. |
void |
advance(double dt)
Advances the time dt seconds and
updates its bodies accordingly.
|
java.util.List |
bodies()
Returns an unmodifiable (i.e., "read-only") list of the bodies in the universe. |
Point2 |
getCenter()
Returns the center of the universe or null
if the universe is infinite. |
Point2 |
getMaximumCorner()
Returns the maximum corner of the universe or null
if the universe is infinite. |
Point2 |
getMinimumCorner()
Returns the minimum corner of the universe or null
if the universe is infinite. |
int |
getType()
Returns the type of the universe. |
void |
removeAll()
Removes all bodies from the universe and sets their owner to null . |
void |
removeBody(Body b)
Removes the body b from the universe and sets its
owner to null . |
int |
size()
Returns the number of bodies in the universe. |
int |
size(java.lang.Class t)
Returns the number of bodies of the type t
in the universe. |
Point2 |
transpose(Point2 p)
Transposes the point p according to the type
of the universe. |
Methods inherited from class java.util.Observable |
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int INFINITE
public static final int FINITE
getMinimumCorner()
, getMaximumCorner()
).getMinimumCorner()
,
getMaximumCorner()
public static final int TOROID
getMinimumCorner()
, getMaximumCorner()
).getMinimumCorner()
,
getMaximumCorner()
Constructor Detail |
public Universe()
public Universe(int t, Point2 min, Point2 max)
t
- The type of the universe (infinite, finite or toroid).min
- The minimum corner of the universe.max
- The maximum corner of the universe.INFINITE
,
FINITE
,
TOROID
Method Detail |
public int getType()
INFINITE
,
FINITE
,
TOROID
public Point2 getMinimumCorner()
null
if the universe is infinite.public Point2 getMaximumCorner()
null
if the universe is infinite.public Point2 getCenter()
null
if the universe is infinite.public void addBody(Body b)
b
to the universe, which is also set
to be the owner of the body.Body.setOwner(Universe)
public void removeBody(Body b)
b
from the universe and sets its
owner to null
.Body.setOwner(Universe)
public void removeAll()
null
.Body.setOwner(Universe)
public java.util.List bodies()
UnsupportedOperationException
.Collections.unmodifiableList(List)
public int size()
public int size(java.lang.Class t)
t
in the universe.public void advance(double dt)
dt
seconds and
updates its bodies accordingly.
The methods advances the bodies iteratively. After each
advancement, it examines whether the body in question is corporeal
and does it collide with any of the remaining (i.e., not yet
advanced) corporeal bodies. If a collision occurs, the method
realizes an elastic collision between the bodies and notifies the
observers.Body.advance(double)
,
Body.isCorporeal()
,
Body.isColliding(Body)
,
Body.elasticCollision(Body)
,
Universe.CollisionNotification
public Point2 transpose(Point2 p)
p
according to the type
of the universe. If the universe is infinite, the method returns
p
. Otherwise, the method returns a new point where
getMinimumCorner.getX() <= result.getX() <=
getMaximumCorner.getX()
and getMinimumCorner.getY()
<= result.getY() <= getMaximumCorner.getY()
.
If the universe is finite, an exceeding point is moved back inside
the rectangle. If the universe is toroid, an exceeding point is
transposed back inside the rectangle by regarding it as a torus
surface.getType()
,
getMinimumCorner()
,
getMaximumCorner()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |