Maarten Baert's website

Game Maker / C++ projects

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

Last modified: Sun, 27 Mar 2011
Refresh

Slider joint


ep_sliderjoint_create

ep_sliderjoint_create(world_id, body1_id, body2_id, x1, y1, x2a, y2a, x2b, y2b, rotation)

Creates a new slider joint.

Returns the id of the new slider joint.

  • world_id: The id of the world.

  • body1_id: The id of the first body.

  • body2_id: The id of the second body.

  • x1: The x component of the anchor point on the first body.

  • y1: The y component of the anchor point on the first body.

  • x2a: The x component of the starting point of the rail on the second body.

  • y2a: The y component of the starting point of the rail on the second body.

  • x2b: The x component of the endpoint of the rail on the second body.

  • y2b: The y component of the endpoint of the rail on the second body.

  • rotation: The relative rotation of the bodies (rot1-rot2).


ep_sliderjoint_destroy

ep_sliderjoint_destroy(world_id, sliderjoint_id)

Destroys the slider joint.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.


ep_sliderjoint_exists

ep_sliderjoint_exists(world_id, sliderjoint_id)

Returns whether the slider joint with the given id exists.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.


ep_sliderjoint_set_max_combined_force

ep_sliderjoint_set_max_combined_force(world_id, sliderjoint_id, maxnormalforce, torqueradius)

Changes the maximum combined force of the slider joint.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.

  • maxnormalforce: The new maximum normal force. Use 0 for no limit.

  • torqueradius: Indicates how the torque relates to the normal force (force = torque/radius). Use 0 for unlimited torque.


ep_sliderjoint_set_motor

ep_sliderjoint_set_motor(world_id, sliderjoint_id, maxmotorforce, motorvel)

Changes the motor of the slider joint.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.

  • maxmotorforce: The maximum motor force.

  • motorvel: The velocity of the motor.


ep_sliderjoint_set_limit_settings

ep_sliderjoint_set_limit_settings(world_id, sliderjoint_id, contact_threshold, velocity_threshold)

Changes the limit settings of the slider joint.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.

  • contact_threshold: The contact threshold.

  • velocity_threshold: The velocity threshold.


ep_sliderjoint_set_lower_limit

ep_sliderjoint_set_lower_limit(world_id, sliderjoint_id, maxlimitforce, position, restitution, velocity)

Changes the lower limit of the slider joint.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.

  • maxlimitforce: The maximum limit force. Set this to 0 to disable the limit.

  • position: The position of the limit.

  • restitution: The coefficient of restitution.

  • velocity: The velocity of the limit. You can use this to change the position over time. The position will not be updated automatically, you have to do that yourself.


ep_sliderjoint_set_upper_limit

ep_sliderjoint_set_upper_limit(world_id, sliderjoint_id, maxlimitforce, position, restitution, velocity)

Changes the upper limit of the slider joint.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.

  • maxlimitforce: The maximum limit force. Set this to 0 to disable the limit.

  • position: The position of the limit.

  • restitution: The coefficient of restitution.

  • velocity: The velocity of the limit. You can use this to change the position over time. The position will not be updated automatically, you have to do that yourself.


ep_sliderjoint_set_lower_spring

ep_sliderjoint_set_lower_spring(world_id, sliderjoint_id, k, position, damping)

Changes the lower spring of the slider joint.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.

  • k: The spring constant. Set this to 0 to disable the spring.

  • position: The position of the spring.

  • damping: The damping force of the spring. Set this to 0 to disable damping (not recommended).


ep_sliderjoint_set_upper_spring

ep_sliderjoint_set_upper_spring(world_id, sliderjoint_id, k, position, damping)

Changes the upper spring of the slider joint.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.

  • k: The spring constant. Set this to 0 to disable the spring.

  • position: The position of the spring.

  • damping: The damping force of the spring. Set this to 0 to disable damping (not recommended).


ep_sliderjoint_get_body1

ep_sliderjoint_get_body1(world_id, sliderjoint_id)

Returns the id of the first body connected to the slider joint.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.


ep_sliderjoint_get_body2

