Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 ... 6
  ignore  |  Print  
  LWJGL - Voxel Engine  (Read 18318 times)
0 Members and 1 Guest are viewing this topic.
Offline Pauler
« Posted 2013-03-28 09:12:30 »

Hey that's the current state of the engine.

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



Hello there, I just started the development of a voxel engine. I seperated the world to 100 chunks, each one containes 16x16x16 dirt blocks. So, I used the distance formula in order to draw only the chunks which are max 32 blocks away from me.

The problem is that when I am starting to go away from the chunks the first chunks that dissappear are the ones which are closer to me, when the opposite was supposed to happend. The whole idea doesn't seem to work good. Can you see what's wrong or can you recommend any other way (with an example) about how to draw only the closest chunks in a x radious?

The distance formula I used:


1  
(float)Math.sqrt(Math.pow(camera.position.x - chunk.centerX,2) + Math.pow(camera.position.y - chunk.centerY,2) + Math.pow(camera.position.z - chunk.centerZ,2)) <  32*Block.width


Where Block.width = 0.7f;

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

Thank you.
Offline Vermeer

JGO Coder


Medals: 16



« Reply #1 - Posted 2013-03-28 09:30:24 »

Hi

You could make it easier to start by just drawing the ones in a square around the player,

Pseudo code;

If(abs(Cam.position.x-chunk.centre.x)<chunk.width*howManyCuncksToDraw) && same for z

Then draw.

Also, it may be best to change the block width to 1f, this may make future things easier.

It's looking good tho  Smiley
Offline Pauler
« Reply #2 - Posted 2013-03-28 09:42:54 »

Thank you for your reply.

I get the exact same result.  Clueless

1  
Math.abs(camera.position.x - chunk.centerX) < World.CHUNK_WIDTH && Math.abs(camera.position.z - chunk.centerZ) < World.CHUNK_LENGTH
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Vermeer

JGO Coder


Medals: 16



« Reply #3 - Posted 2013-03-28 09:48:26 »

Yep, I agree...  The problem must lie somewhere else, what about how you

Draw the chunks.. Are you offsetting the vertecies or chunks, or translating them?
Offline Pauler
« Reply #4 - Posted 2013-03-28 09:58:01 »

Offsetting.
Offline Vermeer

JGO Coder


Medals: 16



« Reply #5 - Posted 2013-03-28 10:13:07 »

I tried this code in my game and it works as expected.


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
for(int c= 0;c<numberOfChunks;c++){
         if(Math.abs(chunks[c].getX()-(int)xpos)<CHUNK_SIZE*2){
            if(Math.abs(chunks[c].getZ()-(int)zpos)<CHUNK_SIZE*2){
            GL11.glLoadIdentity();
            GL11.glRotatef(lookupdown, 1.0f, 0, 0);
            GL11.glRotatef(360.0f - yrot, 0, 1.0f, 0);
            GL11.glTranslatef(-xpos, camHieght , -zpos);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, 1);
            render4(chunks[c]);
            }
         }
      }



Did you offset your vertecies per chunk, or use the world co-ordinates.  Mine are per cunk.

I hope this may be of some help, perhapse more experienced mebers can identify the problem you have?

Offline Pauler
« Reply #6 - Posted 2013-03-28 10:21:12 »

I tried this code in my game and it works as expected.

Did you offset your vertecies per chunk, or use the world co-ordinates.  Mine are per cunk.

I hope this may be of some help, perhapse more experienced mebers can identify the problem you have?



I offset the cubes using common axis for all chunks.
Online matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #7 - Posted 2013-03-28 12:07:24 »

 Shocked

Math.pow(...);
?!? You shouldn't use that one. It's horribly slow. It used for mathematical expressions like
Math.pow(10, 1.45);
.

If you want to have 10 squared you do this:
1  
10*10


If you want to have an expression to be squared then you save it into a variable and multiply it by itself:
1  
2  
int expression = ... ;
int squared = expression * expression;

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Roquen
« Reply #8 - Posted 2013-03-28 12:13:31 »

Think point to plane distance.
Offline Pauler
« Reply #9 - Posted 2013-03-28 12:15:21 »

Think point to plane distance.

