< GeeXLab Reference Guide />

> Back to Reference Guide Index


gh_box2d library

Description

gh_box2d is the module that manages the Box2D Physics engine. This module is in WIP state (work in progress) and can change in future versions of GeeXLab.


Number of functions: 47

  1. gh_box2d.init ()
  2. gh_box2d.terminate ()
  3. gh_box2d.get_version ()
  4. gh_box2d.world_init ()
  5. gh_box2d.world_terminate ()
  6. gh_box2d.world_set_gravity ()
  7. gh_box2d.world_step_simulation ()
  8. gh_box2d.world_clear_forces ()
  9. gh_box2d.world_set_auto_clear_forces ()
  10. gh_box2d.world_create_actor_box ()
  11. gh_box2d.world_create_actor_circle ()
  12. gh_box2d.world_kill_actor ()
  13. gh_box2d.world_create_actor ()
  14. gh_box2d.actor_add_vertices ()
  15. gh_box2d.actor_chain_build ()
  16. gh_box2d.actor_polygon_build ()
  17. gh_box2d.actor_box_set_size ()
  18. gh_box2d.actor_box_build ()
  19. gh_box2d.actor_circle_set_radius ()
  20. gh_box2d.actor_circle_build ()
  21. gh_box2d.actor_apply_transform ()
  22. gh_box2d.actor_set_transform ()
  23. gh_box2d.actor_get_transform ()
  24. gh_box2d.actor_set_damping ()
  25. gh_box2d.actor_set_ccd ()
  26. gh_box2d.actor_set_enabled ()
  27. gh_box2d.actor_set_awake ()
  28. gh_box2d.actor_is_awake ()
  29. gh_box2d.actor_set_sleeping_allowed ()
  30. gh_box2d.actor_set_linear_velocity ()
  31. gh_box2d.actor_set_linear_angular ()
  32. gh_box2d.actor_set_density ()
  33. gh_box2d.actor_set_friction ()
  34. gh_box2d.actor_set_restitution ()
  35. gh_box2d.actor_apply_force ()
  36. gh_box2d.actor_apply_force_to_center ()
  37. gh_box2d.actor_apply_torque ()
  38. gh_box2d.actor_apply_linear_impulse ()
  39. gh_box2d.actor_apply_linear_impulse_to_center ()
  40. gh_box2d.actor_raycast ()
  41. gh_box2d.actor_read_contacts ()
  42. gh_box2d.actor_get_contact_actor ()
  43. gh_box2d.world_kill_joint ()
  44. gh_box2d.world_create_joint_distance ()
  45. gh_box2d.joint_distance_set_stiffness ()
  46. gh_box2d.joint_distance_set_damping ()
  47. gh_box2d.joint_distance_compute_linear_stiffness ()



init

Description

Initializes the Box2D plugin. This the first function to call.


Syntax

ret = gh_box2d.init()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


ret = gh_box2d.init()
			


terminate

Description

Terminates the Box2D plugin. This function should be call in the TERMINATE script.


Syntax

ret = gh_box2d.terminate()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


ret = gh_box2d.terminate()
			


get_version

Description

Returns the version of the Box2D engine.


Syntax

major, minor, revision = gh_box2d.get_version()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


major, minor, revision = gh_box2d.get_version()
			


world_init

Description

Creates and initializes a physics world. Every Box2D demo begins with the creation of a world. A world is the physics hub that manages all Box2D objects.


Syntax

wid = gh_box2d.world_init()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


wid = gh_box2d.world_init()
			


world_terminate

Description

Terminates and destroys a physics world.


Syntax

