Maarten Baert's website

Game Maker / C++ projects

Home Model Creator ExtremePhysics Game Maker DLLs SimpleScreenRecorder AlterPCB Quadcopters   Recent comments Search

Last modified: Sat, 22 Oct 2011
Refresh

World


ep_world_create

ep_world_create()

Creates a new world.

Returns the id of the new world.


ep_world_destroy

ep_world_destroy(world_id)

Destroys the world.

  • world_id: The id of the world.


ep_world_exists

ep_world_exists(world_id)

Returns whether a world with the given id exists.

  • world_id: The id of the world.


ep_world_clear

ep_world_clear(world_id)

Destroys all polygons, bodies, joints, ... in the world.

  • world_id: The id of the world.


ep_world_set_settings

ep_world_set_settings(world_id, timestep, velocity_iterations, position_iterations, contact_threshold, velocity_threshold, baumgarte_factor, mass_bias, position_factor)

Changes the settings of the world. For more details, read this tutorial.

  • world_id: The id of the world.

  • timestep: The length of one time step. The default value is 1.

  • velocity_iterations: The number of iterations used by the velocity solver. Using a higher value increases accuracy. The default value is 20.

  • position_iterations: The number of iterations used by the position solver. Using a higher value increases accuracy. The default value is 10.

  • contact_threshold: The threshold value for collisions. This stops contacts from being destroyed immediately after creation and increases stability.

  • velocity_threshold: The velocity that is lost during collisions. This compensates for the energy collisions add to the system when gravity is used.

  • baumgarte_factor: The bias factor used by the Baumgarte stabilization. Using a lower value will increase stability but decrease accuracy. The default value is 0.1.

  • mass_bias: The bias factor used to calculate the mass of constraints. The best value depends on the complexity of the simulation. The default value is 0.5.

  • position_factor: The bias factor used by the position solver. Using a lower value will sometimes increase stability. The default value is 1.


ep_world_set_primary_axis

ep_world_set_primary_axis(world_id, horizontal)

Changes the primary axis. This doesn't change the results but the simulation will be faster if set correctly. Horizontal scanning is usually faster if there are lots of shapes with similar y-values. This is often the case when (vertical) gravity is used.

  • world_id: The id of the world.

  • horizontal: Indicates whether the world is mostly horizontal. The default value is true.


ep_world_set_sleeping

ep_world_set_sleeping(world_id, enable_sleeping, time_stable, time_outofview, stable_maxvel, stable_maxrotvel)

Changes the sleeping settings of the world.

  • world_id: The id of the world.

  • enable_sleeping: Indicates whether sleeping should be enabled.

  • time_stable: The time objects have to be stable before going to sleep. Set this to 0 to disable sleeping for stable objects.

  • time_outofview: The time objects have to be out of view before going to sleep. Set this to 0 to disable sleeping for objects that are out of view.

  • stable_maxvel: Bodies with a velocity lower than this value are considered stable.

  • stable_maxrotvel: Bodies with a rotational velocity lower than this value are considered stable.


ep_world_update_contacts

ep_world_simulate_step(world_id)

Finds collisions and updates all contacts. You have to call this right before calling ep_world_simulate_step.

  • world_id: The id of the world.


ep_world_simulate_step

ep_world_simulate_step(world_id)

Simulates one time step. Remember to call ep_world_update_contacts first.

  • world_id: The id of the world.


ep_world_collision_test_box

ep_world_collision_test_box(world_id, w, h, x, y, rot, contact_threshold, collidemask1, collidemask2, group)

Returns the number of shapes that collide with a 'virtual' box. You can use ep_world_get_collision_body and ep_world_get_collision_shape to get the ids of the bodies and shapes.

  • world_id: The id of the world.

  • w: The width of the box.

  • h: The height of the box.

  • x: The x coordinate of the box (world coordinates).

  • y: The y coordinate of the box (world coordinates).

  • rot: The rotation of the box (world coordinates).

  • contact_threshold: The contact threshold.

  • collidemask1: The first collision mask.

  • collidemask2: The second collision mask.

  • group: The group. Use 0 for no group.


ep_world_collision_test_line

ep_world_collision_test_line(world_id, x1, y1, x2, y2, contact_threshold, collidemask1, collidemask2, group)

Returns the number of shapes that collide with a 'virtual' line. You can use ep_world_get_collision_body and ep_world_get_collision_shape to get the ids of the bodies and shapes.

  • world_id: The id of the world.

  • x1: The x coordinate of the first point (world coordinates).

  • y1: The y coordinate of the first point (world coordinates).

  • x2: The x coordinate of the second point (world coordinates).

  • y2: The y coordinate of the second point (world coordinates).

  • contact_threshold: The contact threshold.

  • collidemask1: The first collision mask.

  • collidemask2: The second collision mask.

  • group: The group. Use 0 for no group.


