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 - Kaiidyn

Pages: 1 ... 5 6 [7]
91
Support / Re: Heightmap Terrain
« on: November 30, 2010, 12:14:04 pm »

92
Support / Heightmap Terrain
« on: November 29, 2010, 08:59:16 pm »
managed to get heightmap working, and want to share it with all of you :)

When using it make sure you have a Texture Manager with a TextureID ready, (I used a flat gray 128x128 image for this)

Code: [Select]
public class Terrain {

public static float HighestPoint = 0;


static Bitmap bmp = null;
static String pixel = null;
public static Object3D Generate(int X_SIZE, int Z_SIZE, TextureManager tm, String TextureID){

bmp = BitmapFactory.decodeResource(SpaceGrabber.resources, R.drawable.terrain); // the heightmap texture (128x128 due to memory limitations?)

float[][] terrain = new float[X_SIZE][Z_SIZE];

for (int x = 0; x < X_SIZE-1; x++) {
for (int z = 0; z < Z_SIZE-1; z++) {

pixel = Integer.toString(bmp.getPixel(x, z), 16);
terrain[x][z] = Integer.parseInt(pixel.charAt(1) + "" + pixel.charAt(2), 16);

if(terrain[x][z] > HighestPoint){
HighestPoint = terrain[x][z];
}
}

}
for (int x = 0; x < X_SIZE - 1; x++) {
for (int z = 0; z < Z_SIZE - 1; z++) {
terrain[x][z] = (terrain[x][z] + terrain[x + 1][z] + terrain[x][z + 1] + terrain[x + 1][z + 1]) / 4;
}
}
Object3D ground = new Object3D(X_SIZE * Z_SIZE * 2);

float xSizeF = (float) X_SIZE;
float zSizeF = (float) Z_SIZE;

int id = tm.getTextureID(TextureID); // I used a gray 128x128 texture

for (int x = 0; x < X_SIZE - 1; x++) {
for (int z = 0; z < Z_SIZE - 1; z++) {

TextureInfo ti = new TextureInfo(id, (x / xSizeF), (z / zSizeF), ((x + 1) / xSizeF), (z / zSizeF), (x / xSizeF), ((z + 1) / zSizeF));
ground.addTriangle(new SimpleVector(x * 10, terrain[x][z], z * 10), new SimpleVector((x + 1) * 10, terrain[x + 1][z], z * 10),
new SimpleVector(x * 10, terrain[x][z + 1], (z + 1) * 10), ti);

ti = new TextureInfo(id, (x / xSizeF), ((z + 1) / zSizeF), ((x + 1) / xSizeF), (z / zSizeF), ((x + 1) / xSizeF), ((z + 1) / zSizeF));
ground.addTriangle(new SimpleVector(x * 10, terrain[x][z + 1], (z + 1) * 10), new SimpleVector((x + 1) * 10, terrain[x + 1][z], z * 10), new SimpleVector((x + 1) * 10,
terrain[x + 1][z + 1], (z + 1) * 10), ti);
}
}

return ground;
}
}

93
Support / Re: Position in world-space
« on: November 25, 2010, 09:21:03 pm »
Ah yes ofcourse, why didn't I come up with that lol.
That's working now. :)

About the heightmap, I managed to import a raw image but white is 0 and black is -1 and grayscales are between 1 and 255 or something.
How can I convert that to usable values for height?

Kind regards,
Kaiidyn.

94
Support / Re: Position in world-space
« on: November 25, 2010, 11:36:52 am »
I placed a SimpleVector at the x and z position of my player, and the y will always be 0,
I did this to get the actual height of the terrain at x,z.
So that when the SimpleVector is above the terrain, it should return 25 and below the terrain a -25 or whatever
then negativating (as far as thats a word) would return the actual terrain height.
The calcMinDistance does not work when 'looking at' the bottom of a vertex (eg, not dualsided)

