commit
41af3d90da
40
src/cube.c
40
src/cube.c
|
@ -8,7 +8,7 @@ void make_cube_faces(
|
|||
float *data, float ao[6][4], float light[6][4],
|
||||
int left, int right, int top, int bottom, int front, int back,
|
||||
int wleft, int wright, int wtop, int wbottom, int wfront, int wback,
|
||||
float x, float y, float z, float n)
|
||||
float x, float y, float z, float scale, NonCubeType noncube)
|
||||
{
|
||||
static const float positions[6][4][3] = {
|
||||
{{-1, -1, -1}, {-1, -1, +1}, {-1, +1, -1}, {-1, +1, +1}},
|
||||
|
@ -60,19 +60,45 @@ void make_cube_faces(
|
|||
if (faces[i] == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float du = (tiles[i] % 16) * s;
|
||||
float dv = (tiles[i] / 16) * s;
|
||||
int flip = ao[i][0] + ao[i][3] > ao[i][1] + ao[i][2];
|
||||
float y_multiplier = (noncube == NonCubeType_SLAB_LOWER) ? 0.0f : 1.0f;
|
||||
for (int v = 0; v < 6; v++) {
|
||||
int j = flip ? flipped[i][v] : indices[i][v];
|
||||
*(d++) = x + n * positions[i][j][0];
|
||||
*(d++) = y + n * positions[i][j][1];
|
||||
*(d++) = z + n * positions[i][j][2];
|
||||
*(d++) = x + scale * positions[i][j][0];
|
||||
//The origin of the cube is its center.
|
||||
//If we are rendering a slab, the top vertices of the cube are not multiplied by the offsets,
|
||||
// so that the top of the slab is the origin, at the center. This makes slabs half-height.
|
||||
|
||||
//Only the vertices on the top should be 0, or the slab would be a paperlike
|
||||
// horizontal billboard. If the y position is positive, we are above the XZ plane of the
|
||||
// cube and are about to determine the top vertices.
|
||||
if (noncube == NonCubeType_SLAB_LOWER && positions[i][j][1] > 0) {
|
||||
*(d++) = y;
|
||||
}
|
||||
else {
|
||||
*(d++) = y + scale * positions[i][j][1];
|
||||
}
|
||||
|
||||
*(d++) = z + scale * positions[i][j][2];
|
||||
*(d++) = normals[i][0];
|
||||
*(d++) = normals[i][1];
|
||||
*(d++) = normals[i][2];
|
||||
*(d++) = du + (uvs[i][j][0] ? b : a);
|
||||
*(d++) = dv + (uvs[i][j][1] ? b : a);
|
||||
|
||||
//If we have have a slab, are rendering the top vertices, and are on the side --
|
||||
// (i == 2) and (i == 3) are for the top and bottom, see faces and tiles arrays above --
|
||||
// we must subtract half a texture tile to only use the lower half of the texture.
|
||||
// Otherwise, the texture of a full block will be sqeezed onto the slab.
|
||||
if (positions[i][j][1] > 0 && i != 2 && i != 3 && noncube == NonCubeType_SLAB_LOWER) {
|
||||
*(d++) = (dv - (1.0f / 32.0f)) + (uvs[i][j][1] ? b : a);
|
||||
}
|
||||
else {
|
||||
*(d++) = dv + (uvs[i][j][1] ? b : a);
|
||||
}
|
||||
|
||||
*(d++) = ao[i][j];
|
||||
*(d++) = light[i][j];
|
||||
}
|
||||
|
@ -94,7 +120,7 @@ void make_cube(
|
|||
data, ao, light,
|
||||
left, right, top, bottom, front, back,
|
||||
wleft, wright, wtop, wbottom, wfront, wback,
|
||||
x, y, z, n);
|
||||
x, y, z, n, noncube_type(w));
|
||||
}
|
||||
|
||||
void make_plant(
|
||||
|
@ -174,7 +200,7 @@ void make_player(
|
|||
data, ao, light,
|
||||
1, 1, 1, 1, 1, 1,
|
||||
226, 224, 241, 209, 225, 227,
|
||||
0, 0, 0, 0.4);
|
||||
0, 0, 0, 0.4, NonCubeType_NOT_NONCUBE);
|
||||
float ma[16];
|
||||
float mb[16];
|
||||
mat_identity(ma);
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#ifndef _cube_h_
|
||||
#define _cube_h_
|
||||
|
||||
/*
|
||||
void make_cube_faces(
|
||||
float *data, float ao[6][4], float light[6][4],
|
||||
int left, int right, int top, int bottom, int front, int back,
|
||||
int wleft, int wright, int wtop, int wbottom, int wfront, int wback,
|
||||
float x, float y, float z, float n);
|
||||
*/
|
||||
|
||||
void make_cube(
|
||||
float *data, float ao[6][4], float light[6][4],
|
||||
|
|
23
src/item.c
23
src/item.c
|
@ -20,6 +20,7 @@ const int items[] = {
|
|||
Item_LEAVES,
|
||||
Item_CACTUS,
|
||||
Item_NYANCAT,
|
||||
Item_SLAB_LOWER_STONEBRICK,
|
||||
Item_TALL_GRASS,
|
||||
Item_YELLOW_FLOWER,
|
||||
Item_RED_FLOWER,
|
||||
|
@ -132,7 +133,8 @@ const int blocks[256][6] = {
|
|||
{207, 207, 207, 207, 207, 207}, // 63
|
||||
{208, 208, 208, 208, 208, 208}, // 64
|
||||
{210, 210, 210, 210, 210, 210}, // 65
|
||||
{0, 0, 0, 0, 0, 0} // 66
|
||||
{0, 0, 0, 0, 0, 0}, // 66
|
||||
{2, 2, 2, 2, 2, 2}
|
||||
};
|
||||
|
||||
const int plants[256] = {
|
||||
|
@ -150,7 +152,8 @@ const int plants[256] = {
|
|||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, // 24 - 65
|
||||
55 // 66 - vine
|
||||
55, // 66 - vine
|
||||
0 // 67
|
||||
};
|
||||
|
||||
int is_plant(int w) {
|
||||
|
@ -194,6 +197,9 @@ int is_transparent(int w) {
|
|||
if (is_plant(w)) {
|
||||
return 1;
|
||||
}
|
||||
if(is_noncube(w)) {
|
||||
return 1;
|
||||
}
|
||||
switch (w) {
|
||||
case Item_EMPTY:
|
||||
case Item_GLASS:
|
||||
|
@ -222,3 +228,16 @@ int is_climbable(int w) {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int is_noncube(int w) {
|
||||
return noncube_type(w) != NonCubeType_NOT_NONCUBE;
|
||||
}
|
||||
|
||||
NonCubeType noncube_type(int w) {
|
||||
switch(w) {
|
||||
case Item_SLAB_LOWER_STONEBRICK:
|
||||
return NonCubeType_SLAB_LOWER;
|
||||
default:
|
||||
return NonCubeType_NOT_NONCUBE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,9 +61,15 @@ typedef enum {
|
|||
Item_NYANCAT,
|
||||
Item_CACTUS,
|
||||
Item_VINE,
|
||||
Item_SLAB_LOWER_STONEBRICK,
|
||||
Item_max
|
||||
} Item;
|
||||
|
||||
typedef enum {
|
||||
NonCubeType_NOT_NONCUBE,
|
||||
NonCubeType_SLAB_LOWER
|
||||
} NonCubeType;
|
||||
|
||||
extern const int items[];
|
||||
extern const int item_count;
|
||||
extern const int blocks[256][6];
|
||||
|
@ -74,6 +80,9 @@ int is_obstacle(int w);
|
|||
int is_transparent(int w);
|
||||
int is_destructable(int w);
|
||||
int is_climbable(int w);
|
||||
int is_noncube(int w);
|
||||
|
||||
NonCubeType noncube_type(int w);
|
||||
|
||||
typedef struct {
|
||||
#define ITEMSPEC_NAME_LEN 32
|
||||
|
|
|
@ -1136,6 +1136,12 @@ void compute_chunk(WorkerItem *item) {
|
|||
data + offset, min_ao, max_light,
|
||||
ex, ey, ez, 0.5, ew, rotation);
|
||||
}
|
||||
else if (is_noncube(ew) && noncube_type(ew) == NonCubeType_SLAB_LOWER) {
|
||||
make_cube(
|
||||
data + offset, ao, light,
|
||||
f1, f2, f3, f4, f5, f6,
|
||||
ex, ey, ez, 0.5, ew);
|
||||
}
|
||||
else {
|
||||
make_cube(
|
||||
data + offset, ao, light,
|
||||
|
|
Loading…
Reference in New Issue