Author Topic: nCraft (3D minecraft-like game for the nspire)  (Read 113835 times)

0 Members and 2 Guests are viewing this topic.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #180 on: September 27, 2012, 01:34:39 pm »
Here are a couple ideas that could help with the speeding up of the way you sort things:

First off, it is important to note that whenever the camera is within a voxel, the voxels that are rendered are sorted relative to the distance they are to that voxel.  Consequently no matter what voxel the camera is in, the order of the rendered voxels is always the same relative to the center camera voxel.  What this means is that you can presort a large number of voxel positions into an array based on how far they are from a center voxel, and simply use those positions relative to the camera to render.

This works, but it can take up a large amount of memory.  If that is a problem, there is another solution that I discovered when working on my Castle Storm game, which uses a similar rendering method.  The way it would work is by drawing the voxels (still relative to the camera position) in shells, and it is painfully difficult to explain, so if you are interested, I can whip up some sort of gif or example and we can talk from there.

Now, this would speed up the sorting of cubes, but it would not actually speed up the drawing, which is probably another main bottleneck.  First off, since you are only rendering cubes, you can always discard the faces that are facing away from you.  This is a rendering trick you can use on convex objects, that any faces that are facing away from you cannot actually be seen.  Additionally, you can use a simply dot product to detect whether or not a face is facing away from you, so it is super speedy and results in half of your faces being discarded!  Another method would be to look at the cubes surrounding a cube to be rendered.  When you go to render a cube, you can look at neighboring cubes to see if they are solid, if not, you do not have to render the connecting face!  This should result in significant speedups hopefully, since using these methods would drastically cut down on the number of polygons you need to render in any given frame.  

Offline Augs

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 306
  • Rating: +30/-29
    • View Profile
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #181 on: September 27, 2012, 02:02:30 pm »
The update is cool but the controls are awkward, 7 should break blocks and 9 should place blocks.
« Last Edit: September 28, 2012, 02:06:38 pm by Augs »

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #182 on: September 27, 2012, 02:32:42 pm »
Thanks for the help !

First off, it is important to note that whenever the camera is within a voxel, the voxels that are rendered are sorted relative to the distance they are to that voxel.  Consequently no matter what voxel the camera is in, the order of the rendered voxels is always the same relative to the center camera voxel.  What this means is that you can presort a large number of voxel positions into an array based on how far they are from a center voxel, and simply use those positions relative to the camera to render.
Seems interesting. Could you give an exemple ? Because of my poor English skills, I'm not sure that I've got it very well...

This works, but it can take up a large amount of memory.  If that is a problem, there is another solution that I discovered when working on my Castle Storm game, which uses a similar rendering method.  The way it would work is by drawing the voxels (still relative to the camera position) in shells, and it is painfully difficult to explain, so if you are interested, I can whip up some sort of gif or example and we can talk from there
Memory isn't a big problem on the TI-Nspire. i can achieve full world renders, which means that I use an array containing more than 30,000 floats...

Now, this would speed up the sorting of cubes, but it would not actually speed up the drawing, which is probably another main bottleneck.  First off, since you are only rendering cubes, you can always discard the faces that are facing away from you.  This is a rendering trick you can use on convex objects, that any faces that are facing away from you cannot actually be seen.  Additionally, you can use a simply dot product to detect whether or not a face is facing away from you, so it is super speedy and results in half of your faces being discarded!
I already do that :)

Another method would be to look at the cubes surrounding a cube to be rendered.  When you go to render a cube, you can look at neighboring cubes to see if they are solid, if not, you do not have to render the connecting face!  This should result in significant speedups hopefully, since using these methods would drastically cut down on the number of polygons you need to render in any given frame. 
This could improve my drawing function indeed, since I draw every cube that "touches" an empty block...