ep_sliderjoint_get_body2(world_id, sliderjoint_id)

Returns the id of the second body connected to the slider joint.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.


ep_sliderjoint_get_position

ep_sliderjoint_get_position(world_id, sliderjoint_id)

Returns the current position of the slider joint.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.


ep_sliderjoint_get_normal_force

ep_sliderjoint_get_normal_force(world_id, sliderjoint_id)

Returns the normal force applied during the last step.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.


ep_sliderjoint_get_torque

ep_sliderjoint_get_torque(world_id, sliderjoint_id)

Returns the torque applied during the last step.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.


ep_sliderjoint_get_combined_force

ep_sliderjoint_get_combined_force(world_id, sliderjoint_id)

Returns the combined force applied during the last step (abs(normalforce)+abs(torque)/torqueradius).

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.


ep_sliderjoint_get_motor_force

ep_sliderjoint_get_motor_force(world_id, sliderjoint_id)

Returns the motor force applied during the last step.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.


ep_sliderjoint_get_limit_force

ep_sliderjoint_get_limit_force(world_id, sliderjoint_id)

Returns the limit force applied during the last step.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.


ep_sliderjoint_previous

ep_sliderjoint_previous(world_id, sliderjoint_id)

Returns the id of the previous slider joint, or 0 if there is no previous slider joint.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.


ep_sliderjoint_next

ep_sliderjoint_next(world_id, sliderjoint_id)

Returns the id of the next slider joint, or 0 if there is no next slider joint.

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.


ep_sliderjoint_set_uservar

ep_sliderjoint_set_uservar(world_id, sliderjoint_id, index, value)

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

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.

  • index: The index (0-4).

  • value: The new value.


ep_sliderjoint_get_uservar

ep_sliderjoint_get_uservar(world_id, sliderjoint_id, index)

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

  • world_id: The id of the world.

  • sliderjoint_id: The id of the slider joint.

  • index: The index (0-4).


Comments

Earacher

Comment #1: Fri, 8 Feb 2013, 18:48 (GMT+1, DST)

Quote


Hi maarten!
I found a problem,
b1 = ep_body_create_dynamic(global.w,false);
...
b2 = ep_body_create_dynamic(global.w,false);
...
s1 = ep_sliderjoint_create(global.w,b2,b1,0,0,-5,0,5,0,degtorad(0));
...set limit...set spring...

when b1 move(jump,rotate..etc),sometimes b2 dislocation.
see this pic : [img]http://i.imgur.com/42JsJWg.jpg[/img]
How can i solve it? Thank you and sorry for my Eng.

Last modified: Sat, 9 Feb 2013, 5:25 (GMT+1, DST)

Maarten Baert

Administrator

Comment #2: Thu, 14 Feb 2013, 2:39 (GMT+1, DST)

Quote


Quote: Earacher

Hi maarten!
I found a problem,
b1 = ep_body_create_dynamic(global.w,false);
...
b2 = ep_body_create_dynamic(global.w,false);
...
s1 = ep_sliderjoint_create(global.w,b2,b1,0,0,-5,0,5,0,degtorad(0));
...set limit...set spring...

when b1 move(jump,rotate..etc),sometimes b2 dislocation.
see this pic : [img]http://i.imgur.com/42JsJWg.jpg[/img]
How can i solve it? Thank you and sorry for my Eng.

The picture isn't very clear to me, can you post a larger one with debug drawing enabled?

Earacher

Comment #3: Thu, 14 Feb 2013, 7:45 (GMT+1, DST)

Quote


Quote: Maarten Baert
Quote: Earacher

Hi maarten!
I found a problem,
b1 = ep_body_create_dynamic(global.w,false);
...
b2 = ep_body_create_dynamic(global.w,false);
...
s1 = ep_sliderjoint_create(global.w,b2,b1,0,0,-5,0,5,0,degtorad(0));
...set limit...set spring...

when b1 move(jump,rotate..etc),sometimes b2 dislocation.
see this pic : [img]http://i.imgur.com/42JsJWg.jpg[/img]
How can i solve it? Thank you and sorry for my Eng.

The picture isn't very clear to me, can you post a larger one with debug drawing enabled?

