Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (540)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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 7
  ignore  |  Print  
  Voxel - a start  (Read 24850 times)
0 Members and 1 Guest are viewing this topic.
Offline HeroesGraveDev

JGO Kernel


Medals: 320
Projects: 11
Exp: 3 years


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


« Reply #90 - Posted 2013-03-22 20:05:37 »

More realistic jumping can be done by setting the velocity once when the key is pressed and constantly applying gravity.*

Changing Position = Linear = Velocity
Changing Velocity = Quadratic = Acceleration

Acceleration -> Velocity -> Position

* It sort-of works like this in real life. Force is only applied while you are on the ground. After that only gravity affects you (drag is minimal)

Offline steg90

Senior Devvie


Medals: 1



« Reply #91 - Posted 2013-03-22 20:10:48 »

Any chance you could show how you position your camera and did you say your floor is just one block in height? Do you draw this separate of your chunking?

Thanks,

PS - does my camera class look ok?
Offline Vermeer

JGO Coder


Medals: 16



« Reply #92 - Posted 2013-03-22 20:28:08 »

Any chance you could show how you position your camera and did you say your floor is just one block in height? Do you draw this separate of your chunking?

Thanks,

PS - does my camera class look ok?

the floor is the block that im stood on, so there is just the chunk, and the floor is found by litterally dropping out of the sky and landing on a block.

so if a block is 8 high, the floor is 9 in my game. the floor is not drawn,its just the block.  here is my code to calculate that.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
private void updateLogic() {
     
         ground = getGroundLevel(xpos, playerheight, zpos);
         
          playerheight+=yVelocity*TIME_STEP;
         yVelocity+=GRAVITY*TIME_STEP;
     
         if(playerheight<=ground)   {
            isJumping = false;
            yVelocity=0;
            playerheight= ground;
         }
                           }
         



my get ground level method is this:

1  
2  
3  
4  
5  
6  
int groundLevel=y;   
      //System.out.println("ground level =  " +  groundLevel);
      for(int gl = groundLevel;y>-1;y--){ //cycle thorugh the blocks under the player untill we hit one;
     
         if(chunks[c].getblockID(x, gl,z)>0)return gl;
      }


this is how I jump

1  
2  
3  
4  
5  
6  
7  
8  
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { 
           
            if(!isJumping){
               isJumping= true;
               yVelocity=6f;
               
            }
         }

Setup:

float yVelocity=0.0f;
final double TIME_STEP=1/60.0;
final float GRAVITY=-11f;

Before I render the VBO chunks:
1  
2  
3  
4  
//position the player/camera
            GL11.glRotatef(lookupdown, 1.0f, 0, 0);
            GL11.glRotatef(360.0f - yrot, 0, 1.0f, 0);
            GL11.glTranslatef(-xpos, camHieght , -zpos);



I should also mention that I add a walkbias to the cam hight to for rendering only,

I found this part in NeHe's excellent tutorials.
1  
2  
3  
4  
5  
6  
7  
8  
9  
walkbiasangle += 10.0f;

            if (walkbiasangle > 360.0f) {
               walkbiasangle -= 360.0f;
            }

            walkbias = (float) Math.sin(walkbiasangle * piover180) / 20.0f;
           
            }


then I add this to the camHieght at rendertime, but it does not effect the actuall calculations for falling.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline steg90

Senior Devvie


Medals: 1



« Reply #93 - Posted 2013-03-22 20:53:19 »

Thanks for that,

So, you seem to do like me, just draw your chunks, and ground is where the 'player' lands?

What is player height, this set to the size of a block?

I'm just having trouble doing the start position of the camera for the game, want it to be somewhere in the middle of all the chunks.

What is a 'walkbias' by the way??

Thanks
Offline Longor1996
« Reply #94 - Posted 2013-03-22 20:54:18 »

The "walkbias" is the up/down bobbing of the head while walking.
You don't really need it.


Edit:
Random Question: How do you store/manage your chunks while they are loaded?

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline steg90

Senior Devvie


Medals: 1



« Reply #95 - Posted 2013-03-22 21:07:02 »

