Class: Jolt::Body

Inherits:
Object
  • Object
show all
Includes:
BodyDynamics
Defined in:
lib/jolt/body.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BodyDynamics

#activate, #active?, #add_force, #add_torque, #angular_velocity, #angular_velocity=, #apply_angular_impulse, #apply_impulse, #deactivate, #friction, #friction=, #kinematic_move_to, #linear_velocity, #linear_velocity=, #restitution, #restitution=, #sensor=, #sensor?

Constructor Details

#initialize(system, id) ⇒ Body

Returns a new instance of Body.



9
10
11
12
13
14
15
16
# File 'lib/jolt/body.rb', line 9

def initialize(system, id)
  @system = system
  @id = id
  @destroyed = false
  transform = current_transform
  @previous_transform = transform
  @current_transform = transform
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/jolt/body.rb', line 7

def id
  @id
end

#systemObject (readonly)

Returns the value of attribute system.



7
8
9
# File 'lib/jolt/body.rb', line 7

def system
  @system
end

Instance Method Details

#__capture_after_stepObject



82
83
84
85
# File 'lib/jolt/body.rb', line 82

def __capture_after_step
  check_alive!
  @current_transform = current_transform
end

#__capture_before_stepObject



77
78
79
80
# File 'lib/jolt/body.rb', line 77

def __capture_before_step
  check_alive!
  @previous_transform = @current_transform
end

#__mark_destroyedObject



87
88
89
# File 'lib/jolt/body.rb', line 87

def __mark_destroyed
  @destroyed = true
end

#destroyObject



60
61
62
# File 'lib/jolt/body.rb', line 60

def destroy
  @system.__destroy_body(self)
end

#destroyed?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/jolt/body.rb', line 64

def destroyed?
  @destroyed
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


72
73
74
# File 'lib/jolt/body.rb', line 72

def eql?(other)
  other.is_a?(Body) && other.system.equal?(@system) && other.id == @id
end

#hashObject



68
69
70
# File 'lib/jolt/body.rb', line 68

def hash
  [@system.object_id, @id].hash
end

#interpolated(alpha) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/jolt/body.rb', line 49

def interpolated(alpha)
  check_alive!
  alpha = Conversions.finite_float(alpha, "alpha")
  raise InvalidArgumentError, "alpha must be between 0 and 1" unless alpha.between?(0.0, 1.0)

  Transform.new(
    position: @previous_transform.position.lerp(@current_transform.position, alpha),
    rotation: @previous_transform.rotation.slerp(@current_transform.rotation, alpha)
  )
end

#positionObject



18
19
20
# File 'lib/jolt/body.rb', line 18

def position
  read_vec3(:JPH_BodyInterface_GetPosition)
end

#position=(value) ⇒ Object



22
23
24
# File 'lib/jolt/body.rb', line 22

def position=(value)
  write_vec3(:JPH_BodyInterface_SetPosition, value, activation)
end

#rotationObject



26
27
28
29
30
31
# File 'lib/jolt/body.rb', line 26

def rotation
  check_alive!
  native = Native::Quat.new
  Native.JPH_BodyInterface_GetRotation(body_interface, @id, native.pointer)
  Conversions.quat(native)
end

#rotation=(value) ⇒ Object



33
34
35
36
37
# File 'lib/jolt/body.rb', line 33

def rotation=(value)
  check_alive!
  native = Conversions.native_quat(value)
  Native.JPH_BodyInterface_SetRotation(body_interface, @id, native.pointer, activation)
end

#user_dataObject



39
40
41
42
# File 'lib/jolt/body.rb', line 39

def user_data
  check_alive!
  @system.__user_data(@id)
end

#user_data=(value) ⇒ Object



44
45
46
47
# File 'lib/jolt/body.rb', line 44

def user_data=(value)
  check_alive!
  @system.__set_user_data(@id, value)
end