Class: Chipmunk::Body

Inherits:
Object
  • Object
show all
Defined in:
ext/chipmunk/rb_cpBody.c

Direct Known Subclasses

CP::StaticBody

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject


37
38
39
40
41
42
43
# File 'ext/chipmunk/rb_cpBody.c', line 37

static VALUE
rb_cpBodyInitialize(VALUE self, VALUE m, VALUE i) {
  cpBody *body = BODY(self);
  cpBodyInit(body, NUM2DBL(m), NUM2DBL(i));
  body->data = (void *)self;
  return self;
}

Class Method Details

.new_staticObject


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

static VALUE
rb_cpStaticBodyNew(VALUE klass) {
  return rb_cpBodyInitializeStatic(rb_cpBodyAllocStatic(klass));
}

Instance Method Details

#aObject


101
102
103
104
# File 'ext/chipmunk/rb_cpBody.c', line 101

static VALUE
rb_cpBodyGetAngle(VALUE self) {
  return rb_float_new(BODY(self)->a);
}

#a=Object


163
164
165
166
167
# File 'ext/chipmunk/rb_cpBody.c', line 163

static VALUE
rb_cpBodySetAngle(VALUE self, VALUE val) {
  cpBodySetAngle(BODY(self), NUM2DBL(val));
  return val;
}

#activateObject


236
237
238
239
240
# File 'ext/chipmunk/rb_cpBody.c', line 236

static VALUE
rb_cpBodyActivate(VALUE self) {
  cpBodyActivate(BODY(self));
  return self;
}

#ang_velObject


106
107
108
109
# File 'ext/chipmunk/rb_cpBody.c', line 106

static VALUE
rb_cpBodyGetAVel(VALUE self) {
  return rb_float_new(BODY(self)->w);
}

#ang_vel=Object


169
170
171
172
173
# File 'ext/chipmunk/rb_cpBody.c', line 169

static VALUE
rb_cpBodySetAVel(VALUE self, VALUE val) {
  BODY(self)->w = NUM2DBL(val);
  return val;
}

#angleObject


101
102
103
104
# File 'ext/chipmunk/rb_cpBody.c', line 101

static VALUE
rb_cpBodyGetAngle(VALUE self) {
  return rb_float_new(BODY(self)->a);
}

#angle=Object


163
164
165
166
167
# File 'ext/chipmunk/rb_cpBody.c', line 163

static VALUE
rb_cpBodySetAngle(VALUE self, VALUE val) {
  cpBodySetAngle(BODY(self), NUM2DBL(val));
  return val;
}

#apply_forceObject


212
213
214
215
216
# File 'ext/chipmunk/rb_cpBody.c', line 212

static VALUE
rb_cpBodyApplyForce(VALUE self, VALUE f, VALUE r) {
  cpBodyApplyForce(BODY(self), *VGET(f), *VGET(r));
  return self;
}

#apply_impulseObject


218
219
220
221
222
# File 'ext/chipmunk/rb_cpBody.c', line 218

static VALUE
rb_cpBodyApplyImpulse(VALUE self, VALUE j, VALUE r) {
  cpBodyApplyImpulse(BODY(self), *VGET(j), *VGET(r));
  return self;
}

#fObject


96
97
98
99
# File 'ext/chipmunk/rb_cpBody.c', line 96

static VALUE
rb_cpBodyGetForce(VALUE self) {
  return VWRAP(self, &BODY(self)->f);
}

#f=Object


157
158
159
160
161
# File 'ext/chipmunk/rb_cpBody.c', line 157

static VALUE
rb_cpBodySetForce(VALUE self, VALUE val) {
  BODY(self)->f = *VGET(val);
  return val;
}

#forceObject


96
97
98
99
# File 'ext/chipmunk/rb_cpBody.c', line 96

static VALUE
rb_cpBodyGetForce(VALUE self) {
  return VWRAP(self, &BODY(self)->f);
}

#force=Object


157
158
159
160
161
# File 'ext/chipmunk/rb_cpBody.c', line 157

static VALUE
rb_cpBodySetForce(VALUE self, VALUE val) {
  BODY(self)->f = *VGET(val);
  return val;
}

#iObject


75
76
77
78
# File 'ext/chipmunk/rb_cpBody.c', line 75

static VALUE
rb_cpBodyGetMoment(VALUE self) {
  return rb_float_new(BODY(self)->i);
}

#i=Object


139
140
141
142
143
# File 'ext/chipmunk/rb_cpBody.c', line 139