Code: [Select]
terrHeightUp = ground.calcMinDistance(heightCalcPos, new SimpleVector(0,-1,0), 100); // always 2147483647
terrHeightDown = ground.calcMinDistance(heightCalcPos, new SimpleVector(0,1,0), 100);

The terrHeightUp should be when the SimpleVector (heightCalcPos) is below the terrain and return the terrein height in negative value.
but as the terrain is not dual sided it looks straight through it and always returning 2147483647.

Is there a (simple) solution for this?
Or should I make the terrain dualsided (cpu and memory eating process), if so, how?

Current terrain generating script:
Code: [Select]
public class Terrain {

//private static float[][] terrain = new float[128][128];
//private static Object3D ground = null;

public static Object3D Generate(int X_SIZE, int Z_SIZE, TextureManager tm, String TextureID){
/** Generate ground **/
//int X_SIZE = 128;
//int Z_SIZE = 128;
float[][] terrain = new float[X_SIZE][Z_SIZE];

for (int x = 0; x < X_SIZE; x++) {
for (int z = 0; z < Z_SIZE; z++) {

terrain[x][z] = -20 + (float) Math.random() * 40f; // Very simple....
}
}
for (int x = 0; x < X_SIZE - 1; x++) {
for (int z = 0; z < Z_SIZE - 1; z++) {
terrain[x][z] = (terrain[x][z] + terrain[x + 1][z] + terrain[x][z + 1] + terrain[x + 1][z + 1]) / 4;
}
}
Object3D ground = new Object3D(X_SIZE * Z_SIZE * 2);

float xSizeF = (float) X_SIZE;
float zSizeF = (float) Z_SIZE;

int id = tm.getTextureID(TextureID);

for (int x = 0; x < X_SIZE - 1; x++) {
for (int z = 0; z < Z_SIZE - 1; z++) {
/**
* We are now taking the heights calculated above and build the
* actual triangles using this data. The terrain's grid is fixed
* in x and z direction and so are the texture coordinates. The
* only part that varies is the height, represented by the data
* in terrain[][]. jPCT automatically takes care of vertex
* sharing and mesh optimizations (this is why building objects
* this way isn't blazing fast...but it pays out in the
* end...:-)) The Mesh is build with triangle strips in mind
* here. The format for these strips is equal to that of
* OpenGL's triangle strips.
*/

TextureInfo ti = new TextureInfo(id, (x / xSizeF), (z / zSizeF), ((x + 1) / xSizeF), (z / zSizeF), (x / xSizeF), ((z + 1) / zSizeF));
ground.addTriangle(new SimpleVector(x * 10, terrain[x][z], z * 10), new SimpleVector((x + 1) * 10, terrain[x + 1][z], z * 10),
new SimpleVector(x * 10, terrain[x][z + 1], (z + 1) * 10), ti);

ti = new TextureInfo(id, (x / xSizeF), ((z + 1) / zSizeF), ((x + 1) / xSizeF), (z / zSizeF), ((x + 1) / xSizeF), ((z + 1) / zSizeF));
ground.addTriangle(new SimpleVector(x * 10, terrain[x][z + 1], (z + 1) * 10), new SimpleVector((x + 1) * 10, terrain[x + 1][z], z * 10), new SimpleVector((x + 1) * 10,
terrain[x + 1][z + 1], (z + 1) * 10), ti);
}
}

return ground;
}
}

Optional:
I would like to use height-maps instead of randomly generated terrain.
How would I go on about that?

Kind regards,
Kaiidyn.

95
Support / Re: Position in world-space
« on: November 24, 2010, 09:13:09 pm »
Ah yes, setting the ignoreIfLarger fixes the framerate indeed :D

Thanks for the help (again =p) =]

96
Support / Re: Starting a new project
« on: November 24, 2010, 06:47:16 pm »
How to start
Google for eg. jpct Moving object.\

Basically when you want to move an object you use translate(x,y,z) or translate(new SimpleVector(x,y,z)) in the renderloop
the translate works in object-space, so just putting 1 in the x will continually move the object to the right.

