Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 2 3 [4] 5 6
  ignore  |  Print  
  LWJGL - Voxel Engine  (Read 15814 times)
0 Members and 1 Guest are viewing this topic.
Offline Pauler
« Reply #90 - Posted 2013-04-15 22:05:28 »

Now, that I read my reply again I see that it can also have another meaning. I am talking about the array lists and the arrays not about display lists and vbos.

I am using display lists, too , btw.
Offline steg90

Senior Member


Medals: 1



« Reply #91 - Posted 2013-04-15 22:23:43 »

Mmmmm, so what are you using instead of ArrayLists, thought this would be ok?

Thanks
Offline Vermeer

JGO Coder


Medals: 16



« Reply #92 - Posted 2013-04-15 22:30:28 »

I think pauler may mean  to use an array for chunkdata rather than an arrayList?


Edit: I didn't see the 2 above posts, sorry!

Chunk[]

Or Chunk [][][]


So.  Chunk[c].render
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline steg90

Senior Member


Medals: 1



« Reply #93 - Posted 2013-04-15 22:43:55 »

Would that not mean having a static world with Chunk being a static array?

Thanks
Offline Vermeer

JGO Coder


Medals: 16



« Reply #94 - Posted 2013-04-15 22:55:05 »

Perhaps the array[][][] is relative to the player in some way.
Could this array have bounds of say [64][16][64]

And if your position gets near the edge, the new chunks are loaded at the other end of the array in a wrap around effect?

This is pure speculation, as I did have mine represent a static world.

But I think I may try that idea and see if it works...... Smiley
Offline Roquen
« Reply #95 - Posted 2013-04-15 23:02:38 »

Multiple dimension arrays smell bad...esp with fixed lengths.
Offline steg90

Senior Member


Medals: 1



« Reply #96 - Posted 2013-04-15 23:19:04 »

I don't think the bottle neck is the ArrayList, more to do with my distance formula, I've now got this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
         int deltax=Math.abs((int)x - (c.getX() * 32));
         int deltaz=Math.abs((int)z - (c.getZ() * 32));
         int deltay = 1;
         float distance=(float)Math.sqrt((deltax*deltax)+(deltay*deltay)+(deltaz*deltaz));
   
         if(distance < Chunk.CHUNK_SIZE * 8)
         {
            c.render();
         }


* EDIT - this seems to work better but don't know if it is the correct way?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
for(Chunk c : ChunkList)
      {        
         int calc = Math.abs((int)(c.getX() * Chunk.CHUNK_SIZE) - (int)Math.abs(x));
         if(calc < Chunk.CHUNK_SIZE * 2)
         {
            calc = Math.abs((int)(c.getZ() * Chunk.CHUNK_SIZE) - (int)Math.abs(z));
            if(calc < Chunk.CHUNK_SIZE * 2)            
            {
               c.render();
            }
         }
      }


x and y are player position, c.getX and c.getZ are chunks offset, thus chunk 1 is at offset 0, chunk 2 is at offset 1 * Chunk.ChunkSize, offset 2 is at 2 * Chunk.ChunkSize...

But it seems as I get closer to the chunks they are then not rendered? Kind of like reverse effect?!
Offline Pauler
« Reply #97 - Posted 2013-04-17 17:51:31 »

Offline steg90

Senior Member


Medals: 1



« Reply #98 - Posted 2013-04-17 20:52:12 »

That is looking nice.

BTW - do you only hold a certain amount of chunks in memory, i.e. the ones you can see?

Offline Pauler
« Reply #99 - Posted 2013-04-17 21:21:14 »

Less chunks that I can see.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline TH3Fatal

Junior Member


Medals: 2



« Reply #100 - Posted 2013-04-17 21:46:35 »

This looks very nice but forgive me I just quickly read most the posts and was wondering what makes this different from minecraft? Also do you have a way to save and load maps yet?

Offline Pauler
« Reply #101 - Posted 2013-04-17 21:55:18 »

