Class: BulldogPhysics::Joint

Inherits:
ContactGenerator show all
Defined in:
lib/RigidBodies/joint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJoint

Returns a new instance of Joint.



7
8
9
10
11
# File 'lib/RigidBodies/joint.rb', line 7

def initialize()
	@body = [RigidBody.new, RigidBody.new]
	@position = [Vector3.new, Vector3.new]
	@error = 0.0
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



4
5
6
# File 'lib/RigidBodies/joint.rb', line 4

def body
  @body
end

#errorObject

Returns the value of attribute error.



4
5
6
# File 'lib/RigidBodies/joint.rb', line 4

def error
  @error
end

#positionObject

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