dxrubynd 1.4.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1460 @@
1
+ #define WINVER 0x0500 /* �o�[�W������` Windows2000�ȏ� */
2
+ #define _WIN32_WINNT WINVER
3
+
4
+ #include "ruby.h"
5
+ #ifndef RUBY_ST_H
6
+ #include "st.h"
7
+ #endif
8
+
9
+ #define DXRUBY_EXTERN 1
10
+ #include "dxruby.h"
11
+ #include "sprite.h"
12
+ #include "image.h"
13
+ #include "collision.h"
14
+
15
+ static int g_volume_count;
16
+ static int g_volume_allocate_count;
17
+ static struct DXRubyCollision *g_volume_pointer;
18
+
19
+ #ifdef DXRUBY_USE_TYPEDDATA
20
+ extern rb_data_type_t Image_data_type;
21
+ extern rb_data_type_t RenderTarget_data_type;
22
+ extern rb_data_type_t Sprite_data_type;
23
+ #endif
24
+
25
+ /*********************************************************************
26
+ * �Փ˔��菈��
27
+ *
28
+ *********************************************************************/
29
+
30
+ /* ���E�{�����[���쐬 */
31
+ #define volume_box( count, tx, ty, collision ) \
32
+ {\
33
+ int i;\
34
+ (collision)->x1 = (collision)->x2 = (int)tx[0];\
35
+ (collision)->y1 = (collision)->y2 = (int)ty[0];\
36
+ \
37
+ for( i = 1; i < count; i++ )\
38
+ {\
39
+ if( (collision)->x1 > (int)tx[i] )\
40
+ {\
41
+ (collision)->x1 = (int)tx[i];\
42
+ }\
43
+ if( (collision)->x2 < (int)tx[i] )\
44
+ {\
45
+ (collision)->x2 = (int)tx[i];\
46
+ }\
47
+ if( (collision)->y1 > (int)ty[i] )\
48
+ {\
49
+ (collision)->y1 = (int)ty[i];\
50
+ }\
51
+ if( (collision)->y2 < (int)ty[i] )\
52
+ {\
53
+ (collision)->y2 = (int)ty[i];\
54
+ }\
55
+ }\
56
+ }
57
+
58
+ /* ���S�_�Z�o */
59
+ #define set_center( sprite, collision )\
60
+ {\
61
+ struct DXRubyImage *image;\
62
+ if( sprite->vcenter_x == Qnil || sprite->vcenter_y == Qnil )\
63
+ {\
64
+ DXRUBY_CHECK_IMAGE( sprite->vimage );\
65
+ image = DXRUBY_GET_STRUCT( Image, sprite->vimage );\
66
+ collision->center_x = sprite->vcenter_x == Qnil ? image->width / 2 : NUM2FLOAT(sprite->vcenter_x);\
67
+ collision->center_y = sprite->vcenter_y == Qnil ? image->height / 2 : NUM2FLOAT(sprite->vcenter_y);\
68
+ }\
69
+ else\
70
+ {\
71
+ collision->center_x = NUM2FLOAT(sprite->vcenter_x);\
72
+ collision->center_y = NUM2FLOAT(sprite->vcenter_y);\
73
+ }\
74
+ }
75
+
76
+ /* �_�̉�] */
77
+ #define rotation_point( collision, tx, ty, bx, by ) \
78
+ {\
79
+ float angle = 3.141592653589793115997963468544185161590576171875f / 180.0f * collision->angle;\
80
+ float sina = sin( angle );\
81
+ float cosa = cos( angle );\
82
+ float data1x = collision->scale_x * cosa;\
83
+ float data1y = collision->scale_y * sina;\
84
+ float data2x = collision->scale_x * sina;\
85
+ float data2y = collision->scale_y * cosa;\
86
+ float tmpx = (bx), tmpy = (by);\
87
+ \
88
+ tx = (tmpx - collision->center_x) * data1x - (tmpy - collision->center_y) * data1y + collision->center_x + collision->base_x;\
89
+ ty = (tmpx - collision->center_x) * data2x + (tmpy - collision->center_y) * data2y + collision->center_y + collision->base_y;\
90
+ }
91
+
92
+ /* �_�̉�](���S�w��E�X�P�[�����O�Ȃ�) */
93
+ #define rotation_point_out( centerx, centery, angle, x, y ) \
94
+ {\
95
+ float rbangle = 3.141592653589793115997963468544185161590576171875f / 180.0f * (angle);\
96
+ float sina = sin( rbangle );\
97
+ float cosa = cos( rbangle );\
98
+ float rbx = (x), rby = (y);\
99
+ \
100
+ x = (rbx - (centerx)) * cosa - (rby - (centery)) * sina + (centerx);\
101
+ y = (rbx - (centerx)) * sina + (rby - (centery)) * cosa + (centery);\
102
+ }
103
+
104
+ /* ��`���ꎩ�g�̉�](�X�P�[�����O����) */
105
+ #define rotation_box( collision, tx, ty ) \
106
+ {\
107
+ float angle = 3.141592653589793115997963468544185161590576171875f / 180.0f * collision->angle;\
108
+ float sina = sin( angle );\
109
+ float cosa = cos( angle );\
110
+ float data1x = collision->scale_x * cosa;\
111
+ float data1y = collision->scale_y * sina;\
112
+ float data2x = collision->scale_x * sina;\
113
+ float data2y = collision->scale_y * cosa;\
114
+ \
115
+ tx[0] = (collision->bx1 - collision->center_x) * data1x - (collision->by1 - collision->center_y) * data1y + collision->center_x + collision->base_x;\
116
+ ty[0] = (collision->bx1 - collision->center_x) * data2x + (collision->by1 - collision->center_y) * data2y + collision->center_y + collision->base_y;\
117
+ tx[1] = (collision->bx2 - collision->center_x) * data1x - (collision->by1 - collision->center_y) * data1y + collision->center_x + collision->base_x;\
118
+ ty[1] = (collision->bx2 - collision->center_x) * data2x + (collision->by1 - collision->center_y) * data2y + collision->center_y + collision->base_y;\
119
+ tx[2] = (collision->bx2 - collision->center_x) * data1x - (collision->by2 - collision->center_y) * data1y + collision->center_x + collision->base_x;\
120
+ ty[2] = (collision->bx2 - collision->center_x) * data2x + (collision->by2 - collision->center_y) * data2y + collision->center_y + collision->base_y;\
121
+ tx[3] = (collision->bx1 - collision->center_x) * data1x - (collision->by2 - collision->center_y) * data1y + collision->center_x + collision->base_x;\
122
+ ty[3] = (collision->bx1 - collision->center_x) * data2x + (collision->by2 - collision->center_y) * data2y + collision->center_y + collision->base_y;\
123
+ }
124
+
125
+ /* ��`�̉�]�i���S�w��E�X�P�[�����O�Ȃ��j */
126
+ #define rotation_box_out( centerx, centery, angle, x, y ) \
127
+ {\
128
+ float rbangle = 3.141592653589793115997963468544185161590576171875f / 180.0f * angle;\
129
+ float sina = sin( rbangle );\
130
+ float cosa = cos( rbangle );\
131
+ float rbx1 = x[0], rby1 = y[0], rbx2 = x[1], rby2 = y[1], rbx3 = x[2], rby3 = y[2], rbx4 = x[3], rby4 = y[3];\
132
+ \
133
+ x[0] = (rbx1 - centerx) * cosa - (rby1 - centery) * sina + centerx;\
134
+ y[0] = (rbx1 - centerx) * sina + (rby1 - centery) * cosa + centery;\
135
+ x[1] = (rbx2 - centerx) * cosa - (rby2 - centery) * sina + centerx;\
136
+ y[1] = (rbx2 - centerx) * sina + (rby2 - centery) * cosa + centery;\
137
+ x[2] = (rbx3 - centerx) * cosa - (rby3 - centery) * sina + centerx;\
138
+ y[2] = (rbx3 - centerx) * sina + (rby3 - centery) * cosa + centery;\
139
+ x[3] = (rbx4 - centerx) * cosa - (rby4 - centery) * sina + centerx;\
140
+ y[3] = (rbx4 - centerx) * sina + (rby4 - centery) * cosa + centery;\
141
+ }
142
+
143
+ /* ��`�̊g��E�k���i��]�Ȃ��j */
144
+ #define scaling_box( collision, x, y ) \
145
+ {\
146
+ x[0] = x[3] = (collision->bx1 - collision->center_x) * collision->scale_x + collision->center_x + collision->base_x;\
147
+ y[0] = y[1] = (collision->by1 - collision->center_y) * collision->scale_y + collision->center_y + collision->base_y;\
148
+ x[1] = x[2] = (collision->bx2 - collision->center_x) * collision->scale_x + collision->center_x + collision->base_x;\
149
+ y[2] = y[3] = (collision->by2 - collision->center_y) * collision->scale_y + collision->center_y + collision->base_y;\
150
+ }
151
+
152
+ /* �O�p�`���ꎩ�g�̉�](�X�P�[�����O����) */
153
+ #define rotation_triangle( collision, x, y, tx, ty ) \
154
+ {\
155
+ float angle = 3.141592653589793115997963468544185161590576171875f / 180.0f * collision->angle;\
156
+ float sina = sin( angle );\
157
+ float cosa = cos( angle );\
158
+ float data1x = collision->scale_x * cosa;\
159
+ float data1y = collision->scale_y * sina;\
160
+ float data2x = collision->scale_x * sina;\
161
+ float data2y = collision->scale_y * cosa;\
162
+ \
163
+ tx[0] = (x[0] - collision->center_x) * data1x - (y[0] - collision->center_y) * data1y + collision->center_x + collision->base_x;\
164
+ ty[0] = (x[0] - collision->center_x) * data2x + (y[0] - collision->center_y) * data2y + collision->center_y + collision->base_y;\
165
+ tx[1] = (x[1] - collision->center_x) * data1x - (y[1] - collision->center_y) * data1y + collision->center_x + collision->base_x;\
166
+ ty[1] = (x[1] - collision->center_x) * data2x + (y[1] - collision->center_y) * data2y + collision->center_y + collision->base_y;\
167
+ tx[2] = (x[2] - collision->center_x) * data1x - (y[2] - collision->center_y) * data1y + collision->center_x + collision->base_x;\
168
+ ty[2] = (x[2] - collision->center_x) * data2x + (y[2] - collision->center_y) * data2y + collision->center_y + collision->base_y;\
169
+ }
170
+
171
+ /* �O�p�`�̉�]�i���S�w��E�X�P�[�����O�Ȃ��j */
172
+ #define rotation_triangle_out( centerx, centery, angle, x, y ) \
173
+ {\
174
+ float rbangle = 3.141592653589793115997963468544185161590576171875f / 180.0f * angle;\
175
+ float sina = sin( rbangle );\
176
+ float cosa = cos( rbangle );\
177
+ float rbx1 = x[0], rby1 = y[0], rbx2 = x[1], rby2 = y[1], rbx3 = x[2], rby3 = y[2];\
178
+ \
179
+ x[0] = (rbx1 - centerx) * cosa - (rby1 - centery) * sina + centerx;\
180
+ y[0] = (rbx1 - centerx) * sina + (rby1 - centery) * cosa + centery;\
181
+ x[1] = (rbx2 - centerx) * cosa - (rby2 - centery) * sina + centerx;\
182
+ y[1] = (rbx2 - centerx) * sina + (rby2 - centery) * cosa + centery;\
183
+ x[2] = (rbx3 - centerx) * cosa - (rby3 - centery) * sina + centerx;\
184
+ y[2] = (rbx3 - centerx) * sina + (rby3 - centery) * cosa + centery;\
185
+ }
186
+
187
+
188
+ #define intersect(x1, y1, x2, y2, x3, y3, x4, y4) ( ((x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)) * \
189
+ ((x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4)) )
190
+
191
+ struct Vector {
192
+ float x;
193
+ float y;
194
+ };
195
+
196
+
197
+ /*--------------------------------------------------------------------
198
+ (���������p)�O�p�Ɠ_�̔���
199
+ ---------------------------------------------------------------------*/
200
+ /* �E���̎O�p�Ɠ_ */
201
+ static int checktriangle( float x, float y, float x1, float y1, float x2, float y2, float x3, float y3 )
202
+ {
203
+ float cx, cy;
204
+
205
+ if( (x1 - x3) * (y1 - y2) == (x1 - x2) * (y1 - y3) )
206
+ {
207
+ return 0;
208
+ }
209
+
210
+ cx = (x1 + x2 + x3) / 3; /* ���S�_x */
211
+ cy = (y1 + y2 + y3) / 3; /* ���S�_y */
212
+
213
+ if( intersect( x1, y1, x2, y2, x, y, cx, cy ) < 0.0f ||
214
+ intersect( x2, y2, x3, y3, x, y, cx, cy ) < 0.0f ||
215
+ intersect( x3, y3, x1, y1, x, y, cx, cy ) < 0.0f )
216
+ {
217
+ return 0;
218
+ }
219
+ return -1;
220
+ }
221
+
222
+
223
+ /*--------------------------------------------------------------------
224
+ (���������p)�~�Ɛ����̔���
225
+ ---------------------------------------------------------------------*/
226
+ /* �~�Ɛ����̔��� */
227
+ static int checkCircleLine( float x, float y, float r, float x1, float y1, float x2, float y2 )
228
+ {
229
+ float n1, n2, n3;
230
+ /* v�͐����n�_����I�_ */
231
+ /* c�͐����n�_����~���S */
232
+ struct Vector v = {x2 - x1, y2 - y1};
233
+ struct Vector c = {x - x1, y - y1};
234
+
235
+ if( v.x == 0.0f && v.y == 0.0f )
236
+ {
237
+ return check_circle_point(x, y, r, x1, y1);
238
+ }
239
+
240
+ /* ��‚̃x�N�g���̓��ς����߂� */
241
+ n1 = v.x * c.x + v.y * c.y;
242
+
243
+ if( n1 < 0 )
244
+ {
245
+ /* c�̒������~�̔��a��菬�����ꍇ�͌������Ă��� */
246
+ return c.x*c.x + c.y*c.y < r * r ? -1 : 0;
247
+ }
248
+
249
+ n2 = v.x * v.x + v.y * v.y;
250
+
251
+ if( n1 > n2 )
252
+ {
253
+ float len;
254
+ /* �����̏I�_�Ɖ~�̒��S�̋����̓������߂� */
255
+ len = (x2 - x)*(x2 - x) + (y2 - y)*(y2 - y);
256
+ /* �~�̔��a�̓������������ꍇ�͌������Ă��� */
257
+ return len < r * r ? -1 : 0;
258
+ }
259
+ else
260
+ {
261
+ n3 = c.x * c.x + c.y * c.y;
262
+ return ( n3-(n1/n2)*n1 < r * r ) ? -1 : 0;
263
+ }
264
+ return 0;
265
+ }
266
+
267
+
268
+ /* �ȉ~�\���� */
269
+ struct ELLIPSE
270
+ {
271
+ float fRad_X; /* X���a */
272
+ float fRad_Y; /* Y���a */
273
+ float fAngle; /* ��]�p�x */
274
+ float fCx; /* ����_X���W */
275
+ float fCy; /* ����_Y���W */
276
+ };
277
+
278
+ /* �ȉ~�Փ˔���֐� */
279
+ /* http://marupeke296.com/COL_2D_No7_EllipseVsEllipse.html */
280
+ int CollisionEllipse( struct ELLIPSE E1, struct ELLIPSE E2 )
281
+ {
282
+ /* STEP1 : E2��P�ʉ~�ɂ���ϊ���E1�Ɏ{�� */
283
+ float DefAng = E1.fAngle-E2.fAngle;
284
+ float Cos = cos( DefAng );
285
+ float Sin = sin( DefAng );
286
+ float nx = E2.fRad_X * Cos;
287
+ float ny = -E2.fRad_X * Sin;
288
+ float px = E2.fRad_Y * Sin;
289
+ float py = E2.fRad_Y * Cos;
290
+ float ox = cos( E1.fAngle )*(E2.fCx-E1.fCx) + sin(E1.fAngle)*(E2.fCy-E1.fCy);
291
+ float oy = -sin( E1.fAngle )*(E2.fCx-E1.fCx) + cos(E1.fAngle)*(E2.fCy-E1.fCy);
292
+
293
+ /* STEP2 : ��ʎ�A�`G�̎Z�o */
294
+ float rx_pow2 = 1/(E1.fRad_X*E1.fRad_X);
295
+ float ry_pow2 = 1/(E1.fRad_Y*E1.fRad_Y);
296
+ float A = rx_pow2*nx*nx + ry_pow2*ny*ny;
297
+ float B = rx_pow2*px*px + ry_pow2*py*py;
298
+ float D = 2*rx_pow2*nx*px + 2*ry_pow2*ny*py;
299
+ float E = 2*rx_pow2*nx*ox + 2*ry_pow2*ny*oy;
300
+ float F = 2*rx_pow2*px*ox + 2*ry_pow2*py*oy;
301
+ float G = (ox/E1.fRad_X)*(ox/E1.fRad_X) + (oy/E1.fRad_Y)*(oy/E1.fRad_Y) - 1;
302
+
303
+ /* STEP3 : ���s�ړ���(h,k)�y�щ�]�p�x�Ƃ̎Z�o */
304
+ float tmp1 = 1/(D*D-4*A*B);
305
+ float h = (F*D-2*E*B)*tmp1;
306
+ float k = (E*D-2*A*F)*tmp1;
307
+ float Th = (B-A)==0?0:atan( D/(B-A) ) * 0.5f;
308
+
309
+ /* STEP4 : +1�ȉ~�����ɖ߂������œ����蔻�� */
310
+ float CosTh = cos(Th);
311
+ float SinTh = sin(Th);
312
+ float A_tt = A*CosTh*CosTh + B*SinTh*SinTh - D*CosTh*SinTh;
313
+ float B_tt = A*SinTh*SinTh + B*CosTh*CosTh + D*CosTh*SinTh;
314
+ float KK = A*h*h + B*k*k + D*h*k - E*h - F*k + G > 0 ? 0 : A*h*h + B*k*k + D*h*k - E*h - F*k + G;
315
+ float Rx_tt = 1+sqrt(-KK/A_tt);
316
+ float Ry_tt = 1+sqrt(-KK/B_tt);
317
+ float x_tt = CosTh*h-SinTh*k;
318
+ float y_tt = SinTh*h+CosTh*k;
319
+ float JudgeValue = x_tt*x_tt/(Rx_tt*Rx_tt) + y_tt*y_tt/(Ry_tt*Ry_tt);
320
+
321
+ if( JudgeValue <= 1 )
322
+ return TRUE; /* �Փ� */
323
+
324
+ return FALSE;
325
+ }
326
+
327
+
328
+ int check( struct DXRubyCollisionGroup *o, struct DXRubyCollisionGroup *d )
329
+ {
330
+ int i, j;
331
+
332
+ if( o->count == 1 && d->count == 1 )
333
+ {
334
+ struct DXRubyCollision *co = g_volume_pointer + o->index;
335
+ struct DXRubyCollision *cd = g_volume_pointer + d->index;
336
+
337
+ /* �ڍ׃`�F�b�N */
338
+ if( check_sub( co, cd ) )
339
+ {
340
+ return TRUE;
341
+ }
342
+ }
343
+ else
344
+ {
345
+ for( i = 0; i < o->count; i++ )
346
+ {
347
+ for( j = 0; j < d->count; j++ )
348
+ {
349
+ struct DXRubyCollision *co = g_volume_pointer + o->index + i;
350
+ struct DXRubyCollision *cd = g_volume_pointer + d->index + j;
351
+
352
+ /* ���E�{�����[���`�F�b�N���ڍ׃`�F�b�N */
353
+ if( check_box_box( co, cd ) && check_sub( co, cd ) )
354
+ {
355
+ return TRUE;
356
+ }
357
+ }
358
+ }
359
+ }
360
+ return FALSE;
361
+ }
362
+
363
+
364
+ int check_sub( struct DXRubyCollision *o, struct DXRubyCollision *d )
365
+ {
366
+ struct DXRubySprite *o_sprite = DXRUBY_GET_STRUCT( Sprite, o->vsprite );
367
+ struct DXRubySprite *d_sprite = DXRUBY_GET_STRUCT( Sprite, d->vsprite );
368
+ int o_type;
369
+ int d_type;
370
+
371
+ /* collision�ȗ��� */
372
+ if( o->vcollision != Qnil )
373
+ {
374
+ o_type = RARRAY_LEN( o->vcollision );
375
+ }
376
+ else
377
+ {
378
+ o_type = 4;
379
+ }
380
+
381
+ if( d->vcollision != Qnil )
382
+ {
383
+ d_type = RARRAY_LEN( d->vcollision );
384
+ }
385
+ else
386
+ {
387
+ d_type = 4;
388
+ }
389
+
390
+ if( o_type == d_type )
391
+ {/* �����`�̔�r */
392
+ switch ( o_type )
393
+ {
394
+ case 4: /* ��` */
395
+ /* ����������ʼn�]���������� */
396
+
397
+ if( o->rotation_flg || o->scaling_flg ) /* o������]������ */
398
+ { /* d��o���S�ɉ�]���ċ��E�{�����[��������r����B�������Ă��Ȃ���Γ������Ă��Ȃ��B */
399
+ float ox[4], oy[4];
400
+ float dx[4], dy[4];
401
+ struct DXRubyCollision o_collision, d_collision;
402
+ float centerx, centery;
403
+
404
+ if( d->rotation_flg || d->scaling_flg ) /* d������]������ */
405
+ {
406
+ /* d���������̎p���ɉ�] */
407
+ rotation_box( d, dx, dy );
408
+ }
409
+ else /* d���͉�]���Ă��Ȃ����� */
410
+ {
411
+ dx[0] = dx[3] = (float)d->x1;
412
+ dy[0] = dy[1] = (float)d->y1;
413
+ dx[1] = dx[2] = (float)d->x2;
414
+ dy[2] = dy[3] = (float)d->y2;
415
+ }
416
+
417
+ /* o�����S�_ */
418
+ centerx = o->center_x + o->base_x;
419
+ centery = o->center_y + o->base_y;
420
+
421
+ /* o�����S�_�𒆐S��d����] */
422
+ rotation_box_out( centerx, centery, -o->angle, dx, dy )
423
+
424
+ /* d�����E�{�����[���쐬 */
425
+ volume_box( 4, dx, dy, &d_collision );
426
+
427
+ /* o���̃X�P�[�����O */
428
+ scaling_box( o, ox, oy );
429
+
430
+ /* o�����E�{�����[���쐬 */
431
+ volume_box( 4, ox, oy, &o_collision );
432
+
433
+ if( !check_box_box( &o_collision, &d_collision ) )
434
+ {
435
+ return FALSE; /* �������Ă��Ȃ����� */
436
+ }
437
+ }
438
+
439
+ if( d->rotation_flg || d->scaling_flg ) /* d������]������ */
440
+ { /* o��d���S�ɉ�]���ċ��E�{�����[��������r����B�������Ă��Ȃ���Γ������Ă��Ȃ��B */
441
+ float ox[4], oy[4];
442
+ float dx[4], dy[4];
443
+ struct DXRubyCollision o_collision, d_collision;
444
+ float centerx, centery;
445
+
446
+ if( o->rotation_flg || o->scaling_flg ) /* o������]������ */
447
+ {
448
+ /* o���������̎p���ɉ�] */
449
+ rotation_box( o, ox, oy );
450
+ }
451
+ else /* o���͉�]���Ă��Ȃ����� */
452
+ {
453
+ ox[0] = ox[3] = (float)o->x1;
454
+ oy[0] = oy[1] = (float)o->y1;
455
+ ox[1] = ox[2] = (float)o->x2;
456
+ oy[2] = oy[3] = (float)o->y2;
457
+ }
458
+
459
+ /* d�����S�_ */
460
+ centerx = d->center_x + d->base_x;
461
+ centery = d->center_y + d->base_y;
462
+
463
+ /* d�����S�_�𒆐S��o����] */
464
+ rotation_box_out( centerx, centery, -d->angle, ox, oy )
465
+
466
+ /* o�����E�{�����[���쐬 */
467
+ volume_box( 4, ox, oy, &o_collision );
468
+
469
+ /* d���̃X�P�[�����O */
470
+ scaling_box( d, dx, dy );
471
+
472
+ /* d�����E�{�����[���쐬 */
473
+ volume_box( 4, dx, dy, &d_collision );
474
+
475
+ if( !check_box_box( &o_collision, &d_collision ) )
476
+ {
477
+ return FALSE; /* �������Ă��Ȃ����� */
478
+ }
479
+ }
480
+ return TRUE; /* �����ɗ������_�œ������Ă��� */
481
+ break;
482
+ case 3: /* �~���m */
483
+ {
484
+
485
+ if( (o->scale_x != o->scale_y && RTEST(o_sprite->vcollision_sync)) || /* o�����ȉ~ */
486
+ (d->scale_x != d->scale_y && RTEST(d_sprite->vcollision_sync)) ) /* d�����ȉ~ */
487
+ { /* �ǂ��������ȉ~�Ȃ�ȉ~�������ł̏Փ˔�������� */
488
+ struct ELLIPSE e1, e2;
489
+ float ox, oy, or, dx, dy, dr;
490
+ if( RTEST(o_sprite->vcollision_sync) )
491
+ {
492
+ rotation_point( o, ox, oy, NUM2FLOAT(RARRAY_AREF(o->vcollision, 0)), NUM2FLOAT(RARRAY_AREF(o->vcollision, 1)) );
493
+ }
494
+ else
495
+ {
496
+ ox = o->base_x + NUM2INT(RARRAY_AREF(o->vcollision, 0));
497
+ oy = o->base_y + NUM2INT(RARRAY_AREF(o->vcollision, 1));
498
+ }
499
+ or = NUM2FLOAT(RARRAY_AREF(o->vcollision, 2));
500
+
501
+ e1.fCx = ox;
502
+ e1.fCy = oy;
503
+ if( RTEST(o_sprite->vcollision_sync) )
504
+ {
505
+ e1.fRad_X = o->scale_x * or * 1;
506
+ e1.fRad_Y = o->scale_y * or * 1;
507
+ e1.fAngle = 3.141592653589793115997963468544185161590576171875f / 180.0f * o->angle;
508
+ }
509
+ else
510
+ {
511
+ e1.fRad_X = or * 1;
512
+ e1.fRad_Y = or * 1;
513
+ e1.fAngle = 0;
514
+ }
515
+
516
+ if( RTEST(d_sprite->vcollision_sync) )
517
+ {
518
+ rotation_point( d, dx, dy, NUM2FLOAT(RARRAY_AREF(d->vcollision, 0)), NUM2FLOAT(RARRAY_AREF(d->vcollision, 1)) );
519
+ }
520
+ else
521
+ {
522
+ dx = d->base_x + NUM2INT(RARRAY_AREF(d->vcollision, 0));
523
+ dy = d->base_y + NUM2INT(RARRAY_AREF(d->vcollision, 1));
524
+ }
525
+ dr = NUM2FLOAT(RARRAY_AREF(d->vcollision, 2));
526
+
527
+ e2.fCx = dx;
528
+ e2.fCy = dy;
529
+ if( RTEST(d_sprite->vcollision_sync) )
530
+ {
531
+ e2.fRad_X = d->scale_x * dr * 1;
532
+ e2.fRad_Y = d->scale_y * dr * 1;
533
+ e2.fAngle = 3.141592653589793115997963468544185161590576171875f / 180.0f * d->angle;
534
+ }
535
+ else
536
+ {
537
+ e2.fRad_X = dr * 1;
538
+ e2.fRad_Y = dr * 1;
539
+ e2.fAngle = 0;
540
+ }
541
+
542
+ return CollisionEllipse( e1, e2 );
543
+ }
544
+ else
545
+ { /* �^�~���m */
546
+ float ox, oy, or, dx, dy, dr;
547
+
548
+ if( o->rotation_flg ) /* o������]������ */
549
+ {
550
+ rotation_point( o, ox, oy, NUM2FLOAT(RARRAY_AREF(o->vcollision, 0)), NUM2FLOAT(RARRAY_AREF(o->vcollision, 1)) );
551
+ }
552
+ else
553
+ {
554
+ ox = o->base_x + NUM2INT(RARRAY_AREF(o->vcollision, 0));
555
+ oy = o->base_y + NUM2INT(RARRAY_AREF(o->vcollision, 1));
556
+ }
557
+ or = NUM2FLOAT(RARRAY_AREF(o->vcollision, 2)) * o->scale_x;
558
+
559
+ if( d->rotation_flg ) /* d������]������ */
560
+ {
561
+ rotation_point( d, dx, dy, NUM2FLOAT(RARRAY_AREF(d->vcollision, 0)), NUM2FLOAT(RARRAY_AREF(d->vcollision, 1)) );
562
+ }
563
+ else
564
+ {
565
+ dx = d->base_x + NUM2INT(RARRAY_AREF(d->vcollision, 0));
566
+ dy = d->base_y + NUM2INT(RARRAY_AREF(d->vcollision, 1));
567
+ }
568
+ dr = NUM2FLOAT(RARRAY_AREF(d->vcollision, 2)) * d->scale_x;
569
+
570
+ return check_circle_circle( ox, oy, or, dx, dy, dr );
571
+ }
572
+ }
573
+ break;
574
+ case 6: /* �O�p */
575
+ {
576
+ float ox[3], oy[3];
577
+ float dx[3], dy[3];
578
+ float x[3], y[3];
579
+
580
+ if( o->rotation_flg || o->scaling_flg ) /* o������]������ */
581
+ {
582
+ x[0] = NUM2INT(RARRAY_AREF(o->vcollision, 0)) + 0.5f;
583
+ y[0] = NUM2INT(RARRAY_AREF(o->vcollision, 1)) + 0.5f;
584
+ x[1] = NUM2INT(RARRAY_AREF(o->vcollision, 2)) + 0.5f;
585
+ y[1] = NUM2INT(RARRAY_AREF(o->vcollision, 3)) + 0.5f;
586
+ x[2] = NUM2INT(RARRAY_AREF(o->vcollision, 4)) + 0.5f;
587
+ y[2] = NUM2INT(RARRAY_AREF(o->vcollision, 5)) + 0.5f;
588
+
589
+ set_center( o_sprite, o );
590
+ rotation_triangle( o, x, y, ox, oy );
591
+ }
592
+ else
593
+ {
594
+ ox[0] = NUM2INT(RARRAY_AREF(o->vcollision, 0)) + 0.5f + o->base_x;
595
+ oy[0] = NUM2INT(RARRAY_AREF(o->vcollision, 1)) + 0.5f + o->base_y;
596
+ ox[1] = NUM2INT(RARRAY_AREF(o->vcollision, 2)) + 0.5f + o->base_x;
597
+ oy[1] = NUM2INT(RARRAY_AREF(o->vcollision, 3)) + 0.5f + o->base_y;
598
+ ox[2] = NUM2INT(RARRAY_AREF(o->vcollision, 4)) + 0.5f + o->base_x;
599
+ oy[2] = NUM2INT(RARRAY_AREF(o->vcollision, 5)) + 0.5f + o->base_y;
600
+ }
601
+
602
+ if( d->rotation_flg || d->scaling_flg ) /* d������]������ */
603
+ {
604
+ x[0] = NUM2INT(RARRAY_AREF(d->vcollision, 0)) + 0.5f;
605
+ y[0] = NUM2INT(RARRAY_AREF(d->vcollision, 1)) + 0.5f;
606
+ x[1] = NUM2INT(RARRAY_AREF(d->vcollision, 2)) + 0.5f;
607
+ y[1] = NUM2INT(RARRAY_AREF(d->vcollision, 3)) + 0.5f;
608
+ x[2] = NUM2INT(RARRAY_AREF(d->vcollision, 4)) + 0.5f;
609
+ y[2] = NUM2INT(RARRAY_AREF(d->vcollision, 5)) + 0.5f;
610
+
611
+ set_center( d_sprite, d );
612
+ rotation_triangle( d, x, y, dx, dy );
613
+ }
614
+ else
615
+ {
616
+ dx[0] = NUM2INT(RARRAY_AREF(d->vcollision, 0)) + 0.5f + d->base_x;
617
+ dy[0] = NUM2INT(RARRAY_AREF(d->vcollision, 1)) + 0.5f + d->base_y;
618
+ dx[1] = NUM2INT(RARRAY_AREF(d->vcollision, 2)) + 0.5f + d->base_x;
619
+ dy[1] = NUM2INT(RARRAY_AREF(d->vcollision, 3)) + 0.5f + d->base_y;
620
+ dx[2] = NUM2INT(RARRAY_AREF(d->vcollision, 4)) + 0.5f + d->base_x;
621
+ dy[2] = NUM2INT(RARRAY_AREF(d->vcollision, 5)) + 0.5f + d->base_y;
622
+ }
623
+
624
+ return check_line_line(ox[0], oy[0], ox[1], oy[1], dx[1], dy[1], dx[2], dy[2]) ||
625
+ check_line_line(ox[0], oy[0], ox[1], oy[1], dx[2], dy[2], dx[0], dy[0]) ||
626
+ check_line_line(ox[1], oy[1], ox[2], oy[2], dx[0], dy[0], dx[1], dy[1]) ||
627
+ check_line_line(ox[1], oy[1], ox[2], oy[2], dx[2], dy[2], dx[0], dy[0]) ||
628
+ check_line_line(ox[2], oy[2], ox[0], oy[0], dx[0], dy[0], dx[1], dy[1]) ||
629
+ check_line_line(ox[2], oy[2], ox[0], oy[0], dx[1], dy[1], dx[2], dy[2]) ||
630
+ checktriangle(ox[0], oy[0], dx[0], dy[0], dx[1], dy[1], dx[2], dy[2]) ||
631
+ checktriangle(dx[0], dy[0], ox[0], oy[0], ox[1], oy[1], ox[2], oy[2]);
632
+ }
633
+ break;
634
+ case 2: /* �_ */
635
+ return TRUE; /* �����ɗ������_�œ������Ă��� */
636
+ break;
637
+ default:
638
+ rb_raise( eDXRubyError, "Internal error" );
639
+ }
640
+ }
641
+ else
642
+ {/* �Ⴄ�`�̔�r */
643
+ if( o_type > d_type )
644
+ {/* o�̂ق�������������ւ� */
645
+ struct DXRubyCollision *ctemp;
646
+ int itemp;
647
+ ctemp = o;
648
+ o = d;
649
+ d = ctemp;
650
+ itemp = o_type;
651
+ o_type = d_type;
652
+ d_type = itemp;
653
+ }
654
+
655
+ switch( o_type )
656
+ {
657
+ case 2: /* �_ */
658
+ {
659
+ struct DXRubyCollision *point_collision = o;
660
+
661
+ switch( d_type)
662
+ {
663
+ case 3: /* �_�Ɖ~ */
664
+ {
665
+ struct DXRubyCollision *circle_collision = d;
666
+ float cx, cy, cr;
667
+ float px, py;
668
+ float center_x, center_y;
669
+ center_x = circle_collision->center_x + circle_collision->base_x;
670
+ center_y = circle_collision->center_y + circle_collision->base_y;
671
+
672
+ rotation_point( point_collision, px, py, point_collision->bx1 + 0.5f, point_collision->by1 + 0.5f );
673
+
674
+ if( circle_collision->rotation_flg ) /* �~����]������ */
675
+ { /* �_���~��]���S�x�[�X�ʼn�]������ */
676
+ rotation_point_out( center_x, center_y, -circle_collision->angle, px, py );
677
+ }
678
+
679
+ cx = NUM2FLOAT(RARRAY_AREF(circle_collision->vcollision, 0)) + circle_collision->base_x;
680
+ cy = NUM2FLOAT(RARRAY_AREF(circle_collision->vcollision, 1)) + circle_collision->base_y;
681
+ cr = NUM2FLOAT(RARRAY_AREF(circle_collision->vcollision, 2));
682
+
683
+ if( circle_collision->scaling_flg ) /* �~�����ό`���Ă��� */
684
+ { /* �~���^�~�ɂȂ�悤�ɓ_�̍��W��ό`������ */
685
+ px = (px - center_x) / circle_collision->scale_x + center_x;
686
+ py = (py - center_y) / circle_collision->scale_y + center_y;
687
+ }
688
+
689
+ return check_circle_point( cx, cy, cr, px, py );
690
+ }
691
+ break;
692
+ case 4: /* �_�Ƌ�` */
693
+ {
694
+ struct DXRubyCollision *box_collision = d;
695
+
696
+ if( box_collision->rotation_flg || box_collision->scaling_flg ) /* ��`����]������ */
697
+ {/* �_����`���S�ɉ�]���Ĕ�r���� */
698
+ float px[4], py[4];
699
+ float bx[4], by[4];
700
+ struct DXRubyCollision p_collision, b_collision;
701
+ float centerx, centery;
702
+
703
+ px[0] = px[3] = (float)point_collision->x1;
704
+ py[0] = py[1] = (float)point_collision->y1;
705
+ px[1] = px[2] = (float)point_collision->x2;
706
+ py[2] = py[3] = (float)point_collision->y2;
707
+
708
+ /* ��`���ό`���S�_ */
709
+ centerx = box_collision->center_x + box_collision->base_x;
710
+ centery = box_collision->center_y + box_collision->base_y;
711
+
712
+ /* ��`���ό`���S�_�𒆐S�ɓ_����] */
713
+ rotation_box_out( centerx, centery, -box_collision->angle, px, py )
714
+
715
+ /* �_�����E�{�����[���쐬 */
716
+ volume_box( 4, px, py, &p_collision );
717
+
718
+ /* ��`���̊g��E�k�� */
719
+ scaling_box( box_collision, bx, by );
720
+
721
+ /* ��`�����E�{�����[���쐬 */
722
+ volume_box( 4, bx, by, &b_collision );
723
+
724
+ if( !check_box_box( &p_collision, &b_collision ) )
725
+ {
726
+ return FALSE; /* �������Ă��Ȃ����� */
727
+ }
728
+ }
729
+ return TRUE; /* �����ɗ������_�œ������Ă��� */
730
+ }
731
+ break;
732
+ case 6: /* �_�ƎO�p */
733
+ {
734
+ struct DXRubyCollision *tri_collision = d;
735
+ float x[3], y[3], tri_x[3], tri_y[3]; /* �O�p���W */
736
+
737
+ if( tri_collision->rotation_flg || tri_collision->scaling_flg ) /* �O�p������]�E�ό`���Ă��� */
738
+ {
739
+ /* �O�p���������̎p���ɉ�]�E�ό` */
740
+ x[0] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 0)) + 0.5f;
741
+ y[0] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 1)) + 0.5f;
742
+ x[1] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 2)) + 0.5f;
743
+ y[1] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 3)) + 0.5f;
744
+ x[2] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 4)) + 0.5f;
745
+ y[2] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 5)) + 0.5f;
746
+
747
+ rotation_triangle( tri_collision, x, y, tri_x, tri_y );
748
+ }
749
+ else /* �O�p���͉�]�E�ό`���Ă��Ȃ����� */
750
+ {
751
+ tri_x[0] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 0)) + 0.5f + tri_collision->base_x;
752
+ tri_y[0] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 1)) + 0.5f + tri_collision->base_y;
753
+ tri_x[1] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 2)) + 0.5f + tri_collision->base_x;
754
+ tri_y[1] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 3)) + 0.5f + tri_collision->base_y;
755
+ tri_x[2] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 4)) + 0.5f + tri_collision->base_x;
756
+ tri_y[2] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 5)) + 0.5f + tri_collision->base_y;
757
+ }
758
+ return checktriangle(o->x1 + 0.5f, o->y1 + 0.5f, tri_x[0], tri_y[0], tri_x[1], tri_y[1], tri_x[2], tri_y[2]);
759
+ }
760
+ break;
761
+ default:
762
+ rb_raise( eDXRubyError, "Internal error" );
763
+ break;
764
+ }
765
+ rb_raise( eDXRubyError, "Internal error" );
766
+ }
767
+ break;
768
+
769
+ case 3: /* �~ */
770
+ {
771
+ struct DXRubyCollision *circle_collision = o;
772
+
773
+ switch( d_type )
774
+ {
775
+ case 4: /* �~�Ƌ�` */
776
+ {
777
+ struct DXRubyCollision *box_collision = d;
778
+ float box_x[4], box_y[4]; /* ��`���W */
779
+ float circle_x, circle_y, circle_r;
780
+ float center_x, center_y;
781
+
782
+ if( !circle_collision->scaling_flg || circle_collision->scale_x == circle_collision->scale_y ) /* �~���ό`���Ă��Ȃ��A�������͏c������ */
783
+ {
784
+ if( box_collision->scaling_flg ) /* ��`�����ό`���Ă��� */
785
+ { /* �ό`������ */
786
+ scaling_box( box_collision, box_x, box_y );
787
+ if( box_collision->scale_x < 0 )
788
+ {
789
+ float temp;
790
+ temp = box_x[0];
791
+ box_x[0] = box_x[1];
792
+ box_x[1] = temp;
793
+ temp = box_x[2];
794
+ box_x[2] = box_x[3];
795
+ box_x[3] = temp;
796
+ temp = box_y[0];
797
+ box_y[0] = box_y[1];
798
+ box_y[1] = temp;
799
+ temp = box_y[2];
800
+ box_y[2] = box_y[3];
801
+ box_y[3] = temp;
802
+ }
803
+ if( box_collision->scale_y < 0 )
804
+ {
805
+ float temp;
806
+ temp = box_x[0];
807
+ box_x[0] = box_x[3];
808
+ box_x[3] = temp;
809
+ temp = box_x[2];
810
+ box_x[2] = box_x[1];
811
+ box_x[1] = temp;
812
+ temp = box_y[0];
813
+ box_y[0] = box_y[3];
814
+ box_y[3] = temp;
815
+ temp = box_y[2];
816
+ box_y[2] = box_y[1];
817
+ box_y[1] = temp;
818
+ }
819
+ }
820
+ else
821
+ {
822
+ box_x[0] = box_x[3] = box_collision->bx1 + box_collision->base_x;
823
+ box_y[0] = box_y[1] = box_collision->by1 + box_collision->base_y;
824
+ box_x[1] = box_x[2] = box_collision->bx2 + box_collision->base_x;
825
+ box_y[2] = box_y[3] = box_collision->by2 + box_collision->base_y;
826
+ }
827
+
828
+ if( circle_collision->rotation_flg || circle_collision->scaling_flg ) /* �~����]������ */
829
+ {
830
+ /* �~�������̒��S�x�[�X�ʼn�]������ */
831
+ rotation_point( circle_collision, circle_x, circle_y, NUM2FLOAT(RARRAY_AREF(circle_collision->vcollision, 0)), NUM2FLOAT(RARRAY_AREF(circle_collision->vcollision, 1)) );
832
+ }
833
+ else
834
+ {
835
+ circle_x = NUM2FLOAT(RARRAY_AREF(circle_collision->vcollision, 0)) + circle_collision->base_x;
836
+ circle_y = NUM2FLOAT(RARRAY_AREF(circle_collision->vcollision, 1)) + circle_collision->base_y;
837
+ }
838
+
839
+ if( box_collision->rotation_flg ) /* ��`������]������ */
840
+ { /* �~�̒��S�_����`���S�x�[�X�ʼn�]������ */
841
+ rotation_point_out( box_collision->center_x + box_collision->base_x, box_collision->center_y + box_collision->base_y, -box_collision->angle, circle_x, circle_y );
842
+ }
843
+
844
+ circle_r = NUM2FLOAT(RARRAY_AREF(circle_collision->vcollision, 2)) * circle_collision->scale_x;
845
+
846
+ /* ���Ƃ͉~�Ɖ�]���Ă��Ȃ���`�̔���ł�����B */
847
+ return check_point_box(circle_x, circle_y, box_x[0] - circle_r, box_y[0], box_x[2] + circle_r, box_y[2]) ||
848
+ check_point_box(circle_x, circle_y, box_x[0], box_y[0] - circle_r, box_x[2], box_y[2] + circle_r) ||
849
+ check_circle_point(box_x[0], box_y[0], circle_r, circle_x, circle_y) ||
850
+ check_circle_point(box_x[1], box_y[1], circle_r, circle_x, circle_y) ||
851
+ check_circle_point(box_x[2], box_y[2], circle_r, circle_x, circle_y) ||
852
+ check_circle_point(box_x[3], box_y[3], circle_r, circle_x, circle_y);
853
+ }
854
+
855
+ if( box_collision->rotation_flg || box_collision->scaling_flg ) /* ��`������]�E�ό`���Ă��� */
856
+ {
857
+ /* ��`���������̎p���ɉ�]�E�ό` */
858
+ rotation_box( box_collision, box_x, box_y );
859
+ }
860
+ else /* ��`���͉�]�E�ό`���Ă��Ȃ����� */
861
+ {
862
+ box_x[0] = box_x[3] = (float)box_collision->x1;
863
+ box_y[0] = box_y[1] = (float)box_collision->y1;
864
+ box_x[1] = box_x[2] = (float)box_collision->x2;
865
+ box_y[2] = box_y[3] = (float)box_collision->y2;
866
+ }
867
+
868
+ center_x = circle_collision->center_x + circle_collision->base_x;
869
+ center_y = circle_collision->center_y + circle_collision->base_y;
870
+
871
+ if( circle_collision->rotation_flg ) /* �~����]������ */
872
+ {
873
+ /* �~���S�_�𒆐S�ɋ�`��] */
874
+ rotation_box_out( center_x, center_y, -circle_collision->angle, box_x, box_y )
875
+ }
876
+ circle_r = NUM2FLOAT(RARRAY_AREF(circle_collision->vcollision, 2));
877
+
878
+ circle_x = circle_collision->base_x + NUM2FLOAT(RARRAY_AREF(circle_collision->vcollision, 0));
879
+ circle_y = circle_collision->base_y + NUM2FLOAT(RARRAY_AREF(circle_collision->vcollision, 1));
880
+ if( circle_collision->scaling_flg ) /* �~�����ό`���Ă��� */
881
+ { /* �~���^�~�ɂȂ�悤�ɋ�`��ό`������ */
882
+ box_x[0] = (box_x[0] - center_x) / circle_collision->scale_x + center_x;
883
+ box_y[0] = (box_y[0] - center_y) / circle_collision->scale_y + center_y;
884
+ box_x[1] = (box_x[1] - center_x) / circle_collision->scale_x + center_x;
885
+ box_y[1] = (box_y[1] - center_y) / circle_collision->scale_y + center_y;
886
+ box_x[2] = (box_x[2] - center_x) / circle_collision->scale_x + center_x;
887
+ box_y[2] = (box_y[2] - center_y) / circle_collision->scale_y + center_y;
888
+ box_x[3] = (box_x[3] - center_x) / circle_collision->scale_x + center_x;
889
+ box_y[3] = (box_y[3] - center_y) / circle_collision->scale_y + center_y;
890
+ }
891
+
892
+ /* ���� */
893
+ return checktriangle(circle_x, circle_y, box_x[0], box_y[0], box_x[1], box_y[1], box_x[2], box_y[2]) ||
894
+ checktriangle(circle_x, circle_y, box_x[0], box_y[0], box_x[2], box_y[2], box_x[3], box_y[3]) ||
895
+ checkCircleLine(circle_x, circle_y, circle_r, box_x[0], box_y[0], box_x[1], box_y[1]) ||
896
+ checkCircleLine(circle_x, circle_y, circle_r, box_x[1], box_y[1], box_x[2], box_y[2]) ||
897
+ checkCircleLine(circle_x, circle_y, circle_r, box_x[2], box_y[2], box_x[3], box_y[3]) ||
898
+ checkCircleLine(circle_x, circle_y, circle_r, box_x[3], box_y[3], box_x[0], box_y[0]);
899
+ }
900
+ break;
901
+ case 6: /* �~�ƎO�p */
902
+ {
903
+ struct DXRubyCollision *tri_collision = d;
904
+ float x[3], y[3], tri_x[3], tri_y[3]; /* �O�p���W */
905
+ float circle_x, circle_y, circle_r;
906
+ float center_x, center_y;
907
+
908
+ if( tri_collision->rotation_flg || tri_collision->scaling_flg ) /* �O�p������]�E�ό`���Ă��� */
909
+ {
910
+ /* �O�p���������̎p���ɉ�]�E�ό` */
911
+ x[0] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 0)) + 0.5f;
912
+ y[0] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 1)) + 0.5f;
913
+ x[1] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 2)) + 0.5f;
914
+ y[1] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 3)) + 0.5f;
915
+ x[2] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 4)) + 0.5f;
916
+ y[2] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 5)) + 0.5f;
917
+
918
+ rotation_triangle( tri_collision, x, y, tri_x, tri_y );
919
+ }
920
+ else /* �O�p���͉�]�E�ό`���Ă��Ȃ����� */
921
+ {
922
+ tri_x[0] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 0)) + 0.5f + tri_collision->base_x;
923
+ tri_y[0] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 1)) + 0.5f + tri_collision->base_y;
924
+ tri_x[1] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 2)) + 0.5f + tri_collision->base_x;
925
+ tri_y[1] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 3)) + 0.5f + tri_collision->base_y;
926
+ tri_x[2] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 4)) + 0.5f + tri_collision->base_x;
927
+ tri_y[2] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 5)) + 0.5f + tri_collision->base_y;
928
+ }
929
+
930
+ /* �~�̉�]���S */
931
+ center_x = circle_collision->center_x + circle_collision->base_x;
932
+ center_y = circle_collision->center_y + circle_collision->base_y;
933
+
934
+ if( circle_collision->rotation_flg ) /* �~����]������ */
935
+ {
936
+ /* �~���S�_�𒆐S�ɎO�p��] */
937
+ rotation_triangle_out( center_x, center_y, -circle_collision->angle, tri_x, tri_y )
938
+ }
939
+ circle_r = NUM2FLOAT(RARRAY_AREF(circle_collision->vcollision, 2));
940
+
941
+ circle_x = circle_collision->base_x + NUM2INT(RARRAY_AREF(circle_collision->vcollision, 0));
942
+ circle_y = circle_collision->base_y + NUM2INT(RARRAY_AREF(circle_collision->vcollision, 1));
943
+ if( circle_collision->scaling_flg ) /* �~�����ό`���Ă��� */
944
+ { /* �~���^�~�ɂȂ�悤�ɎO�p��ό`������ */
945
+ tri_x[0] = (tri_x[0] - center_x) / circle_collision->scale_x + center_x;
946
+ tri_y[0] = (tri_y[0] - center_y) / circle_collision->scale_y + center_y;
947
+ tri_x[1] = (tri_x[1] - center_x) / circle_collision->scale_x + center_x;
948
+ tri_y[1] = (tri_y[1] - center_y) / circle_collision->scale_y + center_y;
949
+ tri_x[2] = (tri_x[2] - center_x) / circle_collision->scale_x + center_x;
950
+ tri_y[2] = (tri_y[2] - center_y) / circle_collision->scale_y + center_y;
951
+ }
952
+
953
+ /* ���� */
954
+ return checktriangle(circle_x, circle_y, tri_x[0], tri_y[0], tri_x[1], tri_y[1], tri_x[2], tri_y[2]) ||
955
+ checkCircleLine(circle_x, circle_y, circle_r, tri_x[0], tri_y[0], tri_x[1], tri_y[1]) ||
956
+ checkCircleLine(circle_x, circle_y, circle_r, tri_x[1], tri_y[1], tri_x[2], tri_y[2]) ||
957
+ checkCircleLine(circle_x, circle_y, circle_r, tri_x[2], tri_y[2], tri_x[0], tri_y[0]);
958
+ }
959
+ break;
960
+ default:
961
+ rb_raise( eDXRubyError, "Internal error" );
962
+ break;
963
+ }
964
+ }
965
+ case 4: /* ��` */
966
+ {
967
+ struct DXRubyCollision *box_collision = o;
968
+
969
+ switch( d_type )
970
+ {
971
+ case 6: /* ��`�ƎO�p */
972
+ {
973
+ struct DXRubyCollision *tri_collision = d;
974
+ float box_x[4], box_y[4]; /* ��`���W */
975
+ float tri_x[3], tri_y[3]; /* �O�p���W */
976
+ float x[3], y[3];
977
+
978
+ if( box_collision->rotation_flg || box_collision->scaling_flg ) /* ��`����]������ */
979
+ {
980
+ rotation_box( box_collision, box_x, box_y );
981
+ }
982
+ else
983
+ {
984
+ box_x[0] = box_x[3] = (float)box_collision->x1;
985
+ box_y[0] = box_y[1] = (float)box_collision->y1;
986
+ box_x[1] = box_x[2] = (float)box_collision->x2;
987
+ box_y[2] = box_y[3] = (float)box_collision->y2;
988
+ }
989
+
990
+ if( tri_collision->rotation_flg || tri_collision->scaling_flg ) /* �O�p����]������ */
991
+ {
992
+ x[0] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 0)) + 0.5f;
993
+ y[0] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 1)) + 0.5f;
994
+ x[1] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 2)) + 0.5f;
995
+ y[1] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 3)) + 0.5f;
996
+ x[2] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 4)) + 0.5f;
997
+ y[2] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 5)) + 0.5f;
998
+
999
+ rotation_triangle( d, x, y, tri_x, tri_y );
1000
+ }
1001
+ else
1002
+ {
1003
+ tri_x[0] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 0)) + 0.5f + tri_collision->base_x;
1004
+ tri_y[0] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 1)) + 0.5f + tri_collision->base_y;
1005
+ tri_x[1] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 2)) + 0.5f + tri_collision->base_x;
1006
+ tri_y[1] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 3)) + 0.5f + tri_collision->base_y;
1007
+ tri_x[2] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 4)) + 0.5f + tri_collision->base_x;
1008
+ tri_y[2] = NUM2INT(RARRAY_AREF(tri_collision->vcollision, 5)) + 0.5f + tri_collision->base_y;
1009
+ }
1010
+
1011
+ return check_line_line(box_x[0], box_y[0], box_x[1], box_y[1], tri_x[0], tri_y[0], tri_x[1], tri_y[1]) ||
1012
+ check_line_line(box_x[0], box_y[0], box_x[1], box_y[1], tri_x[1], tri_y[1], tri_x[2], tri_y[2]) ||
1013
+ check_line_line(box_x[0], box_y[0], box_x[1], box_y[1], tri_x[2], tri_y[2], tri_x[0], tri_y[0]) ||
1014
+ check_line_line(box_x[1], box_y[1], box_x[2], box_y[2], tri_x[0], tri_y[0], tri_x[1], tri_y[1]) ||
1015
+ check_line_line(box_x[1], box_y[1], box_x[2], box_y[2], tri_x[1], tri_y[1], tri_x[2], tri_y[2]) ||
1016
+ check_line_line(box_x[1], box_y[1], box_x[2], box_y[2], tri_x[2], tri_y[2], tri_x[0], tri_y[0]) ||
1017
+ check_line_line(box_x[2], box_y[2], box_x[3], box_y[3], tri_x[0], tri_y[0], tri_x[1], tri_y[1]) ||
1018
+ check_line_line(box_x[2], box_y[2], box_x[3], box_y[3], tri_x[1], tri_y[1], tri_x[2], tri_y[2]) ||
1019
+ check_line_line(box_x[2], box_y[2], box_x[3], box_y[3], tri_x[2], tri_y[2], tri_x[0], tri_y[0]) ||
1020
+ check_line_line(box_x[3], box_y[3], box_x[0], box_y[0], tri_x[0], tri_y[0], tri_x[1], tri_y[1]) ||
1021
+ check_line_line(box_x[3], box_y[3], box_x[0], box_y[0], tri_x[1], tri_y[1], tri_x[2], tri_y[2]) ||
1022
+ check_line_line(box_x[3], box_y[3], box_x[0], box_y[0], tri_x[2], tri_y[2], tri_x[0], tri_y[0]) ||
1023
+ checktriangle(tri_x[0], tri_y[0], box_x[0], box_y[0], box_x[1], box_y[1], box_x[2], box_y[2]) ||
1024
+ checktriangle(tri_x[0], tri_y[0], box_x[0], box_y[0], box_x[2], box_y[2], box_x[3], box_y[3]) ||
1025
+ checktriangle(box_x[0], box_y[0], tri_x[0], tri_y[0], tri_x[1], tri_y[1], tri_x[2], tri_y[2]);
1026
+ }
1027
+ break;
1028
+ default:
1029
+ rb_raise( eDXRubyError, "Internal error" );
1030
+ break;
1031
+ }
1032
+ }
1033
+ default:
1034
+ rb_raise( eDXRubyError, "Internal error" );
1035
+ break;
1036
+ }
1037
+ rb_raise( eDXRubyError, "Internal error" );
1038
+ }
1039
+ rb_raise( eDXRubyError, "Internal error" );
1040
+ }
1041
+
1042
+ /* �Փ˔���z��̃J�E���g�擾 */
1043
+ int get_volume_count( VALUE vary )
1044
+ {
1045
+ int p, count = 0;
1046
+
1047
+ for( p = 0; p < RARRAY_LEN(vary); p++ )
1048
+ {
1049
+ VALUE vsprite = RARRAY_AREF( vary, p );
1050
+
1051
+ if( TYPE(vsprite) == T_ARRAY )
1052
+ {
1053
+ count += get_volume_count( vsprite );
1054
+ }
1055
+ else
1056
+ {
1057
+ count++;
1058
+ }
1059
+ }
1060
+
1061
+ return count;
1062
+ }
1063
+
1064
+
1065
+ /* AABB���E�{�����[�����̖��ח̈� */
1066
+ static int alloc_volume( int count )
1067
+ {
1068
+ while( g_volume_allocate_count < g_volume_count + count )
1069
+ {
1070
+ g_volume_allocate_count = g_volume_allocate_count * 3 / 2; /* 1.5�{�ɂ��� */
1071
+ g_volume_pointer = realloc( g_volume_pointer, sizeof( struct DXRubyCollision ) * g_volume_allocate_count );
1072
+ }
1073
+
1074
+ g_volume_count += count;
1075
+
1076
+ return g_volume_count - count;
1077
+ }
1078
+
1079
+ /* �z��̏Փ˔���pAABB���E�{�����[���쐬�B�̈�͏�̊֐��Ŋm�ۂ��ēn����� */
1080
+ int make_volume_ary( VALUE vary, struct DXRubyCollisionGroup *group )
1081
+ {
1082
+ int p, count = 0;
1083
+
1084
+ /* �z��̐������{�����[���쐬���� */
1085
+ for( p = 0; p < RARRAY_LEN(vary); p++ )
1086
+ {
1087
+ int tmp;
1088
+ VALUE vsprite = RARRAY_AREF( vary, p );
1089
+
1090
+ if( TYPE(vsprite) == T_ARRAY )
1091
+ {
1092
+ tmp = make_volume_ary( vsprite, group );
1093
+ }
1094
+ else
1095
+ {
1096
+ tmp = make_volume( vsprite, group );
1097
+ }
1098
+ count += tmp;
1099
+ group += tmp;
1100
+ }
1101
+
1102
+ return count;
1103
+ }
1104
+
1105
+
1106
+ /* �P�̂̏Փ˔���pAABB���E�{�����[���쐬 */
1107
+ int make_volume( VALUE vsprite, struct DXRubyCollisionGroup *group )
1108
+ {
1109
+ struct DXRubySprite *sprite;
1110
+
1111
+ /* Sprite����Ȃ���Ζ��� */
1112
+ if( !DXRUBY_CHECK( Sprite, vsprite ) )
1113
+ {
1114
+ return 0;
1115
+ }
1116
+
1117
+ /* �Փ˔��肪�L���łȂ��ꍇ�͖��� */
1118
+ sprite = DXRUBY_GET_STRUCT( Sprite, vsprite );
1119
+ #ifdef DXRUBY15
1120
+ if( !RTEST(sprite->vvisible) || !RTEST(sprite->vcollision_enable) || sprite->vanish )
1121
+ #else
1122
+ if( !RTEST(sprite->vcollision_enable) || sprite->vanish )
1123
+ #endif
1124
+ {
1125
+ return 0;
1126
+ }
1127
+
1128
+ /* �Փ˔���͈͂��ݒ肳��Ă��Ȃ����1�‚������׏��𐶐����� */
1129
+ if( sprite->vcollision == Qnil )
1130
+ {
1131
+ /* collision��image���ݒ肳��Ă��Ȃ���Ζ��� */
1132
+ if( sprite->vimage == Qnil )
1133
+ {
1134
+ return 0;
1135
+ }
1136
+
1137
+ group->vsprite = vsprite;
1138
+ group->index = alloc_volume( 1 );
1139
+ group->count = 1;
1140
+ make_volume_sub( vsprite, sprite->vcollision, g_volume_pointer + group->index );
1141
+ group->x1 = (g_volume_pointer + group->index)->x1;
1142
+ group->y1 = (g_volume_pointer + group->index)->y1;
1143
+ group->x2 = (g_volume_pointer + group->index)->x2;
1144
+ group->y2 = (g_volume_pointer + group->index)->y2;
1145
+
1146
+ return 1;
1147
+ }
1148
+
1149
+ /* �Փ˔���͈͂��z�񂶂�Ȃ���Ζ��� */
1150
+ Check_Type( sprite->vcollision, T_ARRAY );
1151
+ if( RARRAY_LEN(sprite->vcollision) == 0 )
1152
+ {
1153
+ return 0;
1154
+ }
1155
+
1156
+ /* �Փ˔���͈͔z��̒��ɔz�񂪓����Ă����ꍇ�͕����͈̔͂�p���邱�Ƃ��ł��� */
1157
+ if( TYPE(RARRAY_AREF(sprite->vcollision, 0)) == T_ARRAY )
1158
+ {
1159
+ int p2;
1160
+
1161
+ group->vsprite = vsprite;
1162
+ group->index = alloc_volume( RARRAY_LEN(sprite->vcollision) );
1163
+ group->count = RARRAY_LEN(sprite->vcollision);
1164
+
1165
+ for( p2 = 0; p2 < RARRAY_LEN(sprite->vcollision); p2++ )
1166
+ {
1167
+ Check_Type( RARRAY_AREF(sprite->vcollision, p2), T_ARRAY );
1168
+ make_volume_sub( vsprite, RARRAY_AREF(sprite->vcollision, p2), g_volume_pointer + group->index + p2 );
1169
+ }
1170
+
1171
+ /* �O���[�v��AABB���E�����ׂĊ܂ލŏ���AABB���E�𐶐����� */
1172
+ group->x1 = (g_volume_pointer + group->index)->x1;
1173
+ group->y1 = (g_volume_pointer + group->index)->y1;
1174
+ group->x2 = (g_volume_pointer + group->index)->x2;
1175
+ group->y2 = (g_volume_pointer + group->index)->y2;
1176
+ for( p2 = 1; p2 < RARRAY_LEN(sprite->vcollision); p2++ )
1177
+ {
1178
+ if( group->x1 > (g_volume_pointer + group->index + p2)->x1 )
1179
+ {
1180
+ group->x1 = (g_volume_pointer + group->index + p2)->x1;
1181
+ }
1182
+ if( group->x2 < (g_volume_pointer + group->index + p2)->x2 )
1183
+ {
1184
+ group->x2 = (g_volume_pointer + group->index + p2)->x2;
1185
+ }
1186
+ if( group->y1 > (g_volume_pointer + group->index + p2)->y1 )
1187
+ {
1188
+ group->y1 = (g_volume_pointer + group->index + p2)->y1;
1189
+ }
1190
+ if( group->y2 < (g_volume_pointer + group->index + p2)->y2 )
1191
+ {
1192
+ group->y2 = (g_volume_pointer + group->index + p2)->y2;
1193
+ }
1194
+ }
1195
+
1196
+ }
1197
+ else
1198
+ { /* �z�񂶂�Ȃ��ꍇ */
1199
+ group->vsprite = vsprite;
1200
+ group->index = alloc_volume( 1 );
1201
+ group->count = 1;
1202
+ make_volume_sub( vsprite, sprite->vcollision, g_volume_pointer + group->index );
1203
+ group->x1 = (g_volume_pointer + group->index)->x1;
1204
+ group->y1 = (g_volume_pointer + group->index)->y1;
1205
+ group->x2 = (g_volume_pointer + group->index)->x2;
1206
+ group->y2 = (g_volume_pointer + group->index)->y2;
1207
+ }
1208
+
1209
+ return 1;
1210
+ }
1211
+
1212
+
1213
+ /* �Փ˔���pAABB���E�{�����[���쐬sub */
1214
+ void make_volume_sub( VALUE vsprite, VALUE vcol, struct DXRubyCollision *collision )
1215
+ {
1216
+ struct DXRubySprite *sprite;
1217
+ sprite = DXRUBY_GET_STRUCT( Sprite, vsprite );
1218
+
1219
+ collision->vsprite = vsprite;
1220
+ collision->base_x = NUM2FLOAT(sprite->vx);
1221
+ collision->base_y = NUM2FLOAT(sprite->vy);
1222
+ if( RTEST(sprite->voffset_sync) )
1223
+ {
1224
+ struct DXRubyImage *image;
1225
+ if( sprite->vcenter_x == Qnil || sprite->vcenter_y == Qnil )
1226
+ {
1227
+ DXRUBY_CHECK_IMAGE( sprite->vimage );
1228
+ image = DXRUBY_GET_STRUCT( Image, sprite->vimage );
1229
+ collision->base_x -= sprite->vcenter_x == Qnil ? image->width / 2 : NUM2FLOAT(sprite->vcenter_x);
1230
+ collision->base_y -= sprite->vcenter_y == Qnil ? image->height / 2 : NUM2FLOAT(sprite->vcenter_y);
1231
+ }
1232
+ else
1233
+ {
1234
+ collision->base_x -= NUM2FLOAT(sprite->vcenter_x);
1235
+ collision->base_y -= NUM2FLOAT(sprite->vcenter_y);
1236
+ }
1237
+ }
1238
+ collision->angle = NUM2FLOAT(sprite->vangle);
1239
+ collision->scale_x = NUM2FLOAT(sprite->vscale_x);
1240
+ collision->scale_y = NUM2FLOAT(sprite->vscale_y);
1241
+ collision->vcollision = vcol;
1242
+ if( RTEST(sprite->vcollision_sync) ) /* ��]�E�X�P�[�����O�̃t���O */
1243
+ {
1244
+ if( collision->angle != 0.0f )
1245
+ {
1246
+ collision->rotation_flg = TRUE;
1247
+ }
1248
+ else
1249
+ {
1250
+ collision->rotation_flg = FALSE;
1251
+ }
1252
+ if( collision->scale_x != 1.0f || collision->scale_y != 1.0f )
1253
+ {
1254
+ collision->scaling_flg = TRUE;
1255
+ }
1256
+ else
1257
+ {
1258
+ collision->scaling_flg = FALSE;
1259
+ }
1260
+ }
1261
+ else
1262
+ {
1263
+ collision->rotation_flg = FALSE;
1264
+ collision->scaling_flg = FALSE;
1265
+ }
1266
+
1267
+ if( vcol != Qnil )
1268
+ {
1269
+ Check_Type( vcol, T_ARRAY );
1270
+
1271
+ switch (RARRAY_LEN(vcol))
1272
+ {
1273
+ case 2: /* �_ */
1274
+ if( !collision->rotation_flg && !collision->scaling_flg )
1275
+ {
1276
+ collision->bx1 = NUM2FLOAT(RARRAY_AREF(vcol, 0));
1277
+ collision->by1 = NUM2FLOAT(RARRAY_AREF(vcol, 1));
1278
+ collision->bx2 = NUM2FLOAT(RARRAY_AREF(vcol, 0)) + 1;
1279
+ collision->by2 = NUM2FLOAT(RARRAY_AREF(vcol, 1)) + 1;
1280
+ collision->x1 = (int)(collision->base_x + collision->bx1);
1281
+ collision->y1 = (int)(collision->base_y + collision->by1);
1282
+ collision->x2 = (int)(collision->base_x + collision->bx2);
1283
+ collision->y2 = (int)(collision->base_y + collision->by2);
1284
+ }
1285
+ else /* ��]�����_ */
1286
+ {
1287
+ float tx,ty;
1288
+ collision->bx1 = NUM2FLOAT(RARRAY_AREF(vcol, 0));
1289
+ collision->by1 = NUM2FLOAT(RARRAY_AREF(vcol, 1));
1290
+ collision->bx2 = NUM2FLOAT(RARRAY_AREF(vcol, 0)) + 1;
1291
+ collision->by2 = NUM2FLOAT(RARRAY_AREF(vcol, 1)) + 1;
1292
+
1293
+ set_center( sprite, collision );
1294
+ rotation_point( collision, tx, ty, collision->bx1 + 0.5f, collision->by1 + 0.5f );
1295
+
1296
+ collision->x1 = (int)tx;
1297
+ collision->y1 = (int)ty;
1298
+ collision->x2 = (int)tx + 1;
1299
+ collision->y2 = (int)ty + 1;
1300
+ }
1301
+ break;
1302
+ case 3: /* �~ */
1303
+ {
1304
+ float tempx = NUM2FLOAT(RARRAY_AREF(vcol, 0));
1305
+ float tempy = NUM2FLOAT(RARRAY_AREF(vcol, 1));
1306
+ float tempr = NUM2FLOAT(RARRAY_AREF(vcol, 2));
1307
+
1308
+ if( !collision->rotation_flg && !collision->scaling_flg )
1309
+ {
1310
+ collision->x1 = (int)(collision->base_x + tempx - tempr);
1311
+ collision->y1 = (int)(collision->base_y + tempy - tempr);
1312
+ collision->x2 = (int)(collision->base_x + tempx + tempr);
1313
+ collision->y2 = (int)(collision->base_y + tempy + tempr);
1314
+ }
1315
+ else /* ��]�����~ */
1316
+ {
1317
+ float tx,ty;
1318
+
1319
+ if( collision->scale_x != collision->scale_y ) /* �ȉ~�B����̂Ŏb��Ƃ��ċ��E�{�����[������]���ċ��E�{�����[������� */
1320
+ {
1321
+ float x[4], y[4];
1322
+ collision->bx1 = tempx - tempr;
1323
+ collision->by1 = tempy - tempr;
1324
+ collision->bx2 = tempx + tempr;
1325
+ collision->by2 = tempy + tempr;
1326
+
1327
+ set_center( sprite, collision );
1328
+
1329
+ rotation_box( collision, x, y );
1330
+ volume_box( 4, x, y, collision );
1331
+ collision->x2++;
1332
+ collision->y2++;
1333
+ }
1334
+ else /* �^�~ */
1335
+ {
1336
+ set_center( sprite, collision );
1337
+ rotation_point( collision, tx, ty, tempx, tempy );
1338
+ collision->x1 = (int)(tx - tempr * collision->scale_x);
1339
+ collision->y1 = (int)(ty - tempr * collision->scale_x);
1340
+ collision->x2 = (int)(tx + tempr * collision->scale_x);
1341
+ collision->y2 = (int)(ty + tempr * collision->scale_x);
1342
+ }
1343
+ }
1344
+ break;
1345
+ }
1346
+ case 4: /* ��` */
1347
+ if( !collision->rotation_flg && !collision->scaling_flg )
1348
+ {
1349
+ collision->bx1 = NUM2FLOAT(RARRAY_AREF(vcol, 0));
1350
+ collision->by1 = NUM2FLOAT(RARRAY_AREF(vcol, 1));
1351
+ collision->bx2 = NUM2FLOAT(RARRAY_AREF(vcol, 2)) + 1;
1352
+ collision->by2 = NUM2FLOAT(RARRAY_AREF(vcol, 3)) + 1;
1353
+ collision->x1 = (int)(collision->base_x + collision->bx1);
1354
+ collision->y1 = (int)(collision->base_y + collision->by1);
1355
+ collision->x2 = (int)(collision->base_x + collision->bx2);
1356
+ collision->y2 = (int)(collision->base_y + collision->by2);
1357
+ }
1358
+ else /* ��]������` */
1359
+ {
1360
+ float tx[4], ty[4];
1361
+
1362
+ collision->bx1 = NUM2FLOAT(RARRAY_AREF(vcol, 0));
1363
+ collision->by1 = NUM2FLOAT(RARRAY_AREF(vcol, 1));
1364
+ collision->bx2 = NUM2FLOAT(RARRAY_AREF(vcol, 2)) + 1;
1365
+ collision->by2 = NUM2FLOAT(RARRAY_AREF(vcol, 3)) + 1;
1366
+ set_center( sprite, collision );
1367
+
1368
+ rotation_box( collision, tx, ty );
1369
+
1370
+ volume_box( 4, tx, ty, collision );
1371
+ collision->x2++;
1372
+ collision->y2++;
1373
+ }
1374
+ break;
1375
+ case 6: /* �O�p�` */
1376
+ {
1377
+ float tx[3], ty[3];
1378
+ int i;
1379
+ if( !collision->rotation_flg && !collision->scaling_flg )
1380
+ {
1381
+ tx[0] = collision->base_x + NUM2INT(RARRAY_AREF(vcol, 0)) + 0.5f;
1382
+ ty[0] = collision->base_y + NUM2INT(RARRAY_AREF(vcol, 1)) + 0.5f;
1383
+ tx[1] = collision->base_x + NUM2INT(RARRAY_AREF(vcol, 2)) + 0.5f;
1384
+ ty[1] = collision->base_y + NUM2INT(RARRAY_AREF(vcol, 3)) + 0.5f;
1385
+ tx[2] = collision->base_x + NUM2INT(RARRAY_AREF(vcol, 4)) + 0.5f;
1386
+ ty[2] = collision->base_y + NUM2INT(RARRAY_AREF(vcol, 5)) + 0.5f;
1387
+ }
1388
+ else /* ��]�����O�p�` */
1389
+ {
1390
+ float x[3], y[3];
1391
+
1392
+ x[0] = NUM2INT(RARRAY_AREF(vcol, 0)) + 0.5f;
1393
+ y[0] = NUM2INT(RARRAY_AREF(vcol, 1)) + 0.5f;
1394
+ x[1] = NUM2INT(RARRAY_AREF(vcol, 2)) + 0.5f;
1395
+ y[1] = NUM2INT(RARRAY_AREF(vcol, 3)) + 0.5f;
1396
+ x[2] = NUM2INT(RARRAY_AREF(vcol, 4)) + 0.5f;
1397
+ y[2] = NUM2INT(RARRAY_AREF(vcol, 5)) + 0.5f;
1398
+
1399
+ set_center( sprite, collision );
1400
+
1401
+ rotation_triangle( collision, x, y, tx, ty );
1402
+ }
1403
+ volume_box( 3, tx, ty, collision );
1404
+ collision->x2++;
1405
+ collision->y2++;
1406
+ }
1407
+ break;
1408
+ default:
1409
+ rb_raise( eDXRubyError, "collision�̐ݒ肪�s���ł� - Sprite_make_volume" );
1410
+ break;
1411
+ }
1412
+ }
1413
+ else /* �Փ˔���͈͏ȗ����͉摜�T�C�Y�̋�`�Ƃ݂Ȃ� */
1414
+ { /* ��]���Ă��Ȃ���` */
1415
+ struct DXRubyImage *image;
1416
+ DXRUBY_CHECK_IMAGE( sprite->vimage );
1417
+ image = DXRUBY_GET_STRUCT( Image, sprite->vimage );
1418
+ if( !collision->rotation_flg && !collision->scaling_flg )
1419
+ {
1420
+ collision->bx1 = 0;
1421
+ collision->by1 = 0;
1422
+ collision->bx2 = (float)image->width;
1423
+ collision->by2 = (float)image->height;
1424
+ collision->x1 = (int)collision->base_x;
1425
+ collision->y1 = (int)collision->base_y;
1426
+ collision->x2 = (int)(collision->base_x + image->width);
1427
+ collision->y2 = (int)(collision->base_y + image->height);
1428
+ }
1429
+ else /* ��]������` */
1430
+ {
1431
+ float tx[4], ty[4];
1432
+
1433
+ collision->bx1 = 0;
1434
+ collision->by1 = 0;
1435
+ collision->bx2 = (float)image->width;
1436
+ collision->by2 = (float)image->height;
1437
+ collision->center_x = sprite->vcenter_x == Qnil ? image->width / 2 : NUM2FLOAT(sprite->vcenter_x);
1438
+ collision->center_y = sprite->vcenter_y == Qnil ? image->height / 2 : NUM2FLOAT(sprite->vcenter_y);
1439
+
1440
+ rotation_box( collision, tx, ty );
1441
+
1442
+ volume_box( 4, tx, ty, collision );
1443
+ collision->x2++;
1444
+ collision->y2++;
1445
+ }
1446
+ }
1447
+ }
1448
+
1449
+ void collision_init(void)
1450
+ {
1451
+ g_volume_count = 0;
1452
+ g_volume_allocate_count = 16;
1453
+ g_volume_pointer = malloc( sizeof(struct DXRubyCollision) * 16 );
1454
+ }
1455
+
1456
+ void collision_clear(void)
1457
+ {
1458
+ g_volume_count = 0;
1459
+ }
1460
+