Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Lobby

Pages: 1 2 [3] 4 5
31
Bugs / Re: Overlay.setSourceCoordinates() has no effect
« on: February 15, 2014, 02:12:21 pm »
Thank you, that's a working work around. However, now I have to do some confusing calculations for the matrix and I'm not sure whether an extended setSourceCoordinates() method would be easier to implement.

Something other, why SimpleVector has no SimpleVector calcScalarMul(float scalar) method?

32
I really agree with your opinion, so about what do you want to discuss?

In the past my problem about creating games has always been the lack of good ideas, so how to solve this?

33
Bugs / Re: Overlay.setSourceCoordinates() has no effect
« on: February 14, 2014, 08:55:35 pm »
May I suggest to add a method to set the four uv coords manually or at least to set a rotated source rectangle? I want to rotate a background that is an overlay but to rotate the whole overlay is a bad solution I think (therefore the overlay would have to be bigger than the screen).

I hope it doesn't matter that I recycle this thread.

34
Bugs / Re: Overlay.setSourceCoordinates() has no effect
« on: February 10, 2014, 10:18:43 pm »
Thanks, great stuff

35
Bugs / Re: Overlay.setSourceCoordinates() has no effect
« on: February 10, 2014, 09:58:46 pm »
Thank you :)

Do you need these floats now?

Would be nice to get them as soon as possible.

36
Bugs / Re: Overlay.setSourceCoordinates() has no effect
« on: February 10, 2014, 03:00:27 pm »
By the way, would be nice to use float values as source coordinates for better accuracy.