This looks very nice but forgive me I just quickly read most the posts and was wondering what makes this different from minecraft? Also do you have a way to save and load maps yet?
No, it doesn't save or load maps.

Also, I am not trying to create something different. I am justing trying to learn new stuff.
Offline steg90

Senior Member


Medals: 1



« Reply #102 - Posted 2013-04-17 21:58:13 »

To clarify - you only hold the chunks you can see in memory?

@TH3Fatal - we are all doing these sort of 'minecraft' clones for learning purposes :-)
Offline Pauler
« Reply #103 - Posted 2013-04-17 22:05:00 »

I save the chunks which are really close to me temporary to a list, in which I do all my checks. Collision, block picking, etc.
Offline TH3Fatal

Junior Member


Medals: 2



« Reply #104 - Posted 2013-04-17 22:13:35 »

@TH3Fatal - we are all doing these sort of 'minecraft' clones for learning purposes :-)

So am I well the voxel aspect because I have an idea for a small game that can use voxels instead of diving in the deep end of java game development

Offline steg90

Senior Member


Medals: 1



« Reply #105 - Posted 2013-04-17 22:28:56 »

@Pauler - ok, and do you only store these chunks in memory?  What I'm saying is, I have an ArrayList which stores chunks, at the moment it stores all the chunks in my game, which, obviously is a big bottle neck and this isn't how to do it.  I believe you only add chunks to memory when you can see them and remove the ones you can't?

For instance, if you have 64x64 chunks, this in my game is (64x4096 blocks) x (64x4096 blocks) = 524288 , now unless you got a decent graphics card with a good deal of memory, memory will run out.  My gfx card is an Intel 3000 HD, so not very good, uses shared memory I believe??

What I am getting at the moment in my game is, say with 16x16 chunks, runs fine, but once all chunks have been seen, the game slows down and CPU usage goes to 64%...If I then reset my camera position back to 0,0,0 the CPU usage drops back to 19% - any ideas what this could be?!

Thanks 
Offline steg90

Senior Member


Medals: 1



« Reply #106 - Posted 2013-04-18 13:53:23 »

Improved chunk management - dynamic loading and unloading. 
Face culling,
Block culling,
Chunk culling,
Simple block picking,


https://www.youtube.com/watch?v=9Bo9Au2ph4I

Thanks,
Steve

Offline Roquen
« Reply #107 - Posted 2013-04-18 20:03:52 »

Hashing will be significantly slower than a dynamic array.
Offline pitbuller
« Reply #108 - Posted 2013-04-18 20:35:12 »

I don't think the bottle neck is the ArrayList, more to do with my distance formula, I've now got this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
         int deltax=Math.abs((int)x - (c.getX() * 32));
         int deltaz=Math.abs((int)z - (c.getZ() * 32));
         int deltay = 1;
         float distance=(float)Math.sqrt((deltax*deltax)+(deltay*deltay)+(deltaz*deltaz));
   
         if(distance < Chunk.CHUNK_SIZE * 8)
         {
            c.render();
         }




Why you use math abs? Multiplying real number with itself make it positive always. Also you don't need sqrt when comparing distances.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
         int deltax=(int)x - c.getX() * 32;
         int deltaz=(int)z - c.getZ() * 32;
         int deltay = 1;
         int distance2=deltax*deltax+deltay*deltay+deltaz*deltaz;
                   int radius2 = (Chunk.CHUNK_SIZE * 8)
                        radius2*=radius2;//precalculate this
        if(distance2 < radius2)
         {
            c.render();
         }


Offline Vermeer

JGO Coder


Medals: 16



« Reply #109 - Posted 2013-04-18 22:43:33 »

@pauler and @steg.

Both projects looking great. Hoping to get some time to tackle a very large map....Been researching threads to help with getting chunks ready in the background.

I need to do some optimising still first tho!

Your both inspiring me to do more as your projects look great. Smiley
Offline steg90

Senior Member


Medals: 1



