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,
lib/chipmunk-ffi/unsafe.rb,
lib/chipmunk-ffi/arbiter.rb,
lib/chipmunk-ffi/constraint.rb,
lib/chipmunk-ffi/space_hash.rb,
lib/chipmunk-ffi/struct_accessor.rb,
lib/chipmunk-ffi/constraints/pin_joint.rb,
lib/chipmunk-ffi/constraints/gear_joint.rb,
lib/chipmunk-ffi/constraints/pivot_joint.rb,
lib/chipmunk-ffi/constraints/slide_joint.rb,
lib/chipmunk-ffi/constraints/groove_joint.rb,
lib/chipmunk-ffi/constraints/simple_motor.rb,
lib/chipmunk-ffi/constraints/damped_spring.rb,
lib/chipmunk-ffi/constraints/ratchet_joint.rb,
lib/chipmunk-ffi/constraints/rotary_limit_joint.rb,
lib/chipmunk-ffi/constraints/damped_rotary_spring.rb

Defined Under Namespace

Modules: Constraint, Shape, StructAccessor Classes: Arbiter, ArbiterStruct, BB, BBStruct, Body, BodyStruct, CollisionHandlerStruct, ConstraintClassStruct, ConstraintStruct, DampedRotarySpring, DampedRotarySpringStruct, DampedSpring, DampedSpringStruct, GearJoint, GearJointStruct, GrooveJoint, GrooveJointStruct, PinJoint, PinJointStruct, PivotJoint, PivotJointStruct, RatchetJoint, RatchetJointStruct, RotaryLimitJoint, RotaryLimitJointStruct, SegmentQueryInfoStruct, ShapeClassStruct, ShapeStruct, SimpleMotor, SimpleMotorStruct, SlideJoint, SlideJointStruct, Space, SpaceHash, SpaceHashStruct, 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
)
ALL_ONES =

used for layers; will only work on 32 bit values (chipmunk cheats and sets these to -1)

2**32-1

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cp_static_inline(func_sym, args, ret) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chipmunk-ffi.rb', line 23

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).to_i), :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

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



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

def self.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 self.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 self.moment_for_segment(m,v1,v2)
  cpMomentForSegment(m, v1.struct, v2.struct)
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(*args) ⇒ Object



50
# File 'lib/chipmunk-ffi/core.rb', line 50

def moment_for_circle(*args);CP.moment_for_circle(*args);end

#moment_for_poly(*args) ⇒ Object



51
# File 'lib/chipmunk-ffi/core.rb', line 51

def moment_for_poly(*args);CP.moment_for_poly(*args);end

#moment_for_segment(*args) ⇒ Object



52
# File 'lib/chipmunk-ffi/core.rb', line 52

def moment_for_segment(*args);CP.moment_for_segment(*args);end

#zeroObject



204
205
206
# File 'lib/chipmunk-ffi/vec2.rb', line 204

def zero
  ZERO_VEC_2
end