That's debug drawing - -.
see this in testbed: [img]http://i.imgur.com/Ruh89bc.jpg[/img]
my problem is when groundbody is !static sometimes may happen: [img]http://i.imgur.com/dnu0Q1h.jpg[/img]

Maarten Baert

Administrator

Comment #4: Fri, 15 Feb 2013, 1:06 (GMT+1, DST)

Quote


Quote: Earacher

That's debug drawing - -.
see this in testbed: [img]http://i.imgur.com/Ruh89bc.jpg[/img]
my problem is when groundbody is !static sometimes may happen: [img]http://i.imgur.com/dnu0Q1h.jpg[/img]

I've just tried, but I really don't know how you made that happen. The debug drawing indicates that in your last image, the anchor point on the circle is placed wrong. Otherwise the orange dot would have been in the center of the circle, and it isn't.

Can you post the code you're using?

Earacher

Comment #5: Fri, 15 Feb 2013, 15:31 (GMT+1, DST)

Quote


Quote: Maarten Baert
Quote: Earacher

That's debug drawing - -.
see this in testbed: [img]http://i.imgur.com/Ruh89bc.jpg[/img]
my problem is when groundbody is !static sometimes may happen: [img]http://i.imgur.com/dnu0Q1h.jpg[/img]

I've just tried, but I really don't know how you made that happen. The debug drawing indicates that in your last image, the anchor point on the circle is placed wrong. Otherwise the orange dot would have been in the center of the circle, and it isn't.

Can you post the code you're using?

Hi Maarten here is my code:

b0 = ep_body_create_dynamic(global.world,false);
ep_world_multipoly_begin(global.world,10);
....
ep_world_multipoly_end(global.world,true);
poly_first_0 = ep_world_multipoly_get_first(global.world);
poly_last_0 = ep_world_multipoly_get_last(global.world);
for(i=poly_first_0;i<=poly_last_0;i+=1) {
s1 = ep_shape_create_polygon(global.world,b0,i,0,0,0,1);
ep_shape_set_collision(global.world,body,s1,1,2,id);
ep_shape_set_material(global.world,body,s1,0.4,1,0,0); }
ep_body_calculate_mass(global.world,b0);
ep_body_set_gravity(global.world,b0,0,gravity);
ep_body_set_position(global.world,b0,x,y,degtorad(image_angle));

b1 = ep_body_create_dynamic(global.world,false);
s1 = ep_shape_create_box(global.world,b1,2,2,0,0,0,1);
ep_shape_set_collision(global.world,b1,s1,0,0,0);
ep_shape_set_material(global.world,b1,s1,0,0,0,0);
ep_body_calculate_mass(global.world,b1);
ep_body_set_gravity(global.world,b1,0,gravity);
ep_body_set_position(global.world,b1,x,y-4,degtorad(image_angle));

slider1 = ep_sliderjoint_create(global.world,b1,b0,0,0,-6,-4,6,-4,0);
ep_sliderjoint_set_limit_settings(global.world,slider1,0.005,0.001);
ep_sliderjoint_set_lower_spring(global.world,slider1,15,0.5,2);
ep_sliderjoint_set_upper_spring(global.world,slider1,15,0.5,2);
ep_sliderjoint_set_lower_limit(global.world,slider1,0,0,0,0);
ep_sliderjoint_set_upper_limit(global.world,slider1,0,1,0,0);

my intention is sliderjoint b1,b0. b1 doesn't collision with anything just sliderjoint b0.
like gunshot recoil can make b1 motion...
eh...sometimes when spring's k >=30&&damping <=6 that seems to happen.

Last modified: Fri, 15 Feb 2013, 15:41 (GMT+1, DST)

Maarten Baert

Administrator

Comment #6: Fri, 15 Feb 2013, 17:11 (GMT+1, DST)

Quote


Quote: Earacher

Hi Maarten here is my code:

