Voxel - a start

Tried just updating new position and not camera before checking collision, same result.

Code:

http://pastebin.java-gaming.org/3ebf334355c

Note, I’m still checking all the blocks in the chunk - dunno if this is causing the issue of when collision occurs when moving forwards for instance, I then turn around and move forwards, still collision - thus cannot move forwards. This still using AABB too. I’ve just put this in for a simple collision check with no AABB:


Vector3f v = camera.getCameraPosition();
int bx = (int)Math.abs(Math.floor(v.x));
int by = (int)Math.abs(Math.floor(v.y));
int bz = (int)Math.abs(Math.floor(v.z));
Block b = ChunkManager.getInstance().getBlockInChunk(0, bx, by, bz);
if(b.IsActive())
{
	// A collision
}

Need to check other blocks too as @HeroesGraveDev suggests.

*EDIT

Added this:


outerloop:
		for(int x=-1; x < 2; x++)
			for(int y=0; y< 2; y++)
				for(int z=-1; z< 2; z++)
				{
					int bx = (int)Math.abs(Math.floor(v.x))+x;
					int by = (int)Math.abs(Math.floor(v.y))+y;
					int bz = (int)Math.abs(Math.floor(v.z))+z;
					Block b = null;
					b = ChunkManager.getInstance().getBlockInChunk(0, bx, by, bz);
					if(b!=null && b.IsActive())
					{
						loopblockCollision = "LOOP COLLISION FOUND";
						break outerloop;
					}
					else
						loopblockCollision = "LOOP NO COLLISION";
					
				}
		

Video: https://www.youtube.com/watch?v=G1J4GlA0fMk

This gives more accurate collision, now, what to do when there is a collision??

Added some random trees - not very good ones!


https://www.youtube.com/watch?v=kgye7xeCbVI

I see, you are making progress there. :slight_smile: The trees look ok, just some of them may be a bit too small.

Do you plan adding ray casting for voxel picking soon?

Hi Sparky,

Trees need making better - going to look at making them better.

Yes, need to look at the ray casting - still also need go back to collision checks too!

Been working on culling etc, got a lot more fps when removing faces that don’t need drawing and was easy to put in.

Just put my code over to a Dell XPS M1530 laptop - cannot even get one chunk to render 60fps - where as on my mac with an intel 3000 hd graphics card it is fine? I put the code on also a few days ago and it ran fine then, my code hasn’t really changed, don’t know what has happened? Windows had done some updates, but cannot see how that would be making it run so slow? Minecraft is still running on it fine…

Very strange.

Are you using VBOs or DisplayLists or ImmediateMode?
If you are using VBOs, maybe there is a problem with memory. I had some problems at first, then I changed a bit of my code to use VBOs properly and it was better since then.

Hi Sparky,

Using display lists…

I have updated the driver to the latest, maybe this could be the issue?!

Try using jvisualvm to see where the bottleneck is.

Will take a look at the profiler.

Looking at an older project which works fine on the Dell, the main change was using replacing my arraylist to a hashmap, but surely that can’t be the bottle neck?!

My skybox also doesn’t render correct on new version, it just looks like all garbage and I’ve
not even modified the code for that, its been the same for weeks.

It depends on how you’ve used the HashMap.

Just used it to store chunks, then I loop through this hashmap to render them.

Having problems getting the profile tab to appear in visualvm…

This code is causing the issue on the Dell:


private CollisionType isCollision(int dir) {

		Vector3f v = this.camera.getCameraPosition();

		float tempx = (v.x) / BLOCKWIDTH * BLOCKHEIGHT;
		int tempX = (int) tempx;

		float tempz = (v.z) / BLOCKWIDTH * BLOCKHEIGHT;
		int tempZ = (int) tempz;

		float tempy = (v.y) / BLOCKWIDTH * BLOCKHEIGHT;
		int tempY = (int) tempy;

		int bx = (int) tempX;
		int by = (int) tempY;
		int bz = (int) tempZ;

		bx = bx % BLOCKWIDTH;
		bz = bz % BLOCKHEIGHT;
		by = by % BLOCKHEIGHT;

		int zchunk = Math.abs(tempZ / Chunk.CHUNK_SIZE) * WORLDWIDTH;
		int xchunk = Math.abs(tempX / Chunk.CHUNK_SIZE);
		int chunktoget = zchunk + xchunk;

		CollisionType collisionType = CollisionType.NONE;

		Block b = null;
		b = ChunkManager.getInstance().getBlockInChunk(chunktoget,
				Math.abs(bx), (int) Math.abs(by), Math.abs(bz));

		// Check ground
		if (b != null && b.IsActive()) {
			// playerSphere radius is 1
			Vector playerPosition = new Vector();
			playerPosition.x = Math.abs(v.x);
			playerPosition.y = Math.abs(v.y);
			playerPosition.z = Math.abs(v.z);
			playerSphere.update(playerPosition, 1.0f);

			AABB voxel = new AABB(1f, 1f, 1f); // width, height, depth
			Vector voxelPosition = new Vector();
			voxelPosition.x = Math.abs(bx);
			voxelPosition.y = Math.abs(by);
			voxelPosition.z = Math.abs(bz);
			voxel.update(voxelPosition);

			if (CollisionLibrary.testCircleAABB(playerSphere, voxel)) {
				collisionType = CollisionType.GROUND;
				groundLevel = (int) voxelPosition.y;
			}
		}

		// Check chunk for any collisions - should have early bail out
		for (int x = 0; x < Chunk.CHUNK_SIZE; x++) {
			for (int y = 2; y < Chunk.CHUNK_SIZE; y++) {
				for (int z = 0; z < Chunk.CHUNK_SIZE; z++) {
					b = ChunkManager.getInstance().getBlockInChunk(chunktoget,
							x, y, z);

					if (b != null && b.IsActive()) {

						Vector playerPosition = new Vector();
						playerPosition.x = Math.abs(v.x);
						playerPosition.y = Math.abs(v.y);
						playerPosition.z = Math.abs(v.z);
						playerSphere.update(playerPosition, .8f);

						AABB voxel = new AABB(1f, 1f, 1f); // width, height,
															// depth
						Vector voxelPosition = new Vector();
						voxelPosition.x = x;
						voxelPosition.y = y;
						voxelPosition.z = z;
						voxel.update(voxelPosition);

						if (CollisionLibrary
								.testCircleAABB(playerSphere, voxel)) {
							if (direction == 0) {
								collisionType = CollisionType.FRONT;
							}
							if (direction == 1) {
								collisionType = CollisionType.BACK;
							}
							if (direction == 2) {
								collisionType = CollisionType.LEFT;
							}
							if (direction == 3) {
								collisionType = CollisionType.RIGHT;
							}
							return collisionType;
						}
					}
				}
			}
		}

		return collisionType;
	}


Not calling, the game is fine - but the above is fine on my mac?

Update:

Some collision…
Random landscape creation
Very basic trees
Random items


https://www.youtube.com/watch?v=19-0c1iGA2I

Thanks

I like how that’s all looking, looks good with the trees and other blocks in the landscape. Really cool :slight_smile:

Take a look at:

Thanks

The domes look great. Add a surreal feel to the landscape. It’s really looking like a world now, an interesting place to look around! :slight_smile:

Thanks pal :slight_smile:

PS - any insight into how you did the infinite landscape?

To have infinite terrain generation you need 3 things, dynamic storage of world, procedural generation, and chunk loading/unloading.

The first can be achieved by storing chunks in a HashMap
The second I believe you already have, but it might need some adjusting depending on how you did it.
The third is two parts:

  • Loading chunks: You need to loop through all the places a chunk could be in a certain area, then add those positions to and arraylist if a) there isn’t a chunk there, and b) they aren’t already in that list, or the generating list. Then you take chunk positions out of that list, add them to a generating list, and put them in a chunk generation thread. Then every frame, you take complete chunks out of the generating list, and add them to the world.
  • Unloading chunks. Loop through all the loaded chunks, and if they are too far away, unload them.

Seeing as there will be a LOT of methods that read data out of the chunks I prefer to use a fixed size array for it for performance reasons. Just add a couple of shift functions so you can move the relative position of the array when you load/unload data and you’re good to go.

Mike

I used a fixed array of chunks. When you walk into a new chunk the direction indicates that chunks in the distance needs to be loaded. If it is on disk it overwrites the chunks in the array which would be behind you.

This way you only need a fixed amount of chunks. If the chunks don’t exist, I create a new row of them. I used a very basic diamond star idea. The chunk is then saved.

Chunk generation:

I have tried to illustrate the concept. Please note that it is scaled down and not a full implementation of it! Adjust as needed for walking in other directions.

Please ask if I have not covered it very well!