Module: CP

Defined in:
lib/chipmunk.rb,
lib/version.rb,
lib/chipmunk.rb,
lib/chipmunk.rb,
ext/chipmunk/rb_chipmunk.c

Overview

Create derived static objects that know to add themselves as static.

Defined Under Namespace

Modules: Constraint, Object, Shape, StaticShape Classes: Arbiter, BB, Body, BodyStatic, Space, StaticBody, Vec2

Constant Summary collapse

VERSION =
'6.1.3.4'
ZERO_VEC_2 =
Vec2.new(0,0).freeze
ALL_ONES =
Vec2.new(1,1).freeze
ALL_LAYERS =
UINT2NUM((unsigned int)CP_ALL_LAYERS)
NO_GROUP =
UINT2NUM(CP_NO_GROUP)
ContactPoint =
c_cpContactPoint
SegmentQueryInfo =
c_cpSegmentQueryInfo
NearestPointQueryInfo =
c_cpNearestPointQueryInfo

Class Method Summary collapse

Class Method Details

.area_for_box(w, h) ⇒ Object



110
111
112
113
114
# File 'ext/chipmunk/rb_chipmunk.c', line 110

static VALUE
rb_cpAreaForBox(VALUE self, VALUE w, VALUE h) {
  cpFloat i = NUM2DBL(w) * NUM2DBL(h);
  return rb_float_new(i);
}

.area_for_circle(r1, r2) ⇒ Object



83
84
85
86
87
# File 'ext/chipmunk/rb_chipmunk.c', line 83

static VALUE
rb_cpAreaForCircle(VALUE self, VALUE r1, VALUE r2) {
  cpFloat i = cpAreaForCircle(NUM2DBL(r1), NUM2DBL(r2));
  return rb_float_new(i);
}

.area_for_poly(arr) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'ext/chipmunk/rb_chipmunk.c', line 95

static VALUE
rb_cpAreaForPoly(VALUE self, VALUE arr) {
  Check_Type(arr, T_ARRAY);
  // TODO do not cast... use stdint.h in chipmunk
  int numVerts   = (int)RARRAY_LEN(arr);
  VALUE *ary_ptr = RARRAY_PTR(arr);
  cpVect verts[numVerts];

  for(int i = 0; i < numVerts; i++) { 
    verts[i] = *VGET(ary_ptr[i]);
  }
  cpFloat area   = cpAreaForPoly(numVerts, verts);
  return rb_float_new(area);
}

.area_for_segment(v1, v2, r) ⇒ Object



89
90
91
92
93
# File 'ext/chipmunk/rb_chipmunk.c', line 89

static VALUE
rb_cpAreaForSegment(VALUE self, VALUE v1, VALUE v2, VALUE r) {
  cpFloat i = cpAreaForSegment(*VGET(v1), *VGET(v2), NUM2DBL(r));
  return rb_float_new(i);
}

.box_area(w, h) ⇒ Object



110
111
112
113
114
# File 'ext/chipmunk/rb_chipmunk.c', line 110

static VALUE
rb_cpAreaForBox(VALUE self, VALUE w, VALUE h) {
  cpFloat i = NUM2DBL(w) * NUM2DBL(h);
  return rb_float_new(i);
}

.box_moment(m, w, h) ⇒ Object



77
78
79
80
81
# File 'ext/chipmunk/rb_chipmunk.c', line 77

static VALUE
rb_cpMomentForBox(VALUE self, VALUE m, VALUE w, VALUE h) {
  cpFloat i = cpMomentForBox(NUM2DBL(m), NUM2DBL(w), NUM2DBL(h));
  return rb_float_new(i);
}

.centroid_for_poly(arr) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'ext/chipmunk/rb_chipmunk.c', line 135

static VALUE
rb_cpCentroidForPoly(VALUE self,  VALUE arr) {
  Check_Type(arr, T_ARRAY);
  // TODO do not cast... use stdint.h in chipmunk
  int numVerts   = (int)RARRAY_LEN(arr);
  VALUE *ary_ptr = RARRAY_PTR(arr);
  cpVect verts[numVerts];

  for(long i = 0; i < numVerts; i++)
    verts[i] = *VGET(ary_ptr[i]);

  return VNEW(cpCentroidForPoly(numVerts, verts));
}

.circle_area(r1, r2) ⇒ Object



83
84
85
86
87
# File 'ext/chipmunk/rb_chipmunk.c', line 83

static VALUE
rb_cpAreaForCircle(VALUE self, VALUE r1, VALUE r2) {
  cpFloat i = cpAreaForCircle(NUM2DBL(r1), NUM2DBL(r2));
  return rb_float_new(i);
}

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



50
51
52
53
54
# File 'ext/chipmunk/rb_chipmunk.c', line 50

static VALUE
rb_cpMomentForCircle(VALUE self, VALUE m, VALUE r1, VALUE r2, VALUE offset) {
  cpFloat i = cpMomentForCircle(NUM2DBL(m), NUM2DBL(r1), NUM2DBL(r2), *VGET(offset));
  return rb_float_new(i);
}

.clamp(f, min, max) ⇒ Object



117
118
119
120
121
# File 'ext/chipmunk/rb_chipmunk.c', line 117

static VALUE
rb_cpfclamp(VALUE self, VALUE f, VALUE min, VALUE max) {
  cpFloat result = cpfclamp(NUM2DBL(f), NUM2DBL(min), NUM2DBL(max));
  return rb_float_new(result);
}

.flerp(f1, f2, t) ⇒ Object



123
124
125
126
127
# File 'ext/chipmunk/rb_chipmunk.c', line 123

