11
TEST(mprBoxboxAlignedX)
20
ccd.support1 = ccdSupport;
21
ccd.support2 = ccdSupport;
22
ccd.center1 = ccdObjCenter;
23
ccd.center2 = ccdObjCenter;
32
ccdVec3Set(&box1.pos, -5., 0., 0.);
33
ccdVec3Set(&box2.pos, 0., 0., 0.);
34
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
35
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
36
for (i = 0; i < 100; i++){
37
res = ccdMPRIntersect(&box1, &box2, &ccd);
38
if (i < 35 || i > 65){
40
}else if (i != 35 && i != 65){
54
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
55
ccdVec3Set(&box2.pos, 0., 0., 0.);
56
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
57
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
58
for (i = 0; i < 100; i++){
59
res = ccdMPRIntersect(&box1, &box2, &ccd);
61
if (i < 35 || i > 65){
63
}else if (i != 35 && i != 65){
67
box1.pos.v[0] += 0.01;
78
ccdVec3Set(&box1.pos, -5., -0.1, 0.);
79
ccdVec3Set(&box2.pos, 0., 0., 0.);
80
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
81
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
82
for (i = 0; i < 100; i++){
83
res = ccdMPRIntersect(&box1, &box2, &ccd);
85
if (i < 35 || i > 65){
87
}else if (i != 35 && i != 65){
95
TEST(mprBoxboxAlignedY)
104
ccd.support1 = ccdSupport;
105
ccd.support2 = ccdSupport;
106
ccd.center1 = ccdObjCenter;
107
ccd.center2 = ccdObjCenter;
116
ccdVec3Set(&box1.pos, 0., -5., 0.);
117
ccdVec3Set(&box2.pos, 0., 0., 0.);
118
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
119
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
120
for (i = 0; i < 100; i++){
121
res = ccdMPRIntersect(&box1, &box2, &ccd);
123
if (i < 35 || i > 65){
125
}else if (i != 35 && i != 65){
129
box1.pos.v[1] += 0.1;
133
TEST(mprBoxboxAlignedZ)
142
ccd.support1 = ccdSupport;
143
ccd.support2 = ccdSupport;
144
ccd.center1 = ccdObjCenter;
145
ccd.center2 = ccdObjCenter;
154
ccdVec3Set(&box1.pos, 0., 0., -5.);
155
ccdVec3Set(&box2.pos, 0., 0., 0.);
156
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
157
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
158
for (i = 0; i < 100; i++){
159
res = ccdMPRIntersect(&box1, &box2, &ccd);
161
if (i < 35 || i > 65){
163
}else if (i != 35 && i != 65){
167
box1.pos.v[2] += 0.1;
183
ccd.support1 = ccdSupport;
184
ccd.support2 = ccdSupport;
185
ccd.center1 = ccdObjCenter;
186
ccd.center2 = ccdObjCenter;
195
ccdVec3Set(&box1.pos, -5., 0.5, 0.);
196
ccdVec3Set(&box2.pos, 0., 0., 0.);
197
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
198
ccdVec3Set(&axis, 0., 1., 0.);
199
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
201
for (i = 0; i < 100; i++){
202
res = ccdMPRIntersect(&box1, &box2, &ccd);
204
if (i < 33 || i > 67){
206
}else if (i != 33 && i != 67){
210
box1.pos.v[0] += 0.1;
220
ccdVec3Set(&box1.pos, -1.01, 0., 0.);
221
ccdVec3Set(&box2.pos, 0., 0., 0.);
222
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
223
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
225
ccdVec3Set(&axis, 0., 1., 0.);
227
for (i = 0; i < 30; i++){
228
res = ccdMPRIntersect(&box1, &box2, &ccd);
230
if (i != 0 && i != 10 && i != 20){
237
ccdQuatSetAngleAxis(&box1.quat, angle, &axis);
244
static void pConf(ccd_box_t *box1, ccd_box_t *box2, const ccd_vec3_t *v)
246
fprintf(stdout, "# box1.pos: [%lf %lf %lf]\n",
247
ccdVec3X(&box1->pos), ccdVec3Y(&box1->pos), ccdVec3Z(&box1->pos));
248
fprintf(stdout, "# box1->quat: [%lf %lf %lf %lf]\n",
249
box1->quat.q[0], box1->quat.q[1], box1->quat.q[2], box1->quat.q[3]);
250
fprintf(stdout, "# box2->pos: [%lf %lf %lf]\n",
251
ccdVec3X(&box2->pos), ccdVec3Y(&box2->pos), ccdVec3Z(&box2->pos));
252
fprintf(stdout, "# box2->quat: [%lf %lf %lf %lf]\n",
253
box2->quat.q[0], box2->quat.q[1], box2->quat.q[2], box2->quat.q[3]);
254
fprintf(stdout, "# sep: [%lf %lf %lf]\n",
255
ccdVec3X(v), ccdVec3Y(v), ccdVec3Z(v));
256
fprintf(stdout, "#\n");
259
TEST(mprBoxboxSeparate)
265
ccd_vec3_t sep, expsep, expsep2, axis;
267
fprintf(stderr, "\n\n\n---- boxboxSeparate ----\n\n\n");
269
box1.x = box1.y = box1.z = 1.;
276
ccd.support1 = ccdSupport;
277
ccd.support2 = ccdSupport;
278
ccd.center1 = ccdObjCenter;
279
ccd.center2 = ccdObjCenter;
281
ccdVec3Set(&box1.pos, -0.5, 0.5, 0.2);
282
res = ccdMPRIntersect(&box1, &box2, &ccd);
285
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
286
assertTrue(res == 0);
287
ccdVec3Set(&expsep, 0.25, 0., 0.);
288
assertTrue(ccdVec3Eq(&sep, &expsep));
290
ccdVec3Scale(&sep, -1.);
291
ccdVec3Add(&box1.pos, &sep);
292
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
293
assertTrue(res == 0);
294
ccdVec3Set(&expsep, 0., 0., 0.);
295
assertTrue(ccdVec3Eq(&sep, &expsep));
298
ccdVec3Set(&box1.pos, -0.3, 0.5, 1.);
299
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
300
assertTrue(res == 0);
301
ccdVec3Set(&expsep, 0., 0., -0.25);
302
assertTrue(ccdVec3Eq(&sep, &expsep));
306
box1.x = box1.y = box1.z = 1.;
307
box2.x = box2.y = box2.z = 1.;
308
ccdVec3Set(&axis, 0., 0., 1.);
309
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
310
ccdVec3Set(&box1.pos, 0., 0., 0.);
312
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
313
assertTrue(res == 0);
314
ccdVec3Set(&expsep, 0., 0., 1.);
315
ccdVec3Set(&expsep2, 0., 0., -1.);
316
assertTrue(ccdVec3Eq(&sep, &expsep) || ccdVec3Eq(&sep, &expsep2));
320
box1.x = box1.y = box1.z = 1.;
321
ccdVec3Set(&axis, 0., 0., 1.);
322
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
323
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
325
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
326
assertTrue(res == 0);
327
pConf(&box1, &box2, &sep);
331
box1.x = box1.y = box1.z = 1.;
332
ccdVec3Set(&axis, 0., 1., 1.);
333
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
334
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
336
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
337
assertTrue(res == 0);
338
pConf(&box1, &box2, &sep);
343
svtObjPen(&box1, &box2, stdout, "Pen 1", depth, &dir, &pos); \
344
ccdVec3Scale(&dir, depth); \
345
ccdVec3Add(&box2.pos, &dir); \
346
svtObjPen(&box1, &box2, stdout, "Pen 1", depth, &dir, &pos)
348
TEST(mprBoxboxPenetration)
359
fprintf(stderr, "\n\n\n---- boxboxPenetration ----\n\n\n");
361
box1.x = box1.y = box1.z = 1.;
368
ccd.support1 = ccdSupport;
369
ccd.support2 = ccdSupport;
370
ccd.center1 = ccdObjCenter;
371
ccd.center2 = ccdObjCenter;
374
ccdVec3Set(&box2.pos, 0., 0., 0.);
375
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
376
assertTrue(res == 0);
377
recPen(depth, &dir, &pos, stdout, "Pen 1");
381
ccdVec3Set(&box2.pos, 0.1, 0., 0.);
382
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
383
assertTrue(res == 0);
384
recPen(depth, &dir, &pos, stdout, "Pen 1");
388
ccdVec3Set(&box1.pos, -0.3, 0.5, 1.);
389
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
390
assertTrue(res == 0);
391
recPen(depth, &dir, &pos, stdout, "Pen 2");
395
box1.x = box1.y = box1.z = 1.;
396
box2.x = box2.y = box2.z = 1.;
397
ccdVec3Set(&axis, 0., 0., 1.);
398
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
399
ccdVec3Set(&box1.pos, 0.1, 0., 0.1);
401
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
402
assertTrue(res == 0);
403
recPen(depth, &dir, &pos, stdout, "Pen 3");
407
box1.x = box1.y = box1.z = 1.;
408
box2.x = box2.y = box2.z = 1.;
409
ccdVec3Set(&axis, 0., 0., 1.);
410
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
411
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
413
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
414
assertTrue(res == 0);
415
recPen(depth, &dir, &pos, stdout, "Pen 4");
419
box1.x = box1.y = box1.z = 1.;
420
box2.x = box2.y = box2.z = 1.;
421
ccdVec3Set(&axis, 0., 0., 1.);
422
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
423
ccdVec3Set(&box1.pos, -0.5, 0.5, 0.);
425
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
426
assertTrue(res == 0);
427
recPen(depth, &dir, &pos, stdout, "Pen 5");
431
box1.x = box1.y = box1.z = 1.;
432
box2.x = box2.y = box2.z = 1.;
433
ccdVec3Set(&box2.pos, 0.1, 0., 0.);
435
box1.x = box1.y = box1.z = 1.;
436
ccdVec3Set(&axis, 0., 1., 1.);
437
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
438
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
440
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
441
assertTrue(res == 0);
442
recPen(depth, &dir, &pos, stdout, "Pen 6");
446
box1.x = box1.y = box1.z = 1.;
447
ccdVec3Set(&axis, 0., 1., 1.);
448
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
449
ccdVec3Set(&axis, 1., 1., 1.);
450
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
451
ccdQuatMul(&box1.quat, &rot);
452
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
454
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
455
assertTrue(res == 0);
456
recPen(depth, &dir, &pos, stdout, "Pen 7");
460
box1.x = box1.y = box1.z = 1.;
461
box2.x = 0.2; box2.y = 0.5; box2.z = 1.;
462
box2.x = box2.y = box2.z = 1.;
464
ccdVec3Set(&axis, 0., 0., 1.);
465
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
466
ccdVec3Set(&axis, 1., 0., 0.);
467
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
468
ccdQuatMul(&box1.quat, &rot);
469
ccdVec3Set(&box1.pos, -1.3, 0., 0.);
471
ccdVec3Set(&box2.pos, 0., 0., 0.);
473
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
474
assertTrue(res == 0);
475
recPen(depth, &dir, &pos, stdout, "Pen 8");
479
box1.x = box1.y = box1.z = 1.;
480
box2.x = 0.5; box2.y = 0.5; box2.z = .5;
481
ccdVec3Set(&box1.pos, 0., 0., 0.);
482
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
483
ccdVec3Set(&box2.pos, 0., 0.73, 0.);
484
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
486
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
487
assertTrue(res == 0);
488
recPen(depth, &dir, &pos, stdout, "Pen 9");
491
box1.x = box1.y = box1.z = 1.;
492
box2.x = 0.5; box2.y = 0.5; box2.z = .5;
493
ccdVec3Set(&box1.pos, 0., 0., 0.);
494
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
495
ccdVec3Set(&box2.pos, 0.3, 0.738, 0.);
496
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
498
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
499
assertTrue(res == 0);
500
recPen(depth, &dir, &pos, stdout, "Pen 10");