Class: Stagecraft::ObservedQuat
- Inherits:
-
Object
- Object
- Stagecraft::ObservedQuat
show all
- Defined in:
- lib/stagecraft/core/observed_value.rb
Constant Summary
collapse
- COMPONENTS =
%i[x y z w].freeze
Instance Method Summary
collapse
Constructor Details
#initialize(owner, value = Larb::Quat.new) ⇒ ObservedQuat
Returns a new instance of ObservedQuat.
95
96
97
98
|
# File 'lib/stagecraft/core/observed_value.rb', line 95
def initialize(owner, value = Larb::Quat.new)
@owner = owner
@value = coerce(value)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arguments, **keywords, &block) ⇒ Object
157
158
159
160
161
162
|
# File 'lib/stagecraft/core/observed_value.rb', line 157
def method_missing(name, *arguments, **keywords, &block)
return super unless @value.respond_to?(name)
values = arguments.map { |argument| argument.respond_to?(:to_larb) ? argument.to_larb : argument }
@value.public_send(name, *values, **keywords, &block)
end
|
Instance Method Details
#==(other) ⇒ Object
149
150
151
|
# File 'lib/stagecraft/core/observed_value.rb', line 149
def ==(other)
other.respond_to?(:to_a) && to_a == other.to_a
end
|
#inspect ⇒ Object
153
154
155
|
# File 'lib/stagecraft/core/observed_value.rb', line 153
def inspect
"#{self.class.name}[#{to_a.join(", ")}]"
end
|
#normalize! ⇒ Object
137
138
139
|
# File 'lib/stagecraft/core/observed_value.rb', line 137
def normalize!
set(@value.normalize)
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
164
165
166
|
# File 'lib/stagecraft/core/observed_value.rb', line 164
def respond_to_missing?(name, include_private = false)
@value.respond_to?(name, include_private) || super
end
|
#rotate_x!(angle) ⇒ Object
121
122
123
|
# File 'lib/stagecraft/core/observed_value.rb', line 121
def rotate_x!(angle)
rotate_axis!(Larb::Vec3.right, angle)
end
|
#rotate_y!(angle) ⇒ Object
125
126
127
|
# File 'lib/stagecraft/core/observed_value.rb', line 125
def rotate_y!(angle)
rotate_axis!(Larb::Vec3.up, angle)
end
|
#rotate_z!(angle) ⇒ Object
129
130
131
|
# File 'lib/stagecraft/core/observed_value.rb', line 129
def rotate_z!(angle)
rotate_axis!(Larb::Vec3.back, angle)
end
|
#set(x, y = nil, z = nil, w = nil) ⇒ Object
111
112
113
114
115
116
117
118
119
|
# File 'lib/stagecraft/core/observed_value.rb', line 111
def set(x, y = nil, z = nil, w = nil)
values = y.nil? && z.nil? && w.nil? ? x.to_a : [x, y, z, w]
next_value = Larb::Quat.new(*values).normalize
return self if @value == next_value
@value = next_value
changed!
self
end
|
#slerp!(target, amount) ⇒ Object
133
134
135
|
# File 'lib/stagecraft/core/observed_value.rb', line 133
def slerp!(target, amount)
set(@value.slerp(coerce(target), amount))
end
|
#to_a ⇒ Object
145
146
147
|
# File 'lib/stagecraft/core/observed_value.rb', line 145
def to_a
@value.to_a
end
|
#to_larb ⇒ Object
141
142
143
|
# File 'lib/stagecraft/core/observed_value.rb', line 141
def to_larb
Larb::Quat.new(*to_a)
end
|