By the way, I added a function to render full world with F.
You now can see your creations properly :)
Full renders take about 5 secs to generate...
But as I said, I use more than 30,000 floats, so I'm afraid that it might crash grayscale Nspires, which don't have so much RAM. (it doesn't crash the grayscale emulator, though)

Offline Augs

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 306
  • Rating: +30/-29
    • View Profile
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #183 on: September 27, 2012, 02:38:47 pm »
Cool, I made a creation but the problem is that I can't save it. I think this should be the next feature.

edit: this is also the first French victory in 100 years. JK France is great.
« Last Edit: September 27, 2012, 02:41:14 pm by Augs »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #184 on: September 27, 2012, 02:55:24 pm »
Seems interesting. Could you give an exemple ? Because of my poor English skills, I'm not sure that I've got it very well...

Mmm it's a bit hard to explain, but think of it this way.  Every single frame you are sorting the blocks according to distance, and every single frame you arrive at the exact same order.  Every single frame you always render the farthest blocks first, followed by closer blocks, and finally centering on the camera.  Instead of re-sorting the blocks every frame, you could just generate a sorted list when the game starts, that way you never have to sort again.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #185 on: September 27, 2012, 03:11:51 pm »
Seems interesting. Could you give an exemple ? Because of my poor English skills, I'm not sure that I've got it very well...

Mmm it's a bit hard to explain, but think of it this way.  Every single frame you are sorting the blocks according to distance, and every single frame you arrive at the exact same order.  Every single frame you always render the farthest blocks first, followed by closer blocks, and finally centering on the camera.  Instead of re-sorting the blocks every frame, you could just generate a sorted list when the game starts, that way you never have to sort again.
I can't really see how well that would work when you rotate the camera though.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #186 on: September 27, 2012, 03:24:06 pm »
Yes, same for me...

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #187 on: September 27, 2012, 03:33:57 pm »
Seems interesting. Could you give an exemple ? Because of my poor English skills, I'm not sure that I've got it very well...

Mmm it's a bit hard to explain, but think of it this way.  Every single frame you are sorting the blocks according to distance, and every single frame you arrive at the exact same order.  Every single frame you always render the farthest blocks first, followed by closer blocks, and finally centering on the camera.  Instead of re-sorting the blocks every frame, you could just generate a sorted list when the game starts, that way you never have to sort again.
I can't really see how well that would work when you rotate the camera though.

Well I suppose you would have to be considering all blocks around you equally, and then throw them out if they are outside of the camera view.  Since the sorting of blocks should be independent of camera angle anyway.


Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #188 on: September 27, 2012, 04:35:25 pm »
Seems interesting. Could you give an exemple ? Because of my poor English skills, I'm not sure that I've got it very well...

Mmm it's a bit hard to explain, but think of it this way.  Every single frame you are sorting the blocks according to distance, and every single frame you arrive at the exact same order.  Every single frame you always render the farthest blocks first, followed by closer blocks, and finally centering on the camera.  Instead of re-sorting the blocks every frame, you could just generate a sorted list when the game starts, that way you never have to sort again.
I can't really see how well that would work when you rotate the camera though.

Well I suppose you would have to be considering all blocks around you equally, and then throw them out if they are outside of the camera view.  Since the sorting of blocks should be independent of camera angle anyway.


Uh no, it's not, that's my point. Just think about turning 90 degrees to the right for example, your list of sorted blocks will then go from left to right rather than from far to near.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #189 on: September 27, 2012, 04:42:10 pm »
Unless the camera is also moving as it is rotating, the distance from each block to the camera should not be changing.  Since we sort blocks based on how far they are from the camera, and since the distances are not changing, shouldn't the sorted order also not change?

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #190 on: September 27, 2012, 04:45:15 pm »
Well, we don't sort by real distance from the camera though, we sort by the distance from the camera to the plane parallel to the screen that contains the block. And also the camera will definitely be moving in any sort of game situation.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #191 on: September 27, 2012, 04:48:48 pm »
I'm not saying that the camera will not be moving, I am saying that as long as the camera is inside of a single cube, the cubes being drawn will be sorted in the same order regardless of the angle or the location of the camera inside the cube.

Offline AzNg0d1030

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 522
  • Rating: +45/-4
  • Hardcore anime watcher.
    • View Profile
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #192 on: September 27, 2012, 06:09:15 pm »
Oh wow this is amazing! Can't wait for the touchpad implementation
You just lost the game.



Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #193 on: September 27, 2012, 06:56:46 pm »
Just tested.

F*cking great, continue the awesome work.
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: nCraft (3D minecraft-like game for the nspire)
« Reply #194 on: September 27, 2012, 07:13:23 pm »
This is great.
Also seconded on the saving. Even if it's just a savestate or something, it'd be worth it :D
Vy'o'us pleorsdti thl'e gjaemue