At the moment I just generate the same chunk:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public int SetupLandscape()
   {
      float r = 1 + (float)Math.random()*16;
      for (int x = 0; x < CHUNK_SIZE; x++) {
         for (int z = 0; z < CHUNK_SIZE; z++) {
            int height = (int) (SimplexNoise.noise(x / 16f, z / 16f) * Math.random()*16);
            if(height<=0) height = 1;
            for(int y = 0; y < height; y++) // set these blocks on
            {
               Blocks[x][y][z].SetActive(true);
               Blocks[x][y][z].SetType(BlockType.BlockType_Grass);
            }
         }
      }
      return this.rebuildChunk();
   }


I also have this code to do a sphere:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public int SetUpSphere() {
      for (int x = 0; x < CHUNK_SIZE; x++) {
         for (int y = 0; y < CHUNK_SIZE; y++) {
            for (int z = 0; z < CHUNK_SIZE; z++) {
               
               if (Math.sqrt((float) (x-CHUNK_SIZE/2)*(x-CHUNK_SIZE/2) + (y-CHUNK_SIZE/2)*(y-CHUNK_SIZE/2) + (z-CHUNK_SIZE/2)*(z-CHUNK_SIZE/2)) <= CHUNK_SIZE/2)
                   {
                      Blocks[x][y][z].SetActive(true);
                      Blocks[x][y][z].SetType(BlockType.BlockType_Grass);
                   }                              
            }
         }
      }  
      return this.rebuildChunk();
   }


I have a singleton class for my chunkManager, it basically just has an ArrayList of Chunks, which in turn has a 3d array of Block objects.  Thus a linear list.

I add a chunk as follows:

1  
ChunkManager.getInstance().AddChunk(ChunkType.ChunkType_Land,0,0,1);


This adds a basic chunk created from simplex noise at xoffset=0, yoffset=0 and zoffset=1

What do you use to generate your chunks?

Thanks
Offline steg90

Senior Devvie


Medals: 1



« Reply #96 - Posted 2013-03-23 08:41:00 »

PS - what data structure do you store your chunks in?  I'm having an issues getting the correct chunk because it is a linear list...I guess you know the amount of chunks on X * Chunk Size * Z position to get the correct chunk?

Thanks,
Steve

PS - Just using this now to get chunk where we are:

1  
2  
3  
4  
5  
6  
7  
8  
int zchunk = (blockZ / Chunk.CHUNK_SIZE) * CHUNKS_ON_X;      
int xchunk = (blockX / Chunk.CHUNK_SIZE);
int chunkToGet = zchunk + xchunk;

Block b = ChunkManager.getInstance().getBlockInChunk(chunktoget, blockX,blockY,blockZ);
if(!b.isActive() ) {
     // air
}      



Guess at some point, will need to modify the above to take into account the y-chunk?

Offline steg90

Senior Devvie


Medals: 1



« Reply #97 - Posted 2013-03-23 15:08:10 »

Collision checks are driving me mad, just can't seem to get it correctly working.

For instance, for when player jumps, I do the following to get the block that is in front
of the player:

1  
2  
3  
int blockX = (int) Math.abs((pos.x/2));  
int blockZ = (int) Math.abs((pos.z/2))+1;
int blockY = (int) Math.abs(pos.y);


pos is the camera's vector position.

I then do:

1  
2  
3  
int zchunk = (blockZ / Chunk.CHUNK_SIZE) * 1;
int chunk = (blockX / Chunk.CHUNK_SIZE);// + (blockZ / Chunk.CHUNK_SIZE);
int chunktoget = zchunk + chunk;


To get the chunk to get:

1  
Block b = ChunkManager.getInstance().getBlockInChunk(chunktoget, blockX,blockY,blockZ);


then just check if the block is active:

1  
this.bNoCollision = b.IsActive();


Works sometimes, but seems very inaccurate.  I just thought it would be a simple case of getting
the block in front of player and if player jumps and the block is active, I stop moving the camera down.

 Angry Angry Doing my head in!

Thanks
Offline Longor1996
« Reply #98 - Posted 2013-03-23 15:22:24 »

Wait, what?

You are cheking the block in front of the player to check if you have to stop jumping.
I think it would be better to check the block below the player for collisions.

