Class: MSPhysics::World
- Defined in:
- RubyExtension/MSPhysics/world.rb
Overview
Class Method Summary collapse
-
.all_worlds ⇒ Array<World>
Get all worlds.
-
.validate(world) ⇒ void
private
Verify that world is valid.
-
.world_by_address(address) ⇒ World?
Get world by world address.
Instance Method Summary collapse
-
#aabb ⇒ Geom::BoundingBox?
Get world axes aligned bounding box, a bounding box in which all the bodies are included.
-
#add_explosion(center_point, blast_radius, blast_force) ⇒ Boolean
Add an explosion impulse at particular point in the world.
-
#address ⇒ Integer
Get pointer to the world.
-
#bodies ⇒ Array<Body>
Get all bodies in the world.
-
#bodies_in_aabb(min, max) ⇒ Array<Body>
Get all bodies in a particular bounds.
-
#body_count ⇒ Integer
Get the number of bodies in the world.
-
#constraint_count ⇒ Integer
Get the number of constraints in the world.
-
#contact_merge_tolerance ⇒ Numeric
Get world contact merge tolerance.
-
#contact_merge_tolerance=(tolerance) ⇒ Object
Set world contact merge tolerance.
-
#continuous_convex_ray_cast(body, transformation, target, max_hits = 16) ⇒ Array<Hit>
Shoot a convex body from point1 to point2 and get all intersections.
-
#continuous_ray_cast(point1, point2) ⇒ Array<Hit>
Shoot a ray from point1 to point2 and get all intersections.
-
#convex_ray_cast(body, transformation, target) ⇒ Hit?
Shoot a convex body from point1 to point2 and get the closest intersection.
-
#cur_threads_count ⇒ Integer
Get the number of threads currently used by the world.
-
#default_material_id ⇒ Integer
Get world default contact material id.
-
#destroy ⇒ nil
Destroy the world.
-
#destroy_all_bodies ⇒ Integer
Destroy all bodies in the world.
-
#gears ⇒ Array<Gear>
Get all gears in the world.
-
#get_gravity ⇒ Geom::Vector3d
Get world gravity.
-
#initialize ⇒ World
constructor
class << self.
-
#joints ⇒ Array<Joint>
Get all joints in the world.
-
#material_thickness ⇒ Numeric
Get world material thickness in meters, an imaginary thickness between the collision geometry of two colliding bodies.
-
#material_thickness=(thickness) ⇒ Object
Set world material thickness in meters, an imaginary thickness between the collision geometry of two colliding bodies.
-
#max_possible_threads_count ⇒ Integer
Get the maximum possible number of threads to be used by the world.
-
#max_threads_count ⇒ Integer
Get the desired maximum number of threads to be used by the world.
-
#max_threads_count=(count) ⇒ Object
Set the desired maximum number of threads to be used by the world.
-
#ray_cast(point1, point2) ⇒ Hit?
Shoot a ray from point1 to point2 and get the closest intersection.
-
#serialize_to_file(full_path) ⇒ nil
Serialize world into file.
-
#set_gravity(*args) ⇒ nil
Set world gravity.
-
#solver_model ⇒ Integer
Get world solver model.
-
#solver_model=(model) ⇒ Object
Set world solver model.
-
#time ⇒ Numeric
Get world elapsed time in seconds.
-
#update(timestep) ⇒ Numeric
Update world by a time step in seconds.
-
#valid? ⇒ Boolean
Determine if the world is valid (not destroyed).
Methods inherited from Entity
Constructor Details
Class Method Details
.all_worlds ⇒ Array<World>
Worlds that do not have a MSPhysics::World instance are not included in the array.
Get all worlds.
31 32 33 |
# File 'RubyExtension/MSPhysics/world.rb', line 31 def all_worlds MSPhysics::Newton.get_all_worlds() { |ptr, data| data.is_a?(MSPhysics::World) ? data : nil } end |
.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.
12 13 14 15 16 17 |
# File 'RubyExtension/MSPhysics/world.rb', line 12 def validate(world) AMS.validate_type(world, MSPhysics::World) unless world.valid? raise(TypeError, "World #{world} is invalid/destroyed!", caller) end end |
Instance Method Details
#aabb ⇒ Geom::BoundingBox?
Get world axes aligned bounding box, a bounding box in which all the bodies are included.
280 281 282 283 284 285 286 |
# File 'RubyExtension/MSPhysics/world.rb', line 280 def aabb mm = MSPhysics::Newton::World.get_aabb(@address) return unless mm bb = Geom::BoundingBox.new bb.add(mm) bb end |
#add_explosion(center_point, blast_radius, blast_force) ⇒ Boolean
Add an explosion impulse at particular point in the world.
271 272 273 |
# File 'RubyExtension/MSPhysics/world.rb', line 271 def add_explosion(center_point, blast_radius, blast_force) MSPhysics::Newton::World.add_explosion(@address, center_point, blast_radius.to_f, blast_force.to_f) end |
#address ⇒ Integer
Get pointer to the world.
50 51 52 |
# File 'RubyExtension/MSPhysics/world.rb', line 50 def address @address end |
#bodies ⇒ Array<Body>
Bodies that do not have a Body instance are not included in the array.
Get all bodies in the world.
103 104 105 |
# File 'RubyExtension/MSPhysics/world.rb', line 103 def bodies MSPhysics::Newton::World.get_bodies(@address) { |ptr, data| data.is_a?(MSPhysics::Body) ? data : nil } end |
#bodies_in_aabb(min, max) ⇒ Array<Body>
Get all bodies in a particular bounds.
127 128 129 |
# File 'RubyExtension/MSPhysics/world.rb', line 127 def bodies_in_aabb(min, max) MSPhysics::Newton::World.get_bodies_in_aabb(@address, min, max) { |ptr, data| data.is_a?(MSPhysics::Body) ? data : nil } end |
#body_count ⇒ Integer
Get the number of bodies in the world.
133 134 135 |
# File 'RubyExtension/MSPhysics/world.rb', line 133 def body_count MSPhysics::Newton::World.get_body_count(@address) end |
#constraint_count ⇒ Integer
Get the number of constraints in the world.
139 140 141 |
# File 'RubyExtension/MSPhysics/world.rb', line 139 def constraint_count MSPhysics::Newton::World.get_constraint_count(@address) end |
#contact_merge_tolerance ⇒ Numeric
Get world contact merge tolerance.
303 304 305 |
# File 'RubyExtension/MSPhysics/world.rb', line 303 def contact_merge_tolerance MSPhysics::Newton::World.get_contact_merge_tolerance(@address) end |
#contact_merge_tolerance=(tolerance) ⇒ Object
Set world contact merge tolerance.
309 310 311 |
# File 'RubyExtension/MSPhysics/world.rb', line 309 def contact_merge_tolerance=(tolerance) MSPhysics::Newton::World.set_contact_merge_tolerance(@address, tolerance) end |
#continuous_convex_ray_cast(body, transformation, target, max_hits = 16) ⇒ Array<Hit>
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.
248 249 250 251 252 253 254 |
# File 'RubyExtension/MSPhysics/world.rb', line 248 def continuous_convex_ray_cast(body, transformation, target, max_hits = 16) MSPhysics::Body.validate(body, self) transformation = body.get_matrix unless transformation MSPhysics::Newton::World.continuous_convex_ray_cast(@address, body.collision_address, transformation, target, max_hits) { |ptr, data, point, vector, penetration| data.is_a?(MSPhysics::Body) ? Hit.new(data, point, vector) : nil } end |
#continuous_ray_cast(point1, point2) ⇒ Array<Hit>
Shoot a ray from point1 to point2 and get all intersections.
216 217 218 219 220 |
# File 'RubyExtension/MSPhysics/world.rb', line 216 def continuous_ray_cast(point1, point2) MSPhysics::Newton::World.continuous_ray_cast(@address, point1, point2) { |ptr, data, point, vector| data.is_a?(MSPhysics::Body) ? Hit.new(data, point, vector) : nil } end |
#convex_ray_cast(body, transformation, target) ⇒ Hit?
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.
232 233 234 235 236 237 |
# File 'RubyExtension/MSPhysics/world.rb', line 232 def convex_ray_cast(body, transformation, target) MSPhysics::Body.validate(body, self) transformation = body.get_matrix unless transformation res = MSPhysics::Newton::World.convex_ray_cast(@address, body.collision_address, transformation, target) res && res[1].is_a?(MSPhysics::Body) ? Hit.new(res[1], res[2], res[3]) : nil end |
#cur_threads_count ⇒ Integer
Get the number of threads currently used by the world.
87 88 89 |
# File 'RubyExtension/MSPhysics/world.rb', line 87 def cur_threads_count MSPhysics::Newton::World.get_cur_threads_count(@address) end |
#default_material_id ⇒ Integer
Get world default contact material id.
62 63 64 |
# File 'RubyExtension/MSPhysics/world.rb', line 62 def default_material_id MSPhysics::Newton::World.get_default_material_id(@address) end |
#destroy ⇒ nil
Destroy the world.
56 57 58 |
# File 'RubyExtension/MSPhysics/world.rb', line 56 def destroy MSPhysics::Newton::World.destroy(@address) end |
#destroy_all_bodies ⇒ Integer
Destroy all bodies in the world.
145 146 147 |
# File 'RubyExtension/MSPhysics/world.rb', line 145 def destroy_all_bodies MSPhysics::Newton::World.destroy_all_bodies(@address) end |
#gears ⇒ Array<Gear>
Gears that do not have a Gear instance are not included in the array.
Get all gears in the world.
119 120 121 |
# File 'RubyExtension/MSPhysics/world.rb', line 119 def gears MSPhysics::Newton::World.get_gears(@address) { |ptr, data| data.is_a?(MSPhysics::Gear) ? data : nil } end |
#get_gravity ⇒ Geom::Vector3d
Get world gravity.
152 153 154 |
# File 'RubyExtension/MSPhysics/world.rb', line 152 def get_gravity MSPhysics::Newton::World.get_gravity(@address) end |
#joints ⇒ Array<Joint>
Joints that do not have a Joint instance are not included in the array.
Get all joints in the world.
111 112 113 |
# File 'RubyExtension/MSPhysics/world.rb', line 111 def joints MSPhysics::Newton::World.get_joints(@address) { |ptr, data| data.is_a?(MSPhysics::Joint) ? data : nil } end |
#material_thickness ⇒ Numeric
Get world material thickness in meters, an imaginary thickness between the collision geometry of two colliding bodies.
192 193 194 |
# File 'RubyExtension/MSPhysics/world.rb', line 192 def material_thickness MSPhysics::Newton::World.get_material_thickness(@address) end |
#material_thickness=(thickness) ⇒ Object
Set world material thickness in meters, an imaginary thickness between the collision geometry of two colliding bodies.
199 200 201 |
# File 'RubyExtension/MSPhysics/world.rb', line 199 def material_thickness=(thickness) MSPhysics::Newton::World.set_material_thickness(@address, thickness.to_f) end |
#max_possible_threads_count ⇒ Integer
Get the maximum possible number of threads to be used by the world.
68 69 70 |
# File 'RubyExtension/MSPhysics/world.rb', line 68 def max_possible_threads_count MSPhysics::Newton::World.get_max_possible_threads_count(@address) end |
#max_threads_count ⇒ Integer
Get the desired maximum number of threads to be used by the world.
74 75 76 |
# File 'RubyExtension/MSPhysics/world.rb', line 74 def max_threads_count MSPhysics::Newton::World.get_max_threads_count(@address) end |
#max_threads_count=(count) ⇒ Object
Set the desired maximum number of threads to be used by the world.
81 82 83 |
# File 'RubyExtension/MSPhysics/world.rb', line 81 def max_threads_count=(count) MSPhysics::Newton::World.set_max_threads_count(@address, count.to_i) end |
#ray_cast(point1, point2) ⇒ Hit?
Shoot a ray from point1 to point2 and get the closest intersection.
207 208 209 210 |
# File 'RubyExtension/MSPhysics/world.rb', line 207 def ray_cast(point1, point2) res = MSPhysics::Newton::World.ray_cast(@address, point1, point2) res && res[1].is_a?(MSPhysics::Body) ? Hit.new(res[1], res[2], res[3]) : nil end |
#serialize_to_file(full_path) ⇒ nil
Serialize world into file.
297 298 299 |
# File 'RubyExtension/MSPhysics/world.rb', line 297 def serialize_to_file(full_path) MSPhysics::Newton::World.serialize_to_file(@address, full_path) end |
#set_gravity(acceleration) ⇒ nil #set_gravity(ax, ay, az) ⇒ nil
Set world gravity.
166 167 168 169 170 171 172 173 174 175 |
# File 'RubyExtension/MSPhysics/world.rb', line 166 def set_gravity(*args) if args.size == 3 data = [args[0], args[1], args[2]] elsif args.size == 1 data = args[0] else raise(ArgumentError, "Wrong number of arguments! Expected 1 or 3 arguments but got #{args.size}.", caller) end MSPhysics::Newton::World.set_gravity(@address, data) end |
#solver_model ⇒ Integer
Get world solver model.
179 180 181 |
# File 'RubyExtension/MSPhysics/world.rb', line 179 def solver_model MSPhysics::Newton::World.get_solver_model(@address) end |
#solver_model=(model) ⇒ Object
Set world solver model.
185 186 187 |
# File 'RubyExtension/MSPhysics/world.rb', line 185 def solver_model=(model) MSPhysics::Newton::World.set_solver_model(@address, model.to_i) end |
#time ⇒ Numeric
Get world elapsed time in seconds.
290 291 292 |
# File 'RubyExtension/MSPhysics/world.rb', line 290 def time MSPhysics::Newton::World.get_time(@address) end |
#update(timestep) ⇒ Numeric
The smaller the time step the more accurate the simulation will be.
Update world by a time step in seconds.
95 96 97 |
# File 'RubyExtension/MSPhysics/world.rb', line 95 def update(timestep) MSPhysics::Newton::World.update(@address, timestep) end |
#valid? ⇒ Boolean
Determine if the world is valid (not destroyed).
44 45 46 |
# File 'RubyExtension/MSPhysics/world.rb', line 44 def valid? MSPhysics::Newton::World.is_valid?(@address) end |