Module: CP

Extended by:
NiceFFI::Library
Defined in:
lib/chipmunk-ffi.rb,
lib/chipmunk-ffi/bb.rb,
lib/chipmunk-ffi/body.rb,
lib/chipmunk-ffi/core.rb,
lib/chipmunk-ffi/vec2.rb,
lib/chipmunk-ffi/shape.rb,
lib/chipmunk-ffi/space.rb

Defined Under Namespace

Modules: Shape Classes: BB, BBStruct, Body, BodyStruct, CollisionHandlerStruct, SegmentQueryInfoStruct, ShapeClassStruct, ShapeStruct, Space, SpaceStruct, Vec2, Vect

Constant Summary collapse

LOAD_PATHS =

Check if the application has defined CP_PATHS with some paths to check first for chipmunk library.

if defined? ::CP_PATHS
  NiceFFI::PathSet::DEFAULT.prepend( ::CP_PATHS )
else
  NiceFFI::PathSet::DEFAULT
end
CP_FLOAT =
:double
INFINITY =
1.0/0.0
VERSION =
version.freeze
ZERO_VEC_2 =
Vec2.new(0,0).freeze
ShapeType =
enum(
  :circle_shape,
  :segment_shape,
  :poly_shape,
  :num_shapes
)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cp_static_inline(func_sym, args, ret) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/chipmunk-ffi.rb', line 18

def self.cp_static_inline(func_sym, args, ret)
  func_name = "_#{func_sym}"
  attach_variable func_name, :pointer
  const_func_name = func_sym.to_s.upcase

  func = FFI::Function.new(ret, args, FFI::Pointer.new(self.send(func_name)), :convention => :default )
  const_set const_func_name, func

  instance_eval <<-METHOD
  def #{func_sym}(*args)
    const_get('#{const_func_name}').call *args
  end
  METHOD
end

.versionObject



5
6
7
# File 'lib/chipmunk-ffi/core.rb', line 5

def self.version
  cpVersionString
end

Instance Method Details

#bias_coefObject



11
12
13
# File 'lib/chipmunk-ffi/core.rb', line 11

def bias_coef
  cp_bias_coef
end

#bias_coef=(coef) ⇒ Object



14
15
16
# File 'lib/chipmunk-ffi/core.rb', line 14

def bias_coef=(coef)
  cp_bias_coef = coef
end

#collision_slopObject



19
20
21
# File 'lib/chipmunk-ffi/core.rb', line 19

def collision_slop
  cp_collision_slop
end

#collision_slop=(slop) ⇒ Object



22
23
24
# File 'lib/chipmunk-ffi/core.rb', line 22

def collision_slop=(slop)
  cp_collision_slop = slop
end

#moment_for_circle(m, r1, r2, offset) ⇒ Object



27
28
29
# File 'lib/chipmunk-ffi/core.rb', line 27

def moment_for_circle(m,r1,r2,offset)
  cpMomentForCircle(m, r1, r2, offset.struct);
end

#moment_for_poly(m, verts, offset) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/chipmunk-ffi/core.rb', line 37

def moment_for_poly(m,verts,offset)
  mem_pointer = FFI::MemoryPointer.new Vect, verts.size
  vert_structs = verts.collect{|s|s.struct}

  size = Vect.size
  tmp = mem_pointer
  vert_structs.each_with_index {|i, j|
    tmp.send(:put_bytes, 0, i.to_bytes, 0, size)
    tmp += size unless j == vert_structs.length-1 # avoid OOB
  }
  cpMomentForPoly(m, verts.size, mem_pointer, offset.struct)
end

#moment_for_segment(m, v1, v2) ⇒ Object



32
33
34
# File 'lib/chipmunk-ffi/core.rb', line 32

def moment_for_segment(m,v1,v2)
  cpMomentForCircle(m, v1.struct, v2.struct)
end