How about using AABB's like Minecraft does?
That fixes most of the problems.

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline steg90

Senior Devvie


Medals: 1



« Reply #99 - Posted 2013-03-23 15:33:59 »

Hi,

I've also tried the block below, same result:

Here is a small video of the issue:


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


AABB - is there some information about this somewhere?

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

JGO Coder


Medals: 16



« Reply #100 - Posted 2013-03-23 17:49:05 »

Hi

When moving forward, the block in front needs to be checked.

When falling block below you is checked.

Just to note, when jumping forward, you can't jump forward if there is a block there, but as soon as you are higher than the block you would then be able to move forward, then the block below you is the new ground height. So the block doesn't stop you jumping, only jumping forward. The vertical component of your jump is unaffected by forward motion. As herosgrave mentioned its quadratic - but moving forward has no effect on you upward or downward movement.

Because they are cubes, ordered in a grid, I think just taking the int of your position tells you if you are in a block or not.

The only consideration for collision if you want your character to have a physical size and not be a point is that it has a bounding box, and you could test each corner.
This does created additional problems when moving towards the corner of a block.
AABB may be a good way to go. I may do that later, but there are others ways around that.

You also have to test more than one block if you character is higher than one block, in case you want to go under blocks!

Offline steg90

Senior Devvie


Medals: 1



« Reply #101 - Posted 2013-03-24 16:35:52 »

Hi,

Not had time to look at my code yesterday.


I basically just check blocks that are all around you. The X below is a block and O is
the cameras position, so, as can be seen block on right is air and is the only place
we should be able to move to, unless we jump:

XXXXX
XO  XX
XXXXX

Code below gets block to the left of the player:

1  
2  
3  
int blockX = (int) Math.abs((pos.x/2) - 1);  // block to left of player 
int blockZ = (int) Math.abs((pos.z/2));
int blockY = (int) Math.abs(pos.y);


Remember pos.x, pos.z and pos.y is my camera's vector position.
But, still not working...

Need to investigate.

Thanks,
Steve
Offline Vermeer

JGO Coder


Medals: 16



« Reply #102 - Posted 2013-03-24 20:50:26 »

Will have a think about this.
But I noticed that you have pos.x/2   is this because your blocks are 2 big?

if so, i found it easier to make my cubes like this....   -0.5 to 0.5   rather than -1 to 1

also, if thats true , why dont you do pos.y/2 ?


I think you are checking the blocks to north,south,east , west etc of player..... but you may need to instead check the
position of where the player would be if they moved forward, this may be at an angle, so you would check the x and z vector components.
Ill try and make a diagram tommorow.

Does your player move at an angle? or will they only move in 4 directions?

Sorry Ive not been much help!
Offline Longor1996
« Reply #103 - Posted 2013-03-24 21:16:29 »

I think the problem of the OP is, that he hasn't his scales and directions set right.
You should always know exactly how big a voxel is, render-wise and logic-wise.
Also, you should know exactly where south/west/east/up/down/left/right/top/north/whatever is.
If you don't know that, you will run into very big problems.

- Longor1996


Edit:
Oh, and here's a tipp: Do not use simple "Is Box in Box" checks for collision.
Use AABB/AABB velocity intersection. It work's much better.
And it's nerly fail-safe.

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline steg90

Senior Devvie


Medals: 1



« Reply #104 - Posted 2013-03-24 22:03:04 »

Thanks guys,

Think scales could be wrong.  I've zipped project up and it just draws a couple of blocks, you can use space bar to get onto the block (note space just moves player up until you let go at the moment), wsad keys to move.

Yes, drawing blocks from -1.0 to 1.0 hence the divide by 2, just changed now to -0.5 to 0.5 :-)

Added project here if you care to look at the code?! I'd like the camera position set up better, think if you run the project you may see what I mean?

Many thanks, really, really appreciate your help guys.

https://sites.google.com/site/voxbygame/home/downloads

PS - camera moves in all directions, so, yes player moves on diagonals.

Steve
Offline steg90

Senior Devvie


Medals: 1



« Reply #105 - Posted 2013-03-24 23:49:40 »

