ExtremePhysics: all pages

Reference

Last updated 11 September 2011

All function names are lowercase and start with "ep_".

If the return value of a function is not mentioned, the function will return 1 on success and 0 on failure. Almost all other functions will also return 0 on failure.

All angles in ExtremePhysics are in radians.

This reference lists the functions in the latest version of ExtremePhysics. If some function is missing or some arguments are different, make sure you're using the latest version.

Comments

This page used to have a comment section. It's closed now; what remains are the questions I answered.

Chance · 7 October 2010, 19:25

Hi Maarten. Have you considered releasing the Reference as a downloadable document? Maybe an HTML document? Even PDF would be fine.

I find myself using it a lot, and I'm worried your site may be off-air sometimes. I would panic! haha...

Maarten Baert author · 16 October 2010, 15:07

I'm trying to write a script to convert everything to a zip file. It should be finished soon.

-coco- · 11 January 2011, 21:04

Hello Maarten.
I like Extremephysics, it's just genious.
Do you have a project to make a Lib for Extremephysics? (with D&D icons) (with LibBuilder)
I began one, but you should better know Extremephysics than me (mine is really rudymentary).
It think it should help many users.
-Coco-

(Sorry for my english, I just learn it at school)

Maarten Baert author · 13 January 2011, 16:58

Quote: -coco-

Do you have a project to make a Lib for Extremephysics? (with D&D icons) (with LibBuilder)

Currently I don't. ExtremePhysics is rather difficult anyway, I don't think D&D icons would make it easier to use :).

Nickgerrets · 30 December 2012, 16:38

Is there a way to make a very smooth terrain, i tryed boxchaining in your rolling ball example, but i need something much more smoother.

Maarten Baert author · 30 December 2012, 20:14

Quote: Nickgerrets

Is there a way to make a very smooth terrain, i tryed boxchaining in your rolling ball example, but i need something much more smoother.

Use more points, i.e. more boxes :). ExtremePhysics is quite good at handling many boxes as long as they're all static. If you really thing performance will be a problem (because you have a huge world), you should split the terrain into multiple parts and only create the parts that are currently visible.

If you don't want to place all the points manually, try something like Bezier splines. I have an old example with various types of curves:
http://gm.maartenbaert.be/curve.gmk
'cardinal' is probably the easiest. NURBS is more powerful, but don't try to understand it unless you really like complex math :).

Caohimin · 29 June 2013, 23:26

Bonjour Maarten,

Je suis français, et nouvel utilisateur de "Extreme Physics". Je viens vers toi pour essayer de comprendre comment mettre en mouvement un objet ( vaisseau, dans mon cas, en vue du dessus ), je ne sais pas par où commencer... Si tu pouvais m'éclairé un peu.

Merci.

Maarten Baert author · 23 July 2013, 20:13

Quote: Caohimin

Bonjour Maarten,

Je suis français, et nouvel utilisateur de "Extreme Physics". Je viens vers toi pour essayer de comprendre comment mettre en mouvement un objet ( vaisseau, dans mon cas, en vue du dessus ), je ne sais pas par où commencer... Si tu pouvais m'éclairé un peu.

Merci.

I understand your question, but I don't think I can answer this in french, sorry ;).

If you want to move the object with a specific velocity, use ep_body_set_velocity_center. If you just want to push the object, use ep_body_apply_impulse_relative. In any case, don't try to move the body directly (ep_body_set_position), otherwise ExtremePhysics can't simulate collisions correctly.

Lukayson · 30 March 2015, 17:25

Good day, is there possibility how to simulate air resistance? I am making rocket simulator. I need different behavior between vacuum and air. Thank you

Maarten Baert author · 6 April 2015, 00:45

Quote: Lukayson

Good day, is there possibility how to simulate air resistance? I am making rocket simulator. I need different behavior between vacuum and air. Thank you