b0 = ep_body_create_dynamic(global.world,false);
ep_world_multipoly_begin(global.world,10);
....
ep_world_multipoly_end(global.world,true);
poly_first_0 = ep_world_multipoly_get_first(global.world);
poly_last_0 = ep_world_multipoly_get_last(global.world);
for(i=poly_first_0;i<=poly_last_0;i+=1) {
s1 = ep_shape_create_polygon(global.world,b0,i,0,0,0,1);
ep_shape_set_collision(global.world,body,s1,1,2,id);
ep_shape_set_material(global.world,body,s1,0.4,1,0,0); }
ep_body_calculate_mass(global.world,b0);
ep_body_set_gravity(global.world,b0,0,gravity);
ep_body_set_position(global.world,b0,x,y,degtorad(image_angle));

b1 = ep_body_create_dynamic(global.world,false);
s1 = ep_shape_create_box(global.world,b1,2,2,0,0,0,1);
ep_shape_set_collision(global.world,b1,s1,0,0,0);
ep_shape_set_material(global.world,b1,s1,0,0,0,0);
ep_body_calculate_mass(global.world,b1);
ep_body_set_gravity(global.world,b1,0,gravity);
ep_body_set_position(global.world,b1,x,y-4,degtorad(image_angle));

slider1 = ep_sliderjoint_create(global.world,b1,b0,0,0,-6,-4,6,-4,0);
ep_sliderjoint_set_limit_settings(global.world,slider1,0.005,0.001);
ep_sliderjoint_set_lower_spring(global.world,slider1,15,0.5,2);
ep_sliderjoint_set_upper_spring(global.world,slider1,15,0.5,2);
ep_sliderjoint_set_lower_limit(global.world,slider1,0,0,0,0);
ep_sliderjoint_set_upper_limit(global.world,slider1,0,1,0,0);

my intention is sliderjoint b1,b0. b1 doesn't collision with anything just sliderjoint b0.
like gunshot recoil can make b1 motion...
eh...sometimes when spring's k >=30&&damping <=6 that seems to happen.

Springs can become unstable if you use values for k that are way too large, so that's possible. Normally k shouldn't be larger than the mass of the lightest body it is connected to. Damping has some influence too, but not as much as k.

Your limits aren't working because maxlimitforce (3rd argument) is zero. Normally you want to set this to a really high value that's normally never reached.

Earacher

Comment #7: Sat, 16 Feb 2013, 13:32 (GMT+1, DST)

Quote


Quote: Maarten Baert
Quote: Earacher

Hi Maarten here is my code:

b0 = ep_body_create_dynamic(global.world,false);
ep_world_multipoly_begin(global.world,10);
....
ep_world_multipoly_end(global.world,true);
poly_first_0 = ep_world_multipoly_get_first(global.world);
poly_last_0 = ep_world_multipoly_get_last(global.world);
for(i=poly_first_0;i<=poly_last_0;i+=1) {
s1 = ep_shape_create_polygon(global.world,b0,i,0,0,0,1);
ep_shape_set_collision(global.world,body,s1,1,2,id);
ep_shape_set_material(global.world,body,s1,0.4,1,0,0); }
ep_body_calculate_mass(global.world,b0);
ep_body_set_gravity(global.world,b0,0,gravity);
ep_body_set_position(global.world,b0,x,y,degtorad(image_angle));

b1 = ep_body_create_dynamic(global.world,false);
s1 = ep_shape_create_box(global.world,b1,2,2,0,0,0,1);
ep_shape_set_collision(global.world,b1,s1,0,0,0);
ep_shape_set_material(global.world,b1,s1,0,0,0,0);
ep_body_calculate_mass(global.world,b1);
ep_body_set_gravity(global.world,b1,0,gravity);
ep_body_set_position(global.world,b1,x,y-4,degtorad(image_angle));

slider1 = ep_sliderjoint_create(global.world,b1,b0,0,0,-6,-4,6,-4,0);
ep_sliderjoint_set_limit_settings(global.world,slider1,0.005,0.001);
ep_sliderjoint_set_lower_spring(global.world,slider1,15,0.5,2);
ep_sliderjoint_set_upper_spring(global.world,slider1,15,0.5,2);
ep_sliderjoint_set_lower_limit(global.world,slider1,0,0,0,0);
ep_sliderjoint_set_upper_limit(global.world,slider1,0,1,0,0);

