public class World extends Object
Quantities in the world are measured using the SI system (metres, kilograms and seconds):
Vec2
class. A Vec2 has an x-component (increases to the right)
and a y-component (increases upwards).
Once started, the simulation approximates physical behaviour by computing positions and velocities of bodies at discrete time steps (by default, 1/60 of a second). StepListeners can be registered to invoke application code immediately before and after each simulation step. Once started, the simulation can be stopped and resumed.
Warning: When the simulation is running, the world should only be modified from the AWT thread, i.e. using the listener interfaces of this library, the AWT and Swing. In particular, all initialization must be complete before the world is started.
Modifier and Type | Field and Description |
---|---|
static float |
DEFAULT_GRAVITY
Default strength of gravity in metres per second per second.
|
static int |
version
Version of CityEngine
|
Constructor and Description |
---|
World()
Create a new world with the default target frame rate (24).
|
World(int framesPerSecond)
Create a new world with target frame rate.
|
Modifier and Type | Method and Description |
---|---|
void |
addStepListener(StepListener listener)
Register a listener to be notified before and after each simulation step.
|
List<DynamicBody> |
getDynamicBodies()
Get all the dynamic bodies in the world.
|
float |
getGravity()
The strength of gravity in this world.
|
SimulationSettings |
getSimulationSettings()
Get the settings for the physics simulation.
|
List<StaticBody> |
getStaticBodies()
Get all the static bodies in the world.
|
boolean |
isRunning()
Is the simulation running?
|
void |
oneStep()
Advance a paused simulation by one step.
|
void |
removeStepListener(StepListener listener)
Unregister a step listener.
|
void |
setGravity(float g)
Set the strength of gravity in this world.
|
void |
start()
Start (or resume) the simulation.
|
void |
stop()
Stop the simulation.
|
public static final float DEFAULT_GRAVITY
public static final int version
public World(int framesPerSecond)
framesPerSecond
- the target frame rate for the simulationpublic World()
public void start()
public void stop()
If stop() is called during a call to preStep(), the simulation step will not take place.
public boolean isRunning()
public void oneStep()
public SimulationSettings getSimulationSettings()
public void setGravity(float g)
g
- the new gravity strength in metres per second per secondDynamicBody.setGravityScale(float)
public float getGravity()
setGravity(float)
public void addStepListener(StepListener listener)
listener
- the listener to addaddChangeListener(javax.swing.event.ChangeListener)
public void removeStepListener(StepListener listener)
listener
- the listener to removepublic List<StaticBody> getStaticBodies()
public List<DynamicBody> getDynamicBodies()