« Reply #110 - Posted 2013-04-19 08:55:11 »

@Pitbuller - Not using that formula anymore, didn't seem to work for me. Thanks anyway.

@Vermeer - Your project(s) inspire me ;-)  I was thinking of putting a thread in for the dynamic loading - basically run a thread, check if chunk is in view or not, if not, remove from memory (active chunklist array).

@Roquen - dynamic array - thus back to an ArrayList?  This would only be faster if used object indexes - thus say object 10 would be index 10, will have a think about this as need fast look ups.

Offline steg90

Senior Member


Medals: 1



« Reply #111 - Posted 2013-04-19 12:02:36 »

Just added frustum culling but finding using the distance formula better...

As anybody else implemented frustum culling in their voxel project and how does it fair over
doing a distance check?

I think I will use frustum culling for other objects in my project, not for the voxels, will stick with distance formula.
Offline Pauler
« Reply #112 - Posted 2013-04-19 22:22:36 »

<a href="http://www.youtube.com/v/8QPOuDn-ZXA?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/8QPOuDn-ZXA?version=3&amp;hl=en_US&amp;start=</a>

Added save and load.

PS: Camtasia destroyed the fps.
Offline TH3Fatal

Junior Member


Medals: 2



« Reply #113 - Posted 2013-04-19 22:24:50 »

Looks awesome so fare. Nice to see save and loading is working for you Smiley I just got save and loading done for me voxel game thanks to Vermeer.  Cool

Offline pitbuller
« Reply #114 - Posted 2013-04-20 00:04:37 »

Just added frustum culling but finding using the distance formula better...

As anybody else implemented frustum culling in their voxel project and how does it fair over
doing a distance check?

I think I will use frustum culling for other objects in my project, not for the voxels, will stick with distance formula.
Frustum culling is dead cheap. Distance formula can't be faster than it if you use it right. Draw call is at least magnitude slower than any sane bounding box frustum culling method that you can ever write.
For iOs project I frustum cull every particle as optimization.(Sphere frustum test. Even this is better than distance checkl) This was faster than rendering them all with one draw call even before any simd optimizions.
Offline steg90

Senior Member


Medals: 1



« Reply #115 - Posted 2013-04-20 00:30:30 »

Quote
Frustum culling is dead cheap. Distance formula can't be faster than it if you use it right. Draw call is at least magnitude slower than any sane bounding box frustum culling method that you can ever write.

I'm using mark morleys frustum cull, maybe I got it wrong somewhere?

Code: http://pastebin.java-gaming.org/83b53604950

To use the cubeInFrustum, it states to supply the centre of the cube and half the size which is what I'm doing in my code.  Must admit, I don't think it is working as it should though, maybe I've got the x,z and size wrong - I'm taking it that X is half the width and Z half the depth of the chunk - my chunks being 16 blocks wide and 16 blocks depth, you can see I just times the x by 8 and z by 8.
Offline Roquen
« Reply #116 - Posted 2013-04-20 08:27:10 »

The thing about frustum culling is that you should need to check a very small percentage of regions.  At a logical top level you're checking against 5 gradient space (one less since far and near are offsets), quickly planes will drop away as a child region is either totally inside or outside and you're finally left with none to check.
Offline Pauler
« Reply #117 - Posted 2013-04-20 19:27:59 »

This is my first open gl project so I also lack some basic knowledge.

Can some one help me to turn the quads to triangles? It seems a bit complicated as far as I call glbegin and glend only once.

