Class: MSPhysics::BodyContext

Inherits:
CommonContext show all
Defined in:
RubyExtension/MSPhysics/body_context.rb

Overview

BodyContext contains Body events and event-related functions.

Since:

  • 1.0.0

Simulation Events collapse

User Input Events collapse

Instance Method Summary collapse

Methods inherited from CommonContext

#accumulator, #delete_global_var, #delete_var, #frame, #get_global_var, #get_set_global_var, #get_set_var, #get_var, #joybutton, #joypad, #joystick, #key, #key_slider, #leftx, #lefty, #leftz, #numx, #numy, #oscillator, #oscillator2, #oscillator2_slope, #oscillator_slope, #repeater, #rightx, #righty, #rightz, #set_global_var, #set_var, #simulation, #singular_repeater, #slider, #toggle_key, #world

Methods inherited from Entity

#inspect, #to_s

Constructor Details

#initialize(body) ⇒ BodyContext

Returns a new instance of BodyContext

Parameters:

  • body (Body)

    A body to be associated with the context.

Since:

  • 1.0.0

Instance Method Details

#call_event(event, *args) ⇒ Boolean

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.

Trigger an event.

Parameters:

  • event (Symbol, String)

    Event name.

  • args (*args)

    Event arguments.

Returns:

  • (Boolean)

    success

Since:

  • 1.0.0

#eval_script(script, script_name, line) ⇒ Object

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.

Parameters:

  • script (String)
  • script_name (String)
  • line (Fixnum)

Since:

  • 1.0.0

#event_proc_assigned?(event) ⇒ Boolean

Determine whether particular event has a Proc object.

Parameters:

  • event (Symbol, String)

Returns:

  • (Boolean)

Since:

  • 1.0.0

#get_event_proc(event) ⇒ Proc?

Get a Proc object assigned to an event.

Parameters:

  • event (Symbol, String)

Returns:

  • (Proc, nil)

    A Proc object or nil if there is no procedure to an event.

Since:

  • 1.0.0

#on(*events) { ... } ⇒ Fixnum

Assign a block of code to an event or a list of events.

Examples:

on(:keyDown, :keyUp, :keyExtended) { |key, value, char|
  simulation.log_line(key)
}

Parameters:

  • events (Symbol, String)

Yields:

  • A block of code.

Returns:

  • (Fixnum)

    The number of events assigned.

Since:

  • 1.0.0

#onClick {|point| ... } ⇒ Object

Assign a block of code to the onClick event.

Yields:

  • This event is triggered when the body is clicked.

Yield Parameters:

  • point (Geom::Point3d)

    Clicked position in global space.

Since:

  • 1.0.0

#onDrag { ... } ⇒ Object

Assign a block of code to the onDrag event.

Yields:

  • This event is triggered whenever the body is dragged by a mouse.

Since:

  • 1.0.0

#onDraw {|view, bb| ... } ⇒ Object

Assign a block of code to the onDraw event.

Examples:

onDraw { |view, bb|
  pts = [[0,0,100], [100,100,100]]
  # Add points to the view bounding box to prevent the line from being
  # clipped.
  bb.add(pts)
  # Now, draw the line in red.
  view.drawing_color = 'red'
  view.draw(GL_LINES, pts)
}

Yields:

  • This event is triggered whenever the view is redrawn, even when simulation is paused.

Yield Parameters:

  • view (Sketchup::View)
  • bb (Geom::BoundingBox)

Since:

  • 1.0.0

#onEnd { ... } ⇒ Object

Assign a block of code to the onEnd event.

Yields:

  • This event is triggered when simulation ends, right before the bodies are moved back to their starting transformation.

Since:

  • 1.0.0

#onKeyDown {|key, val, char| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onKeyDown event.

Yields:

  • This event is called when the key is pressed.

Yield Parameters:

  • key (String)

    Virtual key name.

  • val (Fixnum)

    Virtual key constant value.

  • char (String)

    Actual key character.

See Also:

Since:

  • 1.0.0

#onKeyExtended {|key, val, char| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onKeyExtended event.

Yields:

  • This event is called when the key is held down.

Yield Parameters:

  • key (String)

    Virtual key name.

  • val (Fixnum)

    Virtual key constant value.

  • char (String)

    Actual key character.

See Also:

Since:

  • 1.0.0

#onKeyUp {|key, val, char| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onKeyUp event.

Yields:

  • This event is called when the key is released.

Yield Parameters:

  • key (String)

    Virtual key name.

  • val (Fixnum)

    Virtual key constant value.

  • char (String)

    Actual key character.

See Also:

Since:

  • 1.0.0

#onLButtonDoubleClick {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onLButtonDoubleClick event.

