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!
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!
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.
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
I wrote a faster implementation for AABBs:
It was made for 2D but can be applied to 3D.
Some thoughts on AABB:
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?
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
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
I’m also glad to be helpful
Update:
I got a new axe! See posts above for how it got there
1QKSCwHpxrs
Bigger map, water tests, and Axe!
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.
Vec3 camDir = camera.getDirectionVector();
Vec3 camPos = camera.getPosition();
So what I do now is a pretty ugly ray-casting (everyone starts ugly):
// 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.
When rotation is nivolved it is no longer an AABB.
What you need is an OBB with SAT.
AABB = Axis Aligned Bounding Box.
OBB = Oriented Bounding Box.
SAT = Separating Axis Theorem
And you can easily cut down the faces that need checking down to 3 by not including the back faces.
And if the camera position is equal to the block position on any axis then you can remove the faces on that axis too.
Best Case Scenario: Check 0 faces.
Worst Case Scenario: Check 3 faces.
Fog is very simple to implement as long as your sky is a single color. When you start messing around with gradients it gets a whole lot more complicated
Mike
Ok,
I got a skybox, so textured cube. Simple fog would be ok for a start
On Block Picking:
If you have the gradient of a line, then you can work out the x coords from the y coords and vice versa.
In case you don’t know linear algebra: [icode]y = mx+c; x = (y-c)/m;[/icode]
With that, you simply find which axis has the least most change (in this case x-axis), and interpolate along that line in ones, until you hit a block. Sometimes, you will have two y coords for one x coord. To avoid missing blocks that actually might be hit, you simply check for blocks on both sides of the intersected line. Once you hit a block, backtrack one space along the line to work out which face the ray intersected.
Of course it needs to be adjusted for 3D.
EDIT: I haven’t actually tried this. I’m implementing it in my own game right now. It should work.
EDIT 2: Almost got it working. I just need to make it check for blocks on both sides of the line then it should be finished.
Hi, thanks for that. I have used Bresenhams line algorithm before in a 2.5D ray caster, also for Line of sight in a Tile based RPG game.
I have picking working fairly well now. I cast a ray from camera. I do it as you have outlined.
I do the vertical calculations first, and then from that I know the horizontal distance, which I just use trig to find the x and z distance. Like with Bresnenhams this can be optimised with similar triangles.
I don’t know the usual resolution, but I’m casting 100 rays over 10 blocks. =0.1 block accuracy. I can improve this when I Find the individual face as you outline below.
The tricky part is if the line intersects exactly on the corner of 2 blocks, an thus traces through them. Mathamatically possible, but not what we want!
Glad you got the raycast working
I’m having trouble with a texture on a cube as I want to texture my blocks now, they look too bland just using colours. I’m getting weird effects, I’ve textured just a cube which looks fine, if my texture is green (grass), then the rest of the blocks which aren’t being textured by the way, will also take on this colour…have you seen anything like this before?..If the texture is brown/crate, then again all my colours on my blocks seemed to get ‘tinted’ with the texture colour?!
I’m using PNGDecoder, also used slick-util with same results.
Thanks and keep up this great work, it is inspiring!
*UPDATE - got it working, I was forgetting to disable the textures for blocks that don’t need a texture!
Is it possible that we could get the source for the new version of your game? I’ve made my own block engine but it’s not great on efficiency / performance, and I’d love to learn from someone better’s code to see where it can be optimised and what methods I should be using.
Update:
3D picking part 1
Added entities
__nHC-NhhNk
Im going away for a few days so no work on this till monday. Someone is going to host the code for me, on my return I will make all the code
available. It’s not fancy code, infact its probably a good example of not what to do. I’t is not optimised, or organised. But I like to just get things working first.
But if it helps solve any problems that people can build on then sure.