ep_body_set_damping gives you basic (linear) air resistance. If this is not accurate enough for what you're doing, then you should simulate the air resistance yourself and apply it either with ep_body_apply_impulse_relative or with ep_force_create.

Lukayson · 11 October 2015, 01:49

Is it possible to have EP 2.2 in Unreal Engine 4? Please

Maarten Baert author · 11 October 2015, 20:01

Quote: Lukayson

Is it possible to have EP 2.2 in Unreal Engine 4? Please

I have no idea, I've never tried using UE4. You have the EP source code, so in theory nothing stops you from tying it together with whatever engine you want. You can get a pure C++ version of EP just by throwing out all the game maker related files from the source code.

Lukayson · 19 October 2015, 16:15

Is there any way to ask directly body, if he has any contacts, please?
I made this solution, but it is performance killer, if I use it to much.
https://drive.google.com/file/d/0B3lN5CN0ykMqRXNFb0pwTVJ6Vlk/view?usp=sharing

it is for this project: https://twitter.com/Cybermotiongame
Thank you

Maarten Baert author · 22 October 2015, 20:51

Quote: Lukayson

Is there any way to ask directly body, if he has any contacts, please?
I made this solution, but it is performance killer, if I use it to much.
https://drive.google.com/file/d/0B3lN5CN0ykMqRXNFb0pwTVJ6Vlk/view?usp=sharing

it is for this project: https://twitter.com/Cybermotiongame
Thank you

Yes, this is all explained in this article. Contacts are stored for each shape, not body.

Lukayson · 7 March 2017, 14:57

Hello, Is there a way to detect if body is sliding on another? I want for example metal part making sparks when sliding on concrete. Thank you

Maarten Baert author · 19 March 2017, 16:28

Quote: Lukayson

Hello, Is there a way to detect if body is sliding on another? I want for example metal part making sparks when sliding on concrete. Thank you

Read this article. Combine this with ep_body_get_xvel_local_point and ep_body_get_yvel_local_point to detect whether the bodies are sliding. Example:

var s, c, b, object;
for(s = ep_body_first_shape(global.world, body); s!=0; s = ep_shape_next(global.world, body, s)) {
    for(c = ep_shape_get_first_contact(global.world, body, s); c!=0; c = ep_shape_get_next_contact(global.world, body, s, c)) {
        b = ep_contact_get_body1(global.world, c);
        if b=body {
            b = ep_contact_get_body2(global.world, c);
        }
        object = ep_body_get_user_var(global.world, b, 0);
        if object.object_index=obj_block {
            // this instance is touching a block
            
            b1 = ep_contact_get_body1(global.world, c);
            gx1 = ep_contact_get_point1_x(global.world, c);
            gy1 = ep_contact_get_point1_y(global.world, c);
            lx1 = ep_body_coord_world_to_local_x(global.world, b1, gx1, gy1);
            ly1 = ep_body_coord_world_to_local_y(global.world, b1, gx1, gy1);
            vx1 = ep_body_get_xvel_local_point(world_id, b1, lx1, ly1);
            vy1 = ep_body_get_yvel_local_point(world_id, b1, lx1, ly1);
            
            b2 = ep_contact_get_body2(global.world, c);
            gx2 = ep_contact_get_point2_x(global.world, c);
            gy2 = ep_contact_get_point2_y(global.world, c);
            lx2 = ep_body_coord_world_to_local_x(global.world, b2, gx2, gy2);
            ly2 = ep_body_coord_world_to_local_y(global.world, b2, gx2, gy2);
            vx2 = ep_body_get_xvel_local_point(world_id, b2, lx2, ly2);
            vy2 = ep_body_get_yvel_local_point(world_id, b2, lx2, ly2);
            
            nx = ep_contact_get_normal_x(global.world, c);
            ny = ep_contact_get_normal_y(global.world, c);
            vel = abs(nx * (vy1 - vy2) - ny * (vx1 - vx2));
            if(vel > 0.1) {
                // generate sparks here
            }
            
        }
    }
}

Not tested.