~ubuntu-branches/debian/jessie/libccd/jessie

« back to all changes in this revision

Viewing changes to src/testsuites/boxcyl.c

  • Committer: Package Import Robot
  • Author(s): Jose Luis Rivero
  • Date: 2014-03-24 16:51:48 UTC
  • Revision ID: package-import@ubuntu.com-20140324165148-mfno979f58rv322z
Tags: upstream-2.0
ImportĀ upstreamĀ versionĀ 2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cu/cu.h>
 
2
#include <ccd/ccd.h>
 
3
#include "common.h"
 
4
#include "support.h"
 
5
 
 
6
 
 
7
#define TOSVT() \
 
8
    svtObjPen(&box, &cyl, stdout, "Pen 1", depth, &dir, &pos); \
 
9
    ccdVec3Scale(&dir, depth); \
 
10
    ccdVec3Add(&cyl.pos, &dir); \
 
11
    svtObjPen(&box, &cyl, stdout, "Pen 1", depth, &dir, &pos)
 
12
 
 
13
 
 
14
TEST(boxcylIntersect)
 
15
{
 
16
    ccd_t ccd;
 
17
    CCD_BOX(box);
 
18
    CCD_CYL(cyl);
 
19
    int res;
 
20
    ccd_vec3_t axis;
 
21
 
 
22
    box.x = 0.5;
 
23
    box.y = 1.;
 
24
    box.z = 1.5;
 
25
    cyl.radius = 0.4;
 
26
    cyl.height = 0.7;
 
27
 
 
28
    CCD_INIT(&ccd);
 
29
    ccd.support1 = ccdSupport;
 
30
    ccd.support2 = ccdSupport;
 
31
 
 
32
    ccdVec3Set(&cyl.pos, 0.1, 0., 0.);
 
33
    res = ccdGJKIntersect(&box, &cyl, &ccd);
 
34
    assertTrue(res);
 
35
 
 
36
    ccdVec3Set(&cyl.pos, .6, 0., 0.);
 
37
    res = ccdGJKIntersect(&box, &cyl, &ccd);
 
38
    assertTrue(res);
 
39
 
 
40
    ccdVec3Set(&cyl.pos, .6, 0.6, 0.);
 
41
    res = ccdGJKIntersect(&box, &cyl, &ccd);
 
42
    assertTrue(res);
 
43
 
 
44
    ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
 
45
    res = ccdGJKIntersect(&box, &cyl, &ccd);
 
46
    assertTrue(res);
 
47
 
 
48
    ccdVec3Set(&axis, 0., 1., 0.);
 
49
    ccdQuatSetAngleAxis(&cyl.quat, M_PI / 3., &axis);
 
50
    ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
 
51
    res = ccdGJKIntersect(&box, &cyl, &ccd);
 
52
    assertTrue(res);
 
53
 
 
54
    ccdVec3Set(&axis, 0.67, 1.1, 0.12);
 
55
    ccdQuatSetAngleAxis(&cyl.quat, M_PI / 4., &axis);
 
56
    ccdVec3Set(&cyl.pos, .6, 0., 0.5);
 
57
    res = ccdGJKIntersect(&box, &cyl, &ccd);
 
58
    assertTrue(res);
 
59
 
 
60
    ccdVec3Set(&axis, -0.1, 2.2, -1.);
 
61
    ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
 
62
    ccdVec3Set(&cyl.pos, .6, 0., 0.5);
 
63
    ccdVec3Set(&axis, 1., 1., 0.);
 
64
    ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
 
65
    ccdVec3Set(&box.pos, .6, 0., 0.5);
 
66
    res = ccdGJKIntersect(&box, &cyl, &ccd);
 
67
    assertTrue(res);
 
68
 
 
69
    ccdVec3Set(&axis, -0.1, 2.2, -1.);
 
70
    ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
 
71
    ccdVec3Set(&cyl.pos, .6, 0., 0.5);
 
72
    ccdVec3Set(&axis, 1., 1., 0.);
 
73
    ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
 
74
    ccdVec3Set(&box.pos, .9, 0.8, 0.5);
 
75
    res = ccdGJKIntersect(&box, &cyl, &ccd);
 
76
    assertTrue(res);
 
77
}
 
