Module: Box2D::WorldJoints

Included in:
World
Defined in:
lib/box2d/world_joints.rb

Instance Method Summary collapse

Instance Method Details

#create_distance_joint(body_a:, body_b:, anchor_a: nil, anchor_b: nil, length: nil, limits: nil, motor: nil, spring: nil, **options) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/box2d/world_joints.rb', line 31

def create_distance_joint(body_a:, body_b:, anchor_a: nil, anchor_b: nil, length: nil, limits: nil,
  motor: nil, spring: nil, **options)
  point_a = anchor_a || body_a.position
  point_b = anchor_b || body_b.position
  create_typed_joint(:distance, body_a:, body_b:, options:) do |definition|
    definition[:localAnchorA] = local_point(body_a, point_a)
    definition[:localAnchorB] = local_point(body_b, point_b)
    definition[:length] = length ? ValueConversion.positive_float(length, label: "length") : distance(point_a, point_b)
    configure_limits(definition, limits, :minLength, :maxLength)
    configure_motor(definition, motor, maximum: :maxMotorForce)
    configure_spring(definition, spring)
  end
end

#create_mouse_joint(body_a:, body_b:, target:, max_force:, hertz: 5.0, damping_ratio: 0.7, **options) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/box2d/world_joints.rb', line 45

def create_mouse_joint(body_a:, body_b:, target:, max_force:, hertz: 5.0, damping_ratio: 0.7, **options)
  create_typed_joint(:mouse, body_a:, body_b:, options:) do |definition|
    definition[:target] = ValueConversion.native_vec2(target, label: "target")
    definition[:maxForce] = ValueConversion.positive_float(max_force, label: "max_force")
    definition[:hertz] = ValueConversion.non_negative_float(hertz, label: "hertz")
    definition[:dampingRatio] = ValueConversion.non_negative_float(damping_ratio, label: "damping_ratio")
  end
end

#create_prismatic_joint(body_a:, body_b:, anchor:, axis: [1, 0], limits: nil, motor: nil, spring: nil, **options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/box2d/world_joints.rb', line 16

def create_prismatic_joint(body_a:, body_b:, anchor:, axis: [1, 0], limits: nil, motor: nil, spring: nil, **options)
  create_typed_joint(:prismatic, body_a:, body_b:, options:) do |definition|
    definition[:localAnchorA] = local_point(body_a, anchor)
    definition[:localAnchorB] = local_point(body_b, anchor)
    definition[:localAxisA] = Native.b2Body_GetLocalVector(
      body_a.id,
      ValueConversion.native_vec2(axis, label: "axis")
    )
    definition[:referenceAngle] = body_b.angle - body_a.angle
    configure_limits(definition, limits, :lowerTranslation, :upperTranslation)
    configure_motor(definition, motor, maximum: :maxMotorForce)
    configure_spring(definition, spring)
  end
end

#create_revolute_joint(body_a:, body_b:, anchor:, limits: nil, motor: nil, spring: nil, **options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/box2d/world_joints.rb', line 5

def create_revolute_joint(body_a:, body_b:, anchor:, limits: nil, motor: nil, spring: nil, **options)
  create_typed_joint(:revolute, body_a:, body_b:, options:) do |definition|
    definition[:localAnchorA] = local_point(body_a, anchor)
    definition[:localAnchorB] = local_point(body_b, anchor)
    definition[:referenceAngle] = body_b.angle - body_a.angle
    configure_limits(definition, limits, :lowerAngle, :upperAngle)
    configure_motor(definition, motor, maximum: :maxMotorTorque)
    configure_spring(definition, spring)
  end
end

#create_weld_joint(body_a:, body_b:, anchor:, linear: nil, angular: nil, **options) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/box2d/world_joints.rb', line 54

def create_weld_joint(body_a:, body_b:, anchor:, linear: nil, angular: nil, **options)
  create_typed_joint(:weld, body_a:, body_b:, options:) do |definition|
    definition[:localAnchorA] = local_point(body_a, anchor)
    definition[:localAnchorB] = local_point(body_b, anchor)
    definition[:referenceAngle] = body_b.angle - body_a.angle
    configure_weld_spring(definition, linear, :linear)
    configure_weld_spring(definition, angular, :angular)
  end
end