I think it is my camera position that is incorrect when i turn around 180 degrees, how do you store your player position?

Thanks
Offline Longor1996
« Reply #106 - Posted 2013-03-25 00:07:39 »

How i store my player position?

I use an Player Entity Object.
In Puzzlez Project, every voxel occupies exactly 1 cubic meter.
Because of that, getting the voxel im standing on is very easy.
1  
world.getVoxel((int)Math.floor(player.position.x),(int)Math.floor(player.position.y-1),(int)Math.floor(player.position.z));


The getVoxel method simply get's the voxel at the given position.
Since all blocks are 1³, i just have to floor the coordinates component's and put them into the getVoxel method.
It's a really good idea to make your voxels 1³ big.
It also makes rendering a bit easier.

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline HeroesGraveDev

JGO Kernel


Medals: 320
Projects: 11
Exp: 3 years


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


« Reply #107 - Posted 2013-03-25 04:03:09 »

Wait, why do you need to know what block you are standing on?

Offline steg90

Senior Devvie


Medals: 1



« Reply #108 - Posted 2013-03-25 08:07:53 »

Thanks @Longor1996

Didn't think of using floor to get largest integer ;-)

Why need to know about what blocking standing on - to stop player falling through a cube?!
Offline HeroesGraveDev

JGO Kernel


Medals: 320
Projects: 11
Exp: 3 years


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


« Reply #109 - Posted 2013-03-25 19:03:38 »

Why not use normal collision detection?

Offline steg90

Senior Devvie


Medals: 1



« Reply #110 - Posted 2013-03-25 23:39:49 »

Thinking of giving up with this  Undecided, just cannot see what I'm doing wrong, all I can think of is the scaling.  This is how I set up the view matrix at the start:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
gluPerspective(
              45.0f,
              (float) Display.getWidth() / (float) Display.getHeight(),
              0.1f,
              100.0f);

      GL11.glTranslatef(0, -2f, -1f);
      gluLookAt(0, 0, -2,
              0, 0, 0,
              0, 1, 0);


Does this look wrong?  I've tried all manner of different values. 

Thanks
Offline Longor1996
« Reply #111 - Posted 2013-03-25 23:59:21 »

It doesn't matter how the view matrix and opengl are setup at all!
The problem is you collision detection. It doesn't work!

You have to use AABB collision detection or something else.
It doesn't work with simple "If Block under Plyer, Stop Falling" stuff.
That works only in 2D games.

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline steg90

Senior Devvie


Medals: 1



« Reply #112 - Posted 2013-03-26 00:11:37 »

It seems to be working for @Vermeer?!

This is what I read:

'
Take the players position vector and transform it into 'voxel space' coordinates.
Check if the voxel that corresponds to the player's voxel position is currently active or not.
If the voxel IS active, it means the player is colliding with the world. since an active voxel is part of the world and should be collided with.
'
AABB something like:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
bool CheckCollision(Block pBox1, Block pBox2)
{
    if(pBox1.xyz1.x > pBox2.xyz2.x) return false;
    if(pBox1.xyz1.y > pBox2.xyz2.y) return false;
    if(pBox1.xyz1.z > pBox2.xyz2.z) return false;
    if(pBox1.xyz2.x < pBox2.xyz1.x) return false;
    if(pBox1.xyz2.y < pBox2.xyz1.y) return false;
    if(pBox1.xyz2.z < pBox2.xyz1.z) return false;

    return true;
}


Thanks for your help.
Offline HeroesGraveDev

JGO Kernel


Medals: 320
Projects: 11
Exp: 3 years


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


« Reply #113 - Posted 2013-03-26 04:20:10 »

I wrote a quicker AABB implementation a while ago.

http://www.java-gaming.org/topics/fast-simple-aabb-collision-detection/28059/view.html

It was made for 2D, but can be easily changed for 3D.

Offline steg90

Senior Devvie


Medals: 1



« Reply #114 - Posted 2013-03-26 08:23:12 »

Hey thanks for that.

I guess, I need to find what block we are at and then do the AABB check?

Thanks,
Steve
Offline steg90

Senior Devvie


