Class: BulldogPhysics::Joint
- Inherits:
-
ContactGenerator
- Object
- ContactGenerator
- BulldogPhysics::Joint
- Defined in:
- lib/RigidBodies/joint.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#error ⇒ Object
Returns the value of attribute error.
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
- #add_contact(contacts, limit) ⇒ Object
-
#initialize ⇒ Joint
constructor
A new instance of Joint.
- #set(a, a_pos, b, b_pos, error) ⇒ Object
Constructor Details
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/RigidBodies/joint.rb', line 4 def body @body end |
#error ⇒ Object
Returns the value of attribute error.
4 5 6 |
# File 'lib/RigidBodies/joint.rb', line 4 def error @error end |
#position ⇒ Object
Returns the value of attribute position.
4 5 6 |
# File 'lib/RigidBodies/joint.rb', line 4 def position @position end |
Instance Method Details
#add_contact(contacts, limit) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/RigidBodies/joint.rb', line 12 def add_contact(contacts, limit) a_pos_world = @body[0].get_point_in_world_space(@position[0]) b_pos_world = @body[1].get_point_in_world_space(@position[1]) a_to_b = b_pos_world - a_pos_world normal = a_to_b.unit length = a_to_b.magnitude if(length.abs > error) puts "add contact" contact = Contact.new contact.body = @body contact.contact_normal = normal contact.contact_point = (a_pos_world + b_pos_world) * 0.5 contact.penetration = length - error contact.friction = 1.0 contact.restitution = 0 contacts << contact return 1 end return 0 end |
#set(a, a_pos, b, b_pos, error) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/RigidBodies/joint.rb', line 35 def set(a, a_pos, b, b_pos, error) @body[0] = a @body[1] = b @position[0] = a_pos @position[1] = b_pos @error = error end |