Class: MSPhysics::Gear
Overview
Constant Summary collapse
- DEFAULT_RATIO =
1.0
Class Method Summary collapse
-
.all_gears ⇒ Array<Gear>
Get all gears.
-
.gear_by_address(address) ⇒ Gear?
Get gear by address.
-
.validate(gear, world = nil) ⇒ void
private
Verify that gear is valid.
Instance Method Summary collapse
-
#address ⇒ Integer
Get pointer the gear.
-
#destroy ⇒ void
Destroy gear.
-
#initialize(world, joint1, joint2) ⇒ Gear
constructor
A new instance of Gear.
-
#joint1 ⇒ MSPhysics::Joint
Get the first joint the gear is linked to.
-
#joint2 ⇒ MSPhysics::Joint
Get the second joint the gear is linked to.
-
#ratio ⇒ Numeric
Get gear ratio.
-
#ratio=(value) ⇒ Object
Set gear ratio.
-
#valid? ⇒ Boolean
Determine whether gear is valid.
-
#world ⇒ MSPhysics::World
Get the world the gear is associated to.
Methods inherited from Entity
Constructor Details
#initialize(world, joint1, joint2) ⇒ Gear
Returns a new instance of Gear.
51 52 53 54 55 56 57 58 |
# File 'RubyExtension/MSPhysics/gear.rb', line 51 def initialize(world, joint1, joint2) MSPhysics::World.validate(world) MSPhysics::Joint.validate(joint1, world) MSPhysics::Joint.validate(joint2, world) @address = MSPhysics::Newton::Gear.create(world.address, joint1.address, joint2.address) MSPhysics::Newton::Gear.set_user_data(@address, self) MSPhysics::Newton::Gear.set_ratio(@address, DEFAULT_RATIO) end |
Class Method Details
.all_gears ⇒ Array<Gear>
Gears that do not have a MSPhysics::Gear instance are not included in the array.
Get all gears.
42 43 44 |
# File 'RubyExtension/MSPhysics/gear.rb', line 42 def all_gears MSPhysics::Newton.get_all_gears() { |ptr, data| data.is_a?(MSPhysics::Gear) ? data : nil } end |
.gear_by_address(address) ⇒ Gear?
Get gear by address.
33 34 35 36 |
# File 'RubyExtension/MSPhysics/gear.rb', line 33 def gear_by_address(address) data = MSPhysics::Newton::Gear.get_user_data(address.to_i) data.is_a?(MSPhysics::Gear) ? data : nil end |
.validate(gear, 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 gear is valid.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'RubyExtension/MSPhysics/gear.rb', line 16 def validate(gear, world = nil) AMS.validate_type(gear, MSPhysics::Gear) unless gear.valid? raise(TypeError, "Gear #{gear} is invalid/destroyed!", caller) end if world != nil AMS.validate_type(world, MSPhysics::World) if gear.world.address != world.address raise(TypeError, "Gear #{gear} belongs to a different world!", caller) end end end |
Instance Method Details
#address ⇒ Integer
Get pointer the gear.
68 69 70 |
# File 'RubyExtension/MSPhysics/gear.rb', line 68 def address @address end |
#destroy ⇒ void
This method returns an undefined value.
Destroy gear.
95 96 97 |
# File 'RubyExtension/MSPhysics/gear.rb', line 95 def destroy MSPhysics::Newton::Gear.destroy(@address) end |
#joint1 ⇒ MSPhysics::Joint
Get the first joint the gear is linked to.
81 82 83 84 |
# File 'RubyExtension/MSPhysics/gear.rb', line 81 def joint1 joint1_address = MSPhysics::Newton::Gear.get_joint1(@address) MSPhysics::Newton::Joint.get_user_data(joint1_address) end |
#joint2 ⇒ MSPhysics::Joint
Get the second joint the gear is linked to.
88 89 90 91 |
# File 'RubyExtension/MSPhysics/gear.rb', line 88 def joint2 joint2_address = MSPhysics::Newton::Gear.get_joint2(@address) MSPhysics::Newton::Joint.get_user_data(joint2_address) end |
#ratio ⇒ Numeric
Get gear ratio.
101 102 103 |
# File 'RubyExtension/MSPhysics/gear.rb', line 101 def ratio MSPhysics::Newton::Gear.get_ratio(@address) end |
#ratio=(value) ⇒ Object
Set gear ratio.
107 108 109 |
# File 'RubyExtension/MSPhysics/gear.rb', line 107 def ratio=(value) MSPhysics::Newton::Gear.set_ratio(@address, value) end |
#valid? ⇒ Boolean
Determine whether gear is valid.
62 63 64 |
# File 'RubyExtension/MSPhysics/gear.rb', line 62 def valid? MSPhysics::Newton::Gear.is_valid?(@address) end |
#world ⇒ MSPhysics::World
Get the world the gear is associated to.
74 75 76 77 |
# File 'RubyExtension/MSPhysics/gear.rb', line 74 def world world_address = MSPhysics::Newton::Gear.get_world(@address) MSPhysics::Newton::Gear.get_user_data(world_address) end |