static VALUE
rb_cpBodySetMoment(VALUE self, VALUE val) {
  cpBodySetMoment(BODY(self), NUM2DBL(val));
  return val;
}

#kinetic_energyObject


379
380
381
382
# File 'ext/chipmunk/rb_cpBody.c', line 379

static VALUE
rb_cpBodyKineticEnergy(VALUE self) {
  return DBL2NUM(cpBodyKineticEnergy(BODY(self)));
}

#local2worldObject


196
197
198
199
# File 'ext/chipmunk/rb_cpBody.c', line 196

static VALUE
rb_cpBodyLocal2World(VALUE self, VALUE v) {
  return VNEW(cpBodyLocal2World(BODY(self), *VGET(v)));
}

#mObject


65
66
67
68
# File 'ext/chipmunk/rb_cpBody.c', line 65

static VALUE
rb_cpBodyGetMass(VALUE self) {
  return rb_float_new(BODY(self)->m);
}

#m=Object


133
134
135
136
137
# File 'ext/chipmunk/rb_cpBody.c', line 133

static VALUE
rb_cpBodySetMass(VALUE self, VALUE val) {
  cpBodySetMass(BODY(self), NUM2DBL(val));
  return val;
}

#m_invObject


70
71
72
73
# File 'ext/chipmunk/rb_cpBody.c', line 70

static VALUE
rb_cpBodyGetMassInv(VALUE self) {
  return rb_float_new(BODY(self)->m_inv);
}

#massObject


65
66
67
68
# File 'ext/chipmunk/rb_cpBody.c', line 65

static VALUE
rb_cpBodyGetMass(VALUE self) {
  return rb_float_new(BODY(self)->m);
}

#mass=Object


133
134
135
136
137
# File 'ext/chipmunk/rb_cpBody.c', line 133

static VALUE
rb_cpBodySetMass(VALUE self, VALUE val) {
  cpBodySetMass(BODY(self), NUM2DBL(val));
  return val;
}

#mass_invObject


70
71
72
73
# File 'ext/chipmunk/rb_cpBody.c', line 70

static VALUE
rb_cpBodyGetMassInv(VALUE self) {
  return rb_float_new(BODY(self)->m_inv);
}

#momentObject


75
76
77
78
# File 'ext/chipmunk/rb_cpBody.c', line 75

static VALUE
rb_cpBodyGetMoment(VALUE self) {
  return rb_float_new(BODY(self)->i);
}

#moment=Object


139
140
141
142
143
# File 'ext/chipmunk/rb_cpBody.c', line 139

static VALUE
rb_cpBodySetMoment(VALUE self, VALUE val) {
  cpBodySetMoment(BODY(self), NUM2DBL(val));
  return val;
}

#moment_invObject


81
82
83
84
# File 'ext/chipmunk/rb_cpBody.c', line 81

static VALUE
rb_cpBodyGetMomentInv(VALUE self) {
  return rb_float_new(BODY(self)->i_inv);
}

#objectObject


368
369
370
371
# File 'ext/chipmunk/rb_cpBody.c', line 368

static VALUE
rb_cpBodyGetData(VALUE self) {
  return rb_iv_get(self, "data");
}

#object=Object


373
374
375
376
377
# File 'ext/chipmunk/rb_cpBody.c', line 373

static VALUE
rb_cpBodySetData(VALUE self, VALUE val) {
  rb_iv_set(self, "data", val);
  return val;
}

#pObject


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

static VALUE
rb_cpBodyGetPos(VALUE self) {
  return VWRAP(self, &BODY(self)->p);
}

#p=Object


145
146
147
148
149
# File 'ext/chipmunk/rb_cpBody.c', line 145

static VALUE
rb_cpBodySetPos(VALUE self, VALUE val) {
  BODY(self)->p = *VGET(val);
  return val;
}

#posObject


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

static VALUE
rb_cpBodyGetPos(VALUE self) {
  return VWRAP(self, &BODY(self)->p);
}

#pos=Object


145
146
147
148
149
# File 'ext/chipmunk/rb_cpBody.c', line 145

static VALUE
rb_cpBodySetPos(VALUE self, VALUE val) {
  BODY(self)->p = *VGET(val);
  return val;
}

#position_funcObject


352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'ext/chipmunk/rb_cpBody.c', line 352

static VALUE
rb_cpBodySetPositionFunc(int argc, VALUE *argv, VALUE self) {
  VALUE block;
  cpBody * body = BODY(self);
  rb_scan_args(argc, argv, "&", &block);
  // Restore defaults if no block
  if (NIL_P(block)) {
    body->position_func = cpBodyUpdatePosition; //Default;
    return Qnil;
  }
  // set block for use in callback
  rb_iv_set(self, "position_func", block);
  body->position_func = bodyPositionCallback;
  return self;
}