gh_box2d.world_terminate(
 wid
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.world_terminate(wid)
			


world_set_gravity

Description

Sets the world gravity vector.


Syntax

gh_box2d.world_set_gravity(
 wid,
 x, y
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.world_set_gravity(wid, 0, -10)
			


world_step_simulation

Description

Performs a world simulation step.


Syntax

gh_box2d.world_step_simulation(
 wid,
 time_step,
 velocity_iterations,
 position_iterations
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


dt = 1.0/60.0			
velocity_iterations = 8
position_iterations = 4
gh_box2d.world_step_simulation(wid, dt, velocity_iterations, position_iterations)
			


world_clear_forces

Description

Clears all forces of all objects. Automatically done after each world_step_simulation() unless you disable this feature with world_set_auto_clear_forces().


Syntax

gh_box2d.world_clear_forces(
 wid
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.world_clear_forces(wid)
			


world_set_auto_clear_forces

Description

Set the auto clear forces state.


Syntax

gh_box2d.world_set_auto_clear_forces(
 wid,
 state
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


state = 0
gh_box2d.world_set_auto_clear_forces(wid, state)
			


world_create_actor_box

Description

Creates a box actor and adds it to the world.


Syntax

aid = gh_box2d.world_create_actor_box(
 wid,
 posx, posy,
 width, height,
 body_type,
 density,
 friction,
 restitution
)

Languages


Parameters


Return Values


Code sample


body_type = "dynamic"			
density = 10.0
friction = 0.1
restitution = 0.4
aid = gh_box2d.world_create_actor_box(wid, posx, posy, width, height, body_type, density, friction, restitution)
			


world_create_actor_circle

Description

Creates a circle (disc?) actor and adds it to the world.


Syntax

aid = gh_box2d.world_create_actor_circle(
 wid,
 posx, posy,
 radius,
 body_type,
 density,
 friction,
 restitution
)

Languages


Parameters


Return Values


Code sample


body_type = "dynamic"			
density = 10.0
friction = 0.1
restitution = 0.4
aid = gh_box2d.world_create_actor_circle(wid, posx, posy, radius, body_type, density, friction, restitution)
			


world_kill_actor

Description

Destroys and remove an actor from the world.


Syntax

gh_box2d.world_kill_actor(
 wid,
 aid
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.world_kill_actor(wid, aid)
			


world_create_actor

Description

Creates a generic actor and adds it to the world. Its shape (circle, box, polygon, chain) must be defined before calling world_step_simulation().


Syntax

aid = gh_box2d.world_create_actor(
 wid,
 posx, posy,
 body_type
)

Languages


Parameters


Return Values


Code sample


body_type = "dynamic"			
aid = gh_box2d.world_create_actor(wid, posx, posy, body_type)
gh_box2d.actor_circle_set_radius(aid, 2.0)
gh_box2d.actor_circle_build(aid)
			


actor_add_vertices

Description

Adds a vertex to the vertices list of an actor. This vertices list will be used to build the shape later.


Syntax

gh_box2d.actor_add_vertices(
 aid,
 x, y
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


b2_triangle = gh_box2d.world_create_actor(b2_world, -3, 10,  "dynamic")
gh_box2d.actor_add_vertices(b2_triangle, -1,-1)
gh_box2d.actor_add_vertices(b2_triangle,  0, 1)
gh_box2d.actor_add_vertices(b2_triangle,  1,-1)
gh_box2d.actor_polygon_build(b2_triangle)
			


actor_chain_build

Description

Builds a chain shaped actor from the vertices list initialized with calls to actor_add_vertices().


Syntax

gh_box2d.actor_chain_build(
 aid
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


b2_chain = gh_box2d.world_create_actor(b2_world, -3, 10,  "dynamic")
gh_box2d.actor_add_vertices(b2_chain, 1, 1)
gh_box2d.actor_add_vertices(b2_chain,  0, -1)
gh_box2d.actor_add_vertices(b2_chain,  -1, -1)
gh_box2d.actor_add_vertices(b2_chain,  -2, 1)
gh_box2d.actor_chain_build(b2_chain)
			


actor_polygon_build

Description

Builds a polygon shaped actor from the vertices list initialized with calls to actor_add_vertices().


Syntax

gh_box2d.actor_polygon_build(
 aid,
 x, y
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


b2_triangle = gh_box2d.world_create_actor(b2_world, -3, 10,  "dynamic")
gh_box2d.actor_add_vertices(b2_triangle, -1,-1)
gh_box2d.actor_add_vertices(b2_triangle,  0, 1)
gh_box2d.actor_add_vertices(b2_triangle,  1,-1)
gh_box2d.actor_polygon_build(b2_triangle)
			


actor_box_set_size

Description

Sets the size of a box shaped actor.


Syntax

gh_box2d.actor_box_set_size(
 aid,
 w, h
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


b2_box = gh_box2d.world_create_actor(b2_world, -3, 10,  "dynamic")
gh_box2d.actor_box_set_size(b2_box, 2.0, 2.0)
gh_box2d.actor_box_build(b2_box)
			


actor_box_build

Description

Builds a box shaped actor.


Syntax

gh_box2d.actor_box_build(
 aid
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


b2_box = gh_box2d.world_create_actor(b2_world, -3, 10,  "dynamic")
gh_box2d.actor_box_set_size(b2_box, 2.0, 2.0)
gh_box2d.actor_box_build(b2_box)
			


actor_circle_set_radius

Description

Sets the radius of a circle shaped actor.


Syntax

gh_box2d.actor_circle_set_radius(
 aid,
 r
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


b2_circle = gh_box2d.world_create_actor(b2_world, -3, 10,  "dynamic")
gh_box2d.actor_circle_set_radius(b2_circle, 2.0, 2.0)
gh_box2d.actor_box_actor_circle_buildbuild(b2_circle)
			


actor_circle_build

Description

Builds a circle shaped actor.


Syntax

gh_box2d.actor_circle_build(
 aid
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


b2_circle = gh_box2d.world_create_actor(b2_world, -3, 10,  "dynamic")
gh_box2d.actor_circle_set_radius(b2_circle, 2.0, 2.0)
gh_box2d.actor_box_actor_circle_buildbuild(b2_circle)
			


actor_apply_transform

Description

Applies the transformation of a Box2D actor to a 3D object.


Syntax

gh_box2d.actor_apply_transform(
 aid,
 object_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_apply_transform(aid, mesh_id)
			


actor_set_transform

Description

Sets the transformation of a Box2D actor.


Syntax

gh_box2d.actor_set_transform(
 aid,
 x, y,
 angle
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_set_transform(aid, x, y, angle)
			


actor_get_transform

Description

Gets the transformation of a Box2D actor.


Syntax

x, y, angle = gh_box2d.actor_get_transform(
 aid
)

Languages


Parameters


Return Values


Code sample


x, y, angle = gh_box2d.actor_get_transform(aid)
			


actor_set_damping

Description

Sets the damping coefficients of a Box2D actor.


Syntax

gh_box2d.actor_set_damping(
 aid,
 linear,
 angular
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_set_damping(aid, linear, angular)
			


actor_set_ccd

Description

Sets the CCD (continuous collision detection) state of a Box2D actor. Useful for fast moving actors like bullets. Disabled by default.


Syntax

gh_box2d.actor_set_ccd(
 aid,
 state
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_set_ccd(aid, state)
			


actor_set_enabled

Description

Sets the enabled state of a Box2D actor.


Syntax

gh_box2d.actor_set_enabled(
 aid,
 state
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_set_enabled(aid, state)
			


actor_set_awake

Description

Sets the awake state of a Box2D actor.


Syntax

gh_box2d.actor_set_awake(
 aid,
 state
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_set_awake(aid, state)
			


actor_is_awake

Description

Gets the awake state of a Box2D actor.


Syntax

state = gh_box2d.actor_is_awake(
 aid
)

Languages


Parameters


Return Values


Code sample


state = gh_box2d.actor_is_awake(aid)
			


actor_set_sleeping_allowed

Description

Sets the sleeping allowed state of a Box2D actor.


Syntax

gh_box2d.actor_set_sleeping_allowed(
 aid,
 state
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_set_sleeping_allowed(aid, state)
			


actor_set_linear_velocity

Description

Sets the linear velocity of a Box2D actor.


Syntax

gh_box2d.actor_set_linear_velocity(
 aid,
 x, y
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_set_linear_velocity(aid, x, y)
			


actor_set_linear_angular

Description

Sets the angular velocity of a Box2D actor.


Syntax

gh_box2d.actor_set_linear_angular(
 aid,
 x
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_set_linear_angular(aid, x)
			


actor_set_density

Description

Sets the density of an actor. The mass will be updated.


Syntax

gh_box2d.actor_set_density(
 aid,
 x
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_set_density(aid, x)
			


actor_set_friction

Description

Sets the friction of an actor.


Syntax

gh_box2d.actor_set_friction(
 aid,
 x
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_set_friction(aid, x)
			


actor_set_restitution

Description

Sets the restitution of an actor.


Syntax

gh_box2d.actor_set_restitution(
 aid,
 x
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_set_restitution(aid, x)
			


actor_apply_force

Description

Apply a force on an actor at a world point.


Syntax

gh_box2d.actor_apply_force(
 aid,
 force_x, force_y,
 point_x, point_y,
 wake
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_apply_force(aid, force_x, force_y, point_x, point_y, wake)
			


actor_apply_force_to_center

Description

Apply a force on the center of mass of an actor.


Syntax

gh_box2d.actor_apply_force_to_center(
 aid,
 force_x, force_y,
 wake
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_apply_force_to_center(aid, force_x, force_y, wake)
			


actor_apply_torque

Description

Apply a torque on an actor.


Syntax

gh_box2d.actor_apply_torque(
 aid,
 torque,
 wake
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_apply_torque(aid, torque, wake)
			


actor_apply_linear_impulse

Description

Apply an impulse on an actor at a world point.


Syntax

gh_box2d.actor_apply_linear_impulse(
 aid,
 impulse_x, impulse_y,
 point_x, point_y,
 wake
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_apply_linear_impulse(aid, impulse_x, impulse_y, point_x, point_y, wake)
			


actor_apply_linear_impulse_to_center

Description

Apply an impulse on the center of mass of an actor.


Syntax

gh_box2d.actor_apply_linear_impulse_to_center(
 aid,
 impulse_x, impulse_y,
 wake
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.actor_apply_linear_impulse_to_center(aid, impulse_x, impulse_y, wake)
			


actor_raycast

Description

Casts a ray on an actor and gets the hit point.


Syntax

ret, hit_point_x, hit_point_y = gh_box2d.actor_raycast(
 aid,
 x0, y0,
 x1, y1
)

Languages


Parameters


Return Values


Code sample


ret, hit_point_x, hit_point_y = gh_box2d.actor_raycast(aid, x0, y0, x1, y1)
			


actor_read_contacts

Description

Sets the angular velocity of a Box2D actor.


Syntax

num_contacts, x, y = gh_box2d.actor_read_contacts(
 aid
)

Languages


Parameters


Return Values


Code sample


num_contacts, x, y = gh_box2d.actor_read_contacts(aid)
			


actor_get_contact_actor

Description

Gets the actor ID of a particular contact.


Syntax

contact_actor_id, cx, cy = gh_box2d.actor_get_contact_actor(
 actor_id,
 contact_index
)

Languages


Parameters


Return Values


Code sample


num_contacts, x, y = gh_box2d.actor_read_contacts(actor_id)
for i=0, num_contacts-1 do
  contact_actor_id, cx, cy = gh_box2d.actor_get_contact_actor(actor_id, i)
	...
end	
			


world_kill_joint

Description

Kills an existing joint.


Syntax

gh_box2d.world_kill_joint(
 wid,
 jid
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.world_kill_joint(wid, jid)
			


world_create_joint_distance

Description

Creates a distance joint between two actors (A and B).


Syntax

jid = gh_box2d.world_create_joint_distance(
 wid,
 a,
 b,
 anchor_a_x, anchor_a_y,
 anchor_b_x, anchor_b_y
)

Languages


Parameters


Return Values


Code sample


jid = gh_box2d.world_create_joint_distance(wid, a, b, anchor_a_x, anchor_a_y, anchor_b_x, anchor_b_y)
			


joint_distance_set_stiffness

Description

Sets the stiffness of a joint.


Syntax

gh_box2d.joint_distance_set_stiffness(
 wid,
 stiffness
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.joint_distance_set_stiffness(jid, stiffness)
			


joint_distance_set_damping

Description

Sets the damping of a joint.


Syntax

gh_box2d.joint_distance_set_damping(
 wid,
 damping
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_box2d.joint_distance_set_damping(jid, damping)
			


joint_distance_compute_linear_stiffness

Description

Utility function that computes the stiffness and damping of a joint.


Syntax

stiffness, damping = gh_box2d.joint_distance_compute_linear_stiffness(
 wid,
 frequency_hz,
 damping_ratio
)

Languages


Parameters


Return Values


Code sample


frequency_hz = 4.0			
damping_ratio = 0.5
stiffness, damping = gh_box2d.joint_distance_compute_linear_stiffness(jid, frequency_hz, damping_ratio)
			






GeeXLab Rootard Guide | Downloads | Contact | Newsletter