ep_world_collision_test_circle

ep_world_collision_test_circle(world_id, r, x, y, contact_threshold, collidemask1, collidemask2, group)

Returns the number of shapes that collide with a 'virtual' circle. You can use ep_world_get_collision_body and ep_world_get_collision_shape to get the ids of the bodies and shapes.

  • world_id: The id of the world.

  • r: The radius of the circle.

  • x: The x coordinate of the circle (world coordinates).

  • y: The y coordinate of the circle (world coordinates).

  • contact_threshold: The contact threshold.

  • collidemask1: The first collision mask.

  • collidemask2: The second collision mask.

  • group: The group. Use 0 for no group.


ep_world_collision_test_polygon

ep_world_collision_test_polygon(world_id, polygon_id, x, y, rot, contact_threshold, collidemask1, collidemask2, group)

Returns the number of shapes that collide with a 'virtual' polygon. You can use ep_world_get_collision_body and ep_world_get_collision_shape to get the ids of the bodies and shapes.

  • world_id: The id of the world.

  • polygon_id: The id of the polygon.

  • x: The x coordinate of the polygon (world coordinates).

  • y: The x coordinate of the polygon (world coordinates).

  • rot: The rotation of the polygon (world coordinates).

  • contact_threshold: The contact threshold.

  • collidemask1: The first collision mask.

  • collidemask2: The second collision mask.

  • group: The group. Use 0 for no group.


ep_world_ray_cast

ep_world_ray_cast(world_id, x, y, vx, vy, collidemask1, collidemask2, group)

Calculates whether a 'virtual' ray intersects a body. You can use ep_world_get_collision_body and ep_world_get_collision_shape to get the id of the body and shape.

Returns the distance to the point of intersection, or -1 if there is no intersection.

  • world_id: The id of the world.

  • x: The x coordinate of the starting point of the ray.

  • y: The y coordinate of the starting point of the ray.

  • vx: The x component of the direction vector of the ray.

  • vy: The y component of the direction vector of the ray.

  • collidemask1: The first collision mask.

  • collidemask2: The second collision mask.

  • group: The group. Use 0 for no group.


ep_world_get_collision_body

ep_world_get_collision_body(world_id, index)

Returns the id of the body that was found by a collision/raycast function.

  • world_id: The id of the world.

  • index: The index of the collision (0 is the first index). The collision functions will return the number of collisions found.


ep_world_get_collision_shape

ep_world_get_collision_shape(world_id, index)

Returns the id of the shape that was found by a collision/raycast function.

  • world_id: The id of the world.

  • index: The index of the collision (0 is the first index). The collision functions will return the number of collisions found.


ep_world_multipoly_begin

ep_world_multipoly_begin(world_id, vertexcount)

Begins a new multipolygon.

  • world_id: The id of the world.

  • vertexcount: The number of vertices.


ep_world_multipoly_end

ep_world_multipoly_end(world_id, showerrors)

Ends the multipolygon and creates the polygons.

  • world_id: The id of the world.

  • showerrors: Whether to show error messages if the polygon is invalid (you might want to disable this if you allow the user to draw polygons). If this is false the function will return 0 without showing any error messages.


ep_world_multipoly_set_vertex

ep_world_multipoly_set_vertex(world_id, index, x, y)

Sets the coordinates of the vertex with the given index.

  • world_id: The id of the world.

  • index: The index (0 is the first index).

  • x: The x coordinate.

  • y: The y coordinate.


ep_world_multipoly_get_first

ep_world_multipoly_get_first(world_id)

Returns the id of the first polygon that was created during the decomposition of the multipolygon.

  • world_id: The id of the world.


ep_world_multipoly_get_last

ep_world_multipoly_get_last(world_id)

Returns the id of the last polygon that was created during the decomposition of the multipolygon.

  • world_id: The id of the world.


ep_world_serialize

ep_world_serialize(world_id)

Converts the entire world to a long hexadecimal string. You can use this string to restore the world to this state later.

  • world_id: The id of the world.


ep_world_unserialize

ep_world_unserialize(world_id, data)

Restores the state of the world from the serialized data.

  • world_id: The id of the world.

  • data: The serialized data created by ep_world_serialize.


ep_world_previous

ep_world_previous(world_id)

Returns the id of the previous world, of 0 if there is no previous world.

  • world_id: The id of the world.


ep_world_next

ep_world_next(world_id)

Returns the id of the next world, of 0 if there is no next world.

  • world_id: The id of the world.


ep_world_set_uservar

ep_world_set_uservar(world_id, index, value)

Changes the value of the user variable with the given index.

  • world_id: The id of the world.

  • index: The index (0-4).

  • value: The new value.


