Class: Motel::Callbacks::Rotation
- Inherits:
-
Omega::Server::Callback
- Object
- Omega::Server::Callback
- Motel::Callbacks::Rotation
- Defined in:
- lib/motel/callbacks/rotation.rb
Overview
Defines a Omega::Server::Callback to only invoke callback if a location rotates a specified minimum axis-angle
Instance Attribute Summary collapse
-
#axis_x ⇒ Object
Axis angle of rotation.
-
#axis_y ⇒ Object
Axis angle of rotation.
-
#axis_z ⇒ Object
Axis angle of rotation.
-
#rot_theta ⇒ Object
Minimum angle location needs to have rotated.
Attributes inherited from Omega::Server::Callback
#endpoint_id, #event_type, #handler, #only_if, #rjr_event
Class Method Summary collapse
-
.json_create(o) ⇒ Object
Create new callback from json representation.
Instance Method Summary collapse
-
#initialize(args = {}, &block) ⇒ Rotation
constructor
Motel::Callbacks::Rotation initializer.
-
#invoke(loc, old_ox, old_oy, old_oz) ⇒ Object
Override Omega::Server::Callback#invoke, call original then reset local orientation.
-
#to_json(*a) ⇒ Object
Convert callback to json representation and return it.
-
#to_s ⇒ Object
Convert callback to human readable string and return it.
Methods inherited from Omega::Server::Callback
Constructor Details
#initialize(args = {}, &block) ⇒ Rotation
Motel::Callbacks::Rotation initializer
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/motel/callbacks/rotation.rb', line 56 def initialize(args = {}, &block) attr_from_args args, :rot_theta => 0, :axis_x => nil, :axis_y => nil, :axis_z => nil @axis_x = @axis_x.to_f unless @axis_x.nil? @axis_y = @axis_y.to_f unless @axis_y.nil? @axis_z = @axis_z.to_f unless @axis_z.nil? @orig_ox = @orig_oy = @orig_oz = nil # only run handler if minimums are met @only_if = proc { |*args| self.check_rotation(*args)} super(args, &block) end |
Instance Attribute Details
#axis_x ⇒ Object
Axis angle of rotation
18 19 20 |
# File 'lib/motel/callbacks/rotation.rb', line 18 def axis_x @axis_x end |
#axis_y ⇒ Object
Axis angle of rotation
18 19 20 |
# File 'lib/motel/callbacks/rotation.rb', line 18 def axis_y @axis_y end |
#axis_z ⇒ Object
Axis angle of rotation
18 19 20 |
# File 'lib/motel/callbacks/rotation.rb', line 18 def axis_z @axis_z end |
#rot_theta ⇒ Object
Minimum angle location needs to have rotated
15 16 17 |
# File 'lib/motel/callbacks/rotation.rb', line 15 def rot_theta @rot_theta end |
Class Method Details
.json_create(o) ⇒ Object
Create new callback from json representation
104 105 106 107 |
# File 'lib/motel/callbacks/rotation.rb', line 104 def self.json_create(o) callback = new(o['data']) return callback end |
Instance Method Details
#invoke(loc, old_ox, old_oy, old_oz) ⇒ Object
Override Omega::Server::Callback#invoke, call original then reset local orientation
79 80 81 82 83 |
# File 'lib/motel/callbacks/rotation.rb', line 79 def invoke(loc, old_ox, old_oy, old_oz) da = get_rotation(loc) super(loc, da) @orig_ox = @orig_ox = @orig_oz = nil end |
#to_json(*a) ⇒ Object
Convert callback to json representation and return it
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/motel/callbacks/rotation.rb', line 91 def to_json(*a) { 'json_class' => self.class.name, 'data' => { :endpoint_id => @endpoint_id, :rot_theta => @rot_theta, :axis_x => @axis_x, :axis_y => @axis_y, :axis_z => @axis_z } }.to_json(*a) end |
#to_s ⇒ Object
Convert callback to human readable string and return it
86 87 88 |
# File 'lib/motel/callbacks/rotation.rb', line 86 def to_s "(#{@rot_theta},#{@axis_x},#{@axis_y},#{@axis_z})" end |