Class: LibSL::LLQuaternion

Inherits:
Object
  • Object
show all
Defined in:
lib/types.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#wObject

Returns the value of attribute w.



368
369
370
# File 'lib/types.rb', line 368

def w
  @w
end

#xObject

Returns the value of attribute x.



368
369
370
# File 'lib/types.rb', line 368

def x
  @x
end

#yObject

Returns the value of attribute y.



368
369
370
# File 'lib/types.rb', line 368

def y
  @y
end

#zObject

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

#encodeObject



364
365
366
# File 'lib/types.rb', line 364

def encode()
	[@x, @y, @z].pack 'e3'
end