Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 ... 3 4 [5] 6 7
  ignore  |  Print  
  Voxel - a start  (Read 23161 times)
0 Members and 1 Guest are viewing this topic.
Offline steg90

Senior Duke


Medals: 1



« Reply #120 - Posted 2013-04-05 11:23:44 »

Got block moving in 16 units, here is the result:


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


Now need to place blocks and remove them, next on the list.

Thanks,
Steve
Offline Vermeer

JGO Coder


Medals: 16



« Reply #121 - Posted 2013-04-05 11:42:41 »

That's looking really good. You have fog too and text. It's all coming together.  Smiley
Offline steg90

Senior Duke


Medals: 1



« Reply #122 - Posted 2013-04-05 11:51:21 »

Thanks Paul,

I guess placing the blocks now is just by using the position of my wire cube?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline steg90

Senior Duke


Medals: 1



« Reply #123 - Posted 2013-04-05 17:34:36 »

Added block placing and removing.  Not fully working yet as only works in one chunk area.

How you guys coping with placing a block in a chunk that yet doesn't exist? For instance, when I create my initial world, it is only one chunk in height, how about if player adds a block above this chunk...or, do we have many chunks that are just 'air'?...


Link:


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


Thanks
Offline Vermeer

JGO Coder


Medals: 16



« Reply #124 - Posted 2013-04-05 18:09:17 »

One way of doing this is to make the chunks above, and have a variable in the chunks such as

Boolean Empty = true;

The chunk would be fully created, but at renderTime

If(!chunk.isEmpty) render chunk

If you place a block in the chunk then Empty = false.


Looking very good btw Smiley
Offline steg90

Senior Duke


Medals: 1



« Reply #125 - Posted 2013-04-05 18:25:56 »

Cheers :-)

Yes, was thinking of say creating the 'world' as say 32x32x32 chunks and like you say, create empty chunks, this would solve the need to check if block we are placing is in a chunk that as of yet doesn't exist.

As chunks are made up of blocks which have a boolean variable in them to see if there are active or not may not need a boolean empty for chunk?

On a side note, wondering what is a neat way of creating trees and I guess these need to appear where there are no blocks above them?!
Offline Vermeer

JGO Coder


Medals: 16



« Reply #126 - Posted 2013-04-06 11:57:00 »

I ran into VBO memory issues trying to make larger chunks, so I kept them at 16^3.

Re: trees
I guess you would need a method that searched a cuboid of given space where the tree would go. If all blocks are empty a tree can go there.

Then there is making the tree.. You could start by having a random height trunk (within limits) then scatter some leaves around the upper part of it. Once it's working you can refine the leaf generation.

I think the hardest part is like you are finding...being able to easily switch from chunk to chunk when calculating things. You need some good utility methods that enable you to do that.
Offline steg90

Senior Duke


Medals: 1



« Reply #127 - Posted 2013-04-06 16:36:01 »

Yeah my chunks are 16^3, meant to say landscape to be made up of 32^3 chunks, but should be a lot more.  Looking at putting the chunks into an octree, but want get collision working first and these damn trees.

I can now add blocks in any chunk.

I read a blog by a guy doing a voxel type game and draws trees depending on weather conditions, the land type etc, sounds interesting!

Offline steg90

Senior Duke


Medals: 1



« Reply #128 - Posted 2013-04-07 22:49:07 »

Implementing collision in my game.  Problem I have is when player jumps on a block, my collision check for blocks in front and behind is telling me there is a collision when the collision is on block under the player...What is best way to implement AABB to make this collision better than just testing what block we are on?

Here is small video of my crappy collision detection:


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

Thanks
Offline Vermeer

JGO Coder


Medals: 16



« Reply #129 - Posted 2013-04-08 11:48:41 »

Hi

Because the blocks are fixed on a grid I still do not think you need AABB as such. You would do for enities that are moving off grid. This is the solution I used, and have used in several games. This only works on things that are exactly aligned to a grid, like voxel cubes.

Please forgive my scribbles....



For a close up of the image:  http://www.java-gaming.org/user-generated-content/members/167679/notes.jpg

The reason AABB is not needed is that the cubes are always a fixed size, and the position of its edge is always known - by definition of what it is. For many games this would not be true and AABB would be needed.

Because you also know where the bottom of the player is you know which vertical block to test.

