Class: LibSL::LLQuaternion
- Inherits:
-
Object
- Object
- LibSL::LLQuaternion
- Defined in:
- lib/types.rb
Instance Attribute Summary collapse
-
#w ⇒ Object
Returns the value of attribute w.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Class Method Summary collapse
Instance Method Summary collapse
- #encode ⇒ Object
-
#initialize(x, y, z, w = nil) ⇒ LLQuaternion
constructor
A new instance of LLQuaternion.
Constructor Details
#initialize(x, y, z, w = nil) ⇒ LLQuaternion
Returns a new instance of LLQuaternion.
369 370 371 372 373 374 375 376 377 |
# File 'lib/types.rb', line 369 def initialize(x, y, z, w=nil) @x, @y, @z = x, y, z if w.nil? then sum = 1 - @x**2 - @y**2 - @z**2 @w = if sum > 0 then Math.sqrt sum else 0 end else @w = w end end |
Instance Attribute Details
#w ⇒ Object
Returns the value of attribute w.
368 369 370 |
# File 'lib/types.rb', line 368 def w @w end |
#x ⇒ Object
Returns the value of attribute x.
368 369 370 |
# File 'lib/types.rb', line 368 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
368 369 370 |
# File 'lib/types.rb', line 368 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
368 369 370 |
# File 'lib/types.rb', line 368 def z @z end |
Class Method Details
.decode(data) ⇒ Object
359 360 361 362 |
# File 'lib/types.rb', line 359 def self.decode(data) data = data.unpack 'e3a*' return self.new(data[0], data[1], data[2]), data[3] end |
Instance Method Details
#encode ⇒ Object
364 365 366 |
# File 'lib/types.rb', line 364 def encode() [@x, @y, @z].pack 'e3' end |