my intention is sliderjoint b1,b0. b1 doesn't collision with anything just sliderjoint b0.
like gunshot recoil can make b1 motion...
eh...sometimes when spring's k >=30&&damping <=6 that seems to happen.

Springs can become unstable if you use values for k that are way too large, so that's possible. Normally k shouldn't be larger than the mass of the lightest body it is connected to. Damping has some influence too, but not as much as k.

Your limits aren't working because maxlimitforce (3rd argument) is zero. Normally you want to set this to a really high value that's normally never reached.

Hi Maarten.
I set b0 mass to 200,b1 mass = 20,k = 8,maxlimitforce = 10000.but it still happen.
in the begining:[img]http://i.imgur.com/njsr5Me.jpg[/img]
then:[img]http://i.imgur.com/RvbJ99u.jpg[/img] or [img]http://i.imgur.com/wuOI6Jl.jpg[/img]
just 1 or 2 pixels,it's not obvious but abnormal.May i made mistake somewhere?

Maarten Baert

Administrator

Comment #8: Sat, 16 Feb 2013, 14:07 (GMT+1, DST)

Quote


Quote: Earacher

Hi Maarten.
I set b0 mass to 200,b1 mass = 20,k = 8,maxlimitforce = 10000.but it still happen.
in the begining:[img]http://i.imgur.com/njsr5Me.jpg[/img]
then:[img]http://i.imgur.com/RvbJ99u.jpg[/img] or [img]http://i.imgur.com/wuOI6Jl.jpg[/img]
just 1 or 2 pixels,it's not obvious but abnormal.May i made mistake somewhere?

I really can't see what's happening on the screenshots, they are too small. Can you send me the GMK? If you don't want everyone to see it, you can also e-mail it (my e-mail address is at the top of the LICENSE.txt file in ExtremePhysics) or send me a PM on the GMC (here).

Last modified: Sat, 16 Feb 2013, 14:07 (GMT+1, DST)

Earacher

Comment #9: Sat, 16 Feb 2013, 18:28 (GMT+1, DST)

Quote


Quote: Maarten Baert
Quote: Earacher

Hi Maarten.
I set b0 mass to 200,b1 mass = 20,k = 8,maxlimitforce = 10000.but it still happen.
in the begining:[img]http://i.imgur.com/njsr5Me.jpg[/img]
then:[img]http://i.imgur.com/RvbJ99u.jpg[/img] or [img]http://i.imgur.com/wuOI6Jl.jpg[/img]
just 1 or 2 pixels,it's not obvious but abnormal.May i made mistake somewhere?

I really can't see what's happening on the screenshots, they are too small. Can you send me the GMK? If you don't want everyone to see it, you can also e-mail it (my e-mail address is at the top of the LICENSE.txt file in ExtremePhysics) or send me a PM on the GMC (here).

Hi Maarten I already sent a E-Mail to you.

Maarten Baert

Administrator

Comment #10: Sat, 23 Feb 2013, 17:35 (GMT+1, DST)

Quote


Quote: Earacher

Hi Maarten I already sent a E-Mail to you.

Okay, I figured it out. It's actually really simple:

ep_world_set_settings(global.world,0.25,20,0,0.1,0.5,0,0.5,1);

The problem is that both position_iterations and baumgarte_factor are 0. This means there is no position correction at all. It's actually surprising that it worked at all :).

I recommend setting position_iterations to 5 or 10. That should fix it.

Earacher

Comment #11: Sun, 24 Feb 2013, 17:38 (GMT+1, DST)

Quote


Quote: Maarten Baert
Quote: Earacher

Hi Maarten I already sent a E-Mail to you.

Okay, I figured it out. It's actually really simple:

ep_world_set_settings(global.world,0.25,20,0,0.1,0.5,0,0.5,1);

The problem is that both position_iterations and baumgarte_factor are 0. This means there is no position correction at all. It's actually surprising that it worked at all :).

I recommend setting position_iterations to 5 or 10. That should fix it.

Thaaank you Maarten,sorry I don't know changing position_iterations affects that.

Write a comment