Revision aaeef328
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlDodecahedron.java | ||
---|---|---|
112 | 112 |
{ |
113 | 113 |
case TYPE_NOT_SPLIT : return 0; |
114 | 114 |
case TYPE_SPLIT_EDGE : return partEdge(point,face); |
115 |
case TYPE_SPLIT_EDGE_COIN: float y = point[1]; |
|
116 |
float x = point[0]; |
|
117 |
return partEdge(point,face) + (x*x+y*y < DIST2D*DIST2D ? 0:5 ); |
|
115 | 118 |
case TYPE_SPLIT_CORNER : // not supported |
116 |
case TYPE_SPLIT_EDGE_COIN: // not supported |
|
117 | 119 |
} |
118 | 120 |
|
119 | 121 |
return 0; |
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlHexahedron.java | ||
---|---|---|
36 | 36 |
super(object,D3D,FACE_AXIS); |
37 | 37 |
} |
38 | 38 |
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 |
|
|
41 |
private int partEdge(float[] point, int face) |
|
42 |
{ |
|
43 |
boolean e0 = point[0] > 0; |
|
44 |
boolean e1 = point[1] > 0; |
|
45 |
return e0 ? (e1 ? 0:1) : (e1 ? 3:2); |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
|
|
50 |
private int partCorner(float[] point, int face) |
|
51 |
{ |
|
52 |
boolean c0 = point[1] >= point[0]; |
|
53 |
boolean c1 = point[1] >=-point[0]; |
|
54 |
return c0 ? (c1 ? 0:3) : (c1 ? 1:2); |
|
55 |
} |
|
56 |
|
|
39 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
40 | 58 |
// corner edge |
41 | 59 |
// \ 0 / 3 | 0 |
... | ... | |
43 | 61 |
// / \ | |
44 | 62 |
// / 2 \ 2 | 1 |
45 | 63 |
|
46 |
int returnPart(int type, int face, float[] touchPoint)
|
|
64 |
int returnPart(int type, int face, float[] point)
|
|
47 | 65 |
{ |
48 | 66 |
switch(type) |
49 | 67 |
{ |
50 |
case TYPE_NOT_SPLIT : return 0; |
|
51 |
case TYPE_SPLIT_EDGE : boolean e0 = touchPoint[0] > 0; |
|
52 |
boolean e1 = touchPoint[1] > 0; |
|
53 |
return e0 ? (e1 ? 0:1) : (e1 ? 3:2); |
|
54 |
case TYPE_SPLIT_CORNER : boolean c0 = touchPoint[1] >= touchPoint[0]; |
|
55 |
boolean c1 = touchPoint[1] >=-touchPoint[0]; |
|
56 |
return c0 ? (c1 ? 0:3) : (c1 ? 1:2); |
|
57 |
case TYPE_SPLIT_EDGE_COIN: // not supported |
|
68 |
case TYPE_NOT_SPLIT : return 0; |
|
69 |
case TYPE_SPLIT_EDGE : return partEdge(point,face); |
|
70 |
case TYPE_SPLIT_CORNER : return partCorner(point,face); |
|
71 |
case TYPE_SPLIT_EDGE_COIN: float y = point[1]; |
|
72 |
float x = point[0]; |
|
73 |
return partEdge(point,face) + (x*x+y*y < DIST2D*DIST2D ? 0:4 ); |
|
58 | 74 |
} |
59 | 75 |
|
60 | 76 |
return 0; |
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlIcosahedron.java | ||
---|---|---|
138 | 138 |
} |
139 | 139 |
|
140 | 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
141 |
// corner edge |
|
142 |
// | \ 0 / |
|
143 |
// 2 | 0 \ / |
|
144 |
// / \ 2 | 1 |
|
145 |
// / 1 \ | |
|
146 | 141 |
|
147 |
int returnPart(int type, int face, float[] touchPoint)
|
|
142 |
private int partEdge(float[] point, int face)
|
|
148 | 143 |
{ |
149 |
switch(type) |
|
150 |
{ |
|
151 |
case TYPE_NOT_SPLIT : return 0; |
|
144 |
float y = (isFaceInverted(face) ? point[1] : -point[1]); |
|
145 |
float x = point[0]; |
|
152 | 146 |
|
153 |
case TYPE_SPLIT_EDGE : float y1 = (isFaceInverted(face) ? touchPoint[1] : -touchPoint[1]); |
|
154 |
float x1 = touchPoint[0]; |
|
147 |
boolean e0 = x>0; |
|
148 |
boolean e1 = y>( SQ3/3)*x; |
|
149 |
boolean e2 = y>(-SQ3/3)*x; |
|
155 | 150 |
|
156 |
boolean e0 = x1>0; |
|
157 |
boolean e1 = y1>( SQ3/3)*x1; |
|
158 |
boolean e2 = y1>(-SQ3/3)*x1; |
|
151 |
if( e1 && e2 ) return 0; |
|
152 |
if( !e1 && e0 ) return 1; |
|
153 |
return 2; |
|
154 |
} |
|
159 | 155 |
|
160 |
if( e1 && e2 ) return 0; |
|
161 |
if( !e1 && e0 ) return 1; |
|
162 |
if( !e0 &&!e2 ) return 2; |
|
163 |
return 0; |
|
156 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
164 | 157 |
|
165 |
case TYPE_SPLIT_CORNER: float y2 = (isFaceInverted(face) ? touchPoint[1] : -touchPoint[1]); |
|
166 |
float x2 = touchPoint[0]; |
|
158 |
private int partCorner(float[] point, int face) |
|
159 |
{ |
|
160 |
float y2 = (isFaceInverted(face) ? point[1] : -point[1]); |
|
161 |
float x2 = point[0]; |
|
167 | 162 |
|
168 |
boolean c0 = x2>0;
|
|
169 |
boolean c1 = y2>( SQ3/3)*x2;
|
|
170 |
boolean c2 = y2>(-SQ3/3)*x2;
|
|
163 |
boolean c0 = x2>0; |
|
164 |
boolean c1 = y2>( SQ3/3)*x2; |
|
165 |
boolean c2 = y2>(-SQ3/3)*x2; |
|
171 | 166 |
|
172 |
if( c0 && c2 ) return 0;
|
|
173 |
if( !c1 &&!c2 ) return 1;
|
|
174 |
if( !c0 && c1 ) return 2;
|
|
175 |
return 0;
|
|
167 |
if( c0 && c2 ) return 0; |
|
168 |
if( !c1 &&!c2 ) return 1; |
|
169 |
return 2; |
|
170 |
}
|
|
176 | 171 |
|
177 |
case TYPE_SPLIT_EDGE_COIN: // not supported |
|
172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
173 |
// corner edge |
|
174 |
// | \ 0 / |
|
175 |
// 2 | 0 \ / |
|
176 |
// / \ 2 | 1 |
|
177 |
// / 1 \ | |
|
178 |
|
|
179 |
int returnPart(int type, int face, float[] point) |
|
180 |
{ |
|
181 |
switch(type) |
|
182 |
{ |
|
183 |
case TYPE_NOT_SPLIT : return 0; |
|
184 |
case TYPE_SPLIT_EDGE : return partEdge(point,face); |
|
185 |
case TYPE_SPLIT_CORNER : return partCorner(point,face); |
|
186 |
case TYPE_SPLIT_EDGE_COIN: float y = point[1]; |
|
187 |
float x = point[0]; |
|
188 |
return partEdge(point,face) + (x*x+y*y < DIST2D*DIST2D ? 0:3 ); |
|
178 | 189 |
} |
179 | 190 |
|
180 | 191 |
return 0; |
... | ... | |
182 | 193 |
|
183 | 194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
184 | 195 |
|
185 |
boolean isInsideFace(int face, float[] p) |
|
196 |
boolean isInsideFace(int face, float[] point)
|
|
186 | 197 |
{ |
187 |
float y = (isFaceInverted(face) ? p[1] : -p[1]);
|
|
188 |
float x = p[0]; |
|
198 |
float y = (isFaceInverted(face) ? point[1] : -point[1]);
|
|
199 |
float x = point[0];
|
|
189 | 200 |
return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x)); |
190 | 201 |
} |
191 | 202 |
} |
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlOctahedron.java | ||
---|---|---|
38 | 38 |
} |
39 | 39 |
|
40 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
41 |
// corner edge |
|
42 |
// | \ 0 / |
|
43 |
// 2 | 0 \ / |
|
44 |
// / \ 2 | 1 |
|
45 |
// / 1 \ | |
|
46 | 41 |
|
47 |
int returnPart(int type, int face, float[] touchPoint)
|
|
42 |
private boolean isFaceInverted(int face)
|
|
48 | 43 |
{ |
49 |
switch(type) |
|
50 |
{ |
|
51 |
case TYPE_NOT_SPLIT : return 0; |
|
44 |
return (face%2)==0; |
|
45 |
} |
|
46 |
|
|
47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
|
49 |
private int partEdge(float[] point, int face) |
|
50 |
{ |
|
51 |
float y = (isFaceInverted(face) ? point[1] : -point[1]); |
|
52 |
float x = point[0]; |
|
53 |
|
|
54 |
boolean e0 = x>0; |
|
55 |
boolean e1 = y>( SQ3/3)*x; |
|
56 |
boolean e2 = y>(-SQ3/3)*x; |
|
52 | 57 |
|
53 |
case TYPE_SPLIT_EDGE : float y1 = (face%2 == 0 ? touchPoint[1] : -touchPoint[1]); |
|
54 |
float x1 = touchPoint[0]; |
|
58 |
if( e1 && e2 ) return 0; |
|
59 |
if( !e1 && e0 ) return 1; |
|
60 |
return 2; |
|
61 |
} |
|
55 | 62 |
|
56 |
boolean e0 = x1>0; |
|
57 |
boolean e1 = y1>( SQ3/3)*x1; |
|
58 |
boolean e2 = y1>(-SQ3/3)*x1; |
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 | 64 |
|
60 |
if( e1 && e2 ) return 0;
|
|
61 |
if( !e1 && e0 ) return 1;
|
|
62 |
if( !e0 &&!e2 ) return 2;
|
|
63 |
return 0;
|
|
65 |
private int partCorner(float[] point, int face)
|
|
66 |
{
|
|
67 |
float y = (isFaceInverted(face) ? point[1] : -point[1]);
|
|
68 |
float x = point[0];
|
|
64 | 69 |
|
65 |
case TYPE_SPLIT_CORNER: float y2 = (face%2 == 0 ? touchPoint[1] : -touchPoint[1]); |
|
66 |
float x2 = touchPoint[0]; |
|
70 |
boolean c0 = x>0; |
|
71 |
boolean c1 = y>( SQ3/3)*x; |
|
72 |
boolean c2 = y>(-SQ3/3)*x; |
|
67 | 73 |
|
68 |
boolean c0 = x2>0; |
|
69 |
boolean c1 = y2>( SQ3/3)*x2; |
|
70 |
boolean c2 = y2>(-SQ3/3)*x2; |
|
74 |
if( c0 && c2 ) return 0; |
|
75 |
if( !c1 &&!c2 ) return 1; |
|
76 |
return 2; |
|
77 |
} |
|
71 | 78 |
|
72 |
if( c0 && c2 ) return 0; |
|
73 |
if( !c1 &&!c2 ) return 1; |
|
74 |
if( !c0 && c1 ) return 2; |
|
75 |
return 0; |
|
79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
80 |
// corner edge |
|
81 |
// | \ 0 / |
|
82 |
// 2 | 0 \ / |
|
83 |
// / \ 2 | 1 |
|
84 |
// / 1 \ | |
|
76 | 85 |
|
77 |
case TYPE_SPLIT_EDGE_COIN: // not supported |
|
86 |
int returnPart(int type, int face, float[] point) |
|
87 |
{ |
|
88 |
switch(type) |
|
89 |
{ |
|
90 |
case TYPE_NOT_SPLIT : return 0; |
|
91 |
case TYPE_SPLIT_EDGE : return partEdge(point,face); |
|
92 |
case TYPE_SPLIT_CORNER : return partCorner(point,face); |
|
93 |
case TYPE_SPLIT_EDGE_COIN : float y = point[1]; |
|
94 |
float x = point[0]; |
|
95 |
return partEdge(point,face) + (x*x+y*y < DIST2D*DIST2D ? 0:3 ); |
|
78 | 96 |
} |
79 | 97 |
|
80 | 98 |
return 0; |
... | ... | |
89 | 107 |
|
90 | 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
91 | 109 |
|
92 |
boolean isInsideFace(int face, float[] p) |
|
110 |
boolean isInsideFace(int face, float[] point)
|
|
93 | 111 |
{ |
94 |
float y = (face%2 == 0 ? p[1] : -p[1]);
|
|
95 |
float x = p[0]; |
|
112 |
float y = (isFaceInverted(face) ? point[1] : -point[1]);
|
|
113 |
float x = point[0];
|
|
96 | 114 |
return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x)); |
97 | 115 |
} |
98 | 116 |
} |
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlTetrahedron.java | ||
---|---|---|
37 | 37 |
super(object,D3D,FACE_AXIS); |
38 | 38 |
} |
39 | 39 |
|
40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
41 |
|
|
42 |
private boolean isFaceInverted(int face) |
|
43 |
{ |
|
44 |
return face>1; |
|
45 |
} |
|
46 |
|
|
47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
|
49 |
private int partEdge(float[] point, int face) |
|
50 |
{ |
|
51 |
float y = (isFaceInverted(face) ? point[1] : -point[1]); |
|
52 |
float x = point[0]; |
|
53 |
|
|
54 |
boolean e0 = x>0; |
|
55 |
boolean e1 = y>( SQ3/3)*x; |
|
56 |
boolean e2 = y>(-SQ3/3)*x; |
|
57 |
|
|
58 |
if( e1 && e2 ) return 0; |
|
59 |
if( !e1 && e0 ) return 1; |
|
60 |
return 2; |
|
61 |
} |
|
62 |
|
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
private int partCorner(float[] point, int face) |
|
66 |
{ |
|
67 |
float y = (isFaceInverted(face) ? point[1] : -point[1]); |
|
68 |
float x = point[0]; |
|
69 |
|
|
70 |
boolean c0 = x>0; |
|
71 |
boolean c1 = y>( SQ3/3)*x; |
|
72 |
boolean c2 = y>(-SQ3/3)*x; |
|
73 |
|
|
74 |
if( c0 && c2 ) return 0; |
|
75 |
if( !c1 &&!c2 ) return 1; |
|
76 |
return 2; |
|
77 |
} |
|
78 |
|
|
40 | 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
41 | 80 |
// corner edge |
42 | 81 |
// | \ 0 / |
... | ... | |
46 | 85 |
// |
47 | 86 |
// COIN: pieces inside the coin just like in EDGE; outside +=3. |
48 | 87 |
|
49 |
int returnPart(int type, int face, float[] touchPoint)
|
|
88 |
int returnPart(int type, int face, float[] point)
|
|
50 | 89 |
{ |
51 | 90 |
switch(type) |
52 | 91 |
{ |
53 | 92 |
case TYPE_NOT_SPLIT : return 0; |
54 |
|
|
55 |
case TYPE_SPLIT_EDGE : float y1 = (face > 1 ? touchPoint[1] : -touchPoint[1]); |
|
56 |
float x1 = touchPoint[0]; |
|
57 |
|
|
58 |
boolean e0 = x1>0; |
|
59 |
boolean e1 = y1>( SQ3/3)*x1; |
|
60 |
boolean e2 = y1>(-SQ3/3)*x1; |
|
61 |
|
|
62 |
if( e1 && e2 ) return 0; |
|
63 |
if( !e1 && e0 ) return 1; |
|
64 |
if( !e0 &&!e2 ) return 2; |
|
65 |
return 0; |
|
66 |
|
|
67 |
case TYPE_SPLIT_CORNER: float y2 = (face > 1 ? touchPoint[1] : -touchPoint[1]); |
|
68 |
float x2 = touchPoint[0]; |
|
69 |
|
|
70 |
boolean c0 = x2>0; |
|
71 |
boolean c1 = y2>( SQ3/3)*x2; |
|
72 |
boolean c2 = y2>(-SQ3/3)*x2; |
|
73 |
|
|
74 |
if( c0 && c2 ) return 0; |
|
75 |
if( !c1 &&!c2 ) return 1; |
|
76 |
if( !c0 && c1 ) return 2; |
|
77 |
return 0; |
|
78 |
case TYPE_SPLIT_EDGE_COIN: float y3 = (face > 1 ? touchPoint[1] : -touchPoint[1]); |
|
79 |
float x3 = touchPoint[0]; |
|
80 |
|
|
81 |
boolean s0 = x3>0; |
|
82 |
boolean s1 = y3>( SQ3/3)*x3; |
|
83 |
boolean s2 = y3>(-SQ3/3)*x3; |
|
84 |
|
|
85 |
int add = (x3*x3+y3*y3<DIST2D*DIST2D ? 0:3 ); |
|
86 |
|
|
87 |
if( s1 && s2 ) return add; |
|
88 |
if( !s1 && s0 ) return add+1; |
|
89 |
if( !s0 &&!s2 ) return add+2; |
|
90 |
return 0; |
|
93 |
case TYPE_SPLIT_EDGE : return partEdge(point,face); |
|
94 |
case TYPE_SPLIT_CORNER : return partCorner(point,face); |
|
95 |
case TYPE_SPLIT_EDGE_COIN: float y = point[1]; |
|
96 |
float x = point[0]; |
|
97 |
return partEdge(point,face) + (x*x+y*y < DIST2D*DIST2D ? 0:3 ); |
|
91 | 98 |
} |
92 | 99 |
|
93 | 100 |
return 0; |
... | ... | |
104 | 111 |
|
105 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
106 | 113 |
|
107 |
boolean isInsideFace(int face, float[] p) |
|
114 |
boolean isInsideFace(int face, float[] point)
|
|
108 | 115 |
{ |
109 |
float y = (face > 1 ? p[1] : -p[1]);
|
|
110 |
float x = p[0]; |
|
116 |
float y = (isFaceInverted(face) ? point[1] : -point[1]);
|
|
117 |
float x = point[0];
|
|
111 | 118 |
return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x)); |
112 | 119 |
} |
113 | 120 |
} |
Also available in: Unified diff
Support split type 'EDGE_COIN' in case of every shape.