Class: Jolt::Shape

Inherits:
Object
  • Object
show all
Extended by:
ShapeBuilders
Defined in:
lib/jolt/shape.rb

Constant Summary collapse

DEFAULT_CONVEX_RADIUS =
0.05

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ShapeBuilders

compound, convex_hull, heightfield, mesh, offset, scaled

Constructor Details

#initialize(pointer, kind) ⇒ Shape

Returns a new instance of Shape.



50
51
52
53
54
# File 'lib/jolt/shape.rb', line 50

def initialize(pointer, kind)
  @pointer = pointer
  @kind = kind
  @released = false
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



48
49
50
# File 'lib/jolt/shape.rb', line 48

def kind
  @kind
end

Class Method Details

.box(half_extents, convex_radius: DEFAULT_CONVEX_RADIUS) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/jolt/shape.rb', line 10

def box(half_extents, convex_radius: DEFAULT_CONVEX_RADIUS)
  Jolt.init
  extents = Conversions.native_vec3(half_extents, name: "half_extents")
  %i[x y z].each do |component|
    raise InvalidArgumentError, "half_extents must be positive" unless extents[component].positive?
  end
  radius = Conversions.non_negative_float(convex_radius, "convex_radius")
  build(Native.JPH_BoxShape_Create(extents.pointer, radius), :box)
end

.capsule(half_height:, radius:) ⇒ Object



25
26
27
28
29
30
# File 'lib/jolt/shape.rb', line 25

def capsule(half_height:, radius:)
  Jolt.init
  height = Conversions.non_negative_float(half_height, "half_height")
  radius = Conversions.positive_float(radius, "radius")
  build(Native.JPH_CapsuleShape_Create(height, radius), :capsule)
end

.cylinder(half_height:, radius:) ⇒ Object



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

def cylinder(half_height:, radius:)
  Jolt.init
  height = Conversions.positive_float(half_height, "half_height")
  radius = Conversions.positive_float(radius, "radius")
  build(Native.JPH_CylinderShape_Create(height, radius), :cylinder)
end

.sphere(radius) ⇒ Object



20
21
22
23
# File 'lib/jolt/shape.rb', line 20

def sphere(radius)
  Jolt.init
  build(Native.JPH_SphereShape_Create(Conversions.positive_float(radius, "radius")), :sphere)
end

Instance Method Details

#must_be_static?Boolean

Returns:

  • (Boolean)


74
75
76
77
# File 'lib/jolt/shape.rb', line 74

def must_be_static?
  check_alive!
  Native.JPH_Shape_MustBeStatic(@pointer)
end

#native_pointerObject



79
80
81
82
# File 'lib/jolt/shape.rb', line 79

def native_pointer
  check_alive!
  @pointer
end

#releaseObject



56
57
58
59
60
61
62
63
# File 'lib/jolt/shape.rb', line 56

def release
  return if @released

  Native.JPH_Shape_Destroy(@pointer)
  @released = true
  @pointer = nil
  nil
end

#released?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/jolt/shape.rb', line 65

def released?
  @released
end

#volumeObject



69
70
71
72
# File 'lib/jolt/shape.rb', line 69

def volume
  check_alive!
  Native.JPH_Shape_GetVolume(@pointer)
end