Module: Chipmunk::Shape

Included in:
Circle, Poly, Segment
Defined in:
ext/chipmunk/rb_cpShape.c

Defined Under Namespace

Classes: Circle, Poly, Segment

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objObject

Class Method Details

.reset_id_counterObject


183
184
185
186
187
# File 'ext/chipmunk/rb_cpShape.c', line 183

static VALUE
rb_cpShapeResetIdCounter(VALUE self) {
  cpResetShapeIdCounter();
  return Qnil;
}

Instance Method Details

#bbObject


142
143
144
145
146
147
148
# File 'ext/chipmunk/rb_cpShape.c', line 142

static VALUE
rb_cpShapeCacheBB(VALUE self) {
  cpShape *shape = SHAPE(self);
  cpShapeCacheBB(shape);

  return rb_cpShapeGetBB(self);
}

#bodyObject


54
55
56
57
# File 'ext/chipmunk/rb_cpShape.c', line 54

static VALUE
rb_cpShapeGetBody(VALUE self) {
  return rb_ivar_get(self, id_body);
}

#body=Object


71
72
73
74
75
76
77
# File 'ext/chipmunk/rb_cpShape.c', line 71

static VALUE
rb_cpShapeSetBody(VALUE self, VALUE body) {
  SHAPE(self)->body = BODY(body);
  rb_ivar_set(self, id_body, body);

  return body;
}

#cache_bbObject


142
143
144
145
146
147
148
# File 'ext/chipmunk/rb_cpShape.c', line 142

static VALUE
rb_cpShapeCacheBB(VALUE self) {
  cpShape *shape = SHAPE(self);
  cpShapeCacheBB(shape);

  return rb_cpShapeGetBB(self);
}

#collision_typeObject


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

static VALUE
rb_cpShapeGetCollType(VALUE self) {
  return rb_iv_get(self, "collType");
}

#collision_type=Object


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

static VALUE
rb_cpShapeSetCollType(VALUE self, VALUE val) {
  VALUE col_type = rb_obj_id(val);
  rb_iv_set(self, "collType", val);
  SHAPE(self)->collision_type = NUM2UINT(col_type);

  return val;
}

#dataObject

to me.


104
105
106
107
# File 'ext/chipmunk/rb_cpShape.c', line 104

static VALUE
rb_cpShapeGetSelf(VALUE self) {
  return self;
}

#eObject


150
151
152
153
# File 'ext/chipmunk/rb_cpShape.c', line 150

static VALUE
rb_cpShapeGetElasticity(VALUE self) {
  return rb_float_new(SHAPE(self)->e);
}

#e=Object


160
161
162
163
164
# File 'ext/chipmunk/rb_cpShape.c', line 160

static VALUE
rb_cpShapeSetElasticity(VALUE self, VALUE val) {
  SHAPE(self)->e = NUM2DBL(val);
  return val;
}

#groupObject


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

static VALUE
rb_cpShapeGetGroup(VALUE self) {
  return rb_iv_get(self, "@group");
}

#group=Object


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

static VALUE
rb_cpShapeSetGroup(VALUE self, VALUE groupValue) {
  rb_iv_set(self, "@group", groupValue);
  SHAPE(self)->group = CP_OBJ2INT(groupValue);

  return groupValue;
}

#layersObject


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

static VALUE
rb_cpShapeGetLayers(VALUE self) {
  return UINT2NUM(SHAPE(self)->layers);
}

#layers=Object


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

static VALUE
rb_cpShapeSetLayers(VALUE self, VALUE layers) {
  SHAPE(self)->layers = NUM2UINT(layers);

  return layers;
}

#nearest_point_queryObject


196
197
198
199
200
201
202
203
204
# File 'ext/chipmunk/rb_cpShape.c', line 196

static VALUE
rb_cpShapeNearestPointQuery(VALUE self, VALUE point) {
  cpNearestPointQueryInfo info;
  cpShapeNearestPointQuery(SHAPE(self), *VGET(point), &info);
  if(info.shape) {
    return rb_cpNearestPointQueryInfoNew((VALUE)info.shape->data, VNEW(info.p), rb_float_new(info.d));
  }
  return Qnil;
}

#objectObject

So we use this as the object setter


93
94
95
96
# File 'ext/chipmunk/rb_cpShape.c', line 93

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

#object=Object


98
99
100
101
102
# File 'ext/chipmunk/rb_cpShape.c', line 98

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

#point_queryObject

Test if a point lies within a shape.


190
191
192
193
194
# File 'ext/chipmunk/rb_cpShape.c', line 190

static VALUE
rb_cpShapePointQuery(VALUE self, VALUE point) {
  cpBool res = cpShapePointQuery(SHAPE(self), *VGET(point));
  return res ? Qtrue : Qfalse;
}

#raw_bbObject


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

static VALUE
rb_cpShapeGetBB(VALUE self) {
  cpBB *bb = malloc(sizeof(cpBB));
  *bb = SHAPE(self)->bb;
  return Data_Wrap_Struct(c_cpBB, NULL, free, bb);
}

#segment_queryObject


207
208
209
210
211
212
213
214
215
# File 'ext/chipmunk/rb_cpShape.c', line 207

static VALUE
rb_cpShapeSegmentQuery(VALUE self, VALUE a, VALUE b) {
  cpSegmentQueryInfo info;
  cpShapeSegmentQuery(SHAPE(self), *VGET(a), *VGET(b), &info);
  if(info.shape) {
    return rb_cpSegmentQueryInfoNew((VALUE)info.shape->data, rb_float_new(info.t), VNEW(info.n));
  }
  return Qnil;
}

#sensor=Object


64
65
66
67
68
69
# File 'ext/chipmunk/rb_cpShape.c', line 64

static VALUE
rb_cpShapeSetSensor(VALUE self, VALUE sensor) {
  int sens = (NIL_P(sensor) || (!sensor)) ? 0 : 1;
  SHAPE(self)->sensor =  sens;
  return sensor;
}

#sensor?Boolean

Returns:

  • (Boolean)

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

static VALUE
rb_cpShapeSensorP(VALUE self) {
  return SHAPE(self)->sensor ? Qtrue : Qfalse;
}

#surface_vObject


172
173
174
175
# File 'ext/chipmunk/rb_cpShape.c', line 172

static VALUE
rb_cpShapeGetSurfaceV(VALUE self) {
  return VWRAP(self, &SHAPE(self)->surface_v);
}

#surface_v=Object


177
178
179
180
181
# File 'ext/chipmunk/rb_cpShape.c', line 177

static VALUE
rb_cpShapeSetSurfaceV(VALUE self, VALUE val) {
  SHAPE(self)->surface_v = *VGET(val);
  return val;
}

#uObject


155
156
157
158
# File 'ext/chipmunk/rb_cpShape.c', line 155

static VALUE
rb_cpShapeGetFriction(VALUE self) {
  return rb_float_new(SHAPE(self)->u);
}

#u=Object


166
167
168
169
170
# File 'ext/chipmunk/rb_cpShape.c', line 166

static VALUE
rb_cpShapeSetFriction(VALUE self, VALUE val) {
  SHAPE(self)->u = NUM2DBL(val);
  return val;
}