Class: MSPhysics::Body
Overview
The Body class represents a physics body in simulation. Every body in simulation is designed to have its own Body object.
Force Control Functions collapse
-
#add_force(*args) ⇒ Boolean
Apply force on the body in Newtons (kg * m/s/s).
-
#add_torque(*args) ⇒ Boolean
Apply torque on the body in Newton-meters (kg * m/s/s * m).
-
#get_force ⇒ Geom::Vector3d
Get the net force, in Newtons, applied on the body after the last world update.
-
#get_torque ⇒ Geom::Vector3d
Get the net torque, in Newton-meters, applied on the body after the last world update.
-
#set_force(*args) ⇒ Boolean
Apply force on the body in Newton (kg * m/s/s).
-
#set_torque(*args) ⇒ Boolean
Apply torque on the body in Newton-meters (kg * m/s/s * m).
Contact Related Functions collapse
-
#contact_points(inc_non_collidable) ⇒ Array<Geom::Point3d>
Get all contact points on the body.
-
#contacts(inc_non_collidable) ⇒ Array<Contact>
Get all contacts on the body.
-
#net_contact_force ⇒ Geom::Vector3d
Get total force generated from contacts on the body.
-
#net_joint_force ⇒ Geom::Vector3d
Get total linear tension, in Newtons, applied by contained and connected joints.
-
#net_joint_torque ⇒ Geom::Vector3d
Get total angular tension, in Newton-meters, applied by contained and connected joints.
-
#touching_bodies(inc_non_collidable) ⇒ Array<Body>
Get all bodies that are in contact with this body.
-
#touching_with?(body) ⇒ Boolean
Determine if this body is in contact with another body.
Joint Associated Functions collapse
-
#attach(body) ⇒ MSPhysics::Fixed
Attach a particular body to this body with a Fixed joint.
-
#attached?(body) ⇒ Boolean
Determine whether a particular body is attached to this body.
-
#detach(body) ⇒ Boolean
Detach a particular attached body from this body.
-
#detach_all ⇒ Integer
Detach all attached bodies from this body.
-
#look_at(pin_dir, accel = 40, damp = 10, strength = 0.9) ⇒ MSPhysics::UpVector?
Make the body’s Z-axis to look in a particular direction.
Class Method Summary collapse
-
.all_bodies ⇒ Array<Body>
Get all bodies.
-
.bodies_aabb_overlap?(body1, body2) ⇒ Boolean
Determine if the bounding boxes of two bodies overlap.
-
.bodies_collidable?(body1, body2) ⇒ Boolean
Determine if two bodies can collide with each other.
-
.bodies_touching?(body1, body2) ⇒ Boolean
Determine if two bodies are in contact.
-
.body_by_address(address) ⇒ Body?
Get body by body address.
-
.closest_points(body1, body2) ⇒ Array<Geom::Point3d>?
Get closest collision points between two bodies.
-
.force_between_bodies(body1, body2) ⇒ Geom::Vector3d
Get contact force between two bodies.
-
.validate(body, world = nil) ⇒ void
private
Verify that body is valid.
-
.validate2(body1, body2, world = nil) ⇒ void
private
Verify that two bodies are valid and unique.
Instance Method Summary collapse
-
#aabb ⇒ Geom::BoundingBox
Get world axes aligned bounding box (AABB) of the body.
-
#actual_matrix_scale ⇒ Geom::Vector3d
Get scale of the body matrix that is a product of group scale and collision scale.
-
#add_impulse(center, delta_vel, timestep) ⇒ Boolean
Add an impulse to a specific point on the body.
-
#add_point_force(point, force) ⇒ Boolean
Add force to a specific point on the body.
-
#address ⇒ Integer
Get pointer to the body.
-
#apply_aerodynamics(drag, wind) ⇒ Boolean
Apply fluid resistance to the body.
-
#apply_buoyancy(plane_origin, plane_normal, density, linear_viscosity, angular_viscosity, linear_current, angular_current, timestep) ⇒ Boolean
Apply buoyancy to the body.
-
#apply_pick_and_drag(pick_pt, dest_pt, stiffness, damp, timestep) ⇒ Boolean
Apply pick and drag to the body.
-
#auto_sleep_enabled=(state) ⇒ Object
Set auto sleep state of the body.
-
#auto_sleep_enabled? ⇒ Boolean
Get the auto-sleep state of the body.
-
#clear_non_collidable_bodies ⇒ Integer
Remove all bodies from the non-collidable list; the bodies that were set non-collidable by the #set_non_collidable_with function.
-
#collidable=(state) ⇒ Object
Set body collidable.
-
#collidable? ⇒ Boolean
Determine whether body is collidable.
-
#collision_address ⇒ Integer
Get pointer to the collision associated with the body.
-
#collision_faces ⇒ Array<Array<Geom::Point3d>>
Get collision faces of the body.
-
#collision_faces2 ⇒ Array<Array<(Array<Geom::Point3d>, Geom::Point3d, Geom::Vector3d, Numeric)>>
Get collision faces of the body.
-
#collision_faces3 ⇒ Array<Array<(Geom::Point3d, Geom::Vector3d, Numeric)>>
Get collision faces of the body.
-
#connected_bodies ⇒ Array<Body>
Get all bodies connected to this body through joints.
-
#connected_joints ⇒ Array<Joint, DoubleJoint>
Get joints whose child bodies associate to this body.
-
#contained_joints ⇒ Array<Joint, DoubleJoint>
Get joints whose parent bodies associate to this body.
-
#context ⇒ BodyContext
Get the associated context.
-
#continuous_collision_check_enabled=(state) ⇒ Object
Enable/disable continuous collision check for this body.
-
#continuous_collision_check_enabled? ⇒ Boolean
Determine whether continuous collision check is enabled for this body.
-
#copy(*args) ⇒ Body
Create a copy of the body.
-
#default_collision_scale ⇒ Geom::Vector3d
Get default scale of the body collision.
-
#density ⇒ Numeric
Get body density in kilograms per cubic meter (kg / m^3).
-
#density=(value) ⇒ Object
Set body density in kilograms per cubic meter (kg / m^3).
-
#destroy(erase_entity = false) ⇒ nil
Destroy the body.
-
#elasticity ⇒ Numeric
Get body coefficient of restitution - bounciness - rebound ratio.
-
#elasticity=(coefficient) ⇒ Object
Set body coefficient of restitution - bounciness - rebound ratio.
-
#friction_enabled=(state) ⇒ Object
Set friction state of the body.
-
#friction_enabled? ⇒ Boolean
Get friction state of the body.
-
#frozen=(state) ⇒ Object
Set body collidable.
-
#frozen? ⇒ Boolean
Determine whether body is frozen.
-
#get_angular_damping ⇒ Geom::Vetor3d
Get the viscous damping coefficient applied to the omega of the body.
-
#get_centre_of_mass ⇒ Geom::Point3d
Get centre of mass of the body in local coordinates.
-
#get_collision_scale ⇒ Geom::Vector3d
Get body collision scale.
-
#get_euler_angles ⇒ Geom::Vector3d
Get body orientation in form of the three Euler angles.
-
#get_linear_damping ⇒ Geom::Vetor3d
Get the viscous damping coefficient applied to the velocity of the body.
-
#get_matrix ⇒ Geom::Transformation
Get body transformation matrix.
-
#get_non_collidable_bodies ⇒ Array<Body>
Get all bodies that are non-collidable with this body; the bodies that were set non-collidable by the #set_non_collidable_with function.
-
#get_omega ⇒ Geom::Vector3d
Get global angular velocity of the body.
-
#get_position(mode = 0) ⇒ Geom::Point3d
Get body position.
-
#get_velocity ⇒ Geom::Vector3d
Get global linear velocity of the body.
-
#gravity_enabled=(state) ⇒ Object
Enable/disable gravitational force on this body.
-
#gravity_enabled? ⇒ Boolean
Determine if gravitational force is enabled on this body.
-
#group ⇒ Sketchup::Group, Sketchup::ComponentInstance
Get the group/component associated with the body.
-
#inertia ⇒ Geom::Vector3d
Get body local inertia.
-
#initialize(*args) ⇒ Body
constructor
A new instance of Body.
-
#integrate_velocity(timestep) ⇒ nil
Integrate linear and angular velocity of the body.
-
#kinetic_friction ⇒ Numeric
Get kinetic friction coefficient of the body.
-
#kinetic_friction=(coefficient) ⇒ Object
Set kinetic friction coefficient of the body.
-
#magnet_force ⇒ Numeric
Get the maximum magnet force in Newton to be applied on the surrounding magnetic bodies.
-
#magnet_force=(force) ⇒ Object
Set the maximum magnet force in Newton to be applied on the surrounding magnetic bodies.
-
#magnet_mode ⇒ Integer
Get the mode for controlling the way this magnet should work.
-
#magnet_mode=(mode) ⇒ Object
Set the mode for controlling the way this magnet should work.
-
#magnet_range ⇒ Numeric
Get the maximum magnet range in meters.
-
#magnet_range=(range) ⇒ Object
Set the maximum magnet range in meters.
-
#magnet_strength ⇒ Numeric
Get the magnet force magnitude to be applied on the surrounding magnetic bodies.
-
#magnet_strength=(magnitude) ⇒ Object
Set the magnet force magnitude to be applied on the surrounding magnetic bodies.
-
#magnetic=(state) ⇒ Object
Set body magnetic.
-
#magnetic? ⇒ Boolean
Determine whether body is magnetic.
-
#mass ⇒ Numeric
Get body mass in kilograms (kg).
-
#mass=(value) ⇒ Object
Set body mass in kilograms (kg).
-
#non_collidable_with?(body) ⇒ Boolean
Determine whether this body is non-collidable with a particular body.
-
#normal_matrix ⇒ Geom::transformation
Get body matrix with no scale factors.
-
#point_velocity(point) ⇒ Geom::Vector3d
Get velocity at a specific point on the body.
-
#reset_mass_properties(density) ⇒ Boolean
Reset/recalculate body volume and mass.
-
#rotation ⇒ Array<Numeric>
Get body orientation in form of the unit quaternion.
-
#set_angular_damping(*args) ⇒ nil
Set the viscous damping coefficient applied to the omega of the body.
-
#set_centre_of_mass(*args) ⇒ nil
Set centre of mass of the body in local coordinates.
-
#set_collision_scale(*args) ⇒ nil
Set body collision scale.
-
#set_euler_angles(*args) ⇒ nil
Set body orientation via the three Euler angles.
-
#set_linear_damping(*args) ⇒ Object
Set the viscous damping coefficient applied to the velocity of the body.
-
#set_matrix(matrix) ⇒ nil
Set body transformation matrix.
-
#set_non_collidable_with(body, state) ⇒ nil
Set this body non-collidable with a particular body.
-
#set_omega(*args) ⇒ nil
Set global angular velocity of the body.
-
#set_position(*args) ⇒ nil
Set body position.
-
#set_velocity(*args) ⇒ nil
Set global linear velocity of the body.
-
#sleeping=(state) ⇒ Object
Set body sleeping.
-
#sleeping? ⇒ Boolean
Determine whether body is sleeping.
-
#softness ⇒ Numeric
Get contact softness coefficient of the body.
-
#softness=(coefficient) ⇒ Object
Set contact softness coefficient of the body.
-
#static=(state) ⇒ Object
Set body static.
-
#static? ⇒ Boolean
Determine whether body is static.
-
#static_friction ⇒ Numeric
Get static friction coefficient of the body.
-
#static_friction=(coefficient) ⇒ Object
Set static friction coefficient of the body.
-
#type ⇒ Integer
Get body type.
-
#valid? ⇒ Boolean
Determine whether this body is valid - not destroyed.
-
#volume ⇒ Numeric
Get body volume in cubic meters (m^3).
-
#volume=(value) ⇒ Object
Set body volume in cubic meters (m^3).
-
#world ⇒ World
Get world in which the body was created.
Methods inherited from Entity
Constructor Details
#initialize(world, entity, shape_id, offset_tra, type_id) ⇒ Body #initialize(body, transformation, reapply_forces, type_id) ⇒ Body
Returns a new instance of Body.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'RubyExtension/MSPhysics/body.rb', line 150 def initialize(*args) if args.size == 5 MSPhysics::World.validate(args[0]) MSPhysics::Collision.validate_entity(args[1]) @group = args[1] collision = MSPhysics::Collision.create(args[0], @group, args[2], args[3]) @address = MSPhysics::Newton::Body.create(args[0].address, collision, @group.transformation, args[4], args[0].default_material_id, @group) if args[2] == 0 bb = AMS::Group.get_bounding_box_from_faces(@group, true, nil, &MSPhysics::Collision::ENTITY_VALIDATION_PROC) scale = AMS::Geometry.get_matrix_scale(@group.transformation) c = bb.center c.x *= scale.x c.y *= scale.y c.z *= scale.z MSPhysics::Newton::Body.set_centre_of_mass(@address, c) if bb.width.to_f < MSPhysics::EPSILON || bb.height.to_f < MSPhysics::EPSILON || bb.depth.to_f < MSPhysics::EPSILON MSPhysics::Newton::Body.set_volume(@address, 1.0) else v = bb.width * bb.height * bb.depth * 0.0254**3 MSPhysics::Newton::Body.set_volume(@address, v) end end MSPhysics::Newton::Collision.destroy(collision) elsif args.size == 4 # Create a clone of an existing body. Body.validate(args[0]) orig_group = args[0].group unless orig_group.valid? raise(TypeError, 'The specified body references a deleted group/component. Copying bodies with invalid linked entities is not acceptable!', caller) end definition = AMS::Group.get_definition(orig_group) @group = Sketchup.active_model.entities.add_instance(definition, orig_group.transformation) @group.name = orig_group.name @group.layer = orig_group.layer @group.material = orig_group.material @address = MSPhysics::Newton::Body.copy(args[0].address, args[1], args[2], args[3], @group) @group.transformation = MSPhysics::Newton::Body.get_matrix(@address) # Preserve source definition if MSPhysics::Replay.record_enabled? && @group.is_a?(Sketchup::Group) MSPhysics::Replay.preset_definition(@group, definition) end else raise(ArgumentError, "Wrong number of arguments! Expected 4..5 arguments but got #{args.size}.", caller) end MSPhysics::Newton::Body.set_user_data(@address, self) @context = MSPhysics::BodyContext.new(self) @look_at_joint = nil @attached_bodies = {} end |
Class Method Details
.all_bodies ⇒ Array<Body>
Bodies that do not have a MSPhysics::Body instance are not included in the array.
Get all bodies.
119 120 121 |
# File 'RubyExtension/MSPhysics/body.rb', line 119 def all_bodies MSPhysics::Newton.get_all_bodies() { |ptr, data| data.is_a?(MSPhysics::Body) ? data : nil } end |
.bodies_aabb_overlap?(body1, body2) ⇒ Boolean
Determine if the bounding boxes of two bodies overlap.
71 72 73 74 |
# File 'RubyExtension/MSPhysics/body.rb', line 71 def bodies_aabb_overlap?(body1, body2) validate2(body1, body2) MSPhysics::Newton::Bodies.aabb_overlap?(body1.address, body2.address) end |
.bodies_collidable?(body1, body2) ⇒ Boolean
Determine if two bodies can collide with each other.
80 81 82 83 |
# File 'RubyExtension/MSPhysics/body.rb', line 80 def bodies_collidable?(body1, body2) validate2(body1, body2) MSPhysics::Newton::Bodies.collidable?(body1.address, body2.address) end |
.bodies_touching?(body1, body2) ⇒ Boolean
Determine if two bodies are in contact.
89 90 91 92 |
# File 'RubyExtension/MSPhysics/body.rb', line 89 def bodies_touching?(body1, body2) validate2(body1, body2) MSPhysics::Newton::Bodies.touching?(body1.address, body2.address) end |
.body_by_address(address) ⇒ Body?
Get body by body address.
62 63 64 65 |
# File 'RubyExtension/MSPhysics/body.rb', line 62 def body_by_address(address) data = MSPhysics::Newton::Body.get_user_data(address.to_i) data.is_a?(MSPhysics::Body) ? data : nil end |
.closest_points(body1, body2) ⇒ Array<Geom::Point3d>?
This works with convex and compound bodies only. Nil will be returned if one the passed bodies have a static mesh or a null collision.
Get closest collision points between two bodies.
101 102 103 104 |
# File 'RubyExtension/MSPhysics/body.rb', line 101 def closest_points(body1, body2) validate2(body1, body2) MSPhysics::Newton::Bodies.get_closest_points(body1.address, body2.address) end |
.force_between_bodies(body1, body2) ⇒ Geom::Vector3d
Get contact force between two bodies.
110 111 112 113 |
# File 'RubyExtension/MSPhysics/body.rb', line 110 def force_between_bodies(body1, body2) validate2(body1, body2) MSPhysics::Newton::Bodies.get_force_in_between(body1.address, body2.address) end |
.validate(body, world = nil) ⇒ 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 body is valid.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'RubyExtension/MSPhysics/body.rb', line 15 def validate(body, world = nil) AMS.validate_type(body, MSPhysics::Body) unless body.valid? raise(TypeError, "Body #{body} is invalid/destroyed!", caller) end if world != nil AMS.validate_type(world, MSPhysics::World) if body.world.address != world.address raise(TypeError, "Body #{body} belongs to a different world!", caller) end end end |
.validate2(body1, body2, world = nil) ⇒ 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 two bodies are valid and unique.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'RubyExtension/MSPhysics/body.rb', line 36 def validate2(body1, body2, world = nil) AMS.validate_type(body1, MSPhysics::Body) AMS.validate_type(body2, MSPhysics::Body) unless body1.valid? raise(TypeError, "Body1 #{body1} is invalid/destroyed!", caller) end unless body2.valid? raise(TypeError, "Body1 #{body1} is invalid/destroyed!", caller) end if body1.address == body2.address raise(TypeError, "Body1 #{body1} and body2 #{body2} link to the same address. Expected two unique bodies!", caller) end if world != nil AMS.validate_type(world, MSPhysics::World) if body1.world.address != world.address raise(TypeError, "Body1 #{body1} belongs to a different world!", caller) end if body2.world.address != world.address raise(TypeError, "Body2 #{body2} belongs to a different world!", caller) end end end |
Instance Method Details
#aabb ⇒ Geom::BoundingBox
Get world axes aligned bounding box (AABB) of the body.
833 834 835 836 837 |
# File 'RubyExtension/MSPhysics/body.rb', line 833 def aabb bb = Geom::BoundingBox.new bb.add MSPhysics::Newton::Body.get_aabb(@address) bb end |
#actual_matrix_scale ⇒ Geom::Vector3d
Get scale of the body matrix that is a product of group scale and collision scale.
1285 1286 1287 |
# File 'RubyExtension/MSPhysics/body.rb', line 1285 def actual_matrix_scale MSPhysics::Newton::Body.get_actual_matrix_scale(@address) end |
#add_force(force) ⇒ Boolean #add_force(fx, fy, fz) ⇒ Boolean
Unlike the #set_force, this function doesn’t overwrite original force, but rather adds force to the force accumulator.
Apply force on the body in Newtons (kg * m/s/s).
949 950 951 952 953 954 955 956 957 958 |
# File 'RubyExtension/MSPhysics/body.rb', line 949 def add_force(*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::Body.add_force(@address, data) end |
#add_impulse(center, delta_vel, timestep) ⇒ Boolean
Add an impulse to a specific point on the body.
925 926 927 |
# File 'RubyExtension/MSPhysics/body.rb', line 925 def add_impulse(center, delta_vel, timestep) MSPhysics::Newton::Body.add_impulse(@address, center, delta_vel, timestep) end |
#add_point_force(point, force) ⇒ Boolean
Add force to a specific point on the body.
913 914 915 |
# File 'RubyExtension/MSPhysics/body.rb', line 913 def add_point_force(point, force) MSPhysics::Newton::Body.add_point_force(@address, point, force) end |
#add_torque(torque) ⇒ Boolean #add_torque(tx, ty, tz) ⇒ Boolean
Unlike the #set_torque, this function doesn’t overwrite original torque, but rather adds torque to the torque accumulator.
Apply torque on the body in Newton-meters (kg * m/s/s * m).
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 |
# File 'RubyExtension/MSPhysics/body.rb', line 999 def add_torque(*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::Body.add_torque(@address, data) end |
#address ⇒ Integer
Get pointer to the body.
208 209 210 |
# File 'RubyExtension/MSPhysics/body.rb', line 208 def address @address end |
#apply_aerodynamics(drag, wind) ⇒ Boolean
WIP
Apply fluid resistance to the body. The resistance force and torque is based upon the body’s linear and angular velocity, orientation of its collision faces, and the drag coefficient.
1179 1180 1181 |
# File 'RubyExtension/MSPhysics/body.rb', line 1179 def apply_aerodynamics(drag, wind) MSPhysics::Newton::Body.apply_aerodynamics(@address, drag, wind) end |
#apply_buoyancy(plane_origin, plane_normal, density, linear_viscosity, angular_viscosity, linear_current, angular_current, timestep) ⇒ Boolean
Apply buoyancy to the body.
1162 1163 1164 |
# File 'RubyExtension/MSPhysics/body.rb', line 1162 def apply_buoyancy(plane_origin, plane_normal, density, linear_viscosity, angular_viscosity, linear_current, angular_current, timestep) MSPhysics::Newton::Body.apply_buoyancy(@address, plane_origin, plane_normal, density, linear_viscosity, angular_viscosity, linear_current, angular_current, timestep) end |
#apply_pick_and_drag(pick_pt, dest_pt, stiffness, damp, timestep) ⇒ Boolean
Apply pick and drag to the body.
1131 1132 1133 |
# File 'RubyExtension/MSPhysics/body.rb', line 1131 def apply_pick_and_drag(pick_pt, dest_pt, stiffness, damp, timestep) MSPhysics::Newton::Body.apply_pick_and_drag(@address, pick_pt, dest_pt, stiffness, damp, timestep) end |
#attach(body) ⇒ MSPhysics::Fixed
Attach a particular body to this body with a Fixed joint.
1333 1334 1335 1336 1337 1338 1339 1340 1341 |
# File 'RubyExtension/MSPhysics/body.rb', line 1333 def attach(body) Body.validate2(self, body, self.world) joint = @attached_bodies[body] return joint if joint && joint.valid? joint = MSPhysics::Fixed.new(self.world, self, body.get_position(1)) joint.connect(body) @attached_bodies[body] = joint joint end |
#attached?(body) ⇒ Boolean
Determine whether a particular body is attached to this body.
1384 1385 1386 1387 |
# File 'RubyExtension/MSPhysics/body.rb', line 1384 def attached?(body) joint = @attached_bodies[body] (joint && joint.valid?) ? true : false end |
#auto_sleep_enabled=(state) ⇒ Object
Keeping auto sleep on is a huge performance plus for simulation. Auto sleep enabled is the default state for a created body; however, for player control, AI control or some other special circumstance, the application may want to control the activation/deactivation of the body.
Set auto sleep state of the body. Auto sleep enables body to automatically go to sleep mode when at rest or become active when activated.
625 626 627 |
# File 'RubyExtension/MSPhysics/body.rb', line 625 def auto_sleep_enabled=(state) MSPhysics::Newton::Body.set_auto_sleep_state(@address, state) end |
#auto_sleep_enabled? ⇒ Boolean
Get the auto-sleep state of the body.
613 614 615 |
# File 'RubyExtension/MSPhysics/body.rb', line 613 def auto_sleep_enabled? MSPhysics::Newton::Body.get_auto_sleep_state(@address) end |
#clear_non_collidable_bodies ⇒ Integer
Remove all bodies from the non-collidable list; the bodies that were set non-collidable by the #set_non_collidable_with function.
659 660 661 |
# File 'RubyExtension/MSPhysics/body.rb', line 659 def clear_non_collidable_bodies MSPhysics::Newton::Body.clear_non_collidable_bodies(@address) end |
#collidable=(state) ⇒ Object
Set body collidable.
578 579 580 |
# File 'RubyExtension/MSPhysics/body.rb', line 578 def collidable=(state) MSPhysics::Newton::Body.set_collidable(@address, state) end |
#collidable? ⇒ Boolean
Determine whether body is collidable.
571 572 573 |
# File 'RubyExtension/MSPhysics/body.rb', line 571 def collidable? MSPhysics::Newton::Body.is_collidable?(@address) end |
#collision_address ⇒ Integer
Get pointer to the collision associated with the body.
214 215 216 |
# File 'RubyExtension/MSPhysics/body.rb', line 214 def collision_address MSPhysics::Newton::Body.get_collision(@address) end |
#collision_faces ⇒ Array<Array<Geom::Point3d>>
Get collision faces of the body.
1097 1098 1099 |
# File 'RubyExtension/MSPhysics/body.rb', line 1097 def collision_faces MSPhysics::Newton::Body.get_collision_faces(@address) end |
#collision_faces2 ⇒ Array<Array<(Array<Geom::Point3d>, Geom::Point3d, Geom::Vector3d, Numeric)>>
Get collision faces of the body.
1108 1109 1110 |
# File 'RubyExtension/MSPhysics/body.rb', line 1108 def collision_faces2 MSPhysics::Newton::Body.get_collision_faces2(@address) end |
#collision_faces3 ⇒ Array<Array<(Geom::Point3d, Geom::Vector3d, Numeric)>>
Get collision faces of the body.
1118 1119 1120 |
# File 'RubyExtension/MSPhysics/body.rb', line 1118 def collision_faces3 MSPhysics::Newton::Body.get_collision_faces3(@address) end |
#connected_bodies ⇒ Array<Body>
Get all bodies connected to this body through joints.
1235 1236 1237 1238 1239 |
# File 'RubyExtension/MSPhysics/body.rb', line 1235 def connected_bodies MSPhysics::Newton::Body.get_connected_bodies(@address) { |ptr, data| data.is_a?(MSPhysics::Body) ? data : nil } end |
#connected_joints ⇒ Array<Joint, DoubleJoint>
Get joints whose child bodies associate to this body.
1227 1228 1229 1230 1231 |
# File 'RubyExtension/MSPhysics/body.rb', line 1227 def connected_joints MSPhysics::Newton::Body.get_connected_joints(@address) { |ptr, data| data.is_a?(MSPhysics::Joint) || data.is_a?(MSPhysics::DoubleJoint) ? data : nil } end |
#contact_points(inc_non_collidable) ⇒ Array<Geom::Point3d>
Get all contact points on the body.
1088 1089 1090 |
# File 'RubyExtension/MSPhysics/body.rb', line 1088 def contact_points(inc_non_collidable) MSPhysics::Newton::Body.get_contact_points(@address, inc_non_collidable) end |
#contacts(inc_non_collidable) ⇒ Array<Contact>
Get all contacts on the body.
1061 1062 1063 1064 1065 |
# File 'RubyExtension/MSPhysics/body.rb', line 1061 def contacts(inc_non_collidable) MSPhysics::Newton::Body.get_contacts(@address, inc_non_collidable) { |ptr, data, point, normal, force, speed| data.is_a?(MSPhysics::Body) ? MSPhysics::Contact.new(data, point, normal, force, speed) : nil } end |
#contained_joints ⇒ Array<Joint, DoubleJoint>
Get joints whose parent bodies associate to this body.
1219 1220 1221 1222 1223 |
# File 'RubyExtension/MSPhysics/body.rb', line 1219 def contained_joints MSPhysics::Newton::Body.get_contained_joints(@address) { |ptr, data| data.is_a?(MSPhysics::Joint) || data.is_a?(MSPhysics::DoubleJoint) ? data : nil } end |
#context ⇒ BodyContext
Get the associated context.
239 240 241 |
# File 'RubyExtension/MSPhysics/body.rb', line 239 def context @context end |
#continuous_collision_check_enabled=(state) ⇒ Object
Continuous collision check is known to affect performance. Be cautions when using it. When performing box stacks it’s better to reduce simulation update step, to 1/256 for instance, rather than enabling continuous collision check as smaller update step will keep simulation running smoothly while avoiding penetration at the same time.
Enable/disable continuous collision check for this body. Continuous collision check prevents this body from passing through other bodies at high speeds.
271 272 273 |
# File 'RubyExtension/MSPhysics/body.rb', line 271 def continuous_collision_check_enabled=(state) MSPhysics::Newton::Body.set_continuous_collision_state(@address, state) end |
#continuous_collision_check_enabled? ⇒ Boolean
Determine whether continuous collision check is enabled for this body. Continuous collision check prevents this body from passing through other bodies at high speeds.
257 258 259 |
# File 'RubyExtension/MSPhysics/body.rb', line 257 def continuous_collision_check_enabled? MSPhysics::Newton::Body.get_continuous_collision_state(@address) end |
#copy(reapply_forces, type) ⇒ Body #copy(transformation, reapply_forces, type) ⇒ Body
Create a copy of the body.
1195 1196 1197 1198 1199 1200 1201 1202 1203 |
# File 'RubyExtension/MSPhysics/body.rb', line 1195 def copy(*args) if args.size == 2 Body.new(self, nil, args[0], args[1]) elsif args.size == 3 Body.new(self, args[0], args[1], args[2]) else raise(ArgumentError, "Wrong number of arguments! Expected 2..3 arguments but got #{args.size}.", caller) end end |
#default_collision_scale ⇒ Geom::Vector3d
Does not include group scale.
Get default scale of the body collision.
1277 1278 1279 |
# File 'RubyExtension/MSPhysics/body.rb', line 1277 def default_collision_scale MSPhysics::Newton::Body.get_default_collision_scale(@address) end |
#density ⇒ Numeric
Get body density in kilograms per cubic meter (kg / m^3).
523 524 525 |
# File 'RubyExtension/MSPhysics/body.rb', line 523 def density MSPhysics::Newton::Body.get_density(@address) end |
#density=(value) ⇒ Object
Density and mass are correlated. If you change density the mass will automatically be recalculated.
Set body density in kilograms per cubic meter (kg / m^3).
531 532 533 |
# File 'RubyExtension/MSPhysics/body.rb', line 531 def density=(value) MSPhysics::Newton::Body.set_density(@address, value) end |
#destroy(erase_entity = false) ⇒ nil
Destroy the body.
247 248 249 250 |
# File 'RubyExtension/MSPhysics/body.rb', line 247 def destroy(erase_entity = false) @group.erase! if @group.valid? && erase_entity MSPhysics::Newton::Body.destroy(@address) end |
#detach(body) ⇒ Boolean
Detach a particular attached body from this body.
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 |
# File 'RubyExtension/MSPhysics/body.rb', line 1349 def detach(body) Body.validate2(self, body, self.world) joint = @attached_bodies[body] if joint && joint.valid? joint.destroy @attached_bodies.delete(body) true else false end end |
#detach_all ⇒ Integer
Detach all attached bodies from this body.
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 |
# File 'RubyExtension/MSPhysics/body.rb', line 1366 def detach_all count = 0 @attached_bodies.each { |body, joint| if joint.valid? joint.destroy count += 1 end } @attached_bodies.clear count end |
#elasticity ⇒ Numeric
Get body coefficient of restitution - bounciness - rebound ratio.
665 666 667 |
# File 'RubyExtension/MSPhysics/body.rb', line 665 def elasticity MSPhysics::Newton::Body.get_elasticity(@address) end |
#elasticity=(coefficient) ⇒ Object
Set body coefficient of restitution - bounciness - rebound ratio.
673 674 675 |
# File 'RubyExtension/MSPhysics/body.rb', line 673 def elasticity=(coefficient) MSPhysics::Newton::Body.set_elasticity(@address, coefficient) end |
#friction_enabled=(state) ⇒ Object
Set friction state of the body.
723 724 725 |
# File 'RubyExtension/MSPhysics/body.rb', line 723 def friction_enabled=(state) MSPhysics::Newton::Body.set_friction_state(@address, state) end |
#friction_enabled? ⇒ Boolean
Get friction state of the body.
716 717 718 |
# File 'RubyExtension/MSPhysics/body.rb', line 716 def friction_enabled? MSPhysics::Newton::Body.get_friction_state(@address) end |
#frozen=(state) ⇒ Object
Set body collidable.
591 592 593 |
# File 'RubyExtension/MSPhysics/body.rb', line 591 def frozen=(state) MSPhysics::Newton::Body.set_frozen(@address, state) end |
#frozen? ⇒ Boolean
Determine whether body is frozen.
584 585 586 |
# File 'RubyExtension/MSPhysics/body.rb', line 584 def frozen? MSPhysics::Newton::Body.is_frozen?(@address) end |
#get_angular_damping ⇒ Geom::Vetor3d
Get the viscous damping coefficient applied to the omega of the body.
872 873 874 |
# File 'RubyExtension/MSPhysics/body.rb', line 872 def get_angular_damping MSPhysics::Newton::Body.get_angular_damping(@address) end |
#get_centre_of_mass ⇒ Geom::Point3d
Get centre of mass of the body in local coordinates.
457 458 459 |
# File 'RubyExtension/MSPhysics/body.rb', line 457 def get_centre_of_mass MSPhysics::Newton::Body.get_centre_of_mass(@address) end |
#get_collision_scale ⇒ Geom::Vector3d
Does not include group scale.
Get body collision scale.
1245 1246 1247 |
# File 'RubyExtension/MSPhysics/body.rb', line 1245 def get_collision_scale MSPhysics::Newton::Body.get_collision_scale(@address) end |
#get_euler_angles ⇒ Geom::Vector3d
Get body orientation in form of the three Euler angles.
350 351 352 |
# File 'RubyExtension/MSPhysics/body.rb', line 350 def get_euler_angles MSPhysics::Newton::Body.get_euler_angles(@address) end |
#get_force ⇒ Geom::Vector3d
This does not include contact and joint reaction forces.
Get the net force, in Newtons, applied on the body after the last world update.
935 936 937 |
# File 'RubyExtension/MSPhysics/body.rb', line 935 def get_force MSPhysics::Newton::Body.get_force(@address) end |
#get_linear_damping ⇒ Geom::Vetor3d
Get the viscous damping coefficient applied to the velocity of the body.
842 843 844 |
# File 'RubyExtension/MSPhysics/body.rb', line 842 def get_linear_damping MSPhysics::Newton::Body.get_linear_damping(@address) end |
#get_matrix ⇒ Geom::Transformation
Get body transformation matrix.
283 284 285 |
# File 'RubyExtension/MSPhysics/body.rb', line 283 def get_matrix MSPhysics::Newton::Body.get_matrix(@address) end |
#get_non_collidable_bodies ⇒ Array<Body>
Get all bodies that are non-collidable with this body; the bodies that were set non-collidable by the #set_non_collidable_with function.
650 651 652 653 654 |
# File 'RubyExtension/MSPhysics/body.rb', line 650 def get_non_collidable_bodies MSPhysics::Newton::Body.get_non_collidable_bodies(@address) { |ptr, data| data.is_a?(MSPhysics::Body) ? data : nil } end |
#get_omega ⇒ Geom::Vector3d
Get global angular velocity of the body.
428 429 430 |
# File 'RubyExtension/MSPhysics/body.rb', line 428 def get_omega MSPhysics::Newton::Body.get_omega(@address) end |
#get_position(mode = 0) ⇒ Geom::Point3d
Get body position.
302 303 304 |
# File 'RubyExtension/MSPhysics/body.rb', line 302 def get_position(mode = 0) MSPhysics::Newton::Body.get_position(@address, mode.to_i) end |
#get_torque ⇒ Geom::Vector3d
This does not include contact and joint reaction torques.
Get the net torque, in Newton-meters, applied on the body after the last world update.
985 986 987 |
# File 'RubyExtension/MSPhysics/body.rb', line 985 def get_torque MSPhysics::Newton::Body.get_torque(@address) end |
#get_velocity ⇒ Geom::Vector3d
Get global linear velocity of the body.
378 379 380 |
# File 'RubyExtension/MSPhysics/body.rb', line 378 def get_velocity MSPhysics::Newton::Body.get_velocity(@address) end |
#gravity_enabled=(state) ⇒ Object
Enable/disable gravitational force on this body.
1207 1208 1209 |
# File 'RubyExtension/MSPhysics/body.rb', line 1207 def gravity_enabled=(state) MSPhysics::Newton::Body.enable_gravity(@address, state) end |
#gravity_enabled? ⇒ Boolean
Determine if gravitational force is enabled on this body.
1213 1214 1215 |
# File 'RubyExtension/MSPhysics/body.rb', line 1213 def gravity_enabled? MSPhysics::Newton::Body.is_gravity_enabled?(@address) end |
#group ⇒ Sketchup::Group, Sketchup::ComponentInstance
Get the group/component associated with the body.
220 221 222 |
# File 'RubyExtension/MSPhysics/body.rb', line 220 def group @group end |
#inertia ⇒ Geom::Vector3d
Inertia is the rotational equivalent of mass. It may be used for damping angular velocity through applying dissipative torque.
If the body is static or has a zero mass, the magnitude of the return inertia will be zero.
Get body local inertia.
503 504 505 |
# File 'RubyExtension/MSPhysics/body.rb', line 503 def inertia MSPhysics::Newton::Body.get_inertia(@address) end |
#integrate_velocity(timestep) ⇒ nil
For this function to have an effect, the body must be kinematic and have a non-zero mass (non-static).
Integrate linear and angular velocity of the body.
416 417 418 |
# File 'RubyExtension/MSPhysics/body.rb', line 416 def integrate_velocity(timestep) MSPhysics::Newton::Body.integrate_velocity(@address, timestep) end |
#kinetic_friction ⇒ Numeric
Get kinetic friction coefficient of the body.
703 704 705 |
# File 'RubyExtension/MSPhysics/body.rb', line 703 def kinetic_friction MSPhysics::Newton::Body.get_kinetic_friction(@address) end |
#kinetic_friction=(coefficient) ⇒ Object
Set kinetic friction coefficient of the body.
709 710 711 |
# File 'RubyExtension/MSPhysics/body.rb', line 709 def kinetic_friction=(coefficient) MSPhysics::Newton::Body.set_kinetic_friction(@address, coefficient) end |
#look_at(pin_dir, accel = 40, damp = 10, strength = 0.9) ⇒ MSPhysics::UpVector?
Make the body’s Z-axis to look in a particular direction.
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 |
# File 'RubyExtension/MSPhysics/body.rb', line 1307 def look_at(pin_dir, accel = 40, damp = 10, strength = 0.9) if pin_dir.nil? if @look_at_joint && @look_at_joint.valid? @look_at_joint.destroy @look_at_joint = nil end return end pin_dir = Geom::Vector3d.new(pin_dir) unless pin_dir.is_a?(Geom::Vector3d) if @look_at_joint.nil? || !@look_at_joint.valid? @look_at_joint = MSPhysics::UpVector.new(self.world, nil, Geom::Transformation.new(ORIGIN, @group.transformation.zaxis)) @look_at_joint.connect(self) end @look_at_joint.set_pin_dir(pin_dir.transform(@look_at_joint.get_pin_matrix.inverse)) @look_at_joint.accel = accel @look_at_joint.damp = damp @look_at_joint.strength = strength return @look_at_joint end |
#magnet_force ⇒ Numeric
This option has an effect if and only if magnet_mode is set to 1.
Get the maximum magnet force in Newton to be applied on the surrounding magnetic bodies.
766 767 768 |
# File 'RubyExtension/MSPhysics/body.rb', line 766 def magnet_force MSPhysics::Newton::Body.get_magnet_force(@address) end |
#magnet_force=(force) ⇒ Object
This option has an effect if and only if magnet_mode is set to 1.
Set the maximum magnet force in Newton to be applied on the surrounding magnetic bodies.
775 776 777 |
# File 'RubyExtension/MSPhysics/body.rb', line 775 def magnet_force=(force) MSPhysics::Newton::Body.set_magnet_force(@address, force) end |
#magnet_mode ⇒ Integer
Get the mode for controlling the way this magnet should work.
-
1; to have the magnet force be calculated with the following equation: actual_magnet_force = f * (d - r)^2 / r^2; where f is the maximum magnet force (in Newtons), d is the distance between this magnet and a magnetic body (in meters), and r is the maximum magnet range (in meters). In this mode, the magnet_force and magnet_range methods are used for controlling the magnet.
-
2; to have magnet force be computed with a slightly different equation: actual_magnet_force = s / d^2; where s is the magnet strength and d is the distance between this magnet and a magnetic body (in meters). In this mode, the magnet_strength method must be used for controlling the magnet.
740 741 742 |
# File 'RubyExtension/MSPhysics/body.rb', line 740 def magnet_mode MSPhysics::Newton::Body.get_magnet_mode(@address) end |
#magnet_mode=(mode) ⇒ Object
Set the mode for controlling the way this magnet should work.
-
Pass 1 to have the magnet force be calculated with the following equation: actual_magnet_force = f * (d - r)^2 / r^2; where f is the maximum magnet force (in Newtons), d is the distance between this magnet and a magnetic body (in meters), and r is the maximum magnet range (in meters). In this mode, the magnet_force and magnet_range methods are used for controlling the magnet.
-
Pass 2 to have magnet force be computed with a slightly different equation: actual_magnet_force = s / d^2; where s is the magnet strength and d is the distance between this magnet and a magnetic body (in meters). In this mode, the magnet_strength method must be used for controlling the magnet.
757 758 759 |
# File 'RubyExtension/MSPhysics/body.rb', line 757 def magnet_mode=(mode) MSPhysics::Newton::Body.set_magnet_mode(@address, mode) end |
#magnet_range ⇒ Numeric
This option has an effect if and only if magnet_mode is set to 1.
Get the maximum magnet range in meters. Magnet force is distributed along the magnet range. Magnetic bodies outside the magnet range are not affected.
785 786 787 |
# File 'RubyExtension/MSPhysics/body.rb', line 785 def magnet_range MSPhysics::Newton::Body.get_magnet_range(@address) end |
#magnet_range=(range) ⇒ Object
This option has an effect if and only if magnet_mode is set to 1.
Set the maximum magnet range in meters. Magnet force is distributed along the magnet range. Magnetic bodies outside the magnet range are not affected.
795 796 797 |
# File 'RubyExtension/MSPhysics/body.rb', line 795 def magnet_range=(range) MSPhysics::Newton::Body.set_magnet_range(@address, range) end |
#magnet_strength ⇒ Numeric
This option has an effect if and only if magnet_mode is set to 2.
Get the magnet force magnitude to be applied on the surrounding magnetic bodies.
804 805 806 |
# File 'RubyExtension/MSPhysics/body.rb', line 804 def magnet_strength MSPhysics::Newton::Body.get_magnet_strength(@address) end |
#magnet_strength=(magnitude) ⇒ Object
This option has an effect if and only if magnet_mode is set to 2.
Set the magnet force magnitude to be applied on the surrounding magnetic bodies.
813 814 815 |
# File 'RubyExtension/MSPhysics/body.rb', line 813 def magnet_strength=(magnitude) MSPhysics::Newton::Body.set_magnet_strength(@address, magnitude) end |
#magnetic=(state) ⇒ Object
Set body magnetic. Magnetic bodies will be affected by other bodies with magnetism.
827 828 829 |
# File 'RubyExtension/MSPhysics/body.rb', line 827 def magnetic=(state) MSPhysics::Newton::Body.set_magnetic(@address, state) end |
#magnetic? ⇒ Boolean
Determine whether body is magnetic.
819 820 821 |
# File 'RubyExtension/MSPhysics/body.rb', line 819 def magnetic? MSPhysics::Newton::Body.is_magnetic?(@address) end |
#mass ⇒ Numeric
Get body mass in kilograms (kg).
509 510 511 |
# File 'RubyExtension/MSPhysics/body.rb', line 509 def mass MSPhysics::Newton::Body.get_mass(@address) end |
#mass=(value) ⇒ Object
Mass and density are correlated. If you change mass the density will automatically be recalculated.
Set body mass in kilograms (kg).
517 518 519 |
# File 'RubyExtension/MSPhysics/body.rb', line 517 def mass=(value) MSPhysics::Newton::Body.set_mass(@address, value) end |
#net_contact_force ⇒ Geom::Vector3d
Get total force generated from contacts on the body.
1053 1054 1055 |
# File 'RubyExtension/MSPhysics/body.rb', line 1053 def net_contact_force MSPhysics::Newton::Body.get_net_contact_force(@address) end |
#net_joint_force ⇒ Geom::Vector3d
Get total linear tension, in Newtons, applied by contained and connected joints.
1038 1039 1040 |
# File 'RubyExtension/MSPhysics/body.rb', line 1038 def net_joint_force MSPhysics::Newton::Body.get_net_joint_tension1(@address) end |
#net_joint_torque ⇒ Geom::Vector3d
Get total angular tension, in Newton-meters, applied by contained and connected joints.
1046 1047 1048 |
# File 'RubyExtension/MSPhysics/body.rb', line 1046 def net_joint_torque MSPhysics::Newton::Body.get_net_joint_tension2(@address) end |
#non_collidable_with?(body) ⇒ Boolean
Determine whether this body is non-collidable with a particular body.
633 634 635 |
# File 'RubyExtension/MSPhysics/body.rb', line 633 def non_collidable_with?(body) MSPhysics::Newton::Body.is_non_collidable_with?(@address, body.address) end |
#normal_matrix ⇒ Geom::transformation
Get body matrix with no scale factors.
277 278 279 |
# File 'RubyExtension/MSPhysics/body.rb', line 277 def normal_matrix MSPhysics::Newton::Body.get_normal_matrix(@address) end |
#point_velocity(point) ⇒ Geom::Vector3d
Get velocity at a specific point on the body.
903 904 905 |
# File 'RubyExtension/MSPhysics/body.rb', line 903 def point_velocity(point) MSPhysics::Newton::Body.get_point_velocity(@address, point) end |
#reset_mass_properties(density) ⇒ Boolean
Reset/recalculate body volume and mass.
552 553 554 |
# File 'RubyExtension/MSPhysics/body.rb', line 552 def reset_mass_properties(density) MSPhysics::Newton::Body.reset_mass_properties(@address, density) end |
#rotation ⇒ Array<Numeric>
Get body orientation in form of the unit quaternion.
343 344 345 |
# File 'RubyExtension/MSPhysics/body.rb', line 343 def rotation MSPhysics::Newton::Body.get_rotation(@address) end |
#set_angular_damping(damp) ⇒ nil #set_angular_damping(dx, dy, dz) ⇒ nil
Set the viscous damping coefficient applied to the omega of the body.
888 889 890 891 892 893 894 895 896 897 |
# File 'RubyExtension/MSPhysics/body.rb', line 888 def set_angular_damping(*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::Body.set_angular_damping(@address, data) end |
#set_centre_of_mass(centre) ⇒ nil #set_velocity(px, py, pz) ⇒ nil
Set centre of mass of the body in local coordinates.
470 471 472 473 474 475 476 477 478 479 |
# File 'RubyExtension/MSPhysics/body.rb', line 470 def set_centre_of_mass(*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::Body.set_centre_of_mass(@address, data) end |
#set_collision_scale(scale) ⇒ nil #set_collision_scale(sx, sy, sz) ⇒ nil
Does not include group scale.
Set body collision scale.
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 |
# File 'RubyExtension/MSPhysics/body.rb', line 1262 def set_collision_scale(*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::Body.set_collision_scale(@address, data) end |
#set_euler_angles(angles) ⇒ nil #set_euler_angles(roll, yaw, pitch) ⇒ nil
The angles are assumed in radians.
Set body orientation via the three Euler angles.
364 365 366 367 368 369 370 371 372 373 |
# File 'RubyExtension/MSPhysics/body.rb', line 364 def set_euler_angles(*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::Body.set_euler_angles(@address, data) end |
#set_force(force) ⇒ Boolean #set_force(fx, fy, fz) ⇒ Boolean
Unlike the #add_force, this function overwrites original force, thus discarding the previously applied force.
Apply force on the body in Newton (kg * m/s/s).
970 971 972 973 974 975 976 977 978 979 |
# File 'RubyExtension/MSPhysics/body.rb', line 970 def set_force(*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::Body.set_force(@address, data) end |
#set_linear_damping(damp) ⇒ Object #set_linear_damping(dx, dy, dz) ⇒ Object
Set the viscous damping coefficient applied to the velocity of the body.
858 859 860 861 862 863 864 865 866 867 |
# File 'RubyExtension/MSPhysics/body.rb', line 858 def set_linear_damping(*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::Body.set_linear_damping(@address, data) end |
#set_matrix(matrix) ⇒ nil
Set body transformation matrix.
293 294 295 |
# File 'RubyExtension/MSPhysics/body.rb', line 293 def set_matrix(matrix) MSPhysics::Newton::Body.set_matrix(@address, matrix) end |
#set_non_collidable_with(body, state) ⇒ nil
Set this body non-collidable with a particular body.
642 643 644 645 |
# File 'RubyExtension/MSPhysics/body.rb', line 642 def set_non_collidable_with(body, state) Body.validate2(self, body, self.world) MSPhysics::Newton::Body.set_non_collidable_with(@address, body.address, state) end |
#set_omega(omega) ⇒ nil #set_omega(vx, vy, vz) ⇒ nil
Set global angular velocity of the body.
441 442 443 444 445 446 447 448 449 450 |
# File 'RubyExtension/MSPhysics/body.rb', line 441 def set_omega(*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::Body.set_omega(@address, data) end |
#set_position(position, mode = 0) ⇒ nil #set_position(px, py, pz, mode = 0) ⇒ nil
Set body position.
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'RubyExtension/MSPhysics/body.rb', line 322 def set_position(*args) mode = 0 if args.size == 4 point = [args[0], args[1], args[2]] mode = args[3] elsif args.size == 3 point = [args[0], args[1], args[2]] elsif args.size == 2 point = args[0] mode = args[1] elsif args.size == 1 point = args[0] else raise(ArgumentError, "Wrong number of arguments! Expected 1..4 arguments but got #{args.size}.", caller) end MSPhysics::Newton::Body.set_position(@address, point, mode) end |
#set_torque(torque) ⇒ Boolean #set_torque(tx, ty, tz) ⇒ Boolean
Unlike the #add_torque, this function overwrites original torque, thus discarding the previously applied torque.
Apply torque on the body in Newton-meters (kg * m/s/s * m).
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 |
# File 'RubyExtension/MSPhysics/body.rb', line 1020 def set_torque(*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::Body.set_torque(@address, data) end |
#set_velocity(velocity) ⇒ nil #set_velocity(vx, vy, vz) ⇒ nil
Set global linear velocity of the body.
391 392 393 394 395 396 397 398 399 400 |
# File 'RubyExtension/MSPhysics/body.rb', line 391 def set_velocity(*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::Body.set_velocity(@address, data) end |
#sleeping=(state) ⇒ Object
This function can only set body active, the sleeping is controlled by equilibrium.
Set body sleeping.
606 607 608 |
# File 'RubyExtension/MSPhysics/body.rb', line 606 def sleeping=(state) MSPhysics::Newton::Body.set_sleeping(@address, state) end |
#sleeping? ⇒ Boolean
Determine whether body is sleeping. Sleeping bodies are bodies at rest.
597 598 599 |
# File 'RubyExtension/MSPhysics/body.rb', line 597 def sleeping? MSPhysics::Newton::Body.is_sleeping?(@address) end |
#softness ⇒ Numeric
Get contact softness coefficient of the body.
679 680 681 |
# File 'RubyExtension/MSPhysics/body.rb', line 679 def softness MSPhysics::Newton::Body.get_softness(@address) end |
#softness=(coefficient) ⇒ Object
Set contact softness coefficient of the body.
685 686 687 |
# File 'RubyExtension/MSPhysics/body.rb', line 685 def softness=(coefficient) MSPhysics::Newton::Body.set_softness(@address, coefficient) end |
#static=(state) ⇒ Object
Set body static.
565 566 567 |
# File 'RubyExtension/MSPhysics/body.rb', line 565 def static=(state) MSPhysics::Newton::Body.set_static(@address, state) end |
#static? ⇒ Boolean
Determine whether body is static.
558 559 560 |
# File 'RubyExtension/MSPhysics/body.rb', line 558 def static? MSPhysics::Newton::Body.is_static?(@address) end |
#static_friction ⇒ Numeric
Get static friction coefficient of the body.
691 692 693 |
# File 'RubyExtension/MSPhysics/body.rb', line 691 def static_friction MSPhysics::Newton::Body.get_static_friction(@address) end |
#static_friction=(coefficient) ⇒ Object
Set static friction coefficient of the body.
697 698 699 |
# File 'RubyExtension/MSPhysics/body.rb', line 697 def static_friction=(coefficient) MSPhysics::Newton::Body.set_static_friction(@address, coefficient) end |
#touching_bodies(inc_non_collidable) ⇒ Array<Body>
Get all bodies that are in contact with this body.
1071 1072 1073 1074 1075 |
# File 'RubyExtension/MSPhysics/body.rb', line 1071 def touching_bodies(inc_non_collidable) MSPhysics::Newton::Body.get_touching_bodies(@address, inc_non_collidable) { |ptr, data| data.is_a?(MSPhysics::Body) ? data : nil } end |
#touching_with?(body) ⇒ Boolean
Determine if this body is in contact with another body.
1080 1081 1082 |
# File 'RubyExtension/MSPhysics/body.rb', line 1080 def touching_with?(body) MSPhysics::Newton::Bodies.touching?(@address, body.address) end |
#type ⇒ Integer
Get body type.
226 227 228 |
# File 'RubyExtension/MSPhysics/body.rb', line 226 def type MSPhysics::Newton::Body.get_type(@address) end |
#valid? ⇒ Boolean
Determine whether this body is valid - not destroyed.
202 203 204 |
# File 'RubyExtension/MSPhysics/body.rb', line 202 def valid? MSPhysics::Newton::Body.is_valid?(@address) end |
#volume ⇒ Numeric
Get body volume in cubic meters (m^3).
537 538 539 |
# File 'RubyExtension/MSPhysics/body.rb', line 537 def volume MSPhysics::Newton::Body.get_volume(@address) end |
#volume=(value) ⇒ Object
Volume and mass are correlated. If you change volume the mass will automatically be recalculated.
Set body volume in cubic meters (m^3).
545 546 547 |
# File 'RubyExtension/MSPhysics/body.rb', line 545 def volume=(value) MSPhysics::Newton::Body.set_volume(@address, value) end |