Class: MSPhysics::Spring

Inherits:
Joint show all
Defined in:
RubyExtension/MSPhysics/joint_spring.rb

Overview

Since:

  • 1.0.0

Constant Summary collapse

DEFAULT_MIN =

Since:

  • 1.0.0

-10.0
DEFAULT_MAX =

Since:

  • 1.0.0

10.0
DEFAULT_LIMITS_ENABLED =

Since:

  • 1.0.0

false
DEFAULT_ROTATION_ENABLED =

Since:

  • 1.0.0

false
DEFAULT_MODE =

Since:

  • 1.0.0

0
DEFAULT_ACCEL =

Since:

  • 1.0.0

40.0
DEFAULT_DAMP =

Since:

  • 1.0.0

0.1
DEFAULT_STRENGTH =

Since:

  • 1.0.0

0.8
DEFAULT_SPRING_CONSTANT =

Since:

  • 1.0.0

40.0
DEFAULT_SPRING_DRAG =

Since:

  • 1.0.0

1.0
DEFAULT_START_POSITION =

Since:

  • 1.0.0

0.0
DEFAULT_CONTROLLER =

Since:

  • 1.0.0

1.0

Constants inherited from Joint

Joint::DEFAULT_BODIES_COLLIDABLE, Joint::DEFAULT_BREAKING_FORCE, Joint::DEFAULT_SOLVER_MODEL, Joint::DEFAULT_STIFFNESS

Instance Method Summary collapse

Methods inherited from Joint

#address, all_joints, #bodies_collidable=, #bodies_collidable?, #breaking_force, #breaking_force=, #child, #connect, #connected?, #destroy, #disconnect, #dof, #get_pin_matrix, #get_pin_matrix2, #get_tension1, #get_tension2, #group, joint_by_address, #name, #name=, #parent, #set_pin_matrix, #solver_model, #solver_model=, #stiffness, #stiffness=, #type, #valid?, validate, #world

Methods inherited from Entity

#inspect, #to_s

Constructor Details

#initialize(world, parent, pin_tra, group = nil) ⇒ Spring

Create a spring joint.

Parameters:

  • world (MSPhysics::World)
  • parent (MSPhysics::Body, nil)
  • pin_tra (Geom::Transformation, Array<Numeric>)

    Pin transformation in global space. Matrix origin is interpreted as the pin position. Matrix Z-axis is interpreted as the pin direction.

  • group (Sketchup::Group, Sketchup::ComponentInstance, nil) (defaults to: nil)

Since:

  • 1.0.0



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 26

def initialize(world, parent, pin_tra, group = nil)
  super(world, parent, pin_tra, group)
  MSPhysics::Newton::Spring.create(@address)
  MSPhysics::Newton::Spring.set_min(@address, DEFAULT_MIN)
  MSPhysics::Newton::Spring.set_max(@address, DEFAULT_MAX)
  MSPhysics::Newton::Spring.enable_limits(@address, DEFAULT_LIMITS_ENABLED)
  MSPhysics::Newton::Spring.enable_rotation(@address, DEFAULT_ROTATION_ENABLED)
  MSPhysics::Newton::Spring.set_mode(@address, DEFAULT_MODE)
  MSPhysics::Newton::Spring.set_accel(@address, DEFAULT_ACCEL)
  MSPhysics::Newton::Spring.set_damp(@address, DEFAULT_DAMP)
  MSPhysics::Newton::Spring.set_strength(@address, DEFAULT_STRENGTH)
  MSPhysics::Newton::Spring.set_spring_constant(@address, DEFAULT_SPRING_CONSTANT)
  MSPhysics::Newton::Spring.set_spring_drag(@address, DEFAULT_SPRING_DRAG)
  MSPhysics::Newton::Spring.set_start_position(@address, DEFAULT_START_POSITION)
  MSPhysics::Newton::Spring.set_controller(@address, DEFAULT_CONTROLLER)
end

Instance Method Details

#accelNumeric

Note:

This option associates with the normal spring mode.

Get spring oscillation acceleration factor.

Returns:

  • (Numeric)

    An acceleration factor, a value greater than or equal to zero.

Since:

  • 1.0.0