This my code in case you are interested:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
public void renderFace(int side) {
     
      switch(side) {
     
      case 1: //bot
       
         GL11.glTexCoord2f(spriteX, spriteY + small);   GL11.glVertex3f(x1, y1, z1);
         GL11.glTexCoord2f(spriteX, spriteY);   GL11.glVertex3f(x1 + width, y1, z1);
         GL11.glTexCoord2f(spriteX + small, spriteY);   GL11.glVertex3f(x1 + width, y1, z1 + length);
         GL11.glTexCoord2f(spriteX + small, spriteY + small);   GL11.glVertex3f(x1, y1, z1 + length);
         break;
     
      case 2: //top
       
         GL11.glTexCoord2f(spriteX, spriteY + small);   GL11.glVertex3f(x1, y1 + height, z1);
         GL11.glTexCoord2f(spriteX, spriteY);   GL11.glVertex3f(x1, y1 + height, z1 + length);
         GL11.glTexCoord2f(spriteX + small, spriteY);   GL11.glVertex3f(x1 + width, y1 + height, z1 + length);
         GL11.glTexCoord2f(spriteX + small, spriteY + small);   GL11.glVertex3f(x1 + width, y1 + height, z1);
         break;
         
      case 3: //back
        GL11.glTexCoord2f(spriteX + small, spriteY + small);   GL11.glVertex3f(x1, y1, z1 + length);
         GL11.glTexCoord2f(spriteX, spriteY + small);   GL11.glVertex3f(x1 + width, y1, z1 + length);
         GL11.glTexCoord2f(spriteX, spriteY);   GL11.glVertex3f(x1 + width, y1 + height, z1 + length);
         GL11.glTexCoord2f(spriteX + small, spriteY);   GL11.glVertex3f(x1 , y1 + height, z1 + length);
         break;
         
      case 4: //front
       
         GL11.glTexCoord2f(spriteX, spriteY + small);   GL11.glVertex3f(x1, y1, z1);
         GL11.glTexCoord2f(spriteX, spriteY);   GL11.glVertex3f(x1, y1 + height, z1);
         GL11.glTexCoord2f(spriteX + small, spriteY);   GL11.glVertex3f(x1 + width, y1 + height, z1);
         GL11.glTexCoord2f(spriteX + small, spriteY + small);   GL11.glVertex3f(x1 + width, y1, z1);  
         break;
         
      case 5: //left
        GL11.glTexCoord2f(spriteX + small, spriteY + small);   GL11.glVertex3f(x1, y1, z1);
         GL11.glTexCoord2f(spriteX, spriteY + small);   GL11.glVertex3f(x1, y1, z1 + length);
         GL11.glTexCoord2f(spriteX, spriteY);   GL11.glVertex3f(x1, y1 + height, z1 + length);
         GL11.glTexCoord2f(spriteX + small, spriteY);   GL11.glVertex3f(x1, y1 + height, z1);
         break;
     
      case 6:
         GL11.glTexCoord2f(spriteX, spriteY + small);   GL11.glVertex3f(x1 + width, y1, z1);
         GL11.glTexCoord2f(spriteX, spriteY);   GL11.glVertex3f(x1 + width, y1 + height, z1);
         GL11.glTexCoord2f(spriteX + small, spriteY);   GL11.glVertex3f(x1 + width, y1 + height, z1 + length);
         GL11.glTexCoord2f(spriteX + small, spriteY + small);   GL11.glVertex3f(x1 + width, y1, z1 + length);
         break;
         
      }
     
   }
Offline Pauler
« Reply #118 - Posted 2013-04-22 13:27:51 »

up.
Offline TH3Fatal

Junior Member


Medals: 2



« Reply #119 - Posted 2013-04-22 13:47:08 »

Are you talking about a 3D triangle or a 2D triangle?

Pages: 1 2 3 [4] 5 6
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (25 views)
2014-04-15 18:08:23

BurntPizza (20 views)
2014-04-15 03:46:01

UprightPath (36 views)
2014-04-14 17:39:50

UprightPath (18 views)
2014-04-14 17:35:47

Porlus (34 views)
2014-04-14 15:48:38

tom_mai78101 (60 views)
2014-04-10 04:04:31

BurntPizza (118 views)
2014-04-08 23:06:04

tom_mai78101 (218 views)
2014-04-05 13:34:39

trollwarrior1 (185 views)
2014-04-04 12:06:45

CJLetsGame (192 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!