ep_world_get_uservar

ep_world_get_uservar(world_id, body_id, index)

Returns the value of the user variable with the given index.

  • world_id: The id of the world.

  • index: The index (0-4).


ep_world_first_polygon

ep_world_first_polygon(world_id)

Returns the id of the first polygon in the world, or 0 if there are no polygons.

  • world_id: The id of the world.


ep_world_last_polygon

ep_world_last_polygon(world_id)

Returns the id of the last polygon in the world, or 0 if there are no polygons.

  • world_id: The id of the world.


ep_world_polygon_count

ep_world_polygon_count(world_id)

Returns the number of polygons in the world. The world keeps track of the number of polygons internally so this function is very fast.

  • world_id: The id of the world.


ep_world_first_body

ep_world_first_body(world_id)

Returns the id of the first body in the world, or 0 if there are no bodies.

  • world_id: The id of the world.


ep_world_last_body

ep_world_last_body(world_id)

Returns the id of the last body in the world, or 0 if there are no bodies.

  • world_id: The id of the world.


ep_world_body_count

ep_world_body_count(world_id)

Returns the number of bodies in the world. The world keeps track of the number of bodies internally so this function is very fast.

  • world_id: The id of the world.


ep_world_first_contact

ep_world_first_contact(world_id)

Returns the id of the first contact in the world, or 0 if there are no contacts.

  • world_id: The id of the world.


ep_world_last_contact

ep_world_last_contact(world_id)

Returns the id of the last contact in the world, or 0 if there are no contacts.

  • world_id: The id of the world.


ep_world_contact_count

ep_world_contact_count(world_id)

Returns the number of contacts in the world. The world keeps track of the number of contacts internally so this function is very fast.

  • world_id: The id of the world.


ep_world_first_hingejoint

ep_world_first_hingejoint(world_id)

Returns the id of the first hinge joint in the world, or 0 if there are no hinge joints.

  • world_id: The id of the world.


ep_world_last_hingejoint

ep_world_last_hingejoint(world_id)

Returns the id of the last hinge joint in the world, or 0 if there are no hinge joints.

  • world_id: The id of the world.


ep_world_hingejoint_count

ep_world_hingejoint_count(world_id)

Returns the number of hinge joints in the world. The world keeps track of the number of hinge joints internally so this function is very fast.

  • world_id: The id of the world.


ep_world_first_distancejoint

ep_world_first_distancejoint(world_id)

Returns the id of the first distance joint in the world, or 0 if there are no distance joints.

  • world_id: The id of the world.


ep_world_last_distancejoint

ep_world_last_distancejoint(world_id)

Returns the id of the last distance joint in the world, or 0 if there are no distance joints.

  • world_id: The id of the world.


ep_world_distancejoint_count

ep_world_distancejoint_count(world_id)

Returns the number of distance joints in the world. The world keeps track of the number of distance joints internally so this function is very fast.

  • world_id: The id of the world.


ep_world_first_railjoint

ep_world_first_railjoint(world_id)

Returns the id of the first rail joint in the world, or 0 if there are no rail joints.

  • world_id: The id of the world.


ep_world_last_railjoint

ep_world_last_railjoint(world_id)

Returns the id of the last rail joint in the world, or 0 if there are no rail joints.

  • world_id: The id of the world.


ep_world_railjoint_count

ep_world_railjoint_count(world_id)

Returns the number of rail joints in the world. The world keeps track of the number of rail joints internally so this function is very fast.

  • world_id: The id of the world.


ep_world_first_sliderjoint

ep_world_first_sliderjoint(world_id)

Returns the id of the first slider joint in the world, or 0 if there are no slider joints.

  • world_id: The id of the world.


ep_world_last_sliderjoint

ep_world_last_sliderjoint(world_id)

Returns the id of the last slider joint in the world, or 0 if there are no slider joints.

  • world_id: The id of the world.


ep_world_sliderjoint_count

ep_world_sliderjoint_count(world_id)

Returns the number of slider joints in the world. The world keeps track of the number of slider joints internally so this function is very fast.

  • world_id: The id of the world.


ep_world_first_view

ep_world_first_view(world_id)

Returns the id of the first view in the world, or 0 if there are no views.

  • world_id: The id of the world.


ep_world_last_view

ep_world_last_view(world_id)

Returns the id of the last view in the world, or 0 if there are no views.

  • world_id: The id of the world.


ep_world_first_water

ep_world_first_water(world_id)

Returns the id of the first water object in the world, or 0 if there are no water objects.

  • world_id: The id of the world.


ep_world_last_water

ep_world_last_water(world_id)

Returns the id of the last water object in the world, or 0 if there are no water objects.

  • world_id: The id of the world.


ep_world_view_count