110
111
112
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 110

def accel
  MSPhysics::Newton::Spring.get_accel(@address)
end

#accel=(value) ⇒ Object

Note:

This option associates with the normal spring mode.

Set spring oscillation acceleration factor.

Parameters:

  • value (Numeric)

    An acceleration factor, a value greater than or equal to zero.

Since:

  • 1.0.0



118
119
120
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 118

def accel=(value)
  MSPhysics::Newton::Spring.set_accel(@address, value)
end

#controllerNumeric

Note:

The actual, desired starting position is, start_position * controller.

Get magnitude and direction of the starting position.

Returns:

  • (Numeric)

Since:

  • 1.0.0



202
203
204
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 202

def controller
  MSPhysics::Newton::Spring.get_controller(@address)
end

#controller=(value) ⇒ Object

Note:

The actual, desired starting position is, start_position * controller.

Set magnitude and direction of the starting position.

Parameters:

  • value (Numeric)

Since:

  • 1.0.0



210
211
212
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 210

def controller=(value)
  MSPhysics::Newton::Spring.set_controller(@address, value)
end

#cur_accelerationNumeric

Get current acceleration in meters per second per second.

Returns:

  • (Numeric)

Since:

  • 1.0.0



228
229
230
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 228

def cur_acceleration
  MSPhysics::Newton::Spring.get_cur_acceleration(@address)
end

#cur_positionNumeric

Get current position in meters with respect to the starting position.

Returns:

  • (Numeric)

Since:

  • 1.0.0



216
217
218
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 216

def cur_position
  MSPhysics::Newton::Spring.get_cur_position(@address)
end

#cur_velocityNumeric

Get current velocity in meters per second.

Returns:

  • (Numeric)

Since:

  • 1.0.0



222
223
224
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 222

def cur_velocity
  MSPhysics::Newton::Spring.get_cur_velocity(@address)
end

#dampNumeric

Note:

This option associates with the normal spring mode.

Get spring oscillation damping coefficient.

Returns:

  • (Numeric)

    A value between 0.0 and 1.0.

Since:

  • 1.0.0



125
126
127
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 125

def damp
  MSPhysics::Newton::Spring.get_damp(@address)
end

#damp=(value) ⇒ Object

Note:

This option associates with the normal spring mode.

Set spring oscillation damping coefficient.

Parameters:

  • value (Numeric)

    A value between 0.0 and 1.0.

Since:

  • 1.0.0



132
133
134
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 132

def damp=(value)
  MSPhysics::Newton::Spring.set_damp(@address, value)
end

#limits_enabled=(state) ⇒ Object

Enable/disable min and max position limits.

Parameters:

  • state (Boolean)

Since:

  • 1.0.0



74
75
76
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 74

def limits_enabled=(state)
  MSPhysics::Newton::Spring.enable_limits(@address, state)
end

#limits_enabled?Boolean

Determine whether min and max position limits are enabled.

Returns:

  • (Boolean)

Since:

  • 1.0.0



68
69
70
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 68

def limits_enabled?
  MSPhysics::Newton::Spring.limits_enabled?(@address)
end

#maxNumeric

Get maximum position in meters with respect to the starting position.

Returns:

  • (Numeric)

Since:

  • 1.0.0



57
58
59
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 57

def max
  MSPhysics::Newton::Spring.get_max(@address)
end

#max=(value) ⇒ Object

Set maximum position in meters with respect to the starting position.

Since:

  • 1.0.0



62
63
64
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 62

def max=(value)
  MSPhysics::Newton::Spring.set_max(@address, value)
end

#minNumeric

Get minimum position in meters with respect to the starting position.

Returns:

  • (Numeric)

Since:

  • 1.0.0



45
46
47
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 45

def min
  MSPhysics::Newton::Spring.get_min(@address)
end

#min=(value) ⇒ Object

Set minimum position in meters with respect to the starting position.

Parameters:

  • value (Numeric)

Since:

  • 1.0.0



51
52
53
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 51

def min=(value)
  MSPhysics::Newton::Spring.set_min(@address, value)
end

#modeInteger

Get mode.

