Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (482)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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 ... 7
  ignore  |  Print  
  LWJGL BlockWorld  (Read 28746 times)
0 Members and 1 Guest are viewing this topic.
Offline steg90

Senior Member


Medals: 1



« Reply #60 - Posted 2013-03-24 22:05:19 »

This is brilliant Vermeer :-)

Just wish I could get my collision to work and then I can move on with my project!

Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #61 - Posted 2013-03-25 02:47:38 »

Wish I was as far along as you! My stupid textures refuse to work... I also need to offset my chunks but that isnt working... *sigh*

Offline Agro
« Reply #62 - Posted 2013-03-25 03:14:34 »

Is collision really that hard? Isn't it just AABBs colliding with a sphere?

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

Senior Member


Medals: 1



« Reply #63 - Posted 2013-03-25 08:04:05 »

Hi,

Collision should be simple, but my issue I think is not getting the correct camera position vector, when turning 180 degs.

Thanks
Online Longor1996
« Reply #64 - Posted 2013-03-25 14:15:17 »

Hi,

Collision should be simple, but my issue I think is not getting the correct camera position vector, when turning 180 degs.

Thanks

How about: Make it impossible that the rotation is bigger than 180 degrees?

It's easy!
1  
2  
while(rotation_y > 180)
    rotation_y -= 180;


Oh, and please use AABB's for collision detection.
It's the most easy collision detection one can think of.

- Longor1996

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

JGO Coder


Medals: 16



« Reply #65 - Posted 2013-03-25 21:13:48 »

Update:

Testing flowing water

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

Senior Member


Medals: 1



« Reply #66 - Posted 2013-03-25 21:44:15 »

Hi,

I want to allow the camera to turn 360 degs :-)

Camera position is fine, I think it is my scaling, please look at this video I have done, we can see that the block I'm on isn't accurate with block I'm trying to jump on, it is as though the block is more than one unit wide...again, this a scaling issue?

video:


https://www.youtube.com/watch?v=OVJrbdVt-b0


When on block 8,0,1 then this is the block we can jump on, but when moving, we can see that we should still be able to jump on block when on block 8,0,2 - it just doesn't seem accurate. Also, when I do get on top of the box and then fall off it, it looks wrong.  Can't fabben it out, should be simple.

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


Above gets position and then I just do this to get the block and check if it is active:

1  
2  
Block b = ChunkManager.getInstance().getBlockInChunk(chunktoget, blockX,blockY,blockZ);
if(!b.isActive() ) {  // do whatever -> move camera down }


This is why I think it is to do with scaling.

I set view matrix up at start:

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


Anything obviously wrong?!

Thanks again and sorry for keep going on about this!
Offline steg90

Senior Member


Medals: 1



« Reply #67 - Posted 2013-03-25 21:47:06 »

That is looking awesome!  Cool
Offline Agro
« Reply #68 - Posted 2013-03-25 22:06:42 »

Gee whiz! Your game is really starting to look cool Cheesy

Offline steg90

Senior Member


Medals: 1



« Reply #69 - Posted 2013-03-26 11:15:24 »

Hi,

How do you keep the block selection on screen i.e. so it doesn't go behind the floor etc when looking down?

I tried glDisable(GL_DEPTH_TEST); but my block appears then inside out so to speak...

Hope you know what I mean?!

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

JGO Coder


Medals: 16



« Reply #70 - Posted 2013-03-26 13:14:55 »

Thank you all for oyur positive comments Smiley

Steg,

You mean the block the player is holding?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
// draw the block the player is holding
     GL11.glLoadIdentity();
      //move the camera
     GL11.glRotatef(20, 1.0f, 0, 0);  //lookupdown
     GL11.glRotatef(360.0f - yrot, 0, 1.0f, 0); //360.0f - yrot
     GL11.glTranslatef(-xpos, (-walkbias/3) - 0.25f - (float)playerheight - hedHeight, -zpos);
     
      //move the block infront of the player
     float xblokpos = xpos - (float) Math.sin((yrot-18) * piover180) * 0.24f;
      float zblokpos = zpos - (float) Math.cos((yrot-18) * piover180) * 0.24f;
     
     
      GL11.glTranslatef(xblokpos, playerheight+1.83f, zblokpos);
      GL11.glRotatef(340.0f + yrot, 0,1f, 0f);
     




its rotated to the side of the player by 18, and tilted down by 20 (GL11.glRotatef(20, 1.0f, 0, 0); )
Once the camera is rotated, I place the block infront of the player with xblokpos zblockpos (the block is 0.24 units from the player camera)
The block is then rotated to maintain its relative rotation to the player
I have also reduced the effect of the walkbias by /3 to minimise, but not remove the bobbing effect on the block, as its close to the camera.

Hope this is of some help. The values you want to use may be trial and error! To get the look you want to have.
Offline Vermeer

JGO Coder


Medals: 16



« Reply #71 - Posted 2013-03-26 13:30:33 »

@Steg

When initialy testing, my movement and block detection, I made the block im standing on change colour, also I had textures with a grid pattern, and drew wireframe boxes to make tests and be sure exactly what was heappening.

Another very good way is to output your character position information, and the position when there has been a collision, and see if they are as expected.
Aslo I dont know if you have negative positions in your map, but depending on how you are working out the block, it may not work as expected when going negative.

This may not be a standard soloution, and im not sugesting you do this, but the solution works in my game.

1  
2  
3  
4  
5  
6  
int x;
         if(xp>=0){
            x=(int)(xp+0.5);
         } else {
            x=(int)(xp-0.5);
         }


I always at 0.5 to the block to get to the block middle, x is a float of a position   so say  29.6 ..  this would mean i check block 30!

Aslo I dont use abs or floor, but I use modulo to get the position in the chunk  so  30%16 = 14 so its block 14 in x on that chunk.

Again I may not be using best practice, but this works fine for me. Other people may be able to sugest alternatives, that work better for your game.
Online Longor1996
« Reply #72 - Posted 2013-03-26 16:59:40 »

And again: How about using AABB?

Here's the Method i use, in Pseudocode.
I learned it from Minecraft's Code a long time ago (After the first Halloween Update),
and now i use it really everywhere.
The best thing about this method is, that it is totally failsafe!

The worst thing that can happen, is when your velocity is insanely high, that you go trough blocks.
Just make sure your velocity is never bigger than your updaterate in milliseconds.

Pseudocode:
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  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
List<AABB> boxes = world.getCollisionBoxesInRange(player.x,player.y,player.z,player.squaredSize);

double cvelocity_x = player.velocity_x;
double cvelocity_y = player.velocity_y;
double cvelocity_z = player.velocity_z;

// X Axis Check
for(AABB box : boxes){
    cvelocity_x = box.getIntersectionOffsetX(player,cvelocity_x);
}

// Z Axis Check
for(AABB box : boxes){
    cvelocity_z = box.getIntersectionOffsetZ(player,cvelocity_z);
}

// Y Axis Check
for(AABB box : boxes){
    cvelocity_y = box.getIntersectionOffsetY(player,cvelocity_y);
}

if(player.velocity_x != cvelocity_x)
    cvelocity_x = 0;

if(player.velocity_z != cvelocity_z)
    cvelocity_z = 0;

if(player.velocity_y != cvelocity_y)
{
    cvelocity_y = 0;
}

player.velocity_x = cvelocity_x;
player.velocity_y = cvelocity_y;
player.velocity_z = cvelocity_z;

player.x += player.velocity_x;
player.y += player.velocity_y;
player.z += player.velocity_z;

player.doRecalculateEntityBoundingBox();

=====================================

    public double getIntersectionOffsetY(AABB boxToTestAgainst, double velocity)
    {
        if (boxToTestAgainst.x1 <= x0 || boxToTestAgainst.x0 >= x1)
        {
            return velocity;
        }

        if (boxToTestAgainst.z1 <= z0 || boxToTestAgainst.z0 >= z1)
        {
            return velocity;
        }

        if (par2 > 0.0D && boxToTestAgainst.y1 <= y0)
        {
            double d = y0 - boxToTestAgainst.y1;

            if (d < velocity)
            {
                velocity= d;
            }
        }

        if (par2 < 0.0D && boxToTestAgainst.y0 >= y1)
        {
            double d1 = y1 - boxToTestAgainst.y0;

            if (d1 > velocity)
            {
                velocity = d1;
            }
        }

        return velocity;
    }


The best thing you can do is to take a look at Minecraft's Collision Code (use MCP to get the code),
and then figure out how it works.
And don't just copy it, because that doesn't help you at all and won't work out very well.
I copyed it too at first, and it didn't work, so i learned hwo it work's and made my own that works with my engine.

- Longor1996



PS: Any fails/errors/mistakes in this post are there because of the extreme headache i have right now.

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

JGO Coder


Medals: 16



« Reply #73 - Posted 2013-03-26 18:51:22 »

And again: How about using AABB?


Hi, thank you for taking the time to post all that. I'll give that a try and let you know how it goes. Though my collision does work, I am after all doing the project to learn new stuff and expand techniques.

Yes, I have already had to be mindful of high a velocity with my code.

I'll also take a peek at minecraft code for this.  Thanks again for taking the time to help.

@steg.  It's no bad thing to try and get it to work your way, then update it when your ready. I stand by my method, but Longor make a convincing case to look at AABB.

Offline Vermeer

JGO Coder


Medals: 16



« Reply #74 - Posted 2013-03-26 19:51:34 »

Time to make a some tools:
Note for the trianglar face I will probably change it to a quad (thats almost a point). Odd how you notice mistakes just as you posting something!





Ill hard code models for now, then switch to a model loader - as described by the Coding Universe if I want more complex models.
Offline steg90

Senior Member


Medals: 1



« Reply #75 - Posted 2013-03-26 19:52:23 »

Hey thanks for all the information guys :-)