#reset_forcesObject


206
207
208
209
210
# File 'ext/chipmunk/rb_cpBody.c', line 206

static VALUE
rb_cpBodyResetForces(VALUE self) {
  cpBodyResetForces(BODY(self));
  return self;
}

#rogue?Boolean

Returns:

  • (Boolean)

296
297
298
299
# File 'ext/chipmunk/rb_cpBody.c', line 296

static VALUE
rb_cpBodyIsRogue(VALUE self) {
  return cpBodyIsRogue(BODY(self)) ? Qtrue : Qfalse;
}

#rotObject


127
128
129
130
# File 'ext/chipmunk/rb_cpBody.c', line 127

static VALUE
rb_cpBodyGetRot(VALUE self) {
  return VWRAP(self, &BODY(self)->rot);
}

#sleep?Boolean

Returns:

  • (Boolean)

281
282
283
284
# File 'ext/chipmunk/rb_cpBody.c', line 281

static VALUE
rb_cpBodyIsSleeping(VALUE self) {
  return cpBodyIsSleeping(BODY(self)) ? Qtrue : Qfalse;
}

#sleep_aloneObject


261
262
263
264
265
266
# File 'ext/chipmunk/rb_cpBody.c', line 261

static VALUE
rb_cpBodySleep(VALUE self) {
  cpBody * body = rb_cpBodySleepValidate(self);
  cpBodySleep(body);
  return self;
}

#sleep_groupObject


268
269
270
271
272
273
274
275
276
277
278
# File 'ext/chipmunk/rb_cpBody.c', line 268

static VALUE
rb_cpBodySleepWithGroup(VALUE self, VALUE vgroup) {
  cpBody * group = NIL_P(vgroup) ? NULL : rb_cpBodySleepValidate(vgroup);
  cpBody * body  = rb_cpBodySleepValidate(self);

  if (!cpBodyIsSleeping(group)) {
    rb_raise(rb_eArgError, "Cannot use a non-sleeping body as a group identifier.");
  }
  cpBodySleepWithGroup(body, group);
  return self;
}

#sleep_selfObject


261
262
263
264
265
266
# File 'ext/chipmunk/rb_cpBody.c', line 261

static VALUE
rb_cpBodySleep(VALUE self) {
  cpBody * body = rb_cpBodySleepValidate(self);
  cpBodySleep(body);
  return self;
}

#sleep_with_groupObject


268
269
270
271
272
273
274
275
276
277
278
# File 'ext/chipmunk/rb_cpBody.c', line 268

static VALUE
rb_cpBodySleepWithGroup(VALUE self, VALUE vgroup) {
  cpBody * group = NIL_P(vgroup) ? NULL : rb_cpBodySleepValidate(vgroup);
  cpBody * body  = rb_cpBodySleepValidate(self);

  if (!cpBodyIsSleeping(group)) {
    rb_raise(rb_eArgError, "Cannot use a non-sleeping body as a group identifier.");
  }
  cpBodySleepWithGroup(body, group);
  return self;
}

#sleep_with_selfObject


261
262
263
264
265
266
# File 'ext/chipmunk/rb_cpBody.c', line 261

static VALUE
rb_cpBodySleep(VALUE self) {
  cpBody * body = rb_cpBodySleepValidate(self);
  cpBodySleep(body);
  return self;
}

#sleeping?Boolean

Returns:

  • (Boolean)

281
282
283
284
# File 'ext/chipmunk/rb_cpBody.c', line 281

static VALUE
rb_cpBodyIsSleeping(VALUE self) {
  return cpBodyIsSleeping(BODY(self)) ? Qtrue : Qfalse;
}

#static?Boolean

Returns:

  • (Boolean)

286
287
288
289
290
291
292
293
294
# File 'ext/chipmunk/rb_cpBody.c', line 286

static VALUE
rb_cpBodyIsStatic(VALUE self) {
  cpBody * body = BODY(self);
  cpBool stat   = 0;
  // cpBodyInitStatic(body);
  stat = cpBodyIsStatic(body);
  return stat ? Qtrue : Qfalse;
  //
}

#tObject


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

static VALUE
rb_cpBodyGetTorque(VALUE self) {
  return rb_float_new(BODY(self)->t);
}

#t=Object


175
176
177
178
179
# File 'ext/chipmunk/rb_cpBody.c', line 175