Returns:

  • (Integer)
    • 0 - if using spring accel, damp, and strength options.

    • 1 - if using Hooke’s spring constant and drag coefficient.

Since:

  • 1.0.0



94
95
96
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 94

def mode
  MSPhysics::Newton::Spring.get_mode(@address)
end

#mode=(value) ⇒ Object

Set mode.

Parameters:

  • value (Integer)
    • 0 - use spring accel, damp, and strength options.

    • 1 - use Hooke’s spring constant and drag coefficient options.

Since:

  • 1.0.0



102
103
104
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 102

def mode=(value)
  MSPhysics::Newton::Spring.set_mode(@address, value)
end

#rotation_enabled=(state) ⇒ Object

Enable/disable rotation along Z-axis of joint.

Parameters:

  • state (Boolean)

Since:

  • 1.0.0



86
87
88
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 86

def rotation_enabled=(state)
  MSPhysics::Newton::Spring.enable_rotation(@address, state)
end

#rotation_enabled?Boolean

Determine whether rotation along Z-axis of joint is enabled.

Returns:

  • (Boolean)

Since:

  • 1.0.0



80
81
82
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 80

def rotation_enabled?
  MSPhysics::Newton::Spring.rotation_enabled?(@address)
end

#spring_constantNumeric

Note:

This option associates with the Hooke’s spring mode.

Get Hooke’s spring constant.

Returns:

  • (Numeric)

    A spring constant in kg/s², a value greater than or equal to zero.

Since:

  • 1.0.0



154
155
156
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 154

def spring_constant
  MSPhysics::Newton::Spring.get_spring_constant(@address)
end

#spring_constant=(value) ⇒ Object

Note:

This option associates with the Hooke’s spring mode.

Set Hooke’s spring constant.

Parameters:

  • value (Numeric)

    A spring constant in kg/s², a value greater than or equal to zero.

Since:

  • 1.0.0



162
163
164
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 162

def spring_constant=(value)
  MSPhysics::Newton::Spring.set_spring_constant(@address, value)
end

#spring_dragNumeric

Note:

This option associates with the Hooke’s spring mode.

Get Hooke’s spring drag.

Returns:

  • (Numeric)

    A spring drag coefficient in kg/s, a value greater than or equal to zero.

Since:

  • 1.0.0



170
171
172
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 170

def spring_drag
  MSPhysics::Newton::Spring.get_spring_drag(@address)
end

#spring_drag=(value) ⇒ Object

Note:

This option associates with the Hooke’s spring mode.

Set Hooke’s spring drag.

Parameters:

  • value (Numeric)

    A spring drag coefficient in kg/s, a value greater than or equal to zero.

Since:

  • 1.0.0



178
179
180
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 178

def spring_drag=(value)
  MSPhysics::Newton::Spring.set_spring_drag(@address, value)
end

#start_positionNumeric

Note:

The actual, desired starting position is, start_position * controller.

Get starting position along joint Z-axis in meters.

Returns:

  • (Numeric)

Since:

  • 1.0.0



186
187
188
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 186

def start_position
  MSPhysics::Newton::Spring.get_start_position(@address)
end

#start_position=(position) ⇒ Object

Note:

The actual, desired starting position is, start_position * controller.

Set starting position along joint Z-axis in meters.

Parameters:

  • position (Numeric)

Since:

  • 1.0.0



194
195
196
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 194

def start_position=(position)
  MSPhysics::Newton::Spring.set_start_position(@address, position)
end

#strengthNumeric

Note:

This option associates with the normal spring mode.

Get spring oscillation strength coefficient.

Returns:

  • (Numeric)

    A value between 0.0 and 1.0.

Since:

  • 1.0.0



139
140
141
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 139

def strength
  MSPhysics::Newton::Spring.get_strength(@address)
end

#strength=(value) ⇒ Object

Note:

This option associates with the normal spring mode.

Set spring oscillation strength coefficient.

Parameters:

  • value (Numeric)

    A value between 0.0 and 1.0.

Since:

  • 1.0.0



146
147
148
# File 'RubyExtension/MSPhysics/joint_spring.rb', line 146

def strength=(value)
  MSPhysics::Newton::Spring.set_strength(@address, value)
end