Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
19867cd
Raw implementation of polygons
recastrodiaz Jan 29, 2012
a9226a0
Merge remote branch 'upstream/GLES2' into GLES2
recastrodiaz Jan 29, 2012
1232454
Polygons' vertices may be changed on the go with the help of updateVe…
recastrodiaz Jan 29, 2012
b39286c
Fixed comment
recastrodiaz Jan 29, 2012
457f45c
Fixed comment
recastrodiaz Jan 29, 2012
3a81267
Polygon may be allocated with a ratio size\n Will not crash if update…
recastrodiaz Jan 30, 2012
c8d1a47
Added PolygonBase for common Polygon code.
recastrodiaz Jan 30, 2012
6fd9bdb
Merge remote branch 'upstream/GLES2' into GLES2
recastrodiaz Jan 31, 2012
282e49a
New Ellipse primitive
recastrodiaz Jan 31, 2012
cea94cb
Added missing changes in previous commit : new Constructors
recastrodiaz Feb 1, 2012
43ace9c
Merge remote branch 'upstream/GLES2' into GLES2
recastrodiaz Feb 6, 2012
e7ba052
Merged && fixed build
recastrodiaz Feb 6, 2012
408fb02
Renamed Polygon -> Polygon2 to avoid merge conflict
recastrodiaz Feb 10, 2012
bd22e37
Merge remote branch 'upstream/GLES2' into GLES2
recastrodiaz Feb 10, 2012
61df9b2
Merge remote branch 'upstream/GLES2' into GLES2
recastrodiaz Feb 11, 2012
5fc8561
Ellipse and PolyLine use Mesh, renamed Polygon2 -> Polygon
recastrodiaz Feb 11, 2012
e846f7f
Removed unused imports
recastrodiaz Feb 11, 2012
2206081
Added feature to update PolyLine vertices
recastrodiaz Feb 11, 2012
960e3ea
Fixed javadoc
recastrodiaz Feb 13, 2012
5e23cbe
Merge remote branch 'upstream/GLES2' into GLES2
recastrodiaz Feb 13, 2012
3321f8f
Started mesh uv mapping
recastrodiaz Feb 14, 2012
3bd446d
Polygon uses Mesh instead of PolygonBase
recastrodiaz Feb 14, 2012
10f9d3e
Merge remote branch 'upstream/GLES2' into GLES2
recastrodiaz Feb 14, 2012
7903cdb
Merge branch 'GLES2' into uvmesh
recastrodiaz Feb 14, 2012
14e3b16
added experimental textured polygon
recastrodiaz Feb 15, 2012
53872ed
added experimental textured polygon support
recastrodiaz Feb 15, 2012
00056d1
Merge remote branch 'upstream/GLES2' into uvmesh
recastrodiaz Feb 28, 2012
19aa181
Merge remote branch 'upstream/GLES2' into GLES2
recastrodiaz Feb 28, 2012
685e703
Removed unused files
recastrodiaz Feb 28, 2012
1ba289b
Merge branch 'GLES2' into uvmesh
recastrodiaz Feb 28, 2012
4e3eb34
Fixed compiler error
recastrodiaz Feb 28, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions src/org/andengine/entity/primitive/Ellipse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package org.andengine.entity.primitive;

import org.andengine.opengl.vbo.VertexBufferObject.DrawType;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttribute;

