Class: CP::Arbiter

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

Instance Method Summary collapse

Instance Method Details

#aObject

rb_define_alloc_func(c_cpArbiter, rb_cpArbiterAlloc); rb_define_method(c_cpArbiter , “initialize”, rb_cpArbiterInitialize, 2);


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

static VALUE
rb_cpArbiterGetA(VALUE self) {
  cpArbiter *arb = ARBITER(self);
  CP_ARBITER_GET_SHAPES(arb, a, b)
  return (VALUE)a->data;
}

#bObject


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

static VALUE
rb_cpArbiterGetB(VALUE self) {
  cpArbiter *arb = ARBITER(self);
  CP_ARBITER_GET_SHAPES(arb, a, b)
  return (VALUE)b->data;
}

#bodiesObject


108
109
110
111
112
113
# File 'ext/chipmunk/rb_cpArbiter.c', line 108

static VALUE
rb_cpArbiterGetBodies(VALUE self) {
  cpArbiter *arb = ARBITER(self);
  CP_ARBITER_GET_BODIES(arb, a, b)
  return rb_ary_new3(2, (VALUE)a->data, (VALUE)b->data);
}

#contactsObject


141
142
143
144
# File 'ext/chipmunk/rb_cpArbiter.c', line 141

static VALUE
rb_cpArbiterGetCount(VALUE self) {
  return INT2NUM(cpArbiterGetCount(ARBITER(self)));
}

#countObject


141
142
143
144
# File 'ext/chipmunk/rb_cpArbiter.c', line 141

static VALUE
rb_cpArbiterGetCount(VALUE self) {
  return INT2NUM(cpArbiterGetCount(ARBITER(self)));
}

#eObject


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

static VALUE
rb_cpArbiterGetE(VALUE self) {
  return rb_float_new(ARBITER(self)->e);
}

#e=Object


135
136
137
138
139
# File 'ext/chipmunk/rb_cpArbiter.c', line 135

static VALUE
rb_cpArbiterSetE(VALUE self, VALUE e) {
  ARBITER(self)->e = NUM2DBL(e);
  return e;
}

#each_contactObject


209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'ext/chipmunk/rb_cpArbiter.c', line 209

static VALUE
rb_cpArbiterEachContact(VALUE self) {
  cpArbiter *arb = ARBITER(self);
  int i          = 0;
  for( i = 0; i < cpArbiterGetCount(arb); i++) {
    VALUE index = INT2NUM(i);
    VALUE contact, normal;
    normal  = rb_cpArbiterGetNormal(self, index);
    contact = rb_cpArbiterGetPoint(self, index);
    /* Yield an array of contact and normal */
    rb_yield(rb_ary_new3(2, contact, normal));
  }
  return self;
}

#first_contact?Boolean

Returns:

  • (Boolean)

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

static VALUE
rb_cpArbiterIsFirstContact(VALUE self) {
  int b = cpArbiterIsFirstContact(ARBITER(self));
  return b ? Qtrue : Qfalse;
}

#ignoreObject

Ignore is new in the 5.x API, I think.


94
95
96
97
98
99
# File 'ext/chipmunk/rb_cpArbiter.c', line 94

static VALUE
rb_cpArbiterIgnore(VALUE self) {
  cpArbiter *arb = ARBITER(self);
  cpArbiterIgnore(arb);
  return Qnil;
}

#impulseObject


82
83
84
85
86
87
88
89
90
91
# File 'ext/chipmunk/rb_cpArbiter.c', line 82

static VALUE
rb_cpArbiterGetImpulse(int argc, VALUE *argv, VALUE self) {
  VALUE friction = Qnil;
  rb_scan_args(argc, argv, "01", &friction);
  if (NIL_P(friction) || friction == Qnil) {
    return rb_cpArbiterTotalImpulse(self);
  }
  /* Here, it's with friction */
  return rb_cpArbiterTotalImpulseWithFriction(self);
}

#lengthObject


141
142
143
144
# File 'ext/chipmunk/rb_cpArbiter.c', line 141

static VALUE
rb_cpArbiterGetCount(VALUE self) {
  return INT2NUM(cpArbiterGetCount(ARBITER(self)));
}

#normalObject


169
170
171
172
173
174
175
176
177
# File 'ext/chipmunk/rb_cpArbiter.c', line 169

static VALUE
rb_cpArbiterGetNormal(VALUE self, VALUE index) {
  cpArbiter *arb = ARBITER(self);
  int i          = NUM2INT(index);
  if (arbiterBadIndex(arb, i)) {
    rb_raise(rb_eIndexError, "No such normal.");
  }
  return VNEW(cpArbiterGetNormal(arb, i));
}

#pointObject


179
180
181
182
183
184
185
186
187
# File 'ext/chipmunk/rb_cpArbiter.c', line 179

static VALUE
rb_cpArbiterGetPoint(VALUE self, VALUE index) {
  cpArbiter *arb = ARBITER(self);
  int i          = NUM2INT(index);
  if (arbiterBadIndex(arb, i)) {
    rb_raise(rb_eIndexError, "No such contact point.");
  }
  return VNEW(cpArbiterGetPoint(arb, i));
}

#pointsObject


232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'ext/chipmunk/rb_cpArbiter.c', line 232

VALUE
rb_cpArbiterGetContactPointSet(VALUE arbiter) {
  cpArbiter * arb       = ARBITER(arbiter);
  cpContactPointSet set = cpArbiterGetContactPointSet(arb);
  VALUE result          = rb_ary_new();
  for(int index = 0; index < set.count; index++) {
    VALUE point   = VNEW(set.points[index].point);
    VALUE normal  = VNEW(set.points[index].normal);
    VALUE dist    = DBL2NUM(set.points[index].dist);
    VALUE contact = rb_cpContactPointNew(point, normal, dist);
    rb_ary_push(result, contact);
  }
  return result;
}

#shapesObject


101
102
103
104
105
106
# File 'ext/chipmunk/rb_cpArbiter.c', line 101

static VALUE
rb_cpArbiterGetShapes(VALUE self) {
  cpArbiter *arb = ARBITER(self);
  CP_ARBITER_GET_SHAPES(arb, a, b)
  return rb_ary_new3(2, (VALUE)a->data, (VALUE)b->data);
}

#sizeObject


141
142
143
144
# File 'ext/chipmunk/rb_cpArbiter.c', line 141

static VALUE
rb_cpArbiterGetCount(VALUE self) {
  return INT2NUM(cpArbiterGetCount(ARBITER(self)));
}

#to_sObject


201
202
203
204
205
206
207
# File 'ext/chipmunk/rb_cpArbiter.c', line 201

static VALUE
rb_cpArbiterToString(VALUE self) {
  char str[256];
  cpArbiter *arb = ARBITER(self);
  sprintf(str, "#<CP::Arbiter:%p>", arb);
  return rb_str_new2(str);
}

#uObject


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

static VALUE
rb_cpArbiterGetU(VALUE self) {
  return rb_float_new(ARBITER(self)->u);
}

#u=Object


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

static VALUE
rb_cpArbiterSetU(VALUE self, VALUE u) {
  ARBITER(self)->u = NUM2DBL(u);
  return u;
}