static VALUE
rb_cpflerp(VALUE self, VALUE f1, VALUE f2, VALUE t) {
  cpFloat result = cpflerp(NUM2DBL(f1), NUM2DBL(f2), NUM2DBL(t));
  return rb_float_new(result);
}

.flerpconst(f1, f2, d) ⇒ Object



129
130
131
132
133
# File 'ext/chipmunk/rb_chipmunk.c', line 129

static VALUE
rb_cpflerpconst(VALUE self, VALUE f1, VALUE f2, VALUE d) {
  cpFloat result = cpflerpconst(NUM2DBL(f1), NUM2DBL(f2), NUM2DBL(d));
  return rb_float_new(result);
}

.moment_for_box(m, w, h) ⇒ Object



77
78
79
80
81
# File 'ext/chipmunk/rb_chipmunk.c', line 77

static VALUE
rb_cpMomentForBox(VALUE self, VALUE m, VALUE w, VALUE h) {
  cpFloat i = cpMomentForBox(NUM2DBL(m), NUM2DBL(w), NUM2DBL(h));
  return rb_float_new(i);
}

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



50
51
52
53
54
# File 'ext/chipmunk/rb_chipmunk.c', line 50

static VALUE
rb_cpMomentForCircle(VALUE self, VALUE m, VALUE r1, VALUE r2, VALUE offset) {
  cpFloat i = cpMomentForCircle(NUM2DBL(m), NUM2DBL(r1), NUM2DBL(r2), *VGET(offset));
  return rb_float_new(i);
}

.moment_for_poly(m, arr, offset) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'ext/chipmunk/rb_chipmunk.c', line 62

static VALUE
rb_cpMomentForPoly(VALUE self, VALUE m, VALUE arr, VALUE offset) {
  Check_Type(arr, T_ARRAY);
  // TODO do not cast... use stdint.h in chipmunk
  int numVerts    = (int)RARRAY_LEN(arr);
  VALUE *ary_ptr  = RARRAY_PTR(arr);
  cpVect verts[numVerts];

  for(long i = 0; i < numVerts; i++)
    verts[i] = *VGET(ary_ptr[i]);

  cpFloat inertia = cpMomentForPoly(NUM2DBL(m), numVerts, verts, *VGET(offset));
  return rb_float_new(inertia);
}

.moment_for_segment(m, v1, v2) ⇒ Object



56
57
58
59
60
# File 'ext/chipmunk/rb_chipmunk.c', line 56

static VALUE
rb_cpMomentForSegment(VALUE self, VALUE m, VALUE v1, VALUE v2) {
  cpFloat i = cpMomentForSegment(NUM2DBL(m), *VGET(v1), *VGET(v2));
  return rb_float_new(i);
}

.poly_area(arr) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'ext/chipmunk/rb_chipmunk.c', line 95

static VALUE
rb_cpAreaForPoly(VALUE self, VALUE arr) {
  Check_Type(arr, T_ARRAY);
  // TODO do not cast... use stdint.h in chipmunk
  int numVerts   = (int)RARRAY_LEN(arr);
  VALUE *ary_ptr = RARRAY_PTR(arr);
  cpVect verts[numVerts];

  for(int i = 0; i < numVerts; i++) { 
    verts[i] = *VGET(ary_ptr[i]);
  }
  cpFloat area   = cpAreaForPoly(numVerts, verts);
  return rb_float_new(area);
}

.poly_moment(m, arr, offset) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'ext/chipmunk/rb_chipmunk.c', line 62

static VALUE
rb_cpMomentForPoly(VALUE self, VALUE m, VALUE arr, VALUE offset) {
  Check_Type(arr, T_ARRAY);
  // TODO do not cast... use stdint.h in chipmunk
  int numVerts    = (int)RARRAY_LEN(arr);
  VALUE *ary_ptr  = RARRAY_PTR(arr);
  cpVect verts[numVerts];

  for(long i = 0; i < numVerts; i++)
    verts[i] = *VGET(ary_ptr[i]);

  cpFloat inertia = cpMomentForPoly(NUM2DBL(m), numVerts, verts, *VGET(offset));
  return rb_float_new(inertia);
}

.recenter_poly(arr) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'ext/chipmunk/rb_chipmunk.c', line 149

static VALUE
rb_cpRecenterPoly(VALUE self,  VALUE arr) {
  Check_Type(arr, T_ARRAY);
  // TODO do not cast... use stdint.h in chipmunk
  int numVerts   = (int)RARRAY_LEN(arr);
  VALUE *ary_ptr = RARRAY_PTR(arr);
  cpVect verts[numVerts];

  for(long i = 0; i < numVerts; i++)
    verts[i] = *VGET(ary_ptr[i]);

  cpRecenterPoly(numVerts, verts);

  for(long i = 0; i < numVerts; i++)
    ary_ptr[i] = VNEW(verts[i]);
  return arr;
}

.segment_area(v1, v2, r) ⇒ Object



89
90
91
92
93
# File 'ext/chipmunk/rb_chipmunk.c', line 89

static VALUE
rb_cpAreaForSegment(VALUE self, VALUE v1, VALUE v2, VALUE r) {
  cpFloat i = cpAreaForSegment(*VGET(v1), *VGET(v2), NUM2DBL(r));
  return rb_float_new(i);
}

.segment_moment(m, v1, v2) ⇒ Object



56
57
58
59
60
# File 'ext/chipmunk/rb_chipmunk.c', line 56

static VALUE
rb_cpMomentForSegment(VALUE self, VALUE m, VALUE v1, VALUE v2) {
  cpFloat i = cpMomentForSegment(NUM2DBL(m), *VGET(v1), *VGET(v2));
  return rb_float_new(i);
}