The AABB looks great, will google the MCP stuff and look.

I guess it be a good idea to change the block colours that are around the player?
My player is basically the camera's position, is this correct?

I already output player position, block we are on etc, block on is correct and where collision should occur but it isn't very accurate, may need something like you have done with the offset of 0.5 or something?

I don't understand though how you would use this:

1  
2  
3  
4  
5  
6  
int x;
         if(xp>=0){
            x=(int)(xp+0.5);
         } else {
            x=(int)(xp-0.5);
         }

What is xp?

Yes, the block the player is holding, I just do this:

1  
2  
3  
4  
5  
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_DEPTH_TEST);
glLoadIdentity();  
glTranslatef(-1,0,4f);  
glRotatef(20,0,0,1);


But cube now inside out but doesn't go through the floor...I guess this is wrong?

What do you set your playerheight too and do you need to take this into account when doing your collision check?

Thanks again, really appreciate all this!

Offline steg90

Senior Member


Medals: 1



« Reply #76 - Posted 2013-03-26 19:53:10 »

That tool looks awesome  Grin
Offline Vermeer

JGO Coder


Medals: 16



« Reply #77 - Posted 2013-03-26 20:10:08 »

@steg

The xp is player x.   So I use it in my function to get the current block. I put it on to show that if the player position is negative I subtract 0.5. That's all it does.

No, don't disable depth test, that will make a mess (only do that for 2d)

My player is the camera yea. The camera is 1.8 high above the players feet(floor)


Offline steg90

Senior Member


Medals: 1



« Reply #78 - Posted 2013-03-26 20:21:59 »

ok, did use the depth test for my skybox...although got the skybox turned off at the moment.

Without depth test disabled, this video shows what happens:


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


Guess I've not got the camera set at the correct height or something?

Do you use gluLookat? I've got this at the start:

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

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

      glMatrixMode(GL_MODELVIEW);


Just doesn't seem to look right?...


Offline Vermeer

JGO Coder


Medals: 16



« Reply #79 - Posted 2013-03-26 21:51:23 »

I forgot to mention something steg,

The box the player is holding is a small block, I forget how big exactly, but much smaller than a game cube, it may be like 0.1 big

It just looks big as its near the camera, this means it won't touch the floor!



Offline steg90

Senior Member


Medals: 1



« Reply #80 - Posted 2013-03-26 22:03:34 »

Lol,

Thanks for that, mine does touch the floor as I got mine as 0.5!

Will try 0.1 and see if it helps ;-)

PS - how did you put the small cross in middle of screen, it a sprite?

Thanks again!
Offline Vermeer

JGO Coder


Medals: 16



« Reply #81 - Posted 2013-03-26 22:05:48 »

Ah ok, that should solve your problem.

The crosshair is part of my bitmap font, but basically yea it's just a sprite rendered on a quad in orthographic mode.
Offline steg90

Senior Member


Medals: 1



