Class: MSPhysics::World

Inherits:
Entity
  • Object
show all
Defined in:
RubyExtension/MSPhysics/world.rb

Overview

Since:

  • 1.0.0

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#inspect, #to_s

Constructor Details

#initialize(scale = 1) ⇒ World

Returns a new instance of World

Parameters:

  • scale (Numeric) (defaults to: 1)

    A value between 0.1 and 100.0. If you're simulating tiny objects, it's good to set world scale to a big value, like 40.

Since:

  • 1.0.0

Class Method Details

.all_worldsArray<World>

Note:

Worlds that do not have a MSPhysics::World instance are not included in the array.

Get all worlds.

Returns:

Since:

  • 1.0.0

.validate(world) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Verify that world is valid.

Parameters:

Raises:

  • (TypeError)

    if the world is invalid or destroyed.

Since:

  • 1.0.0

.world_by_address(address) ⇒ World?

Get world by world address.

Parameters:

  • address (Fixnum)

Returns:

  • (World, nil)

    A World object if successful.

Since:

  • 1.0.0

Instance Method Details

#aabbGeom::BoundingBox?

Get world axes aligned bounding box, a bounding box in which all the bodies are included.

Returns:

  • (Geom::BoundingBox, nil)

    A bounding box object, containing the minimum and maximum points of the world bounding box. Nil is returned if the world has no bodies.

Since:

  • 1.0.0

#add_explosion(center_point, blast_radius, blast_force) ⇒ Boolean

Add an explosion impulse at particular point in the world.

Examples:

# Adding an impulsive explosion
onStart {
  center_point = this.get_position(1)
  blast_radius = 100
  blast_force = 1000 / simulation.update_timestep
  world.add_explosion(center_point, blast_radius, blast_force)
}

Parameters:

  • center_point (Geom::Point3d, Array<Numeric>)

    A point of impulse.

  • blast_radius (Numeric)

    A blast radius in meters. Objects beyond the blast radius are not affected.

  • blast_force (Numeric)

    Maximum blast force in Newtons. The force is distributed linearly along the blast radius.

Returns:

  • (Boolean)

    success

Since:

  • 1.0.0

#addressFixnum

Get pointer to the world.

Returns:

  • (Fixnum)

Since:

  • 1.0.0

#bodiesArray<Body>

Note:

Bodies that do not have a Body instance are not included in the array.

Get all bodies in the world.

Returns:

Since:

  • 1.0.0

#bodies_in_aabb(min, max) ⇒ Array<Body>

Get all bodies in a particular bounds.

Parameters:

  • min (Geom::Point3d, Array<Numeric>)

    Minimum point in the bounding box.

  • max (Geom::Point3d, Array<Numeric>)

    Maximum point in the bounding box.

Returns:

Since:

  • 1.0.0

#body_countFixnum

Get the number of bodies in the world.

Returns:

  • (Fixnum)

Since:

  • 1.0.0

#constraint_countFixnum

Get the number of constraints in the world.

Returns:

  • (Fixnum)

Since:

  • 1.0.0

#contact_merge_toleranceNumeric

Get world contact merge tolerance.

Returns:

  • (Numeric)

Since:

  • 1.0.0

#contact_merge_tolerance=(tolerance) ⇒ Object

Set world contact merge tolerance.

Parameters:

  • tolerance (Numeric)

    Default value is 0.001. Minimum value is 0.001.

Since:

  • 1.0.0

#continuous_convex_ray_cast(body, transformation, target, max_hits = 16) ⇒ Array<Hit>

Note:

If given body does not have a convex collision, the function will return an empty array.

Shoot a convex body from point1 to point2 and get all intersections.

Parameters:

  • transformation (Geom::Transformation, Array<Numeric>, nil)

    Body orientation and start position. Pass nil to ray cast from body's current transformation.

  • target (Geom::Point3d, Array<Numeric>)

    Ray destination point.

  • max_hits (Fixnum) (defaults to: 16)

    Maximum number of hits, a value b/w 1 and 256.

Returns:

Since:

  • 1.0.0

#continuous_ray_cast(point1, point2) ⇒ Array<Hit>

Shoot a ray from point1 to point2 and get all intersections.

Parameters:

  • point1 (Geom::Point3d, Array<Numeric>)

    Ray starting point.

  • point2 (Geom::Point3d, Array<Numeric>)

    Ray destination point.

Returns:

Since:

  • 1.0.0

#convex_ray_cast(body, transformation, target) ⇒ Hit?

Note:

If given body does not have a convex collision, the function will return nil.

Shoot a convex body from point1 to point2 and get the closest intersection.

Parameters:

  • body (Body)

    A convex body.

  • transformation (Geom::Transformation, Array<Numeric>, nil)

    Body orientation and start position. Pass nil to ray cast from body's current transformation.

  • target (Geom::Point3d, Array<Numeric>)

    Ray destination point.

