From: Andy Spencer Date: Sun, 21 Apr 2013 22:02:15 +0000 (+0000) Subject: Draw the pile of cards X-Git-Url: http://pileus.org/git/?p=~andy%2Fspades;a=commitdiff_plain;h=d65c3512981486a4b392bd782367cd2902624afe Draw the pile of cards --- diff --git a/src/org/pileus/spades/Cards.java b/src/org/pileus/spades/Cards.java index b9fd098..c04e345 100644 --- a/src/org/pileus/spades/Cards.java +++ b/src/org/pileus/spades/Cards.java @@ -125,6 +125,7 @@ public class Cards extends GLSurfaceView implements GLSurfaceView.Renderer /* Properties */ public String[] hand; // cards to display + public String[] pile; // played cards to display /* GLSurfaceView Methods */ public Cards(Context context) @@ -147,6 +148,10 @@ public class Cards extends GLSurfaceView implements GLSurfaceView.Renderer "Kc", "3c", "10d", "9d", "8d", "7d", "2d" }; + this.pile = new String[] { + "As", "7s", "6s" + }; + this.index = new HashMap(52); for (int i = 0; i < 52; i++) this.index.put(this.cards[i], i); @@ -229,6 +234,7 @@ public class Cards extends GLSurfaceView implements GLSurfaceView.Renderer /* Draw objects */ this.drawTable(); + this.drawPile(); this.drawHand(); this.drawPick(); } @@ -361,6 +367,25 @@ public class Cards extends GLSurfaceView implements GLSurfaceView.Renderer GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, 4); } + private void drawPile() + { + /* Draw played cards */ + for (int i = 0; i < 4; i++) { + if (i >= this.pile.length || this.pile[i] == null) + continue; + + float ang = i * 90f; + + Matrix.setIdentityM(this.model, 0); + + Matrix.rotateM(this.model, 0, -ang, 0f, 0f, 1f); + Matrix.translateM(this.model, 0, -0.30f, 0f, 0f); + Matrix.rotateM(this.model, 0, ang, 0f, 0f, 1f); + Matrix.scaleM(this.model, 0, 3f, 3f, 0f); + + this.drawCard(this.pile[i]); + } + } private void drawHand() { @@ -392,7 +417,6 @@ public class Cards extends GLSurfaceView implements GLSurfaceView.Renderer Matrix.rotateM(this.model, 0, ang, 0f, 0f, -1f); Matrix.translateM(this.model, 0, 0f, 0.15f, 0f); - GLES20.glUniformMatrix4fv(this.modelHandle, 1, false, this.model, 0); this.drawCard(this.hand[i]); } } @@ -404,7 +428,6 @@ public class Cards extends GLSurfaceView implements GLSurfaceView.Renderer Matrix.setIdentityM(this.model, 0); Matrix.rotateM(this.model, 0, 45f, 1f, 0f, 0f); Matrix.translateM(this.model, 0, 0f, 0f, 1.20f); - GLES20.glUniformMatrix4fv(this.modelHandle, 1, false, this.model, 0); this.drawCard(this.hand[this.pick]); } } @@ -415,6 +438,9 @@ public class Cards extends GLSurfaceView implements GLSurfaceView.Renderer int front = this.face[idx]; int back = this.red; + /* Set model matrix */ + GLES20.glUniformMatrix4fv(this.modelHandle, 1, false, this.model, 0); + /* Draw front */ GLES20.glVertexAttribPointer(this.vertHandle, 3, GLES20.GL_FLOAT, false, 3*4, this.faceBuf); GLES20.glVertexAttribPointer(this.mapHandle, 2, GLES20.GL_FLOAT, false, 2*4, this.mapBuf);