Class: GlimR::Quaternion
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Array
#-@, #add, #cross_product, #delete_first, #dot, #sub
Class Method Details
.[](w, x, y, z) ⇒ Object
255 256 257 258 259 |
# File 'lib/glimr/renderer/transform.rb', line 255 def self.[](w,x,y,z) aa = new aa.push(w,x,y,z) aa end |
Instance Method Details
#normalize ⇒ Object
261 262 263 |
# File 'lib/glimr/renderer/transform.rb', line 261 def normalize self.class[*(Vector[*self] * (1.0 / Vector[*self].r)).to_a] end |
#to_aa ⇒ Object
275 276 277 278 279 280 281 282 |
# File 'lib/glimr/renderer/transform.rb', line 275 def to_aa w,x,y,z = normalize c = w angle = (Math.acos(c) * 2) * (180/Math::PI) s = Math.sqrt( 1 - c*c ) s = 1 if (s.abs < 0.0005) AngleAxis[angle, x/s, y/s, z/s] end |
#to_matrix ⇒ Object
265 266 267 268 269 270 271 272 273 |
# File 'lib/glimr/renderer/transform.rb', line 265 def to_matrix w,x,y,z = normalize [ [1-2*y*y-2*z*z, 2*x*y-2*w*z, 2*z*x+2*w*y, 0], [2*x*y+2*w*z, 1-2*x*x-2*z*z, 2*y*z-2*w*x, 0], [2*z*x-2*w*y, 2*y*z+2*w*x, 1-2*x*x-2*y*y, 0], [0,0,0,1] ].transpose.flatten end |
#to_quat ⇒ Object
284 285 286 |
# File 'lib/glimr/renderer/transform.rb', line 284 def to_quat self end |