78
 
 
79
 
 
80
TEST(boxcylPenEPA)
 
81
{
 
82
    ccd_t ccd;
 
83
    CCD_BOX(box);
 
84
    CCD_CYL(cyl);
 
85
    int res;
 
86
    ccd_vec3_t axis;
 
87
    ccd_real_t depth;
 
88
    ccd_vec3_t dir, pos;
 
89
 
 
90
    box.x = 0.5;
 
91
    box.y = 1.;
 
92
    box.z = 1.5;
 
93
    cyl.radius = 0.4;
 
94
    cyl.height = 0.7;
 
95
 
 
96
    CCD_INIT(&ccd);
 
97
    ccd.support1 = ccdSupport;
 
98
    ccd.support2 = ccdSupport;
 
99
 
 
100
    ccdVec3Set(&cyl.pos, 0.1, 0., 0.);
 
101
    res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
 
102
    assertTrue(res == 0);
 
103
    recPen(depth, &dir, &pos, stdout, "Pen 1");
 
104
    //TOSVT();
 
105
 
 
106
    ccdVec3Set(&cyl.pos, .6, 0., 0.);
 
107
    res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
 
108
    assertTrue(res == 0);
 
109
    recPen(depth, &dir, &pos, stdout, "Pen 2");
 
110
    //TOSVT(); <<<
 
111
 
 
112
    ccdVec3Set(&cyl.pos, .6, 0.6, 0.);
 
113
    res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
 
114
    assertTrue(res == 0);
 
115
    recPen(depth, &dir, &pos, stdout, "Pen 3");
 
116
    //TOSVT();
 
117
 
 
118
    ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
 
119
    res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
 
120
    assertTrue(res == 0);
 
121
    recPen(depth, &dir, &pos, stdout, "Pen 4");
 
122
    //TOSVT();
 
123
 
 
124
    ccdVec3Set(&axis, 0., 1., 0.);
 
125
    ccdQuatSetAngleAxis(&cyl.quat, M_PI / 3., &axis);
 
126
    ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
 
127
    res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
 
128
    assertTrue(res == 0);
 
129
    recPen(depth, &dir, &pos, stdout, "Pen 5");
 
130
    //TOSVT();
 
131
 
 
132
    ccdVec3Set(&axis, 0.67, 1.1, 0.12);
 
133
    ccdQuatSetAngleAxis(&cyl.quat, M_PI / 4., &axis);
 
134
    ccdVec3Set(&cyl.pos, .6, 0., 0.5);
 
135
    res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
 
136
    assertTrue(res == 0);
 
137
    recPen(depth, &dir, &pos, stdout, "Pen 6");
 
138
    //TOSVT();
 
139
 
 
140
    ccdVec3Set(&axis, -0.1, 2.2, -1.);
 
141
    ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
 
142
    ccdVec3Set(&cyl.pos, .6, 0., 0.5);
 
143
    ccdVec3Set(&axis, 1., 1., 0.);
 
144
    ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
 
145
    ccdVec3Set(&box.pos, .6, 0., 0.5);
 
146
    res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
 
147
    assertTrue(res == 0);
 
148
    recPen(depth, &dir, &pos, stdout, "Pen 7");
 
149
    //TOSVT();
 
150
 
 
151
    ccdVec3Set(&axis, -0.1, 2.2, -1.);
 
152
    ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
 
153
    ccdVec3Set(&cyl.pos, .6, 0., 0.5);
 
154
    ccdVec3Set(&axis, 1., 1., 0.);
 
155
    ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
 
156
    ccdVec3Set(&box.pos, .9, 0.8, 0.5);
 
157
    res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
 
158
    assertTrue(res == 0);
 
159
    recPen(depth, &dir, &pos, stdout, "Pen 8");
 
160
    //TOSVT();
 
161
}
 
162