« Reply #82 - Posted 2013-03-26 22:52:25 »

Hi,

Yes, setting to 0.1 did the trick and trial and error with glTranslatef and glRotatef, lol.

Not got the block in hand moving with the players walkbias yet, will do though, got the camera moving with the walkbias, that nehe tutorial is great.

Not looked at rendering a sprite as of yet, new to OpenGL, only been using around a month now, so will need to take a look at how you do this.

Need to allow player to place a cube now, want to show a wireframe cube say 2 units in front of player, is this easy to do?

Thanks again,
Steve
Offline HeroesGraveDev

JGO Kernel


Medals: 245
Projects: 11
Exp: 2 years


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


« Reply #83 - Posted 2013-03-27 03:57:14 »

I wrote a faster implementation for AABBs:

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

It was made for 2D but can be applied to 3D.

Offline Vermeer

JGO Coder


Medals: 16



« Reply #84 - Posted 2013-03-27 15:51:20 »

Some thoughts on AABB:



http://www.java-gaming.org/user-generated-content/members/167679/aabb.jpg

My ingame solution is similar, but I use a circle rather than a box for the easiest. I handle vertical collisons (falling / jumping differently as this will be axis aligned - ie you dont tilt forwards and backwards)

What are you thoughts on dealing with non axis aligned collisions  ....1, 2, 3 or another solution?
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #85 - Posted 2013-03-27 15:56:00 »

What are you thoughts on dealing with non axis aligned collisions  ....1, 2, 3 or another solution?

definitely SAT: Seperating Axis Theorem. It's pretty easy for... actually every shape.

I've implemented it myself. Didn't get getting the Minimal Translation Vector (MTV) working, but that doesn't seem to be useful to you. And you could try it too... Anyway, here's the code:
The 'Quad' class (mind the 'implements SATObject'!): https://github.com/matheus23/Utils/blob/master/Utils/src/org/matheusdev/util/collision/Quad.java
Where all the magic happens: https://github.com/matheus23/Utils/blob/master/Utils/src/org/matheusdev/util/collision/Collision.java

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Vermeer

JGO Coder


Medals: 16



« Reply #86 - Posted 2013-03-27 17:42:09 »

Thank you for that Matheus, I will have a good look over that.

Btw your game look excellent, loved the demo of the networking. Very zippy movement and accurate. Nice graphics too. Thanks for posting!
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #87 - Posted 2013-03-27 18:00:10 »

Thank you for that Matheus, I will have a good look over that.

Btw your game look excellent, loved the demo of the networking. Very zippy movement and accurate. Nice graphics too. Thanks for posting!

Oh, thank you Smiley
I'm also glad to be helpful Wink

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Vermeer

JGO Coder


Medals: 16



« Reply #88 - Posted 2013-03-27 21:04:19 »

Update:

I got a new axe! See posts above for how it got there Smiley

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

Bigger map, water tests, and Axe!
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #89 - Posted 2013-03-27 21:24:18 »

Just a little thought on how I'd do picking:

I have a Vector indicating the "lookAt": The direction the camera is looking.
And I have a Vector telling me the position of the camera.
1  
2  
Vec3 camDir = camera.getDirectionVector();
Vec3 camPos = camera.getPosition();


So what I do now is a pretty ugly ray-casting (everyone starts ugly):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
// Make this variable greater, and more positions will be iterated over => more precise
final int steps = 10;
// This is the range the player has, being able to grab blocks (in this case 4 blocks)
final float range = 4f;
Vec3 deltaStep = new Vec3(camDir).normalize().mul(range / (float) steps);
Vec3 currentPos = new Vec3(camPos);
for (int i = 0; i < steps; i++) {
    currentPos.add(deltaStep);
    Block block = world.getBlockAt((int) currentPos.x, (int) currentPos.y);
    if (block != null) {
         return block;
    }
}


This way you can already pick blocks to destroy them...
But I honestly have no concrete Idea of how to do picking of single faces of a block...

I'd probably do that normal picking, and then construct a line out of the picking position, where the block was found and the camera position, and then test all the faces of the cube for intersection with the constructed line.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Pages: 1 2 [3] 4 5 ... 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.

atombrot (26 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (13 views)
2014-08-16 06:20:21

Tekkerue (20 views)
2014-08-16 06:12:11

Rayexar (59 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!