From 81d7a145a729bda14fe2e0c474a0b435d54acc46 Mon Sep 17 00:00:00 2001 From: "Zer..om" Date: Sat, 6 Jul 2013 14:29:19 +0000 Subject: [PATCH] Added the ability to create a quad with the origin at the center. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10695 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../src/core/com/jme3/scene/shape/Quad.java | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/engine/src/core/com/jme3/scene/shape/Quad.java b/engine/src/core/com/jme3/scene/shape/Quad.java index 283882dc2..7a42bc651 100644 --- a/engine/src/core/com/jme3/scene/shape/Quad.java +++ b/engine/src/core/com/jme3/scene/shape/Quad.java @@ -77,6 +77,21 @@ public class Quad extends Mesh { updateGeometry(width, height, flipCoords); } + /** + * Create a quad with the given width and height. The quad + * is always created in the XY plane. + * + * @param width The X extent or width + * @param height The Y extent or width + * @param flipCoords If true, the texture coordinates will be flipped + * along the Y axis. + * @param originAtCenter If true then the origin of the quad will be at the center + * of the quad, rather than at one corner. + */ + public Quad(float width, float height, boolean flipCoords, boolean originAtCenter){ + updateGeometry(width, height, flipCoords, originAtCenter); + } + public float getHeight() { return height; } @@ -88,16 +103,29 @@ public class Quad extends Mesh { public void updateGeometry(float width, float height){ updateGeometry(width, height, false); } - + public void updateGeometry(float width, float height, boolean flipCoords) { + updateGeometry(width, height, flipCoords, false); + } + + public void updateGeometry(float width, float height, boolean flipCoords, boolean originAtCenter) { this.width = width; this.height = height; - setBuffer(Type.Position, 3, new float[]{0, 0, 0, - width, 0, 0, - width, height, 0, - 0, height, 0 - }); - + if (originAtCenter) { + float halfWidth = width*0.5f; + float halfHeight = height*0.5f; + setBuffer(Type.Position, 3, new float[]{-halfWidth, -halfHeight, 0, + halfWidth, -halfHeight, 0, + halfWidth, halfHeight, 0, + -halfWidth, halfHeight, 0 + }); + } else { + setBuffer(Type.Position, 3, new float[]{0, 0, 0, + width, 0, 0, + width, height, 0, + 0, height, 0 + }); + } if (flipCoords){ setBuffer(Type.TexCoord, 2, new float[]{0, 1,