/**
*
* @author Rodrigo Castro
* @since 16:47:01 - 31.01.2012
*/
public class Ellipse extends PolyLine {
// ===========================================================
// Constants
// ===========================================================

static final int LOW_RESOLUTION = 15;
static final int MEDIUM_RESOLUTION = 30;
static final int HIGH_RESOLUTION = 50;
static final int DEFAULT_RESOLUTION = HIGH_RESOLUTION;

// ===========================================================
// Fields
// ===========================================================

protected final int mResolution;

// ===========================================================
// Constructors
// ===========================================================

/**
* Uses a default {@link HighPerformanceMeshVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
*/
public Ellipse(final float pX, final float pY, final float pRadiusA, final float pRadiusB, final VertexBufferObjectManager pVertexBufferObjectManager) {
this(pX, pY, pRadiusA, pRadiusB, Line.LINE_WIDTH_DEFAULT, pVertexBufferObjectManager);
}

/**
* Uses a default {@link HighPerformanceMeshVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
*/
public Ellipse(final float pX, final float pY, final float pRadiusA, final float pRadiusB, final float pLineWidth, final VertexBufferObjectManager pVertexBufferObjectManager) {
this(pX, pY, pRadiusA, pRadiusB, pLineWidth, DEFAULT_RESOLUTION, pVertexBufferObjectManager);
}

/**
* Uses a default {@link HighPerformanceMeshVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
*/
public Ellipse(final float pX, final float pY, final float pRadiusA, final float pRadiusB, final float pLineWidth, final int pResolution, final VertexBufferObjectManager pVertexBufferObjectManager) {
this(pX, pY, pRadiusA, pRadiusB, pLineWidth, pResolution, pVertexBufferObjectManager, DrawMode.LINE_LOOP);
}

public Ellipse(final float pX, final float pY, final float pRadiusA, final float pRadiusB, final float pLineWidth, final int pResolution, final VertexBufferObjectManager pVertexBufferObjectManager, DrawMode pDrawMode) {
this(pX, pY, pRadiusA, pRadiusB, pLineWidth, pResolution, pVertexBufferObjectManager, pDrawMode, DrawType.STATIC);
}


/**
* Uses a default {@link HighPerformanceMeshVertexBufferObject} with the {@link VertexBufferObjectAttribute}s: {@link Rectangle#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
*/
public Ellipse(final float pX, final float pY, final float pRadiusA, final float pRadiusB, final float pLineWidth, final int pResolution, final VertexBufferObjectManager pVertexBufferObjectManager, DrawMode pDrawMode, final DrawType pDrawType) {
super(pX, pY, buildEllipseVertices(pRadiusA, pRadiusB, pResolution), pLineWidth, pVertexBufferObjectManager, pDrawMode, pDrawType);

mResolution = pResolution;
}

// ===========================================================
// Getter & Setter
// ===========================================================

/**
*
* @param pRadiusA
* @param pRadiusB
* @return true if vertices were correctly updated
* false otherwise
*/
/*
public boolean setRadius( float pRadiusA, float pRadiusB )
{
return this.updateVertices(buildEllipseVertices(pRadiusA, pRadiusB, mResolution));
}
*/

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

// ===========================================================
// Methods
// ===========================================================

private static float[] buildEllipseVertices(float pRadiusA, float pRadiusB, int pResolution) {

float[] vertices = new float[VERTEX_SIZE * pResolution];

for( int i = 0; i < pResolution; i++)
{
double theta = 2. * Math.PI * (double)i / (double) pResolution;
float x = (float) ( (double)pRadiusA * Math.cos( theta ));
float y = (float) ( (double)pRadiusB * Math.sin( theta ));

vertices[(i * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_X] = x;
vertices[(i * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_Y] = y;
}

return vertices;
}

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
99 changes: 98 additions & 1 deletion src/org/andengine/entity/primitive/Mesh.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.andengine.entity.primitive;

import java.security.spec.MGF1ParameterSpec;

import org.andengine.engine.camera.Camera;
import org.andengine.entity.shape.IShape;
import org.andengine.entity.shape.RectangularShape;
import org.andengine.entity.shape.Shape;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.shader.PositionColorShaderProgram;
import org.andengine.opengl.shader.constants.ShaderProgramConstants;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.util.GLState;
import org.andengine.opengl.vbo.HighPerformanceVertexBufferObject;
import org.andengine.opengl.vbo.IVertexBufferObject;
Expand Down Expand Up @@ -47,10 +51,20 @@ public class Mesh extends Shape {
protected final IMeshVertexBufferObject mMeshVertexBufferObject;
private int mVertexCountToDraw;
private int mDrawMode;
protected ITextureRegion mTextureRegion;

// ===========================================================
// Constructors
// ===========================================================

/**
* Uses a default {@link HighPerformanceMeshVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
*/
public Mesh(final float pX, final float pY, final float[] pBufferData, final int pVertexCount, final DrawMode pDrawMode, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) {
this(pX, pY, pBufferData, pVertexCount, pDrawMode, pVertexBufferObjectManager, DrawType.STATIC);
mTextureRegion = pTextureRegion;
this.onUpdateTextureCoordinates();
}

/**
* Uses a default {@link HighPerformanceMeshVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
Expand All @@ -65,6 +79,13 @@ public Mesh(final float pX, final float pY, final float[] pBufferData, final int
public Mesh(final float pX, final float pY, final float[] pBufferData, final int pVertexCount, final DrawMode pDrawMode, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
this(pX, pY, pVertexCount, pDrawMode, new HighPerformanceMeshVertexBufferObject(pVertexBufferObjectManager, pBufferData, pVertexCount, pDrawType, true, Mesh.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT));
}

/**
* Uses a default {@link HighPerformanceMeshVertexBufferObject} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
*/
public Mesh(final float pX, final float pY, final float[] pVertexX, final float[] pVertexY, final DrawMode pDrawMode, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
this(pX, pY, pVertexX.length, pDrawMode, new HighPerformanceMeshVertexBufferObject(pVertexBufferObjectManager, buildVertexList(pVertexX, pVertexY), pVertexX.length, pDrawType, true, Mesh.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT));
}

public Mesh(final float pX, final float pY, final int pVertexCount, final DrawMode pDrawMode, final IMeshVertexBufferObject pMeshVertexBufferObject) {
super(pX, pY, PositionColorShaderProgram.getInstance());
Expand Down Expand Up @@ -93,6 +114,10 @@ public void setVertexCountToDraw(final int pVertexCountToDraw) {
public void setDrawMode(final DrawMode pDrawMode) {
this.mDrawMode = pDrawMode.mDrawMode;
}

public ITextureRegion getTextureRegion() {
return this.mTextureRegion;
}

// ===========================================================
// Methods for/from SuperClass/Interfaces
Expand All @@ -106,7 +131,11 @@ public IMeshVertexBufferObject getVertexBufferObject() {
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
super.preDraw(pGLState, pCamera);


// Check if polygon uses a texture
if( mTextureRegion != null)
this.mTextureRegion.getTexture().bind(pGLState);

this.mMeshVertexBufferObject.bind(pGLState, this.mShaderProgram);
}

Expand All @@ -131,6 +160,10 @@ protected void onUpdateColor() {
protected void onUpdateVertices() {
this.mMeshVertexBufferObject.onUpdateVertices(this);
}

protected void onUpdateTextureCoordinates() {
this.mMeshVertexBufferObject.onUpdateTextureCoordinates(this);
}

@Override
@Deprecated
Expand All @@ -155,6 +188,24 @@ public boolean collidesWith(final IShape pOtherShape) {
// Methods
// ===========================================================

protected static float[] buildVertexList(float[] pVertexX, float[] pVertexY)
{
assert( pVertexX.length == pVertexY.length );

float[] bufferData = new float[VERTEX_SIZE * pVertexX.length];
updateVertexList(pVertexX, pVertexY, bufferData);
return bufferData;
}

protected static void updateVertexList(float[] pVertexX, float[] pVertexY, float[] pBufferData)
{
for( int i = 0; i < pVertexX.length; i++)
{
pBufferData[(i * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_X] = pVertexX[i];
pBufferData[(i * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_Y] = pVertexY[i];
}
}

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
Expand All @@ -171,6 +222,7 @@ public static interface IMeshVertexBufferObject extends IVertexBufferObject {
public float[] getBufferData();
public void onUpdateColor(final Mesh pMesh);
public void onUpdateVertices(final Mesh pMesh);
public void onUpdateTextureCoordinates(final Mesh pMesh);
}

public static class HighPerformanceMeshVertexBufferObject extends HighPerformanceVertexBufferObject implements IMeshVertexBufferObject {
Expand Down Expand Up @@ -221,6 +273,51 @@ public void onUpdateVertices(final Mesh pMesh) {

this.setDirtyOnHardware();
}

@Override
public void onUpdateTextureCoordinates(final Mesh pMesh) {
final float[] bufferData = this.mBufferData;

final ITextureRegion textureRegion = pMesh.getTextureRegion(); // TODO Optimize with field access?

final float u;
final float v;
final float u2;
final float v2;

u = textureRegion.getU();
u2 = textureRegion.getU2();
v = textureRegion.getV();
v2 = textureRegion.getV2();

if(textureRegion.isRotated()) {
bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;

bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;

bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;

bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
} else {
bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;

bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;

bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;

bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
}

this.setDirtyOnHardware();
}

// ===========================================================
// Methods
Expand Down
Loading