Class: CP::Body
- Inherits:
-
Object
- Object
- CP::Body
- Includes:
- Object
- Defined in:
- lib/chipmunk.rb,
ext/chipmunk/rb_cpBody.c
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #a ⇒ Object
- #a=(val) ⇒ Object
- #activate ⇒ Object
- #add_to_space(space) ⇒ Object
- #ang_vel ⇒ Object
- #ang_vel=(val) ⇒ Object
- #angle ⇒ Object
- #angle=(val) ⇒ Object
- #apply_force(f, r) ⇒ Object
- #apply_impulse(j, r) ⇒ Object
- #chipmunk_objects ⇒ Object
- #f ⇒ Object
- #f=(val) ⇒ Object
- #force ⇒ Object
- #force=(val) ⇒ Object
- #i ⇒ Object
- #i=(val) ⇒ Object
- #initialize(m, i) ⇒ Object constructor
- #kinetic_energy ⇒ Object
- #local2world(v) ⇒ Object
- #m ⇒ Object
- #m=(val) ⇒ Object
- #m_inv ⇒ Object
- #mass ⇒ Object
- #mass=(val) ⇒ Object
- #mass_inv ⇒ Object
- #moment ⇒ Object
- #moment=(val) ⇒ Object
- #moment_inv ⇒ Object
- #object ⇒ Object
- #object=(val) ⇒ Object
- #p ⇒ Object
- #p=(val) ⇒ Object
- #pos ⇒ Object
- #pos=(val) ⇒ Object
- #position_func(*args) ⇒ Object
- #remove_from_space(space) ⇒ Object
- #reset_forces ⇒ Object
- #rogue? ⇒ Boolean
- #rot ⇒ Object
- #sleep? ⇒ Boolean
- #sleep_alone ⇒ Object
- #sleep_group(vgroup) ⇒ Object
- #sleep_self ⇒ Object
- #sleep_with_group(vgroup) ⇒ Object
- #sleep_with_self ⇒ Object
- #sleeping? ⇒ Boolean
- #static? ⇒ Boolean
- #t ⇒ Object
- #t=(val) ⇒ Object
- #torque ⇒ Object
- #torque=(val) ⇒ Object
- #update_position(dt) ⇒ Object
- #update_velocity(g, dmp, dt) ⇒ Object
- #v ⇒ Object
- #v=(val) ⇒ Object
- #v_limit ⇒ Object
- #v_limit=(val) ⇒ Object
- #vel ⇒ Object
- #vel=(val) ⇒ Object
- #velocity_func(*args) ⇒ Object
- #w ⇒ Object
- #w=(val) ⇒ Object
- #w_limit ⇒ Object
- #w_limit=(val) ⇒ Object
- #world2local(v) ⇒ Object
Constructor Details
#initialize(m, i) ⇒ Object
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_static ⇒ Object
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
#a ⇒ Object
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=(val) ⇒ 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;
}
|
#activate ⇒ Object
236 237 238 239 240 |
# File 'ext/chipmunk/rb_cpBody.c', line 236 static VALUE rb_cpBodyActivate(VALUE self) { cpBodyActivate(BODY(self)); return self; } |
#add_to_space(space) ⇒ Object
48 49 50 |
# File 'lib/chipmunk.rb', line 48 def add_to_space(space) space.add_body(self) end |
#ang_vel ⇒ Object
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=(val) ⇒ 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;
}
|
#angle ⇒ Object
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=(val) ⇒ 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_force(f, r) ⇒ Object
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_impulse(j, r) ⇒ Object
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;
}
|
#chipmunk_objects ⇒ Object
44 45 46 |
# File 'lib/chipmunk.rb', line 44 def chipmunk_objects [self] end |
#f ⇒ Object
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=(val) ⇒ 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;
}
|
#force ⇒ Object
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=(val) ⇒ 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;
}
|
#i ⇒ Object
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=(val) ⇒ 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_energy ⇒ Object
379 380 381 382 |
# File 'ext/chipmunk/rb_cpBody.c', line 379 static VALUE rb_cpBodyKineticEnergy(VALUE self) { return DBL2NUM(cpBodyKineticEnergy(BODY(self))); } |
#local2world(v) ⇒ Object
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)));
}
|
#m ⇒ Object
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=(val) ⇒ 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_inv ⇒ Object
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);
}
|
#mass ⇒ Object
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=(val) ⇒ 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_inv ⇒ Object
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);
}
|
#moment ⇒ Object
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=(val) ⇒ 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_inv ⇒ Object
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);
}
|
#object ⇒ Object
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=(val) ⇒ 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;
}
|
#p ⇒ Object
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=(val) ⇒ 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;
}
|
#pos ⇒ Object
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=(val) ⇒ 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_func(*args) ⇒ Object
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;
}
|
#remove_from_space(space) ⇒ Object
52 53 54 |
# File 'lib/chipmunk.rb', line 52 def remove_from_space(space) space.remove_body(self) end |
#reset_forces ⇒ Object
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
296 297 298 299 |
# File 'ext/chipmunk/rb_cpBody.c', line 296 static VALUE rb_cpBodyIsRogue(VALUE self) { return cpBodyIsRogue(BODY(self)) ? Qtrue : Qfalse; } |
#rot ⇒ Object
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
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_alone ⇒ Object
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_group(vgroup) ⇒ Object
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_self ⇒ Object
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_group(vgroup) ⇒ Object
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_self ⇒ Object
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
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
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;
//
}
|
#t ⇒ Object
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=(val) ⇒ 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;
}
|
#torque ⇒ Object
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=(val) ⇒ 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_position(dt) ⇒ Object
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_velocity(g, dmp, dt) ⇒ Object
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;
}
|
#v ⇒ Object
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=(val) ⇒ 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_limit ⇒ Object
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=(val) ⇒ 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;
}
|
#vel ⇒ Object
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=(val) ⇒ 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_func(*args) ⇒ Object
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;
}
|
#w ⇒ Object
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=(val) ⇒ 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_limit ⇒ Object
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=(val) ⇒ 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;
}
|
#world2local(v) ⇒ Object
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)));
}
|