Hello,
The fresh air isn't fresh anymore. Outside it is worse than inside. But inside it is not good, too. So, my brain starts to stop thinking properly.
Here is my question:
I have a voxel volume with 64x64x64 voxels. I want to divide that volume into several chunks, so I have 4 32x32x32 volumes instead of one big. My problem is now, I can't figure out now, how to get the chunk where a point is in!
So, when I got a point at (5|5|5) it would be the first chunk. I'm also looking for a mathematical solution, rather than looping all chunks, because I have to care about speed here.
Is there any non-grilled brain that can help me? :D
To warm for thinking... I need math help.
Quote:Original post by mind in a box
I have a voxel volume with 64x64x64 voxels. I want to divide that volume into several chunks, so I have 4 32x32x32 volumes instead of one big.
Definitely not thinking straight. That would be 8 32x32x32 volumes.
Quote:My problem is now, I can't figure out now, how to get the chunk where a point is in!
If you are given voxel (x,y,z), check what side of 32 each coordinate falls. Build a 3-bit number with the results of the comparisons. That number tells you which chunk you are in.
If you start counting at 0, everything works.
Well, my brain is pretty grilled too, but I think you would have 8 volumes, wouldn't you?
In order to identify a chunk, you can give each chunk a number, ie. define an order for those chunks. If you subdivide your volume once (8 equally sized cubes), then you can give the volume with (x>0, y>0, z>0) the index 0 (if your volumes ranges from -length/2 to +length/2), etc...
If all your sectors have the same length on one axis, then you can use modulo to calculate in which sector a point lies in, which will even work when you subdivide your volume into 3*3*3 cubes (and ofcourse more).
In order to identify a chunk, you can give each chunk a number, ie. define an order for those chunks. If you subdivide your volume once (8 equally sized cubes), then you can give the volume with (x>0, y>0, z>0) the index 0 (if your volumes ranges from -length/2 to +length/2), etc...
If all your sectors have the same length on one axis, then you can use modulo to calculate in which sector a point lies in, which will even work when you subdivide your volume into 3*3*3 cubes (and ofcourse more).
Quote:Original post by alvaroQuote:Original post by mind in a box
I have a voxel volume with 64x64x64 voxels. I want to divide that volume into several chunks, so I have 4 32x32x32 volumes instead of one big.
Definitely not thinking straight. That would be 8 32x32x32 volumes.
Lol, Yes, indeed. :)
Quote:
If you are given voxel (x,y,z), check what side of 32 each coordinate falls. Build a 3-bit number with the results of the comparisons. That number tells you which chunk you are in.
The 8 chunks were just a example. I need more than that, so just comparing sides won't work. Lets say I need 16x16x16 chunks for clearness.
Edit: Ninja'd, I'll read your posting now, SIS.
Edit2: Okay, I don't understand it. I never used Modulo before. What does it exactly?
Quote:Original post by mind in a box
The 8 chunks were just a example. I need more than that, so just comparing sides won't work. Lets say I need 16x16x16 chunks for clearness.
How about you tell us what you need, then?
Let's deal with one dimension at a time. If you have 64 numbers (numbered 0, 1, 2, ... 63) and you divide them into 4 chunks of size 16, you can determine which chunk n is in by computing n/16, rounding down (which, conveniently enough, is what `n/16' means in C and many derived languages, for positive values of n). The result is 0, 1, 2 or 3.
Since we have 3 coordinates, we do that for each coordinate, and we end up with 3 numbers under 4. If you put them together and interpret them as a number in base 4, you'll get the number of the chunk you are in.
Quote:Original post by mind in a box
Okay, got it until the "base 4" part. Does it meanMyValue%=4;
?
I mean this.
Ah, I see. Doing mathematics in English is somewhat harder for me. :)
But I don't understand that part now aswell: "If you put them together and interpret them as a number in base 4, you'll get the number of the chunk you are in."
Put together means +?
interpret them as a number in base 4 means MyNumber^4 or 4^MyNumber?
I'm sorry for asking so dump questions, but I learned mathematic only in german. :(
But I don't understand that part now aswell: "If you put them together and interpret them as a number in base 4, you'll get the number of the chunk you are in."
Put together means +?
interpret them as a number in base 4 means MyNumber^4 or 4^MyNumber?
I'm sorry for asking so dump questions, but I learned mathematic only in german. :(
An example: We divide 64x64x64 in chunks of size 16x16x16, and we want to know which chunk (20,60,35) will be in.
20/16 = 1
60/16 = 3
35/16 = 2
Put them together: 132.
Interpret that in base 4: 1*4^2 + 3*4^1 + 2*4^0 = 1*16 + 3*4 + 2*1 = 30
So it's in chunk number 30.
20/16 = 1
60/16 = 3
35/16 = 2
Put them together: 132.
Interpret that in base 4: 1*4^2 + 3*4^1 + 2*4^0 = 1*16 + 3*4 + 2*1 = 30
So it's in chunk number 30.
Oops, modulo was the wrong term. I wanted to explain something very similar to what alvaro said.
Damn heat...
Damn heat...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement