Class: Bullet3::Transform

Inherits:
Object
  • Object
show all
Defined in:
lib/bullet3/linear_math/transform.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rotation = Quaternion.identity, origin = Vector3.zero) ⇒ Transform

Returns a new instance of Transform.



11
12
13
14
# File 'lib/bullet3/linear_math/transform.rb', line 11

def initialize(rotation = Quaternion.identity, origin = Vector3.zero)
  @rotation = Quaternion.coerce(rotation)
  @origin = Vector3.coerce(origin)
end

Instance Attribute Details

#originObject

Returns the value of attribute origin.



5
6
7
# File 'lib/bullet3/linear_math/transform.rb', line 5

def origin
  @origin
end

#rotationObject

Returns the value of attribute rotation.



5
6
7
# File 'lib/bullet3/linear_math/transform.rb', line 5

def rotation
  @rotation
end

Class Method Details

.identityObject



7
8
9
# File 'lib/bullet3/linear_math/transform.rb', line 7

def self.identity
  new
end

Instance Method Details

#*(other) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/bullet3/linear_math/transform.rb', line 20

def *(other)
  case other
  when Transform
    self.class.new(rotation * other.rotation, transform_vector(other.origin))
  else
    transform_vector(other)
  end
end

#basisObject



16
17
18
# File 'lib/bullet3/linear_math/transform.rb', line 16

def basis
  rotation.to_matrix
end

#inverseObject



29
30
31
32
# File 'lib/bullet3/linear_math/transform.rb', line 29

def inverse
  inverse_rotation = rotation.inverse.normalized
  self.class.new(inverse_rotation, inverse_rotation.to_matrix * -origin)
end

#inverse_times(other) ⇒ Object



34
35
36
# File 'lib/bullet3/linear_math/transform.rb', line 34

def inverse_times(other)
  inverse * other
end

#to_aObject



38
39
40
# File 'lib/bullet3/linear_math/transform.rb', line 38

def to_a
  [origin.to_a, rotation.to_a]
end