37
Bugs / Re: Overlay.setSourceCoordinates() has no effect
« on: February 10, 2014, 01:26:19 pm »
Ok, it's not a bug, but the documentation forgot to mention that I have to use the Overlay constructor with parameter modifyUV set to true :'( .

38
Bugs / Overlay.setSourceCoordinates() has no effect
« on: February 10, 2014, 12:04:11 am »
Hello, I tried to get an overlay to show just a part of the source texture by using the method setSourceCoordinates(). Unfortunately, this method seems to have no effect at all, it just doesn't matter what parameters I use (while other methods like setNewCoordinates() work properly).

39
Support / Re: Blitting with rotation
« on: February 09, 2014, 10:18:09 pm »
In 2D it's neat to have calls like DrawImage(Image, x, y, Rotation) instead of handling collections of objects. It can make things easier :D .

But I understand your point, so also for 2D 3D objects would be the best solution in regard of performance.

40
Support / Re: Blitting with rotation
« on: February 09, 2014, 10:03:44 pm »
For a 2D particle engine for example, would you suggest to hold all particle images as overlays? Also when it means that you have to create and remove ten overlays a second? Yes, one could use something like a Overlay-Pool, but this sounds like a lot of work...

41
Support / Re: Terrain grid issue..
« on: February 09, 2014, 07:31:25 pm »
Are you sure that it is a failure of vertex coords? As I already had to learn the wireframe Rendering doesn't work properly.

Quote
Incidentally I would love to use the in-built getPlane(int, int) function, but this doesn't allow me to create for odd sizes, hence doing this manually.

You could also use the Terrain class I will release soon:

Terrain.java:
Code: [Select]
package com.example.myterrain;

import android.graphics.Bitmap;

import com.threed.jpct.GLSLShader;
import com.threed.jpct.GenericVertexController;
import com.threed.jpct.Mesh;
import com.threed.jpct.Object3D;
import com.threed.jpct.PolygonManager;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureInfo;
import com.threed.jpct.TextureManager;

/**
 * Subclass of Object3D to create and manage terrains in jpct-ae. Only squared terrains are supported.
 *
 * @author Lobby Divinus
 */
public class Terrain extends Object3D {

private static final long serialVersionUID = 7329791217357939144L;

private float[][] heightData;
private int width;
private int depth;

private float size;
private float height;

/**
* Creates a terrain with given number of width and depth quads.
* @param width number of quads in width
* @param depth number of quads in depth
*/
public Terrain(int width, int depth) {
this(width, depth, new float[width + 1][depth + 1], 1f, 1f);
}

/**
* Creates a terrain from grey values of a bitmap. Pay attention on that the actual number of quads in width and
* depth is 1 smaller than the width and height of the bitmap.
* @param bitmap to generate terrain from
*/
public Terrain(Bitmap bitmap) {
this(bitmap, 1f, 1f);
}

/**
* Creates a terrain from grey values of a bitmap. Pay attention on that the actual number of quads in width and
* depth is 1 smaller than the width and height of the bitmap.
* @param bitmap to generate terrain from
* @param size quadsize
* @param height factor of height scalation (default is 1)
*/
public Terrain(Bitmap bitmap, float size, float height) {
this(bitmap, size, height, new BitmapGreyHeightExtractor());
}

/**
* Creates a terrain from grey values of a bitmap. Pay attention on that the actual number of quads in width and
* depth is 1 smaller than the width and height of the bitmap.
* @param bitmap to generate terrain from
* @param size quadsize
* @param height factor of height scale (default is 1)
* @param extractor to get height data from bitmap
*/
public Terrain(Bitmap bitmap, float size, float height, IBitmapHeightExtractor extractor) {
super(2 * bitmap.getWidth() * bitmap.getHeight());

this.size = size;
this.height = height;

width = bitmap.getWidth();
depth = bitmap.getHeight();
heightData = new float[width][depth];

extractor.init(bitmap);
for (int x = 0; x < width; x++) {
for (int z = 0; z < depth; z++) {
heightData[x][z] = extractor.extract(x, z);
}
}

buildMesh();
}

/**
* Creates a terrain with given number of width and depth quads.
* @param width number of quads in width
* @param depth number of quads in depth
* @param heights array that contains height value for each vertex, must have size [width - 1][depth - 1]
* @param size quadsize
* @param height factor of height scale (default is 1)
*/
public Terrain(int width, int depth, float[][] heights, float size, float height) {
super(2 * width * depth);
this.heightData = heights;
this.width = width + 1;
this.depth = depth + 1;

this.size = size;
this.height = height;

buildMesh();
}

/**
* Returns number of quads in width.
* @return number of quads
*/
public int getEdgeWidth() {
return width - 1;
}

/**
* Returns number of quads in depth
* @return number of quads
*/
public int getEdgeDepth() {
return depth - 1;
}

/**
* Returns height scale.
* @return height
*/
public float getHeight() {
return height;
}

/**
* Returns quad size
* @return quad size
*/
public float getQuadSize() {
return size;
}


public float getCenteredSmoothedY(float x, float z, float smooth) {
return getSmoothedY(x / size - 0.5f + width / 2f, z / size - 0.5f + depth / 2f, smooth);
}

public SimpleVector getCenteredSmoothedNormal(float x, float z, float smooth) {
return getSmoothedNormal(x / size - 0.5f + width / 2f, z / size - 0.5f + depth / 2f, smooth);
}

public float getCenteredY(float x, float z) {
return getY(x / size - 0.5f + width / 2f, z / size - 0.5f + depth / 2f);
}

public SimpleVector getCenteredNormal(float x, float z) {
return getNormal(x / size - 0.5f + width / 2f, z / size - 0.5f + depth / 2f);
}

public float getSmoothedY(float x, float z, float smooth) {
if (x < 0 || z < 0 || x > width - 1 || z > depth - 1) {
return 0f;
}

float result = 0f;
result += getY(x - smooth, z);
result += getY(x + smooth, z);
result += getY(x, z + smooth);
result += getY(x, z - smooth);
result /= 4;

result += getY(x, z);
result /= 2;

return result;
}

public SimpleVector getSmoothedNormal(float x, float z, float smooth) {
if (x < 0 || z < 0 || x > width - 1 || z > depth - 1) {
return new SimpleVector(0f, -1f, 0f);
}

SimpleVector result = new SimpleVector();

float height = getY(x,z);
SimpleVector v0 = new SimpleVector(smooth, getY(x + smooth, z) - height, 0);
SimpleVector v1 = new SimpleVector(0, getY(x, z + smooth) - height, smooth);
SimpleVector v2 = new SimpleVector(- smooth, getY(x - smooth, z) - height, 0);
SimpleVector v3 = new SimpleVector(0, getY(x, z - smooth) - height, - smooth);
v0 = v0.calcCross(v1);
v2 = v2.calcCross(v3);

result.add(v0);
result.add(v2);
result.scalarMul(0.5f);

return result;
}

public SimpleVector getSmoothedQuadNormal(float x, float z) {
if (x < 0 || z < 0 || x > width - 1 || z > depth - 1) {
return new SimpleVector(0f, -1f, 0f);
}

int ix = (int) x;
int iz = (int) z;
float mx = x % 1;
float mz = z % 1;

SimpleVector normal1;
SimpleVector normal2;

normal1 = getNormal(ix, iz);
normal1.scalarMul((1 - mx) + (1 - mz));

normal2 = getNormal(ix + 0.8f, iz + 0.8f);
normal2.scalarMul(mx + mz);

normal1.add(normal2);

return normal1;
}

/**
* Determines the height of a x, z position in quad coordinate system.
* @param x coordinate
* @param z coordinate
* @return height of x, z or 0 if x, z is out of terrain
*/
public float getY(float x, float z) {
if (x < 0 || z < 0 || x > width - 1 || z > depth - 1) {
return 0f;
}

float mx = x % 1;
float mz = z % 1;

if (Math.min(mx, 1 - mx) < 0.001f && Math.min(mz,  1 - mz) < 0.001f) {
return getPointY((int) (x + 0.5f), (int) (z + 0.5f));
}

int lX;
int lZ;
int o1X;
int o1Z;
int o2X;
int o2Z;

if (mx + mz < 1) {
lX = (int) x;
lZ = (int) z;
o1X = 0;
o1Z = 1;
o2X = 1;
o2Z = 0;
} else {
lX = (int) x + 1;
lZ = (int) z + 1;
o1X = 0;
o1Z = - 1;
o2X = - 1;
o2Z = 0;
}

float lH = - height * heightData[lX][depth - lZ - 1];
float o1H = - height * heightData[lX + o1X][depth - lZ - o1Z - 1];
float o2H = - height * heightData[lX + o2X][depth - lZ - o2Z - 1];

SimpleVector o1V = SimpleVector.create(size * o1X, o1H - lH, size * o1Z);
SimpleVector o2V = SimpleVector.create(size * o2X, o2H - lH, size * o2Z);
o1V.scalarMul((1 - o1Z) / 2 + o1Z * (mz));
o2V.scalarMul((1 - o2X) / 2 + o2X * (mx));
return lH + o1V.y + o2V.y;
}

/**
* Determines height of a vertex at given position in quad coordinate system. If position is out of the terrain
* 0 will be returned.
* @param x coordinate
* @param z coordinate
* @return absolute height value
*/
public float getPointY(int x, int z) {
if (x < 0 || z < 0 || x > width - 1 || z > depth - 1) {
return 0f;
}

return this.height * (- this.heightData[x][depth - z - 1]);
}

/**
* Sets height for the vertex at the given position in quad coordinate system. If position is out of the terrain
* the call will be ignored.
* @param x coordinate in quad coordiante system
* @param h new height value, by convention this is in 0..1
* @param z coordinate in quad coordinate system
*/
public void setPointHeight(int x, float h, int z) {
if (x < 0 || z < 0 || x > width - 1 || z > depth - 1) {
return;
}

heightData[x][depth - z - 1] = h;
applyHeightData();
}

/**
* Calculates normal vector for given x, z position in quad coordinate system. If position is out of the terrain
* null will be returned.
* @param x coordinate in quad coordinate system
* @param z coordinate in quad coordinate system
* @return normal vector
*/
public SimpleVector getNormal(float x, float z) {
if (x < 0 || z < 0 || x > width - 1 || z > depth - 1) {
return null;
}

int lX;
int lZ;
int o1X;
int o1Z;
int o2X;
int o2Z;

if (x % 1 + z % 1 <= 1) {
lX = (int) x;
lZ = (int) z;
o1X = 0;
o1Z = 1;
o2X = 1;
o2Z = 0;
} else {
lX = (int) x + 1;
lZ = (int) z + 1;
o1X = 0;
o1Z = - 1;
o2X = - 1;
o2Z = 0;
}

float lH = -height * heightData[lX][lZ];
float o1H = -height * heightData[lX + o1X][lZ + o1Z];
float o2H = -height * heightData[lX + o2X][lZ + o2Z];

SimpleVector o1V = SimpleVector.create(size * o1X, o1H - lH, size * o1Z);
SimpleVector o2V = SimpleVector.create(size * o2X, o2H - lH, size * o2Z);
return o2V.calcCross(o1V);
}

private void buildMesh() {
// Prepare vertices
SimpleVector[][] v = new SimpleVector[width][depth];
for (int x = 0; x < width; x++) {
for (int z = 0; z < depth; z++) {
v[x][z] = new SimpleVector(size * (x + 0.5f - width / 2f), - height * heightData[x][depth - z - 1], size * (z + 0.5f - depth / 2f));
}
}


// Create quads
float uC = 0f;
float vC = 1f;
float uStep = 1f / (width - 1);
float vStep = -1f / (depth - 1);
for (int x = 0; x + 1 < width; x++) {
vC = 1f;
for (int z = 0; z + 1 < depth; z++) {
addTriangle(v[x][z + 1], uC, vC + vStep, v[x][z], uC, vC, v[x + 1][z], uC + uStep, vC);
addTriangle(v[x + 1][z], uC + uStep, vC, v[x + 1][z + 1], uC + uStep, vC + vStep, v[x][z + 1], uC, vC + vStep);


// Use other diagonal for quads (made calculations more complex :/ )
//addTriangle(v[x][z + 1], uC, vC + vStep, v[x][z], uC, vC, v[x + 1][z + 1], uC + uStep, vC + vStep);
//addTriangle(v[x + 1][z + 1], uC + uStep, vC + vStep, v[x][z], uC, vC, v[x + 1][z], uC + uStep, vC);

vC += vStep;
}
uC += uStep;
}
}

private void applyHeightData() {
Mesh mesh = getMesh();

mesh.setVertexController(new GenericVertexController() {
private static final long serialVersionUID = 1L;
@Override
public void apply() {
SimpleVector[] source = getSourceMesh();
SimpleVector[] dest = getDestinationMesh();
for (int i = 0; i < source.length; i++) {
int x = (int) Math.floor(source[i].x / size + width / 2.0);
int z = (int) Math.floor(source[i].z / size + depth / 2.0);
dest[i].y = -height * heightData[x][depth - z - 1];
}
}
}, false);

mesh.applyVertexController();
mesh.removeVertexController();
}

/**
* Applies multiple textures on the terrain. A base texture, given with mask, will be used to select which of the
* other (up to three) textures should be shown at a specific position. For stage 1 color channel red will be used
* and so on.
* The base texture is stretched over the whole terrain. Other textures can be scaled using xScale and yScale.
*
* In order to use more than two texture in total on the terrain you should modify Config.maxTextureLayers to a
* value of 3 or more (is 2 by default).
*
* To use this method you should also apply a specific shader. You can use the default one by calling
* applayTerrainShader().
*
* @param mask name of the ground texture to use
* @param maps other texture names
* @param modes blending modes, use TextureInfo.MODE_ADD to gain good results
* @param xScale x scale for textures
* @param yScale y scale for textures
*/
public void setTerrainTextures(String mask, String[] maps, int[] modes, float[] xScale, float[] yScale) {
TextureManager mgr = TextureManager.getInstance();
int[] texIds = new int[1 + maps.length];
TextureInfo info = new TextureInfo(texIds[0]);
texIds[0] = mgr.getTextureID(mask);
for (int i = 0; i < maps.length; i++) {
texIds[i + 1] = mgr.getTextureID(maps[i]);
info.add(texIds[i + 1], modes[i]);
}

PolygonManager pmgr = getPolygonManager();
for (int poly = 0; poly < getMesh().getTriangleCount(); poly++) {
SimpleVector v0 = pmgr.getTextureUV(poly, 0);
SimpleVector v1 = pmgr.getTextureUV(poly, 1);
SimpleVector v2 = pmgr.getTextureUV(poly, 2);
info.set(texIds[0], 0, v0.x, v0.y, v1.x, v1.y, v2.x, v2.y,TextureInfo.MODE_REPLACE);
for (int i = 0; i < maps.length; i++) {
info.set(texIds[i + 1], i + 1,
v0.x * xScale[i], v0.y * yScale[i],
v1.x * xScale[i], v1.y * xScale[i],
v2.x * xScale[i], v2.y * xScale[i],
modes[i]);
}
pmgr.setPolygonTexture(poly, info);
}
}

/**
* Applies terrain texture shader on the mesh so that it can use up to 4 textures for multitexturing. The texture
* at stage 0 defines where the other textures should be drawn (red = state 1 etc.).
*/
public void applyTerrainShader() {

setShader(terrainShader);
}

private final static String TERRAIN_VERTEX_SHADER = "uniform mat4 modelViewMatrix;" +
"uniform mat4 modelViewProjectionMatrix;" +
"uniform mat4 textureMatrix;" +
"uniform vec4 additionalColor;" +
"uniform vec4 ambientColor;" +
"uniform float alpha;" +
"uniform float shininess;" +
"uniform bool useColors;" +
"uniform float fogStart;" +
"uniform float fogEnd;" +
"uniform vec3 fogColor;" +
"uniform int lightCount;" +
"uniform vec3 lightPositions[8];" +
"uniform vec3 diffuseColors[8];" +
"uniform vec3 specularColors[8];" +
"uniform float attenuation[8];" +
"attribute vec4 position;" +
"attribute vec3 normal;" +
"attribute vec4 color;" +
"attribute vec2 texture0;" +
"attribute vec2 texture1;" +
"attribute vec2 texture2;" +
"attribute vec2 texture3;" +
"varying vec2 texCoord[4];" +
"varying vec4 vertexColor;" +
"varying vec3 fogVertexColor;" +
"varying float fogWeight;" +
"const vec4 WHITE = vec4(1,1,1,1);" +
"void main() {" +
" texCoord[0] = (textureMatrix * vec4(texture0, 0, 1)).xy;" +
" texCoord[1] = texture1;" +
" texCoord[2] = texture2;" +
" texCoord[3] = texture3;" +
" vec4 vertexPos = modelViewMatrix * position;" +
" vertexColor = ambientColor + additionalColor;" +
" if (lightCount>0) {" +
" vec3 normalEye   = normalize(modelViewMatrix * vec4(normal, 0.0)).xyz;" +
" float angle = dot(normalEye, normalize(lightPositions[0] - vertexPos.xyz));" +
" if (angle > 0.0) {" +
" vertexColor += vec4((diffuseColors[0] * angle + specularColors[0] * pow(angle, shininess))*(1.0/(1.0+length(lightPositions[0] - vertexPos.xyz)*attenuation[0])), 1);" +
" }" +
" if (lightCount>1) {" +
" angle = dot(normalEye, normalize(lightPositions[1] - vertexPos.xyz));" +
" if (angle > 0.0) {" +
" vertexColor += vec4((diffuseColors[1] * angle + specularColors[1] * pow(angle, shininess))*(1.0/(1.0+length(lightPositions[1] - vertexPos.xyz)*attenuation[1])), 1);" +
" }" +
" if (lightCount>2) {" +
" angle = dot(normalEye, normalize(lightPositions[2] - vertexPos.xyz));" +
" if (angle > 0.0) {" +
" vertexColor += vec4((diffuseColors[2] * angle + specularColors[2] * pow(angle, shininess))*(1.0/(1.0+length(lightPositions[2] - vertexPos.xyz)*attenuation[2])), 1);" +
" }" +
" if (lightCount>3) {" +
" angle = dot(normalEye, normalize(lightPositions[3] - vertexPos.xyz));" +
" if (angle > 0.0) {" +
" vertexColor += vec4((diffuseColors[3] * angle + specularColors[3] * pow(angle, shininess))*(1.0/(1.0+length(lightPositions[3] - vertexPos.xyz)*attenuation[3])), 1);" +
" }" +
" if (lightCount>4) {" +
" angle = dot(normalEye, normalize(lightPositions[4] - vertexPos.xyz));" +
" if (angle > 0.0) {" +
" vertexColor += vec4((diffuseColors[4] * angle + specularColors[4] * pow(angle, shininess))*(1.0/(1.0+length(lightPositions[4] - vertexPos.xyz)*attenuation[4])), 1);" +
" }" +
" if (lightCount>5) {" +
" angle = dot(normalEye, normalize(lightPositions[5] - vertexPos.xyz));" +
" if (angle > 0.0) {" +
" vertexColor += vec4((diffuseColors[5] * angle + specularColors[5] * pow(angle, shininess))*(1.0/(1.0+length(lightPositions[5] - vertexPos.xyz)*attenuation[5])), 1);" +
" }" +
" if (lightCount>6) {" +
" angle = dot(normalEye, normalize(lightPositions[6] - vertexPos.xyz));" +
" if (angle > 0.0) {" +
" vertexColor += vec4((diffuseColors[6] * angle + specularColors[6] * pow(angle, shininess))*(1.0/(1.0+length(lightPositions[6] - vertexPos.xyz)*attenuation[6])), 1);" +
" }" +
" if (lightCount>7) {" +
" angle = dot(normalEye, normalize(lightPositions[7] - vertexPos.xyz));" +
" if (angle > 0.0) {" +
" vertexColor += vec4((diffuseColors[7] * angle + specularColors[7] * pow(angle, shininess))*(1.0/(1.0+length(lightPositions[7] - vertexPos.xyz)*attenuation[7])), 1);" +
" }" +
" }" +
" }" +
" }" +
" }" +
" }" +
" }" +
" }" +
" }" +
" if (fogStart != -1.0) {" +
" fogWeight = clamp((-vertexPos.z - fogStart) / (fogEnd - fogStart), 0.0, 1.0);" +
" fogVertexColor = fogColor * fogWeight;" +
" } else {" +
" fogWeight = -1.0;" +
" }" +
" vertexColor=vec4(min(WHITE, vertexColor).xyz, alpha);" +
" if (useColors) {" +
" vertexColor *= color;" +
" }" +
" gl_Position = modelViewProjectionMatrix * position;" +
"}";

private final static String TERRAIN_FRAGMENT_SHADER = "precision mediump float;" +
"uniform sampler2D textureUnit0;" +
"uniform sampler2D textureUnit1;" +
"uniform sampler2D textureUnit2;" +
"uniform sampler2D textureUnit3;" +
"uniform int textureCount;" +
"uniform int blendingMode[4];" +
"varying vec2 texCoord[4];" +
"varying vec4 vertexColor;" +
"varying float fogWeight;" +
"varying vec3 fogVertexColor;" +
"const vec4 WHITE = vec4(1,1,1,1);" +
"void main() {" +
" vec4 mask = texture2D(textureUnit0, texCoord[0]) * vertexColor;" +
" vec4 col = vec4(0,0,0,0);" +
" if (textureCount>1) {" +
" if (blendingMode[1]==0) {" +
" col *= mask.x * texture2D(textureUnit1, texCoord[1]);" +
" } else if (blendingMode[1]==1) {" +
" col += mask.x * texture2D(textureUnit1, texCoord[1]);" +
" } else if (blendingMode[1]==3) {" +
" col *= mask.x * (WHITE - texture2D(textureUnit1, texCoord[1]));" +
" } else if (blendingMode[1]==2) {" +
" col = mask.x * texture2D(textureUnit1, texCoord[1]);" +
" }" +
" if (textureCount>2) {" +
" if (blendingMode[2]==0) {" +
" col *= mask.y * texture2D(textureUnit2, texCoord[2]);" +
" } else if (blendingMode[2]==1) {" +
" col += mask.y * texture2D(textureUnit2, texCoord[2]);" +
" } else if (blendingMode[2]==3) {" +
" col *= mask.y * (WHITE - texture2D(textureUnit2, texCoord[2]));" +
" } else if (blendingMode[2]==2) {" +
" col = mask.y * texture2D(textureUnit2, texCoord[2]);" +
" }" +
" if (textureCount>3) {" +
" if (blendingMode[3]==0) {" +
" col *= mask.z * texture2D(textureUnit3, texCoord[3]);" +
" } else if (blendingMode[3]==1) {" +
" col += mask.z * texture2D(textureUnit3, texCoord[3]);" +
" } else if (blendingMode[3]==3) {" +
" col *= mask.z * (WHITE - texture2D(textureUnit3, texCoord[3]));" +
" } else if (blendingMode[3]==2) {" +
" col = mask.z * texture2D(textureUnit3, texCoord[3]);" +
" }" +
" }" +
" }" +
" }" +
" if (fogWeight>-0.9) {" +
" col.xyz = (1.0-fogWeight) * col.xyz + fogVertexColor;" +
" }" +
" gl_FragColor=col;" +
"}";

private static GLSLShader terrainShader = new GLSLShader(TERRAIN_VERTEX_SHADER, TERRAIN_FRAGMENT_SHADER);
}

IBitmapHeightExtractor.java:
Code: [Select]
package com.example.myterrain;

import android.graphics.Bitmap;

public interface IBitmapHeightExtractor {

void init(Bitmap bitmap);

float extract(int x, int y);

}

BitmapGreyHeightExtractor.java:
Code: [Select]
package com.example.myterrain;

import android.graphics.Bitmap;
import android.graphics.Color;

public class BitmapGreyHeightExtractor implements IBitmapHeightExtractor {

private Bitmap bitmap;

@Override
public void init(Bitmap bitmap) {
this.bitmap = bitmap;
}

@Override
public float extract(int x, int y) {
int col = bitmap.getPixel(x, y);
int grey = (Color.red(col) + Color.green(col) + Color.blue(col)) / 3;
return grey / 255f;
}

}

Not ready yet, so don't expect to much ;) .

42
Support / Blitting with rotation
« on: February 09, 2014, 07:28:41 pm »
Hello, would it be possible to add rotation support to blitting on a FrameBuffer? I think using Overlay isn't appreciated if you have a lot of dynamicially things to draw, is it?

43
German corner / Re: Wiederverwendung von World möglich?
« on: January 09, 2014, 11:40:20 pm »
Ich habe nichts weiter mit dem Welt-Objekt gemacht und langes Herumprobieren hat mich nun schließlich zum Ergebnis gebracht, dass ich den Renderer (wie in meinem ReuseWorld Projekt) wiederverwenden muss, denn ansonsten kommt es eben zu oben beschriebenen Verhalten. Da ich den Renderer von der Spielelogik entkoppelt habe sollte es eigentlich unabhängig vom Renderer funktionieren, das finde ich jetzt doch sehr verwirrdend ???

So sieht der Renderer aus, wie man sieht ist er komplett vom Rest entkoppelt (hält selbst keine Objekte) und sollte somit eigentlich austauschbar sein:
Code: [Select]
private class Renderer implements GLSurfaceView.Renderer {
@Override
public void onDrawFrame(GL10 arg0) {
game.onUpdate();
game.onRender();
}

@Override
public void onSurfaceChanged(GL10 arg0, int width, int height) {
if (buffer != null) {
buffer.dispose();
}
buffer = new FrameBuffer(width, height);
}

@Override
public void onSurfaceCreated(GL10 arg0, EGLConfig arg1) {
}
}

Ich würde mal vermuten dass die Ursache irgendwelche Arbeiten im Hintergrund sind.

44
German corner / Re: Wiederverwendung von World möglich?
« on: January 09, 2014, 11:00:21 pm »
Gut, dann liegt es wohl an mir. Um dem Problem näher zu kommen habe ich versucht ein minimal kleines Programm zu schreiben, das mir zeigen sollte ob ich einen grundsätzlichen Denkfehler habe - und Tatsache, das Testprogramm läuft so wie gewünscht. Nun muss ich nur noch herausfinden, was ich in meinem Projekt anders gemacht habe... :-\

Falls noch jemand über so ein Problem stolpern sollte, hier mein Testprogramm in dem World erfolgreich wiederverwendet wird. Dass es funktioniert zeigt sich daran, dass die App auch nach einer Änderung der Ausrichtung noch funktioniert.

45
German corner / Wiederverwendung von World möglich?
« on: January 09, 2014, 10:10:55 pm »
Hallöchen,

ich spiele jetzt schon ein bisschen länger mit jpct-ae herum und stelle mir nun die Frage, ob es wirklich wie in den Samples gezeigt, nötig ist immer eine neue Welt zu erstellen wenn das Programm zwischenzeitlich pausiert oder Ähnliches wurde. Globale statische Instanzen bleiben dabei offensichtlich (siehe z.B. TextureManager) ja auch erhalten, aber wenn ich auf gleiche Art und Weise versuche meine World-Instanz wiederzuverwenden ist von den erstellten Objekten in der 3D-Welt nichts mehr zu sehen. Den Framebuffer erstelle ich jedes Mal neu, und wenn ich immer ein neues World-Objekt erstelle klappt das auch wunderbar - nur entspricht das nicht ganz dem "nur einmal Laden und Vorbereiten" Prinzip das ich von Computerprogrammen kenne und recht bequem ist wenn man nicht den Weltzustand jedes Mal speichern und wieder neu aufbauen möchte.

Pages: 1 2 [3] 4 5