Sparky's little Cube World Project

Hello!

You could have already guessed it: I joined the club creating cube world games! I am doing this because I am now taking my first steps in 3D-game-programming and this seems to be fairly easy and enjoyable. I am working with LWJGL.

Last things I did: (roughly)

  • get Shaders working (GLSL 1.20 / 1.30)
  • setting up movement in 3D space (matrix stuff)
  • setting up a standard cube (only one texture for now)
  • setting up a chunk that can hold many cubes
  • managing the performance by culling everything away that is not needed at the moment (not fully finished yet)
  • enable manipulating cubes by removing or placing them

The visuals is simple at the moment, sort of binary: either there is a cube or there is not. Because I have not had the time to implement different kinds of cubes. It is not very high on my priority list.

So I am now going to show what it looks like at the moment.

http://www.rm2k-tv.de/stuff/bencraft/craft_screenshot1.png

And here is a video:

GKxiF8YavXc

I will be working on this the next few days I think. I will update here if there is any good process on it.

Ok, I forgot about the jar if you like to try it. It should be ready for windows and linux:
here

Please report me any errors. :slight_smile:

The download is a 404

Yeah, fixed it! Thank you. :slight_smile:

Wow that looks really good. Will take a look! Will look with interest. It great to have more cube world projects! :slight_smile:

EDIT*

Had a look, thats fantastic. Nice 3d picking btw!

Your picking is very good, may I ask - did you use ray casting or glReadpixels? Or both?

Thank you, Vermeer. :slight_smile:

Honestly, I don’t know anything of glReadPixels. So, yes, I used ray casting. It took me some time to get the idea of the vectors and the role of the dot products in this thing, but after that, it was easy. (Edit: I was mixing things up, no dotProduct in my code) This is my code:

http://pastebin.java-gaming.org/3e222042c57
note: getMin(X) and others are the corners of the cube.

I have made a new video showing the raycasting by drawing the ray as a line.

IPq6JQf3KT4

This is pretty great! I love how your camera slides a little when you stop walking, it makes it feel more realistic than abruptly stopping! But, why do you render the backs of the cubes that are inside the chunk? In my voxel engine, I only render faces that are absolutely needed. So for instance, I render a chunk out like yours. Now, yours will render cubes while mine just renders the front face of the cube. I don’t know if that made any sense at all but… I’m just wondering why you render out faces that are hidden behind other faces, wouldn’t that be slightly less efficient than just rendering only the faces that are visible?

You should watch the first video to the end again :wink:

Oh darn, I did it again :confused: But he still was rendering them at the end, he just enabled back face culling I think! So why even have it off in the first place? Unless I’m wrong and he actually had it on the whole time…

It is a good question, opiop.

I did it because I was often confused while debugging, running into a wall and not being able to see anything. And after all I wanted to make sure that everything renders the way that I want it to be. So I disabled backface-culling and I had no problems anymore. Of course there is an impact on efficiency, but when I am done or not in debugging mode, then it will always be turned on. :slight_smile:

Please, if there are other things that are questionable or weird or anything, please ask or tell me.

I actually had the same problem last night! Thank you for the ray casting code, I think next I’ll try to implement block placing/destruction.

Good luck on your game, I’ll be watching! :slight_smile:

Edit:
Actually, you are using ray casting correct? Isn’t that a very old way of picking in 3D? I feel like

glReadPixels()

is a better way to do it, but I have no idea!

Thank you! :slight_smile:

[quote=“opiop65,post:13,topic:41383”]
No offense, but this should be obvious now. :wink: Yes, I do.

[quote=“opiop65,post:13,topic:41383”]
Hmmm, of course there are differences in performance, that can be arguments for using certain techniques, but in the math itself, I see no problems. It is fairly simple, doesn’t use square roots, just divisions here and there. And it gives me information about the surface that the ray has hit i.e. the normal of the face. Can glReadPixels() do this? I don’t know much about it, but it seems like it could be a problem to get information about the orientation of the face the pixel belongs to.

EDIT: The algorithm was published by Andrew Woo in “Fast Ray-Box intersection” in Andrew Glassner’s “Graphics Gems” in 1990.

Oh, glReadPixels() is aweful!
I use glReadPixels only for making screenshots, I don’t really know what you are trying to archive with them

glReadPixels gives you an array of color values, which each pixel on a framebuffer has. To generate that array the driver needs to send all the data from your graphics card to your cpu / ram to make it accessible for the cpu.

That operation is very, very expensive. It’s a lot about copying and stuff…

I don’t even really understand what you are trying to archive with getting the pixel values from your framebuffer? Do you want to draw unique colors for each block of your game to a second framebuffer and then read the color value of the pixel in the middle of the screen and then translate that color back to a position in your voxel world?

That’s definitely not the purpose of glReadPixels()…

Sparky’s solution is the right solution (if he is doing it with the bresenham-algorithm… ::slight_smile: )

Hmmm, am I? I don’t think so. I have skipped the chapter about bresenham in my book. Maybe I should go back there. :persecutioncomplex:
In my last post I edited where the algorithm that I am using is from:

[quote]The algorithm was published by Andrew Woo in “Fast Ray-Box intersection” in Andrew Glassner’s “Graphics Gems” in 1990.
[/quote]

[/quote]
Eh… Couldn’t find the book’s chapter on google, probably you could just post some source? :slight_smile:

I posted the source in this thread. Here it is: http://pastebin.java-gaming.org/3e222042c57

I got it from my favorite book: http://gamemath.com/about-the-book/
It is really, really good! 8)

So here is my promised version with collision detection. I had some problems with it because I am unexperienced and a bit dumb, but now I have it neeeeeaaaarly working! :slight_smile:

You can test it here: Alpha2

I still have severe problems with performance. Because of this there are still 888 cubes per chunk. This is what I am going to fix next. I can’t wait. :slight_smile:

I will post a video of it, when it is ready!

You aint dumb @Sparky83!

Anyway, tried to run your jar and I got this on my terminal:

Exception in thread “main” java.lang.UnsupportedClassVersionError: engine/EngineMain : Unsupported major.minor version 51.0

Running on a Macbook Pro.