20
20
import static com .aphidmobile .flip .FlipRenderer .*;
21
21
import static com .aphidmobile .utils .TextureUtils .*;
22
22
import static javax .microedition .khronos .opengles .GL10 .*;
23
-
24
- import android .util .FloatMath ;
23
+ import static android .util .FloatMath .*;
25
24
26
25
import javax .microedition .khronos .opengles .GL10 ;
27
26
import java .nio .FloatBuffer ;
@@ -31,6 +30,25 @@ public class Card {
31
30
public static final int AXIS_TOP = 0 ;
32
31
public static final int AXIS_BOTTOM = 1 ;
33
32
33
+ /**
34
+ * The indices of x,y,z for vertices (0, 0), (0, 1), (1, 1), (1, 0)
35
+ */
36
+ public static final int X_00 = 0 ;
37
+ public static final int Y_00 = 1 ;
38
+ public static final int Z_00 = 2 ;
39
+
40
+ public static final int X_01 = 3 ;
41
+ public static final int Y_01 = 4 ;
42
+ public static final int Z_01 = 5 ;
43
+
44
+ public static final int X_11 = 6 ;
45
+ public static final int Y_11 = 7 ;
46
+ public static final int Z_11 = 8 ;
47
+
48
+ public static final int X_10 = 9 ;
49
+ public static final int Y_10 = 10 ;
50
+ public static final int Z_10 = 11 ;
51
+
34
52
private float cardVertices [];
35
53
36
54
private short [] indices = {0 , 1 , 2 , 0 , 2 , 3 };
@@ -130,30 +148,28 @@ public void draw(GL10 gl) {
130
148
if (orientationVertical ){
131
149
if (angle > 0 ) {
132
150
if (axis == AXIS_TOP ) {
133
- gl .glTranslatef (0 , cardVertices [1 ], 0f );
151
+ gl .glTranslatef (0 , cardVertices [Y_00 ], 0f );
134
152
gl .glRotatef (-angle , 1f , 0f , 0f );
135
- gl .glTranslatef (0 , -cardVertices [1 ], 0f );
153
+ gl .glTranslatef (0 , -cardVertices [Y_00 ], 0f );
136
154
} else {
137
- gl .glTranslatef (0 , cardVertices [7 ], 0f );
155
+ gl .glTranslatef (0 , cardVertices [Y_11 ], 0f );
138
156
gl .glRotatef (angle , 1f , 0f , 0f );
139
- gl .glTranslatef (0 , -cardVertices [7 ], 0f );
157
+ gl .glTranslatef (0 , -cardVertices [Y_11 ], 0f );
140
158
}
141
159
}
142
160
} else {
143
161
if (angle > 0 ) {
144
162
if (axis == AXIS_TOP ) {
145
- gl .glTranslatef (cardVertices [0 ], 0 , 0f );
163
+ gl .glTranslatef (cardVertices [X_00 ], 0 , 0f );
146
164
gl .glRotatef (-angle , 0f , 1f , 0f );
147
- gl .glTranslatef (-cardVertices [0 ], 0 , 0f );
165
+ gl .glTranslatef (-cardVertices [X_00 ], 0 , 0f );
148
166
} else {
149
- gl .glTranslatef (cardVertices [6 ], 0 , 0f );
167
+ gl .glTranslatef (cardVertices [X_11 ], 0 , 0f );
150
168
gl .glRotatef (angle , 0f , 1f , 0f );
151
- gl .glTranslatef (-cardVertices [6 ], 0 , 0f );
169
+ gl .glTranslatef (-cardVertices [X_11 ], 0 , 0f );
152
170
}
153
171
}
154
-
155
172
}
156
-
157
173
158
174
gl .glVertexPointer (3 , GL_FLOAT , 0 , vertexBuffer );
159
175
gl .glDrawElements (GL_TRIANGLES , indices .length , GL_UNSIGNED_SHORT , indexBuffer );
@@ -166,36 +182,33 @@ public void draw(GL10 gl) {
166
182
gl .glDisableClientState (GL_TEXTURE_COORD_ARRAY );
167
183
gl .glDisable (GL_TEXTURE_2D );
168
184
}
169
-
185
+
186
+ float w ,h ,z ;
187
+ float [] shadowVertices ;
188
+
170
189
if (angle > 0 ) {
171
190
gl .glDisable (GL_LIGHTING );
172
191
gl .glDisable (GL_DEPTH_TEST );
173
192
174
193
if (axis == AXIS_TOP ) {
175
- float w ,h ,z ;
176
- float [] shadowVertices ;
177
194
if (orientationVertical ){
178
- w = cardVertices [9 ] - cardVertices [0 ];
179
- h = (cardVertices [1 ] - cardVertices [4 ]) * (1f - FloatMath .cos (d2r (angle )));
180
- z = (cardVertices [1 ] - cardVertices [4 ]) * FloatMath .sin (d2r (angle ));
195
+ h = (cardVertices [Y_00 ] - cardVertices [Y_01 ]) * (1.0f - cos (d2r (angle )));
196
+ z = (cardVertices [Y_00 ] - cardVertices [Y_01 ]) * sin (d2r (angle ));
181
197
shadowVertices = new float []{
182
- cardVertices [0 ], h + cardVertices [4 ] , z ,
183
- cardVertices [3 ], cardVertices [4 ], 0f ,
184
- w , cardVertices [7 ], 0f ,
185
- w , h + cardVertices [4 ] , z
198
+ cardVertices [X_00 ], cardVertices [Y_01 ] + h , z ,
199
+ cardVertices [X_01 ], cardVertices [Y_01 ], 0f ,
200
+ cardVertices [ X_11 ] , cardVertices [Y_11 ], 0f ,
201
+ cardVertices [ X_10 ], cardVertices [Y_01 ] + h , z
186
202
};
187
- } else {
188
- w = (cardVertices [9 ] - cardVertices [0 ]) * (1f - FloatMath .cos (d2r (angle )));
189
- h = (cardVertices [1 ] - cardVertices [4 ]);
190
- z = (cardVertices [1 ] - cardVertices [4 ]) * FloatMath .sin (d2r (angle ));
191
-
203
+ } else { //horizontal
204
+ w = (cardVertices [X_10 ] - cardVertices [X_00 ]) * (1.0f - cos (d2r (angle )));
205
+ z = (cardVertices [X_10 ] - cardVertices [X_00 ]) * sin (d2r (angle ));
192
206
shadowVertices = new float []{
193
- cardVertices [9 ] - w , cardVertices [1 ], z ,
194
- cardVertices [6 ] - w , cardVertices [4 ], z ,
195
- cardVertices [6 ], cardVertices [7 ], 0f ,
196
- cardVertices [9 ], cardVertices [10 ], 0f
207
+ cardVertices [X_10 ] - w , cardVertices [Y_00 ], z ,
208
+ cardVertices [X_11 ] - w , cardVertices [Y_01 ], z ,
209
+ cardVertices [X_11 ], cardVertices [Y_11 ], 0f ,
210
+ cardVertices [X_10 ], cardVertices [Y_10 ], 0f
197
211
};
198
-
199
212
}
200
213
201
214
float alpha = 1f * (90f - angle ) / 90f ;
@@ -204,27 +217,23 @@ public void draw(GL10 gl) {
204
217
gl .glVertexPointer (3 , GL_FLOAT , 0 , toFloatBuffer (shadowVertices ));
205
218
gl .glDrawElements (GL_TRIANGLES , indices .length , GL_UNSIGNED_SHORT , indexBuffer );
206
219
} else {
207
- float w ,h ,z ;
208
- float [] shadowVertices ;
209
220
if (orientationVertical ){
210
- w = cardVertices [9 ] - cardVertices [0 ];
211
- h = (cardVertices [1 ] - cardVertices [4 ]) * (1f - FloatMath .cos (d2r (angle )));
212
- z = (cardVertices [1 ] - cardVertices [4 ]) * FloatMath .sin (d2r (angle ));
221
+ h = (cardVertices [Y_00 ] - cardVertices [Y_01 ]) * (1f - cos (d2r (angle )));
222
+ z = (cardVertices [Y_00 ] - cardVertices [Y_01 ]) * sin (d2r (angle ));
213
223
shadowVertices = new float []{
214
- cardVertices [0 ], cardVertices [1 ], 0f ,
215
- cardVertices [3 ], cardVertices [1 ] - h , z ,
216
- w , cardVertices [1 ] - h , z ,
217
- w , cardVertices [1 ], 0f
224
+ cardVertices [X_00 ], cardVertices [Y_00 ], 0f ,
225
+ cardVertices [X_01 ], cardVertices [Y_00 ] - h , z ,
226
+ cardVertices [ X_11 ] , cardVertices [Y_00 ] - h , z ,
227
+ cardVertices [ X_10 ] , cardVertices [Y_00 ], 0f
218
228
};
219
- } else {
220
- w = (cardVertices [9 ] - cardVertices [0 ]) * (1f - FloatMath .cos (d2r (angle )));
221
- h = (cardVertices [1 ] - cardVertices [4 ]);
222
- z = (cardVertices [1 ] - cardVertices [4 ]) * FloatMath .sin (d2r (angle ));
229
+ } else { //horizontal
230
+ w = (cardVertices [X_10 ] - cardVertices [X_00 ]) * (1f - cos (d2r (angle )));
231
+ z = (cardVertices [X_10 ] - cardVertices [X_00 ]) * sin (d2r (angle ));
223
232
shadowVertices = new float []{
224
- cardVertices [0 ], cardVertices [1 ], 0f ,
225
- cardVertices [3 ], cardVertices [4 ], 0f ,
226
- cardVertices [0 ] + w , cardVertices [7 ], z ,
227
- cardVertices [3 ] + w , cardVertices [10 ], z
233
+ cardVertices [X_00 ], cardVertices [Y_00 ], 0f ,
234
+ cardVertices [X_01 ], cardVertices [Y_01 ], 0f ,
235
+ cardVertices [X_00 ] + w , cardVertices [Y_11 ], z ,
236
+ cardVertices [X_01 ] + w , cardVertices [Y_10 ], z
228
237
};
229
238
}
230
239
float alpha = 1f * (90f - angle ) / 90f ;
0 commit comments