Medals: 1



« Reply #115 - Posted 2013-04-02 09:36:21 »

Small video of how my voxel little project is looking now.  Thanks to everybody for helping.


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


To do: Full collision detection, only draw chunks that are in view, block replacement and addition, plus lots more...
Offline steg90

Senior Devvie


Medals: 1



« Reply #116 - Posted 2013-04-03 22:31:37 »

Trying to get a wire frame cube to be drawn just in front of camera (like camera is in center of it).  I want this cube to move with the camera, got part of it working, but when turn past 45 degs, it doesn't appear to be working.

I use this code to position the cube:

1  
2  
3  
4  
5  
6  
Vector3f pos = camera.getCameraPosition(); // get camera x,y,z position vector
float yrot = camera.getCameraYaw();  // get rotation on y-axis
float xpos = pos.x  + (float)Math.sin( Math.toRadians(yrot));
float zpos = pos.z + (float)Math.cos(Math.toRadians(yrot));
zpos -= 2;
cube.render(0.5f, -xpos, pos.y, -zpos,yrot);


Cube is then just translated with glTranslatef(x,y,z) in the cube.render function.

Anyway of keeping this cube in line with the camera position and rotation?

Link here to what is happening:


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


Also, when placing a removing a block, I guess you need to take the camera's position vector and its rotation to work out where block is to be placed?

Thanks

Offline Vermeer

JGO Coder


Medals: 16



« Reply #117 - Posted 2013-04-04 17:17:49 »

Try see if this works...


float xpos = pos.x +(float)Math.sin( Math.toRadians(yrot)) * amountToMove;
float zpos = pos.z +(float)Math.cos(Math.toRadians(yrot)) * amountToMove;

amountToMove is the block displacement from the player


But not this:
zpos -= 2;

Offline Vermeer

JGO Coder


Medals: 16



« Reply #118 - Posted 2013-04-04 17:22:34 »

You may also want to rotate that wireframe block with the yrot value as well so it maintains the same relative rotation to the player. It may even be -yrot!

You have this working for the block the player is holding... It should be no different?
Offline steg90

Senior Devvie


Medals: 1



« Reply #119 - Posted 2013-04-04 18:05:44 »

Thanks @Vermeer,

I did this in the end:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
                            Vector3f pos = camera.getCameraPosition();
             double cameraPitchInRadians = Math.toRadians(camera.getCameraPitch());
             double cameraYawInRadians = Math.toRadians(camera.getCameraYaw());
             // coefficient - possibly not needed
             float f = (float)Math.cos(cameraPitchInRadians);
                     
             float newX = 6 * f * (float)Math.sin(cameraYawInRadians);
             float newZ = 6 * f * (float)Math.cos(cameraYawInRadians);
             float newY = 6 * (float)Math.sin(cameraPitchInRadians);
           
             newY += 1;
             cube.render(0.5f, -newX + -(pos.x), newY + -(pos.y), newZ + -(pos.z),
                  0);


As for the block player is holding, didn't need any transformation, basically I did:

1  
   player.updatePlayer(0, 0, camera.getCameraPosition(), camera.getWalkBias());


and in the updatePlayer, just used identity matrix and did a translation on Y with the walk bias.

My wireframe block I've put 3 blocks in front of the player, it moves as the player moves, but need it to move my blocks width at a time on x,y,z ( 16 units ).

Thanks,
Steve
Pages: 1 2 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.

Mr.CodeIt (23 views)
2014-12-23 03:34:11

rwatson462 (53 views)
2014-12-15 09:26:44

Mr.CodeIt (45 views)
2014-12-14 19:50:38

BurntPizza (85 views)
2014-12-09 22:41:13

BurntPizza (110 views)
2014-12-08 04:46:31

JscottyBieshaar (78 views)
2014-12-05 12:39:02

SHC (89 views)
2014-12-03 16:27:13

CopyableCougar4 (96 views)
2014-11-29 21:32:03

toopeicgaming1999 (155 views)
2014-11-26 15:22:04

toopeicgaming1999 (152 views)
2014-11-26 15:20:36
Resources for WIP games
by kpars
2014-12-18 10:26:14

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