Yields:

  • This event is called when the left mouse button is double clicked.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onLButtonDown {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onLButtonDown event.

Yields:

  • This event is called when the left mouse button is pressed.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onLButtonUp {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onLButtonUp event.

Yields:

  • This event is called when the left mouse button is released.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onMButtonDoubleClick {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onMButtonDoubleClick event.

Yields:

  • This event is called when the middle mouse button is double clicked.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onMButtonDown {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onMButtonDown event.

Yields:

  • This event is called when the middle mouse button is pressed.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onMButtonUp {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onMButtonUp event.

Yields:

  • This event is called when the middle mouse button is released.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onMouseMove {|x, y, view| ... } ⇒ Object

Assign a block of code to the onMouseMove event.

Yields:

  • This event is called when the mouse is moved.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)
  • view (Sketchup::View)

Since:

  • 1.0.0

#onMouseWheelRotate {|x, y, dir| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onMouseWheelRotate event.

Yields:

  • This event is called when the mouse wheel is rotated.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)
  • dir (Fixnum)

    Rotate direction: -1 - down, 1 - up.

Since:

  • 1.0.0

#onMouseWheelTilt {|x, y, dir| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onMouseWheelTilt event.

Yields:

  • This event is called when the mouse wheel is tilted.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)
  • dir (Fixnum)

    Tilt direction: -1 - left, 1 - right.

Since:

  • 1.0.0

#onPause { ... } ⇒ Object

Assign a block of code to the onPause event.

Yields:

  • This event is triggered when simulation is paused.

Since:

  • 1.0.0

#onPlay { ... } ⇒ Object

Assign a block of code to the onPlay event.

Yields:

  • This event is triggered when simulation is played. It is not called when simulation starts.

Since:

  • 1.0.0

#onPostFrame { ... } ⇒ Object

Assign a block of code to the onPostFrame event.

Yields:

  • This event is triggered every time after the frame is changed, particularly after the ##onTick event.

Since:

  • 1.0.0

#onPostUpdate { ... } ⇒ Object

Assign a block of code to the onUpdate event.

Yields:

  • This event is triggered every time after the world is updated, particularly after the ##onUpdate event. Just like ##onUpdate, this event can be triggered multiple times per frame.

Since:

  • 1.0.0

#onPreFrame { ... } ⇒ Object

Assign a block of code to the onPreFrame event.

Yields:

  • This event is triggered every time before the frame is changed, particularly before the ##onTick event.

Since:

  • 1.0.0

#onPreUpdate { ... } ⇒ Object

Assign a block of code to the onPreUpdate event.

Yields:

  • This event is triggered every time before the world is updated, particularly before the ##onUpdate event. Just like ##onUpdate, this event can be triggered multiple times per frame.

Since:

  • 1.0.0

#onRButtonDoubleClick {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onRButtonDoubleClick event.

Yields:

  • This event is called when the right mouse button is double clicked.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onRButtonDown {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onRButtonDown event.

Yields:

  • This event is called when the right mouse button is pressed.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onRButtonUp {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onRButtonUp event.

Yields:

  • This event is called when the right mouse button is released.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onStart { ... } ⇒ Object

Assign a block of code to the onStart event.

Yields:

  • This event is triggered once when simulation starts, hence when the frame is zero. No world updates are made at this point.

Since:

  • 1.0.0

#onTick { ... } ⇒ Object

Assign a block of code to the onTick event.

Yields:

  • This event is triggered every time the frame is changed, specifically after all the world updates of the frame take place and after group transformations are updated.

Since:

  • 1.0.0

#onTouch {|toucher, point, normal, force, speed| ... } ⇒ Object

Assign a block of code to the onTouch event.

Yields:

  • This event is triggered when this body comes in contact with another body.

Yield Parameters:

  • toucher (Body)
  • point (Geom::Point3d)
  • normal (Geom::Vector3d)
  • force (Geom::Vector3d)

    in Newtons.

  • speed (Numeric)

    in meters per second.

Since:

  • 1.0.0

#onTouching {|toucher| ... } ⇒ Object

Assign a block of code to the onTouching event.

Yields:

  • This event is triggered every frame when the body is in an extended contact with another body.

Yield Parameters:

Since:

  • 1.0.0

#onUnclick { ... } ⇒ Object

Assign a block of code to the onUnclick event.

Yields:

  • This event is triggered when the body is unclicked.

Since:

  • 1.0.0

#onUntouch {|toucher| ... } ⇒ Object

Note:

Sometimes you may want to know whether particular body is in contact with another body. Relying on events is not always the best technique. To determine whether this body is in contact with another body, use this.touching_with?(some_other_body) or this.touching_bodies.

Assign a block of code to the onUntouch event.

Yields:

  • This event is triggered when particular body is no longer in contact with another body. When this procedure is triggered it doesn't always mean the body is free from all contacts. This means particular toucher has stopped touching the body.

Yield Parameters:

Since:

  • 1.0.0

#onUpdate { ... } ⇒ Object

Assign a block of code to the onUpdate event.

Yields:

  • This event is triggered every time the world is updated. For instance, if the world update rate is three, this event will be triggered three times per frame. For performance purposes, group transformations are not updated at this point. Only the transformations for the bodies referencing the groups are updated. This event is suitable for applying forces and velocities.

Since:

  • 1.0.0

#onXButton1DoubleClick {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onXButton1DoubleClick event.

Yields:

  • This event is called when the X1 mouse button is double clicked.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onXButton1Down {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onXButton1Down event.

Yields:

  • This event is called when the X1 mouse button is pressed.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onXButton1Up {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onXButton1Up event.

Yields:

  • This event is called when the X1 mouse button is released.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onXButton2DoubleClick {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onXButton2DoubleClick event.

Yields:

  • This event is called when the X2 mouse button is double clicked.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onXButton2Down {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onXButton2Down event.

Yields:

  • This event is called when the X2 mouse button is pressed.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#onXButton2Up {|x, y| ... } ⇒ Object

Note:

Windows only!

Assign a block of code to the onXButton2Up event.

Yields:

  • This event is called when the X2 mouse button is released.

Yield Parameters:

  • x (Fixnum)
  • y (Fixnum)

Since:

  • 1.0.0

#set_event_proc(event, proc) ⇒ Boolean

Assign a Proc object to an event.

Parameters:

  • event (Symbol, String)
  • proc (Proc, nil)

    A Proc object or nil to remove procedure from an event.

Returns:

  • (Boolean)

    success

Since:

  • 1.0.0

#thisBody

Get the associated body.

Returns:

Since:

  • 1.0.0