static VALUE
rb_cpBodySetTorque(VALUE self, VALUE val) {
  BODY(self)->t = NUM2DBL(val);
  return val;
}

#torqueObject


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

static VALUE
rb_cpBodyGetTorque(VALUE self) {
  return rb_float_new(BODY(self)->t);
}

#torque=Object


175
176
177
178
179
# File 'ext/chipmunk/rb_cpBody.c', line 175

static VALUE
rb_cpBodySetTorque(VALUE self, VALUE val) {
  BODY(self)->t = NUM2DBL(val);
  return val;
}

#update_positionObject


230
231
232
233
234
# File 'ext/chipmunk/rb_cpBody.c', line 230

static VALUE
rb_cpBodyUpdatePosition(VALUE self, VALUE dt) {
  cpBodyUpdatePosition(BODY(self), NUM2DBL(dt));
  return self;
}

#update_velocityObject


224
225
226
227
228
# File 'ext/chipmunk/rb_cpBody.c', line 224

static VALUE
rb_cpBodyUpdateVelocity(VALUE self, VALUE g, VALUE dmp, VALUE dt) {
  cpBodyUpdateVelocity(BODY(self), *VGET(g), NUM2DBL(dmp), NUM2DBL(dt));
  return self;
}

#vObject


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

static VALUE
rb_cpBodyGetVel(VALUE self) {
  return VWRAP(self, &BODY(self)->v);
}

#v=Object


151
152
153
154
155
# File 'ext/chipmunk/rb_cpBody.c', line 151

static VALUE
rb_cpBodySetVel(VALUE self, VALUE val) {
  BODY(self)->v = *VGET(val);
  return val;
}

#v_limitObject


116
117
118
119
# File 'ext/chipmunk/rb_cpBody.c', line 116

static VALUE
rb_cpBodyGetVLimit(VALUE self) {
  return rb_float_new(BODY(self)->v_limit);
}

#v_limit=Object


182
183
184
185
186
# File 'ext/chipmunk/rb_cpBody.c', line 182

static VALUE
rb_cpBodySetVLimit(VALUE self, VALUE val) {
  BODY(self)->v_limit = NUM2DBL(val);
  return val;
}

#velObject


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

static VALUE
rb_cpBodyGetVel(VALUE self) {
  return VWRAP(self, &BODY(self)->v);
}

#vel=Object


151
152
153
154
155
# File 'ext/chipmunk/rb_cpBody.c', line 151

static VALUE
rb_cpBodySetVel(VALUE self, VALUE val) {
  BODY(self)->v = *VGET(val);
  return val;
}

#velocity_funcObject


328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'ext/chipmunk/rb_cpBody.c', line 328

static VALUE
rb_cpBodySetVelocityFunc(int argc, VALUE *argv, VALUE self) {
  VALUE block;
  cpBody * body = BODY(self);
  rb_scan_args(argc, argv, "0&", &block);
  // Restore defaults if no block
  if (NIL_P(block)) {
    body->velocity_func = cpBodyUpdateVelocity; //Default;
    return Qnil;
  }
  // set block for use in callback
  rb_iv_set(self, "velocity_func", block);
  body->velocity_func = bodyVelocityCallback;
  return self;
}

#wObject


106
107
108
109
# File 'ext/chipmunk/rb_cpBody.c', line 106

static VALUE
rb_cpBodyGetAVel(VALUE self) {
  return rb_float_new(BODY(self)->w);
}

#w=Object


169
170
171
172
173
# File 'ext/chipmunk/rb_cpBody.c', line 169

static VALUE
rb_cpBodySetAVel(VALUE self, VALUE val) {
  BODY(self)->w = NUM2DBL(val);
  return val;
}

#w_limitObject


121
122
123
124
# File 'ext/chipmunk/rb_cpBody.c', line 121

static VALUE
rb_cpBodyGetWLimit(VALUE self) {
  return rb_float_new(BODY(self)->w_limit);
}

#w_limit=Object


188
189
190
191
192
# File 'ext/chipmunk/rb_cpBody.c', line 188

static VALUE
rb_cpBodySetWLimit(VALUE self, VALUE val) {
  BODY(self)->w_limit = NUM2DBL(val);
  return val;
}

#world2localObject


201
202
203
204
# File 'ext/chipmunk/rb_cpBody.c', line 201

static VALUE
rb_cpBodyWorld2Local(VALUE self, VALUE v) {
  return VNEW(cpBodyWorld2Local(BODY(self), *VGET(v)));
}