ep_world_view_count(world_id)

Returns the number of views in the world. The world keeps track of the number of views internally so this function is very fast.

  • world_id: The id of the world.


ep_world_shape_count

ep_world_shape_count(world_id)

Returns the number of shapes in the world. The world keeps track of the number of shapes internally so this function is very fast.

  • world_id: The id of the world.


ep_world_force_count

ep_world_force_count(world_id)

Returns the number of forces in the world. The world keeps track of the number of forces internally so this function is very fast.

  • world_id: The id of the world.


Comments

Zerozero11

Comment #1: Sun, 13 Jan 2013, 1:08 (GMT+1, DST)

Quote


Hey!

Sorry to bother you again, but say I have a shape, and there is an imaginary line through its center of mass which is parallel to the shape's velocity.

I want to find the vertex of the shape, one on each side, that is furthest from the line (and not the center of mass). Should I use ray casts for this?

The current way I'm thinking of is using a ray cast from a distant point down this line and finding where it stops hitting the object - but I'm positive there's a faster way...

Maarten Baert

Administrator

Comment #2: Sun, 13 Jan 2013, 2:18 (GMT+1, DST)

Quote


Quote: Zerozero11

Hey!

Sorry to bother you again, but say I have a shape, and there is an imaginary line through its center of mass which is parallel to the shape's velocity.

I want to find the vertex of the shape, one on each side, that is furthest from the line (and not the center of mass). Should I use ray casts for this?

The current way I'm thinking of is using a ray cast from a distant point down this line and finding where it stops hitting the object - but I'm positive there's a faster way...

Shapes don't have a center of mass or velocity, so I assume you mean a body with one shape.

What you're asking sounds like a support function. ExtremePhysics doesn't have this, but you can do it yourself in GML. Assuming your polygon is located at (0,0) and not rotated relative to the body, this should work:

var vx, vy, d, n, i, lx, ly, xx, yy, leftdist, rightdist, leftx, lefty, rightx, righty;
vx = ep_body_get_xvel_center(global.world, body);
vy = ep_body_get_yvel_center(global.world, body);
d = sqrt(vx * vx + vy * vy);

if d < 0.0001 {
    vx = 1;
    vy = 0;
} else {
    vx /= d;
    vy /= d;
}

leftdist = 0;
rightdist = 0;
leftx = x;
lefty = y;
rightx = x;
righty = y;

n = ep_polygon_get_vertex_count(global.world, poly);
for(i = 0; i < n; i += 1) {
    lx = ep_polygon_get_vertex_x(global.world, poly, i);
    ly = ep_polygon_get_vertex_y(global.world, poly, i);
    xx = ep_body_coord_local_to_world_x(global.world, body, lx, ly);
    yy = ep_body_coord_local_to_world_y(global.world, body, lx, ly);
    d = xx * vy - yy * vx;
    if d > leftdist {
        leftdist = d;
        leftx = xx;
        lefty = yy;
    }
    if -d > rightdist {
        rightdist = -d;
        rightx = xx;
        righty = yy;
    }
}

(not tested)

Zerozero11

Comment #3: Sun, 13 Jan 2013, 5:16 (GMT+1, DST)

Quote


Oh man oh man thank you so much Marten!

Earacher

Comment #4: Wed, 28 Aug 2013, 16:02 (GMT+1, DST)

Quote


hi maarten,why "ep_world_collision_test_" test a body with polygon shape return more than 1?

oh really sorry i didn't see that
"Returns the number of shapes that collide with a 'virtual' box. You can use ep_world_get_collision_body and ep_world_get_collision_shape to get the ids of the bodies and shapes." excuse me :P

Last modified: Wed, 28 Aug 2013, 16:06 (GMT+1, DST)

Lukayson

Comment #5: Wed, 28 Sep 2016, 23:27 (GMT+1, DST)

Quote


Hello, I have struggle with slow motion in my game. Ii looked like, that it works just right, until I added replay feature.
Now, when I activate slowmotion while replay, it behaves slightly diferent , and in longer levels, result is absolutly diferent (It happens also in gameplay while slowmotion, but its not noticible)

does EP do something somewhere else, except in those 2 scripts?
ep_world_update_contacts(4);
ep_world_simulate_step(4);

every movement in game is by servos using ep_hingejoint_set_motor

I call servo scripts and ep_body_get_rot, every time this happens 4 times:
ep_world_update_contacts(4);
ep_world_simulate_step(4);

Thank you very much

Lukayson

Comment #6: Thu, 29 Sep 2016, 0:28 (GMT+1, DST)

Quote


Only contacting you itself helped me this time, because after posting my problem, I realized its not true, that i am calling servo script exactly after every 4 updating contacts and simulating steps.
Now it works well, thank you :)

Write a comment