Notes: I have made up a hoizontal movment value of 0.15f, it could be higher/lower. Vertical jump speed would depend on current acceleration.

To make movment even better, the player could have horizonatal acceleration too, once you have collision in place.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline steg90

Senior Duke


Medals: 1



« Reply #130 - Posted 2013-04-08 13:35:05 »

Thanks for the image and advice :-)

I take it you need to check when you move forwards, backwards, strafe left / right and jump?

This is my collision code:

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  
private boolean isCollision(int dir)
   {
      Vector3f v = camera.getCameraPosition();
      double cameraPitchInRadians = Math.toRadians(camera.getCameraPitch());  // XROT
      double cameraYawInRadians = Math.toRadians(camera.getCameraYaw());  // YROT
      float f = (float)Math.cos(cameraPitchInRadians);              
      float newX = dir * f * (float)Math.sin(cameraYawInRadians);
      float newZ = dir * f * (float)Math.cos(cameraYawInRadians);
         
      float tempx = (newX + v.x) / BLOCKWIDTH * BLOCKHEIGHT;
       int tempX = (int)tempx;
       
       float tempz = (newZ -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;  // * 3 is the amount of chunks on Z
      int xchunk = Math.abs(tempX / Chunk.CHUNK_SIZE);// + (blockZ / Chunk.CHUNK_SIZE);
      int chunktoget = zchunk + xchunk;

      Block b = ChunkManager.getInstance().getBlockInChunk(chunktoget,
               Math.abs(bx),
               Math.abs(by+1),
               Math.abs(bz));
      return b.IsActive();
}


An example of it being called - this is in my main update loop:

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  
                        if(!isCollision(0))
                        {
                                camera.down(0.05f);   // move player down as no collision
                        }

         if (Keyboard.isKeyDown(Keyboard.KEY_W))// move forwards
         {
            if(!isCollision(1))
            {
               camera.walkBackwards(movementSpeed * dt);
            }
         }
         
                        if (Keyboard.isKeyDown(Keyboard.KEY_S))// move backwards
         {
           
            if(!isCollision(-1))
            {
               camera.walkForward(movementSpeed * dt);
            }
         }
         if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) // jump...
         {  
            camera.jump(movementSpeed * dt);
         }


Not done checks for strafe left/right.  Works for forwards and backwards but like I said, when jumped onto a block and then I try to move forwards, still thinks there is a collision?!

Cheers,
Steve
Offline Vermeer

JGO Coder


Medals: 16



« Reply #131 - Posted 2013-04-08 14:21:15 »

I found some odd floating point errors when calculating the players falling..

I found the exact floor of the block, and had to keep updating the players position to be the value of the floor. Otherwise floating point errors would mean that the player ended up trapped in a block just like you mention.

If ground = 3  and player <3. Then player height = 3.

It meant the player couldn't get to 2.9998874 with errors and get stuck.

Try adding some floats in a loop and you will see what I mean. You won't get the exact answers you expect. This may or may not be relevant.....
Offline steg90

Senior Duke


Medals: 1



« Reply #132 - Posted 2013-04-08 15:12:20 »

It is weird,

When my game starts, player is at 0.5f on the Y, when I jump and land, player is then at 0.99f on the ground?  When I land on a block, say block that is one high, my player Y is then 1.99f which seems correct, but then I cannot move forward as like I say, thinks there is a collision even though my collision when moving forward is checking +1 extra on Y coordinate...so, when on a block at position  1.99f and I move forward I check at 2.99f on the Y, this is why I cannot understand that it thinks there still is a collision.

Thanks

Offline steg90

Senior Duke


Medals: 1



« Reply #133 - Posted 2013-04-09 16:15:14 »

Finally got the bug sorted, was a silly mistake but fixed it through outputting debug info to the window.  So now I can collide with blocks and jump on and off them.  Must admit, it isn't perfect, I guess you would need AABB for that...

One issue I want to sort out is to allow the player to build a block one unit in front of them, at the moment, it is about 4 units in front, using this to get the Z (how far in screen - hypotenuse of triangle):

1  
2  
3  
4  
Vector3f v = camera.getCameraPosition();
double cameraYawInRadians = Math.toRadians(camera.getCameraYaw());
float f = (float)Math.cos(cameraPitchInRadians);              
float newZ = 6 * f * (float)Math.cos(cameraYawInRadians);


