Module: CP

Defined in:
lib/chipmunk.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, Body, BodyStatic, SegmentQueryInfo, Space, StaticBody, Vec2

Constant Summary collapse

VERSION =
'6.1.3.3'
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
NearestPointQueryInfo =
c_cpNearestPointQueryInfo

Class Method Summary collapse

Class Method Details

.area_for_boxObject


112
113
114
115
116
# File 'ext/chipmunk/rb_chipmunk.c', line 112

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

.area_for_circleObject


85
86
87
88
89
# File 'ext/chipmunk/rb_chipmunk.c', line 85

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

.area_for_polyObject


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

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_segmentObject


91
92
93
94
95
# File 'ext/chipmunk/rb_chipmunk.c', line 91

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_areaObject


112
113
114
115
116
# File 'ext/chipmunk/rb_chipmunk.c', line 112

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

.box_momentObject


79
80
81
82
83
# File 'ext/chipmunk/rb_chipmunk.c', line 79

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_polyObject


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

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_areaObject


85
86
87
88
89
# File 'ext/chipmunk/rb_chipmunk.c', line 85

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

.circle_momentObject


52
53
54
55
56
# File 'ext/chipmunk/rb_chipmunk.c', line 52

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);
}

.clampObject


119
120
121
122
123
# File 'ext/chipmunk/rb_chipmunk.c', line 119

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);
}

.flerpObject


125
126
127
128
129
# File 'ext/chipmunk/rb_chipmunk.c', line 125

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);
}

.flerpconstObject


131
132
133
134
135
# File 'ext/chipmunk/rb_chipmunk.c', line 131

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_boxObject


79
80
81
82
83
# File 'ext/chipmunk/rb_chipmunk.c', line 79

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_circleObject


52
53
54
55
56
# File 'ext/chipmunk/rb_chipmunk.c', line 52

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_polyObject


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

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_segmentObject


58
59
60
61
62
# File 'ext/chipmunk/rb_chipmunk.c', line 58

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_areaObject


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

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_momentObject


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

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_polyObject


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

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_areaObject


91
92
93
94
95
# File 'ext/chipmunk/rb_chipmunk.c', line 91

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_momentObject


58
59
60
61
62
# File 'ext/chipmunk/rb_chipmunk.c', line 58

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);
}