Returns:

  • (Hit, nil)

    A Hit object or nil if no intersections occurred.

Since:

  • 1.0.0

#cur_threads_countFixnum

Get the number of threads currently used by the world.

Returns:

  • (Fixnum)

Since:

  • 1.0.0

#default_material_idFixnum

Get world default contact material id.

Returns:

  • (Fixnum)

Since:

  • 1.0.0

#destroynil

Destroy the world.

Returns:

  • (nil)

Since:

  • 1.0.0

#destroy_all_bodiesFixnum

Destroy all bodies in the world.

Returns:

  • (Fixnum)

    The number of bodies destroyed.

Since:

  • 1.0.0

#gearsArray<Gear>

Note:

Gears that do not have a Gear instance are not included in the array.

Get all gears in the world.

Returns:

Since:

  • 1.0.0

#get_gravityGeom::Vector3d

Get world gravity.

Returns:

  • (Geom::Vector3d)

    Gravitational acceleration vector. The magnitude of the vector is expressed in meters per second per second (m/s/s).

Since:

  • 1.0.0

#jointsArray<Joint>

Note:

Joints that do not have a Joint instance are not included in the array.

Get all joints in the world.

Returns:

Since:

  • 1.0.0

#material_thicknessNumeric

Get world material thickness in meters, an imaginary thickness between the collision geometry of two colliding bodies.

Returns:

  • (Numeric)

    A value between 0.0 and 1/32.0.

Since:

  • 1.0.0

#material_thickness=(thickness) ⇒ Object

Set world material thickness in meters, an imaginary thickness between the collision geometry of two colliding bodies.

Parameters:

  • thickness (Numeric)

    This value is clamped between 0.0 and 1/32.0.

Since:

  • 1.0.0

#max_possible_threads_countFixnum

Get the maximum possible number of threads to be used by the world.

Returns:

  • (Fixnum)

Since:

  • 1.0.0

#max_threads_countFixnum

Get the desired maximum number of threads to be used by the world.

Returns:

  • (Fixnum)

Since:

  • 1.0.0

#max_threads_count=(count) ⇒ Object

Set the desired maximum number of threads to be used by the world.

Parameters:

  • count (Fixnum)

    This value is clamped between one and the maximum number of CPUs can be used in the system.

Since:

  • 1.0.0

#ray_cast(point1, point2) ⇒ Hit?

Shoot a ray from point1 to point2 and get the closest intersection.

Parameters:

  • point1 (Geom::Point3d, Array<Numeric>)

    Ray starting point.

  • point2 (Geom::Point3d, Array<Numeric>)

    Ray destination point.

Returns:

  • (Hit, nil)

    A Hit object or nil if no intersections occurred.

Since:

  • 1.0.0

#scaleNumeric

Get world scale.

Returns:

  • (Numeric)

    A value between 0.1 and 100.

Since:

  • 1.0.0

#serialize_to_file(full_path) ⇒ nil

Serialize world into file.

Parameters:

  • full_path (String)

Returns:

  • (nil)

Since:

  • 1.0.0

#set_gravity(acceleration) ⇒ nil #set_gravity(ax, ay, az) ⇒ nil

Set world gravity.

Overloads:

  • #set_gravity(acceleration) ⇒ nil

    Parameters:

    • acceleration (Geom::Vector3d, Array<Numeric>)

      Gravitational acceleration vector. The magnitude of the vector is assumed in meters per second per second (m/s/s).

  • #set_gravity(ax, ay, az) ⇒ nil

    Parameters:

    • ax (Numeric)

      Acceleration along X-axis in m/s/s.

    • ay (Numeric)

      Acceleration along Y-axis in m/s/s.

    • az (Numeric)

      Acceleration along Z-axis in m/s/s.

Returns:

  • (nil)

Since:

  • 1.0.0

#solver_modelFixnum

Get world solver model.

Returns:

  • (Fixnum)

    Number of passes, a value between 1 and 256.

Since:

  • 1.0.0

#solver_model=(model) ⇒ Object

Set world solver model.

Parameters:

  • model (Fixnum)

    Number of passes, a value between 1 and 256.

Since:

  • 1.0.0

#timeNumeric

Get world elapsed time in seconds.

Returns:

  • (Numeric)

Since:

  • 1.0.0

#update(timestep) ⇒ Numeric

Note:

The smaller the time step the more accurate the simulation will be.

Update world by a time step in seconds.

Parameters:

  • timestep (Numeric)

    This value is clamped between 1/30.0 and 1/1200.0.

Returns:

  • (Numeric)

    The update time step.

Since:

  • 1.0.0

#valid?Boolean

Determine if the world is valid (not destroyed).

Returns:

  • (Boolean)

Since:

  • 1.0.0