• Create Account

### #Actualmgoss

Posted 13 May 2012 - 01:53 PM

There a much easier way of finding blocks. If you have an 3 dimensional array. For instance, a Blocks[16, 128, 16] for a chunk.

float x = position.X;
float y = position.Y;
float z = position.Z;
int x = ((int)x / SCALE) % 16;
int y = ((int)y / SCALE) % 128;
int z = ((int)z / SCALE) % 16;


scale is how big your blocks are. Then you can say Block b = Blocks[x, y, z];

If you want to pick what blocks you clicked on. Then do this

const int range = SCALE * 10; //10 = Distance in radius
for(int x = playerX - range; x <= playerX + range; x += SCALE)
{
for(int z = playerZ - range; z <= playerZ + range; z += SCALE)
{
for(int y = playerY - range; y <= playerY + range; y += SCALE)
{
SignedVector3i xyz = GetBlockIndex(new Vector3(x, y, z));
Block b = Block[xyz.x, xyz.y, xyz.z];
//Create a bounding box around that block and it's 6 bounding boxes for each face. Then use a ray to see which side it intersected at.
}
}
}


### #5mgoss

Posted 13 May 2012 - 01:53 PM

There a much easier way of finding blocks. If you have an 3 dimensional array. For instance, a Blocks[16, 128, 16] for a chunk.

float x = position.X;
float y = position.Y;
float z = position.Z;
int x = ((int)x / SCALE) % 16;
int y = ((int)y / SCALE) % 128;
int z = ((int)z / SCALE) % 16;


scale is how big your blocks are. Then you can say Block b = Blocks[x, y, z];

If you want to pick what blocks you clicked on. Then do this

const int range = SCALE * 10; //10 = Distance in radius
for(int x = playerX - range; x <= playerX + range; x += SCALE)
{
for(int z = playerZ - range; z <= playerZ + range; z += SCALE)
{
for(int y = playerY - range; y <= playerY + range; y += SCALE)
{
SignedVector3i xyz = GetBlockIndex(new Vector3(x, y, z));
Block b = Block[xyz., xyz.y, xyz.z];
//Create a bounding box around that block and it's 6 bounding boxes for each face. Then use a ray to see which side it intersected at.
}
}
}


### #4mgoss

Posted 13 May 2012 - 01:52 PM

There a much easier way of finding blocks. If you have an 3 dimensional array. For instance, a Blocks[16, 128, 16] for a chunk.

float x = position.X;
float y = position.Y;
float z = position.Z;
int x = ((int)x / SCALE) % 16;
int y = ((int)y / SCALE) % 128;
int z = ((int)z / SCALE) % 16;


scale is how big your blocks are. Then you can say Block b = Blocks[x, y, z];

If you want to pick what blocks you clicked on. Then do this

const int range = SCALE * 10; //10 = Distance in radius
for(int x = playerX - range; x <= playerX + range; x += SCALE)
{
for(int z = playerZ - range; z <= playerZ + range; z += SCALE)
{
for(int y = playerY - range; y <= playerY + range; y += SCALE)
{
SignedVector3i xyz = GetBlockIndex(new Vector3(x, y, z));
Block b = Blocks[xyz., xyz.y, xyz.z];
//Create a bounding box around that block and it's 6 bounding boxes for each face. Then use a ray to see which side it intersected at.
}
}
}


### #3mgoss

Posted 13 May 2012 - 12:27 AM

There a much easier way of finding blocks. If you have an 3 dimensional array. For instance, a Blocks[16, 128, 16] for a chunk.

float x = position.X;
float y = position.Y;
float z = position.Z;
int x = ((int)x / SCALE) % 16;
int y = ((int)y / SCALE) % 128;
int z = ((int)z / SCALE) % 16;


scale is how big your blocks are. Then you can say Block b = Blocks[x, y, z];

If you want to pick what blocks you clicked on. Then do this

const int range = SCALE * 10; //10 = Distance in radius
for(int x = playerX - range; x <= playerX + range; x += SCALE)
{
for(int z = playerZ - range; z <= playerZ + range; z += SCALE)
{
for(int y = playerY - range; y <= playerY + range; y += SCALE)
{
SignedVector3i xyz = GetBlockIndex(new Vector3(x, y, z));
//Create a bounding box around that block and it's 6 bounding boxes for each face. Then use a ray to see which side it intersected at.
}
}
}


### #2mgoss

Posted 13 May 2012 - 12:22 AM

There a much easier way of finding blocks. If you have an 3 dimensional array. For instance, a Blocks[16, 128, 16] for a chunk.

float x = position.X;
float y = position.Y;
float z = position.Z;

int x = ((int)x / SCALE) % 16;
int y = ((int)y / SCALE) % 128;
int z = ((int)z / SCALE) % 16;

scale is how big your blocks are. Then you can say Block b = Blocks[x, y, z];

If you want to pick what blocks you clicked on. Then do this

const int range = SCALE * 10; //10 = Distance in radius
for(int x = playerX - range; x <= playerX + range; x += SCALE)
{
for(int z = playerZ - range; z <= playerZ + range; z += SCALE)
{
for(int y = playerY - range; y <= playerY + range; y += SCALE)
{
SignedVector3i xyz = GetBlockIndex(new Vector3(x, y, z));
//Create a bounding box around that block and it's 6 bounding boxes for each face. Then use a ray to see which side it intersected at.
}
}
}

### #1mgoss

Posted 13 May 2012 - 12:17 AM

There a much easier way of finding blocks. If you have an 3 dimensional array. For instance, a Blocks[16, 128, 16] for a chunk.

float x = position.X;
float y = position.Y;
float z = position.Z;

int x = ((int)x / SCALE) % 16;
int y = ((int)y / SCALE) % 128;
int z = ((int)z / SCALE) % 16;

scale is how big your blocks are. Then you can say Block b = Blocks[x, y, z];

PARTNERS