Or, the players height needs to be more...
Offline Vermeer

JGO Coder


Medals: 16



« Reply #134 - Posted 2013-04-11 17:39:26 »

To change the distance of placement, rather than have it at a set value you will need to implement 3d picking. Test what block you are looking at, so if you look at a block 1 unit away you can build there, or look at a block 3 units away and build there.

Offline steg90

Senior Duke


Medals: 1



« Reply #135 - Posted 2013-04-12 22:51:43 »

Using sphere to AABB for collision detection, but having issues, this video shows the problem:


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


Note, at the moment I'm checking all blocks in the chunk player is in.

So, walk forwards and collision occurs, then turn around say 100 degrees and then move forwards, still got a collision so cannot move forwards - maybe this is because I'm checking all blocks in the chunk and I guess should just check the one in front if moving forwards, one behind if moving backwards etc?

Thanks
Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


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


« Reply #136 - Posted 2013-04-12 23:14:13 »

Just use the simpler method I described in some other thread (simplified):

1. Floor positions at (x-xsize, y-ysize, z-zsize) and (x+xsize, y+ysize, z+zsize).
2. Use for loops to get every block between the two positions.
3. If there are any blocks, collision is true.
4. Otherwise, collision is false.

Sphere-AABB is only useful if you want people to be able to 'roll' over the edges of blocks instead of just falling once you get to a certain point. And that requires more physics.

Most players won't care anyway.

Offline steg90

Senior Duke


Medals: 1



« Reply #137 - Posted 2013-04-12 23:20:10 »

Hi,

Thanks for that, but could you clarify what xsize, ysize and zsize are?

If my player is just one unit which the blocks are too, do we just not check the block in front, behind, left or right depending on if moving forwards/backwards etc?

I did use AABB to AABB but got same result as Sphere to AABB - think my issue is not detecting the collision, but what to do once a collision has occurred.
Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


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


« Reply #138 - Posted 2013-04-12 23:42:56 »

1. Create a new position that is the same as the old position
2. When moving, change the new position, not the old one.
3. Check the new position for collisions. If there is a collision, leave the old position the same.
4. If there isn't a collision, set the old position to the new position.

And xsize, ysize and zsize are the (half) size of the player on that axis. (if the player is 1x1x1 then xsize, ysize and zsize are 0.5)

Offline steg90

Senior Duke


Medals: 1



« Reply #139 - Posted 2013-04-13 09:21:05 »

@HeroesGraveDev - thanks, will give it a shot.

So, instead of checking every block, just check the ones you mentioned.

Offline steg90

Senior Duke


Medals: 1



« Reply #140 - Posted 2013-04-13 09:57:53 »

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
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??
Offline steg90

Senior Duke


Medals: 1



« Reply #141 - Posted 2013-04-19 15:01:01 »

Added some random trees - not very good ones!


https://www.youtube.com/watch?v=kgye7xeCbVI
Offline Sparky83
« Reply #142 - Posted 2013-04-19 15:41:38 »

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

Do you plan adding ray casting for voxel picking soon?
Offline steg90

Senior Duke


Medals: 1



« Reply #143 - Posted 2013-04-19 16:40:33 »

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. 
Offline steg90

Senior Duke


Medals: 1



« Reply #144 - Posted 2013-04-19 20:26:44 »

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.




Offline Sparky83
« Reply #145 - Posted 2013-04-19 20:38:16 »

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.
Offline steg90

Senior Duke


Medals: 1



« Reply #146 - Posted 2013-04-19 20:42:12 »

Hi Sparky,

Using display lists...

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

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


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


« Reply #147 - Posted 2013-04-19 20:44:42 »

Try using jvisualvm to see where the bottleneck is.

Offline steg90

Senior Duke


Medals: 1



« Reply #148 - Posted 2013-04-19 21:28:32 »

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.


Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


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


« Reply #149 - Posted 2013-04-19 21:35:58 »

It depends on how you've used the HashMap.

Pages: 1 ... 3 4 [5] 6 7
  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.

Longarmx (38 views)
2014-10-17 03:59:02

Norakomi (29 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (56 views)
2014-10-14 00:39:48

TehJavaDev (55 views)
2014-10-14 00:35:47

TehJavaDev (46 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!