Class: MSPhysics::Joint
- Defined in:
- RubyExtension/MSPhysics/joint.rb
Overview
An abstract for all joints.
Direct Known Subclasses
BallAndSocket, Corkscrew, CurvyPiston, CurvySlider, Fixed, Hinge, Motor, Piston, Plane, PointToPoint, Servo, Slider, Spring, Universal, UpVector
Constant Summary collapse
- DEFAULT_SOLVER_MODEL =
2
- DEFAULT_STIFFNESS =
1.00
- DEFAULT_BODIES_COLLIDABLE =
false
- DEFAULT_BREAKING_FORCE =
0.0
Class Method Summary collapse
-
.all_joints ⇒ Array<Joint>
Get all joints.
-
.joint_by_address(address) ⇒ Joint?
Get joint by address.
-
.validate(joint, world = nil) ⇒ void
private
Verify that joint is valid.
Instance Method Summary collapse
-
#address ⇒ Integer
Get pointer the joint.
-
#bodies_collidable=(state) ⇒ Object
Set parent body collidable/noncollidable with its child body.
-
#bodies_collidable? ⇒ Boolean
Determine whether parent body is collidable with its child body.
-
#breaking_force ⇒ Numeric
Get joint breaking force in Newtons.
-
#breaking_force=(force) ⇒ Object
Set joint breaking force in Newtons.
-
#child ⇒ MSPhysics::Body?
Get joint child body.
-
#connect(child) ⇒ Boolean
Connect joint to its desired child body.
-
#connected? ⇒ Boolean
Determine whether joint is connected to its child body.
-
#destroy ⇒ void
Destroy joint.
-
#disconnect ⇒ Boolean
Disconnect joint from its child body.
-
#dof ⇒ Integer
Get joint maximum degrees of freedom.
-
#get_pin_matrix ⇒ Geom::Transformation
Get joint pin transformation in global space.
-
#get_pin_matrix2(mode) ⇒ Geom::Transformation?
Get joint pin transformation in global space.
-
#get_tension1 ⇒ Geom::Vecotor3d
Get primary tension force on a joint, which is usually the linear tension, in Newtons, in global space.
-
#get_tension2 ⇒ Geom::Vecotor3d
Get secondary tension force on a joint, which is usually the angular tension, in Newton-meters, in global space.
-
#group ⇒ Sketchup::Group, ...
Get group/component associated with the joint.
-
#initialize(world, parent, pin_tra, group_inst = nil) ⇒ Joint
constructor
A new instance of Joint.
-
#name ⇒ String
Get joint name.
-
#name=(value) ⇒ Object
Set joint name.
-
#parent ⇒ MSPhysics::Body?
Get joint parent body.
-
#set_pin_matrix(matrix) ⇒ nil
Set joint pin transformation in global space.
-
#solver_model ⇒ Integer
Get solver model for calculating the constraint forces.
-
#solver_model=(model) ⇒ Object
Set solver model for calculating the constraint forces.
-
#stiffness ⇒ Numeric
Get joint stiffness.
-
#stiffness=(value) ⇒ Object
Set joint stiffness.
-
#type ⇒ Integer
Get joint type.
-
#valid? ⇒ Boolean
Determine whether joint is valid.
-
#world ⇒ MSPhysics::World
Get the world the joint is associated to.
Methods inherited from Entity
Constructor Details
#initialize(world, parent, pin_tra, group_inst = nil) ⇒ Joint
Returns a new instance of Joint.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'RubyExtension/MSPhysics/joint.rb', line 58 def initialize(world, parent, pin_tra, group_inst = nil) if self.class == MSPhysics::Joint raise(TypeError, "Creating an instance of the Joint abstract class is not allowed!", caller) end MSPhysics::World.validate(world) MSPhysics::Body.validate(parent, world) if parent parent_address = parent ? parent.address : nil @address = MSPhysics::Newton::Joint.create(world.address, parent_address, pin_tra, group_inst) MSPhysics::Newton::Joint.set_user_data(@address, self) MSPhysics::Newton::Joint.set_stiffness(@address, DEFAULT_STIFFNESS) MSPhysics::Newton::Joint.set_bodies_collidable(@address, DEFAULT_BODIES_COLLIDABLE) MSPhysics::Newton::Joint.set_breaking_force(@address, DEFAULT_BREAKING_FORCE) MSPhysics::Newton::Joint.set_solver_model(@address, DEFAULT_SOLVER_MODEL) @name = '' end |
Class Method Details
.all_joints ⇒ Array<Joint>
Joints that do not have a MSPhysics::Joint instance are not included in the array.
Get all joints.
46 47 48 |
# File 'RubyExtension/MSPhysics/joint.rb', line 46 def all_joints MSPhysics::Newton.get_all_joints() { |ptr, data| data.is_a?(MSPhysics::Joint) ? data : nil } end |
.joint_by_address(address) ⇒ Joint?
Get joint by address.
37 38 39 40 |
# File 'RubyExtension/MSPhysics/joint.rb', line 37 def joint_by_address(address) data = MSPhysics::Newton::Joint.get_user_data(address.to_i) data.is_a?(MSPhysics::Joint) ? data : nil end |
.validate(joint, 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 joint is valid.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'RubyExtension/MSPhysics/joint.rb', line 20 def validate(joint, world = nil) AMS.validate_type(joint, MSPhysics::Joint) unless joint.valid? raise(TypeError, "Joint #{joint} is invalid/destroyed!", caller) end if world != nil AMS.validate_type(world, MSPhysics::World) if joint.world.address != world.address raise(TypeError, "Joint #{joint} belongs to a different world!", caller) end end end |
Instance Method Details
#address ⇒ Integer
Get pointer the joint.
82 83 84 |
# File 'RubyExtension/MSPhysics/joint.rb', line 82 def address @address end |
#bodies_collidable=(state) ⇒ Object
Set parent body collidable/noncollidable with its child body.
186 187 188 |
# File 'RubyExtension/MSPhysics/joint.rb', line 186 def bodies_collidable=(state) MSPhysics::Newton::Joint.set_bodies_collidable(@address, state) end |
#bodies_collidable? ⇒ Boolean
Determine whether parent body is collidable with its child body.
180 181 182 |
# File 'RubyExtension/MSPhysics/joint.rb', line 180 def bodies_collidable? MSPhysics::Newton::Joint.bodies_collidable?(@address) end |
#breaking_force ⇒ Numeric
Get joint breaking force in Newtons.
204 205 206 |
# File 'RubyExtension/MSPhysics/joint.rb', line 204 def breaking_force MSPhysics::Newton::Joint.get_breaking_force(@address) end |
#breaking_force=(force) ⇒ Object
Set joint breaking force in Newtons.
210 211 212 |
# File 'RubyExtension/MSPhysics/joint.rb', line 210 def breaking_force=(force) MSPhysics::Newton::Joint.set_breaking_force(@address, force) end |
#child ⇒ MSPhysics::Body?
Get joint child body.
147 148 149 150 |
# File 'RubyExtension/MSPhysics/joint.rb', line 147 def child address = MSPhysics::Newton::Joint.get_child(@address) address ? MSPhysics::Body.body_by_address(address) : nil end |
#connect(child) ⇒ Boolean
Connect joint to its desired child body.
108 109 110 111 |
# File 'RubyExtension/MSPhysics/joint.rb', line 108 def connect(child) MSPhysics::Body.validate(child, self.world) MSPhysics::Newton::Joint.connect(@address, child.address) end |
#connected? ⇒ Boolean
Determine whether joint is connected to its child body.
121 122 123 |
# File 'RubyExtension/MSPhysics/joint.rb', line 121 def connected? MSPhysics::Newton::Joint.is_connected?(@address) end |
#destroy ⇒ void
This method returns an undefined value.
Destroy joint.
101 102 103 |
# File 'RubyExtension/MSPhysics/joint.rb', line 101 def destroy MSPhysics::Newton::Joint.destroy(@address) end |
#disconnect ⇒ Boolean
Disconnect joint from its child body.
115 116 117 |
# File 'RubyExtension/MSPhysics/joint.rb', line 115 def disconnect MSPhysics::Newton::Joint.disconnect(@address) end |
#dof ⇒ Integer
Get joint maximum degrees of freedom.
127 128 129 |
# File 'RubyExtension/MSPhysics/joint.rb', line 127 def dof MSPhysics::Newton::Joint.get_dof(@address) end |
#get_pin_matrix ⇒ Geom::Transformation
Get joint pin transformation in global space.
154 155 156 |
# File 'RubyExtension/MSPhysics/joint.rb', line 154 def get_pin_matrix MSPhysics::Newton::Joint.get_pin_matrix(@address) end |
#get_pin_matrix2(mode) ⇒ Geom::Transformation?
Get joint pin transformation in global space.
174 175 176 |
# File 'RubyExtension/MSPhysics/joint.rb', line 174 def get_pin_matrix2(mode) MSPhysics::Newton::Joint.get_pin_matrix2(@address, mode) end |
#get_tension1 ⇒ Geom::Vecotor3d
Get primary tension force on a joint, which is usually the linear tension, in Newtons, in global space.
236 237 238 |
# File 'RubyExtension/MSPhysics/joint.rb', line 236 def get_tension1 MSPhysics::Newton::Joint.get_tension1(@address) end |
#get_tension2 ⇒ Geom::Vecotor3d
Get secondary tension force on a joint, which is usually the angular tension, in Newton-meters, in global space.
244 245 246 |
# File 'RubyExtension/MSPhysics/joint.rb', line 244 def get_tension2 MSPhysics::Newton::Joint.get_tension2(@address) end |
#group ⇒ Sketchup::Group, ...
Get group/component associated with the joint.
88 89 90 |
# File 'RubyExtension/MSPhysics/joint.rb', line 88 def group MSPhysics::Newton::Joint.get_group(@address) end |
#name ⇒ String
Get joint name.
250 251 252 |
# File 'RubyExtension/MSPhysics/joint.rb', line 250 def name @name.dup end |
#name=(value) ⇒ Object
Set joint name
256 257 258 |
# File 'RubyExtension/MSPhysics/joint.rb', line 256 def name=(value) @name = value.to_s.dup end |
#parent ⇒ MSPhysics::Body?
Get joint parent body.
140 141 142 143 |
# File 'RubyExtension/MSPhysics/joint.rb', line 140 def parent address = MSPhysics::Newton::Joint.get_parent(@address) address ? MSPhysics::Body.body_by_address(address) : nil end |
#set_pin_matrix(matrix) ⇒ nil
Set joint pin transformation in global space.
161 162 163 |
# File 'RubyExtension/MSPhysics/joint.rb', line 161 def set_pin_matrix(matrix) MSPhysics::Newton::Joint.set_pin_matrix(@address, matrix) end |
#solver_model ⇒ Integer
Get solver model for calculating the constraint forces.
219 220 221 |
# File 'RubyExtension/MSPhysics/joint.rb', line 219 def solver_model MSPhysics::Newton::Joint.get_solver_model(@address) end |
#solver_model=(model) ⇒ Object
Set solver model for calculating the constraint forces.
228 229 230 |
# File 'RubyExtension/MSPhysics/joint.rb', line 228 def solver_model=(model) MSPhysics::Newton::Joint.set_solver_model(@address, model) end |
#stiffness ⇒ Numeric
Get joint stiffness.
192 193 194 |
# File 'RubyExtension/MSPhysics/joint.rb', line 192 def stiffness MSPhysics::Newton::Joint.get_stiffness(@address) end |
#stiffness=(value) ⇒ Object
Set joint stiffness
198 199 200 |
# File 'RubyExtension/MSPhysics/joint.rb', line 198 def stiffness=(value) MSPhysics::Newton::Joint.set_stiffness(@address, value) end |
#type ⇒ Integer
Get joint type.
134 135 136 |
# File 'RubyExtension/MSPhysics/joint.rb', line 134 def type MSPhysics::Newton::Joint.get_type(@address) end |
#valid? ⇒ Boolean
Determine whether joint is valid.
76 77 78 |
# File 'RubyExtension/MSPhysics/joint.rb', line 76 def valid? MSPhysics::Newton::Joint.is_valid?(@address) end |
#world ⇒ MSPhysics::World
Get the world the joint is associated to.
94 95 96 97 |
# File 'RubyExtension/MSPhysics/joint.rb', line 94 def world world_address = MSPhysics::Newton::Joint.get_world(@address) MSPhysics::Newton::World.get_user_data(world_address) end |