I am pretty sure, it gonna have the same result.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mike

JGO Ninja


Medals: 71
Projects: 1
Exp: 5 years


Java guru wanabee


« Reply #10 - Posted 2013-03-28 14:17:46 »

Maybe this is a silly question, but are you sure that when you move the camera, you are moving it in the correct direction without any kind of translate or inverted axis? Smiley

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline Roquen
« Reply #11 - Posted 2013-03-28 14:23:06 »

view frustum is a near plane, a far plane + top,bottom,right,left.  near/far are just offsets from one another and a uniform grid is easy to parametrize in terms of the planes coordinate frame, you can then hierarchically (and very cheaply) reject points...aka outside of view.   
Offline Pauler
« Reply #12 - Posted 2013-03-28 14:49:06 »

Maybe this is a silly question, but are you sure that when you move the camera, you are moving it in the correct direction without any kind of translate or inverted axis? Smiley

Mike
Dude, you are awesome, thank you. Yeah, the axis where inverted in the camera class, not in the distance formula as I thought in the first place. It works now.
Offline Pauler
« Reply #13 - Posted 2013-03-28 14:51:23 »

Leave this open if it is possible because I am sure much more problems will popup, soon.
Offline Mike

JGO Ninja


Medals: 71
Projects: 1
Exp: 5 years


Java guru wanabee


« Reply #14 - Posted 2013-03-28 16:23:40 »

Dude, you are awesome, thank you. Yeah, the axis where inverted in the camera class, not in the distance formula as I thought in the first place. It works now.

I guess the wrong post was quoted? Smiley

No problem at all, will you stop ruining other people's buildings in SoF now? ;-)

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline Pauler
« Reply #15 - Posted 2013-03-28 21:56:43 »

Another two problems. I cannot really see what causes them.

The first one is that at the left bottom corner of the bottom side of every chunk is not being drawn correctly. It seems that for some reason it grabs some parts of the neighbour texture. (Keep in mind that I use the old minecraft spritesheet for testing.)

The second one is that the back side of the grass blocks is not being rendered correctly, too. I found out that when I remove the texture from the top side of the grass block this bug dissapears.

First one:
http://tinypic.com/r/2mw7zaa/6

Second one:
http://i50.tinypic.com/2cpx82d.png

Normal block render function: (The chunk render function calls this method for each block.)
http://pastebin.java-gaming.org/5b8dd3c1753

Grass block render: (I used a differend method because it doesn't folow the same pattern. It takes the texture rotated, and it uses another texture for top side.)
http://pastebin.java-gaming.org/b8ddc47135e

<a href="http://www.youtube.com/v/miI4i0Qp76k?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/miI4i0Qp76k?version=3&amp;hl=en_US&amp;start=</a>
Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #16 - Posted 2013-03-28 22:21:29 »

Your problems are caused by incorrect texture coordinates.

Unfortunately, trying to read the provided code hurts my brain. Wink

Check over all the coordinates.

Also: DON'T USE GL_QUADS!

Offline Pauler
« Reply #17 - Posted 2013-03-28 22:29:09 »

Your problems are caused by incorrect texture coordinates.

Unfortunately, trying to read the provided code hurts my brain. Wink

Check over all the coordinates.

Also: DON'T USE GL_QUADS!

I use display lists and and I have reduced the use of some rendering commands as much as possible.

Also, I don't believe that it comes from a coords mistake, because I had the same problem at an old project. (Except if I made the same mistake back then.)

If these errors are caused by coords mistakes then these mistakes are surerly good hidden.

PS: My next step would be to use vbos.
Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #18 - Posted 2013-03-28 22:39:16 »

Your problems are caused by incorrect texture coordinates.

Unfortunately, trying to read the provided code hurts my brain. Wink

Check over all the coordinates.

Also: DON'T USE GL_QUADS!

I use display lists and and I have reduced the use of some rendering commands as much as possible.

Also, I don't believe that it comes from a coords mistake, because I had the same problem at an old project. (Except if I made the same mistake back then.)

If these errors are caused by coords mistakes then these mistakes are surerly good hidden.

PS: My next step would be to use vbos.

Well, it definitely looks to me like a coords mistake.
I think that because the textures are warped towards the corners - a common sign of misplaced tex coords.

Offline Mike

JGO Ninja


Medals: 71
Projects: 1
Exp: 5 years


Java guru wanabee


« Reply #19 - Posted 2013-03-28 22:47:03 »

It is definitely looks like a texture coord issue, maybe not in the code you posted, but somewhere it is. You need to post more code to be able to say where the issue is.

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline Pauler
« Reply #20 - Posted 2013-03-29 18:43:34 »

It is definitely looks like a texture coord issue, maybe not in the code you posted, but somewhere it is. You need to post more code to be able to say where the issue is.

Mike

Block class:
http://pastebin.java-gaming.org/c73e2821254

Grass:
http://pastebin.java-gaming.org/73e2292145c

Init texture_2d
1  
2  
3  
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
Offline Vermeer

JGO Coder


Medals: 16



« Reply #21 - Posted 2013-03-29 19:07:12 »

Hi

That's odd, as your other stone blocks are ok! Just the first one to be rendered? Or last?

I'll have a good look over the grass one, that mistake is on every block, so it must be the co-ordinates, or are you drawing those blocks somehow differently to the rest of the blocks?

Will have a look over it.
Offline Pauler
« Reply #22 - Posted 2013-03-29 19:14:55 »

The difference between grass and the rest of the blocks is that it uses another texture for the top side and the bottom side. Also, I took the grass texture coords from the opposite direction starting from the left bottom corner of the texture instead of the top left corner. I did that because the grass was displayed rotated.

Also, the buggish corner is the first of the last z row, I think.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
for(int x = 0; x < World.CHUNK_WIDTH; x++) {

         for (int y = 0; y < World.CHUNK_HEIGHT; y++) {

            for (int z = 0; z < World.CHUNK_LENGTH; z++) {

               blocks.add(new Air(this.x + x * Block.width, y * Block.height, this.z + z * Block.length));

            }

         }

      }
Offline Pauler
« Reply #23 - Posted 2013-03-29 23:22:28 »

I figured out that the second problem occurs only on blocks that don't use the same texture for all the 6 sides. It happends only to blocks like grass.
Offline Pauler
« Reply #24 - Posted 2013-04-02 21:24:16 »

up.
Offline Pauler
« Reply #25 - Posted 2013-04-03 22:44:14 »

I managed to find whats causes these two problems (by myself Cranky), and I managed to fix them.

Fyi, the problem was that some sides need to be drawn clockwise and some others counter clockwise. Also, this fixed the face-culling bug I faced.
Offline Pauler
« Reply #26 - Posted 2013-04-08 16:57:18 »

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

This is the current state of my voxel engine. I used lists so far, and it seems that I have to move to arrays.
Offline steg90

Senior Member


Medals: 1



« Reply #27 - Posted 2013-04-08 18:26:21 »

Looking good,

Do you do a check to see if cube is in view before rendering?

Any collision checks yet?

Keep up the good work.
Offline Pauler
« Reply #28 - Posted 2013-04-08 18:32:46 »

I got a collision check that actually works the only problem is that I haven't figured out yet how to stop camera movement when it collides. It may sounds simple but II get some weird results. Even though, it print a collision message when you collide to a block.

About your rendering question, I only use front face culling.

After turning lists into arrays I got way more fps. 256 of 16^3 chunks almost 2k fps.
Offline Vermeer

JGO Coder


Medals: 16



« Reply #29 - Posted 2013-04-08 19:18:58 »

That is looking really good. Love the trees.

Good how your limiting chunk drawing. Nice work.
Pages: [1] 2 3 ... 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.

ctomni231 (37 views)
2014-07-18 06:55:21

Zero Volt (35 views)
2014-07-17 23:47:54

danieldean (28 views)
2014-07-17 23:41:23

MustardPeter (31 views)
2014-07-16 23:30:00

Cero (46 views)
2014-07-16 00:42:17

Riven (47 views)
2014-07-14 18:02:53

OpenGLShaders (36 views)
2014-07-14 16:23:47

Riven (36 views)
2014-07-14 11:51:35

quew8 (32 views)
2014-07-13 13:57:52

SHC (69 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!