97
Support / Re: Position in world-space
« on: November 24, 2010, 06:21:22 pm »
Okay,

I got this working:
terrHeight = ground.calcMinDistance(playerPos, new SimpleVector(0,1,0));

But I get a framerate drop like.... INSANE.
Could you explain the other method a bit more?
As I don't really understand what it is supposed to do (or how to make it)

Kind regards,
Kaiidyn.

98
Support / Position in world-space
« on: November 24, 2010, 01:43:28 pm »
I need to get the position of my object in world space.
and with that I need to get the terrain height (terrain generated with this script: http://www.jpct.net/forum2/index.php/topic,1343.0.html )

Something like

Code: [Select]
SimpleVector playerPosition = new SimpleVector();
playerPosition.set(player.getPositionInWorldSpace());
ground.getHeight(playerPosition.x, playerPosition.z);

Is this possible?

Kind regards,
Kaiidyn.

99
Support / Re: Rotating Object
« on: November 23, 2010, 10:55:21 pm »
Awesome, got it working now :)
thanks mate

100
Support / Rotating Object
« on: November 23, 2010, 03:23:53 pm »
When using Object3D.rotateX the object rotates the object with the value given.
Is it possible to do like Object3D.rotateX(Math.toRadians(45)); in the renderloop and keep the object rotated at 45 degrees, instead of adding 45 deg. to the current rotation value?

Edit: Also is it possible to get the current rotate value?

101
Support / Re: Texturing a Primitive
« on: November 21, 2010, 10:32:42 pm »
OK, thanks for the reply..
I currently don't have any modelling programs installed that I can actually work with,
Do have AC3D and Blender installed, but AC3D's export function just fails, and I don't like how Blender works.
Will download 3ds Max again when I'm at my parents place with better internet =p (next weekend:p)
Unless someone else could model me a button like this one or this one that can animate (pressing the button) *puppyeyes* :p

Kind regards and thanks again,
Kaiidyn.

Edit: Managed to get it working with AC3D :)

102
Projects / Re: Alpha version of Benchmark, was: GUI example anyone?
« on: November 21, 2010, 01:53:00 pm »
Fillrate ST/MT 9.56/9.57 MP/sec.
High object count: 37.21 fps
Multiple lights: 55.61 fps
High polygon count: 45.39 fps
Keyframe animation: 55.70fps
Game level: 55.75 fps
TOTAL SCORE: 6760

On a SGS

103
Support / Texturing a Primitive
« on: November 21, 2010, 10:06:09 am »
Hello,

I just started out a couple of days ago with 3D programming for Android,
And jPCT-ae really got my attention, It's easy to use and well documented.
But I got a problem putting a texture on a Ellipsoid primitive.

Code: [Select]
TextureManager.getInstance().flush();
TextureManager tm = TextureManager.getInstance();
Resources res = Engine.resources;

/** LOAD TEXTURES **/
Texture random = new Texture(Engine.resources.getDrawable(R.raw.random));
tm.addTexture("random", random);

TextureInfo randomTex = new TextureInfo(tm.getTextureID("random"));

button1 = Primitives.getEllipsoid(64, 0.5f);
button1.setTexture(randomTex);
button1.build();
button1.translate(0, -125, 0);
world.addObject(button1);
All this code is located in onSurfaceCreated.

The texture I'm trying to put on.

I got the feeling it does actually work, but partially,
As I see my entire mesh in red.
I think I need to do something with the UV Mapping, but have no idea how that works.
Or, it has something to do with texture scaling.. that the image is too big for the object.

My question therefor is, how do I downscale the texture to match my object, or how does UV Mapping work?

Kind regards,
Kaiidyn.


Edit:
Figured out that it is actually a problem with the UV mapping,
the center of the texture (where i have the text) gets put on the side of the Ellipsoid that has been squeezed by the scaleHeight.
What I want is that the text in the texture is set on the top of the primitive as a button, like This one.
But I have no idea how to do that.

Pages: 1 ... 5 6 [7]