Crafter map problem
Posted: Thu Apr 07, 2011 4:18 pm
Okay I'm going to go insane with this
You've probably seen my newest side project Crafter (a minecraft remake) and it's my first real attempt at anything related to the 3D world (or at least from complete scratch).
I'm not sure if I was right to do this but I decided the best way to store the map would be similar to 2D tile games, so in a 3D array.
My problem is hard to explain so I'll try and explain it as I go along.
Here is how the map gets rendered:
But the important parts, or at least he parts I'm having problems with is here:
i_x and i_z are just for the index of the array...I think that could be to do with the problem.
My brain is literally gone to sleep with this so here's a video trying to explain it:
I've probably done a really bad job of explaining this, so any questions please ask.
Thanks.
EDIT:
So if I do like
That's fine
But if I do:
It twitches around weirdly.
You've probably seen my newest side project Crafter (a minecraft remake) and it's my first real attempt at anything related to the 3D world (or at least from complete scratch).
I'm not sure if I was right to do this but I decided the best way to store the map would be similar to 2D tile games, so in a 3D array.
My problem is hard to explain so I'll try and explain it as I go along.
Here is how the map gets rendered:
Code: Select all
void Crafter::Map::Render() {
void Crafter::Map::Render() {
//glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glEnable(GL_TEXTURE_2D);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
glBindTexture(GL_TEXTURE_2D,t_BlockSet.tex);
crop = t_BlockSet.Crop;
width = t_BlockSet.fWidth;
height = t_BlockSet.fHeight;
crop.w = crop.h = 16;
float camX = GetCamera()->GetX();
float camZ = GetCamera()->GetZ();
float camY = GetCamera()->GetY();
printf("x- %f\ny- %f\nz- %f\n\n",camX,camY,camZ);
i_x = 0, i_z = 0;
float bs = 4.0f; // size of cubes
glPushMatrix();
glColor3f(1,1,1);
glBegin(GL_QUADS);
for ( y = 0;y < 64;y++ ) {
if ( y < 0 ) {
y = 0;
}
for ( x = camX - 12;x < camX + 12;x += 4.0f ) {
for ( z = camZ - 12;z < camZ + 12;z += 4.0 ) {
i_z = (int)z;
i_x = (int)x;
if (i_x < 0 ) {
i_x -= i_x*2;
}
if (i_z < 0 ) {
i_z -= i_z*2;
}
int id = Blocks[i_x][i_z][y]; // get the id of the block
if ( id == 0 ) {
continue; // the is no block here
}
crop.x = (float)(id % 8 * 16) - 16; // clipping on the sheet (-16 to back up a single tile)
crop.y = (float)(id / 8 * 16);
/******************
Vertex crap
*******************/
}
}
}
}
}
glEnd();
glPopMatrix();
}
Code: Select all
float camX = GetCamera()->GetX();
float camZ = GetCamera()->GetZ();
float camY = GetCamera()->GetY();
printf("x- %f\ny- %f\nz- %f\n\n",camX,camY,camZ);
i_x = 0, i_z = 0;
float bs = 4.0f; // size of cubes
glPushMatrix();
glColor3f(1,1,1);
glBegin(GL_QUADS);
for ( y = 0;y < 64;y++ ) {
if ( y < 0 ) {
y = 0;
}
for ( x = camX - 12;x < camX + 12;x += 4.0f ) {
for ( z = camZ - 12;z < camZ + 12;z += 4.0 ) {
My brain is literally gone to sleep with this so here's a video trying to explain it:
I've probably done a really bad job of explaining this, so any questions please ask.
Thanks.
EDIT:
So if I do like
Code: Select all
for ( x = 0;x < camX + 20; x += 4.0 )
But if I do:
Code: Select all
for ( x = camX - 20; x < camX + 20;x += 4.0 )