add block rotate
This commit is contained in:
parent
d2416946d9
commit
900e4ae098
@ -106,6 +106,7 @@ void setup_definitions() {
|
|||||||
block = new Block(BLOCK_WOOD, 7);
|
block = new Block(BLOCK_WOOD, 7);
|
||||||
block->textureFaces[2] = 8;
|
block->textureFaces[2] = 8;
|
||||||
block->textureFaces[3] = 8;
|
block->textureFaces[3] = 8;
|
||||||
|
block->rotatable = true;
|
||||||
Block::blocks[block->id] = block;
|
Block::blocks[block->id] = block;
|
||||||
|
|
||||||
block = new Block(BLOCK_LEAVES, 9);
|
block = new Block(BLOCK_LEAVES, 9);
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
INDEX += CHUNK_VERTEX_SIZE;
|
INDEX += CHUNK_VERTEX_SIZE;
|
||||||
|
|
||||||
|
|
||||||
#define SETUP_UV(INDEX) float u1 = ((INDEX) % 16) * uvsize;\
|
#define SETUP_UV(INDEX) float u1 = ((INDEX) % 16) * uvsize;\
|
||||||
float v1 = 1-((1 + (INDEX) / 16) * uvsize);\
|
float v1 = 1-((1 + (INDEX) / 16) * uvsize);\
|
||||||
float u2 = u1 + uvsize;\
|
float u2 = u1 + uvsize;\
|
||||||
float v2 = v1 + uvsize;
|
float v2 = v1 + uvsize;
|
||||||
@ -43,17 +43,41 @@ VoxelRenderer::VoxelRenderer() {
|
|||||||
VoxelRenderer::~VoxelRenderer(){
|
VoxelRenderer::~VoxelRenderer(){
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, unsigned int id, size_t& index){
|
inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, voxel vox, size_t& index){
|
||||||
float l;
|
float l;
|
||||||
float uvsize = 1.0f/16.0f;
|
float uvsize = 1.0f/16.0f;
|
||||||
|
|
||||||
Block* block = Block::blocks[id];
|
Block* block = Block::blocks[vox.id];
|
||||||
unsigned char group = block->drawGroup;
|
unsigned char group = block->drawGroup;
|
||||||
|
int textureCopyFaces[6];
|
||||||
|
int rot = 0;
|
||||||
|
|
||||||
|
for (int i=0; i<6; i++){
|
||||||
|
textureCopyFaces[i] = block->textureFaces[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (block->rotatable){
|
||||||
|
if (vox.states == 0x31){
|
||||||
|
rot = 1;
|
||||||
|
textureCopyFaces[0] = block->textureFaces[2];
|
||||||
|
textureCopyFaces[1] = block->textureFaces[3];
|
||||||
|
textureCopyFaces[2] = block->textureFaces[0];
|
||||||
|
textureCopyFaces[3] = block->textureFaces[1];
|
||||||
|
} else if (vox.states == 0x32){
|
||||||
|
rot = 2;
|
||||||
|
} else if (vox.states == 0x33){
|
||||||
|
rot = 3;
|
||||||
|
textureCopyFaces[2] = block->textureFaces[4];
|
||||||
|
textureCopyFaces[3] = block->textureFaces[5];
|
||||||
|
textureCopyFaces[4] = block->textureFaces[2];
|
||||||
|
textureCopyFaces[5] = block->textureFaces[3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!IS_BLOCKED(x,y+1,z,group)){
|
if (!IS_BLOCKED(x,y+1,z,group)){
|
||||||
l = 1.0f;
|
l = 1.0f;
|
||||||
|
|
||||||
SETUP_UV(block->textureFaces[3]);
|
SETUP_UV(textureCopyFaces[3]);
|
||||||
|
|
||||||
const float lr = LIGHT(x,y+1,z, 0) / 15.0f;
|
const float lr = LIGHT(x,y+1,z, 0) / 15.0f;
|
||||||
const float lg = LIGHT(x,y+1,z, 1) / 15.0f;
|
const float lg = LIGHT(x,y+1,z, 1) / 15.0f;
|
||||||
@ -80,18 +104,36 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
float ls2 = (LIGHT(x+1,y+1,z,3) + ls*30 + LIGHT(x+1,y+1,z+1,3) + LIGHT(x,y+1,z+1,3)) / 75.0f;
|
float ls2 = (LIGHT(x+1,y+1,z,3) + ls*30 + LIGHT(x+1,y+1,z+1,3) + LIGHT(x,y+1,z+1,3)) / 75.0f;
|
||||||
float ls3 = (LIGHT(x+1,y+1,z,3) + ls*30 + LIGHT(x+1,y+1,z-1,3) + LIGHT(x,y+1,z-1,3)) / 75.0f;
|
float ls3 = (LIGHT(x+1,y+1,z,3) + ls*30 + LIGHT(x+1,y+1,z-1,3) + LIGHT(x,y+1,z-1,3)) / 75.0f;
|
||||||
|
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr0, lg0, lb0, ls0);
|
if ((rot == 0) || (rot == 2)){
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1, lg1, lb1, ls1);
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2, lg2, lb2, ls2);
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr0, lg0, lb0, ls0);
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2, lg2, lb2, ls2);
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v1, lr3, lg3, lb3, ls3);
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
||||||
|
} else if (rot == 1){
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v1, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr2,lg2,lb2,ls2);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr3,lg3,lb3,ls3);
|
||||||
|
} else if (rot == 3){
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!IS_BLOCKED(x,y-1,z,group)){
|
if (!IS_BLOCKED(x,y-1,z,group)){
|
||||||
l = 0.75f;
|
l = 0.75f;
|
||||||
|
|
||||||
SETUP_UV(block->textureFaces[2]);
|
SETUP_UV(textureCopyFaces[2]);
|
||||||
|
|
||||||
const float lr = LIGHT(x,y-1,z, 0) / 15.0f;
|
const float lr = LIGHT(x,y-1,z, 0) / 15.0f;
|
||||||
const float lg = LIGHT(x,y-1,z, 1) / 15.0f;
|
const float lg = LIGHT(x,y-1,z, 1) / 15.0f;
|
||||||
@ -118,19 +160,37 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
float ls2 = (LIGHT(x-1,y-1,z+1,3) + ls*30 + LIGHT(x-1,y-1,z,3) + LIGHT(x,y-1,z+1,3)) / 75.0f;
|
float ls2 = (LIGHT(x-1,y-1,z+1,3) + ls*30 + LIGHT(x-1,y-1,z,3) + LIGHT(x,y-1,z+1,3)) / 75.0f;
|
||||||
float ls3 = (LIGHT(x+1,y-1,z-1,3) + ls*30 + LIGHT(x+1,y-1,z,3) + LIGHT(x,y-1,z-1,3)) / 75.0f;
|
float ls3 = (LIGHT(x+1,y-1,z-1,3) + ls*30 + LIGHT(x+1,y-1,z,3) + LIGHT(x,y-1,z-1,3)) / 75.0f;
|
||||||
|
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
if ((rot == 0) || (rot == 2)){
|
||||||
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
} else if (rot == 1){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v2, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u1,v1, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v2, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u1,v1, lr1,lg1,lb1,ls1);
|
||||||
|
} else if (rot == 3){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IS_BLOCKED(x+1,y,z,group)){
|
if (!IS_BLOCKED(x+1,y,z,group)){
|
||||||
l = 0.95f;
|
l = 0.95f;
|
||||||
|
|
||||||
SETUP_UV(block->textureFaces[1]);
|
SETUP_UV(textureCopyFaces[1]);
|
||||||
|
|
||||||
const float lr = LIGHT(x+1,y,z, 0) / 15.0f;
|
const float lr = LIGHT(x+1,y,z, 0) / 15.0f;
|
||||||
const float lg = LIGHT(x+1,y,z, 1) / 15.0f;
|
const float lg = LIGHT(x+1,y,z, 1) / 15.0f;
|
||||||
@ -157,18 +217,36 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
float ls2 = (LIGHT(x+1,y+1,z+1,3) + ls*30 + LIGHT(x+1,y,z+1,3) + LIGHT(x+1,y+1,z,3)) / 75.0f;
|
float ls2 = (LIGHT(x+1,y+1,z+1,3) + ls*30 + LIGHT(x+1,y,z+1,3) + LIGHT(x+1,y+1,z,3)) / 75.0f;
|
||||||
float ls3 = (LIGHT(x+1,y-1,z+1,3) + ls*30 + LIGHT(x+1,y,z+1,3) + LIGHT(x+1,y-1,z,3)) / 75.0f;
|
float ls3 = (LIGHT(x+1,y-1,z+1,3) + ls*30 + LIGHT(x+1,y,z+1,3) + LIGHT(x+1,y-1,z,3)) / 75.0f;
|
||||||
|
|
||||||
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
if ((rot == 0) || (rot == 2)){
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
||||||
|
} else if (rot == 1){
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr3,lg2,lb2,ls2);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v1, lr1,lg3,lb3,ls3);
|
||||||
|
} else if (rot == 3){
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v2, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v1, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v2, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v1, lr3,lg2,lb2,ls2);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v1, lr1,lg3,lb3,ls3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!IS_BLOCKED(x-1,y,z,group)){
|
if (!IS_BLOCKED(x-1,y,z,group)){
|
||||||
l = 0.85f;
|
l = 0.85f;
|
||||||
|
|
||||||
SETUP_UV(block->textureFaces[0]);
|
SETUP_UV(textureCopyFaces[0]);
|
||||||
|
|
||||||
const float lr = LIGHT(x-1,y,z, 0) / 15.0f;
|
const float lr = LIGHT(x-1,y,z, 0) / 15.0f;
|
||||||
const float lg = LIGHT(x-1,y,z, 1) / 15.0f;
|
const float lg = LIGHT(x-1,y,z, 1) / 15.0f;
|
||||||
@ -195,19 +273,37 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
float ls2 = (LIGHT(x-1,y+1,z-1,3) + ls*30 + LIGHT(x-1,y,z-1,3) + LIGHT(x-1,y+1,z,3)) / 75.0f;
|
float ls2 = (LIGHT(x-1,y+1,z-1,3) + ls*30 + LIGHT(x-1,y,z-1,3) + LIGHT(x-1,y+1,z,3)) / 75.0f;
|
||||||
float ls3 = (LIGHT(x-1,y-1,z+1,3) + ls*30 + LIGHT(x-1,y,z+1,3) + LIGHT(x-1,y-1,z,3)) / 75.0f;
|
float ls3 = (LIGHT(x-1,y-1,z+1,3) + ls*30 + LIGHT(x-1,y,z+1,3) + LIGHT(x-1,y-1,z,3)) / 75.0f;
|
||||||
|
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
if ((rot == 0) || (rot == 2)){
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
} else if (rot == 1){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
} else if (rot == 3){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v2, lr3,lg3,lb3,ls3);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IS_BLOCKED(x,y,z+1,group)){
|
if (!IS_BLOCKED(x,y,z+1,group)){
|
||||||
l = 0.9f;
|
l = 0.9f;
|
||||||
|
|
||||||
SETUP_UV(block->textureFaces[5]);
|
SETUP_UV(textureCopyFaces[5]);
|
||||||
|
|
||||||
const float lr = LIGHT(x,y,z+1, 0) / 15.0f;
|
const float lr = LIGHT(x,y,z+1, 0) / 15.0f;
|
||||||
const float lg = LIGHT(x,y,z+1, 1) / 15.0f;
|
const float lg = LIGHT(x,y,z+1, 1) / 15.0f;
|
||||||
@ -234,18 +330,36 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
float ls2 = l*(LIGHT(x-1,y+1,z+1,3) + ls*30 + LIGHT(x,y+1,z+1,3) + LIGHT(x-1,y,z+1,3)) / 75.0f;
|
float ls2 = l*(LIGHT(x-1,y+1,z+1,3) + ls*30 + LIGHT(x,y+1,z+1,3) + LIGHT(x-1,y,z+1,3)) / 75.0f;
|
||||||
float ls3 = l*(LIGHT(x+1,y-1,z+1,3) + ls*30 + LIGHT(x,y-1,z+1,3) + LIGHT(x+1,y,z+1,3)) / 75.0f;
|
float ls3 = l*(LIGHT(x+1,y-1,z+1,3) + ls*30 + LIGHT(x,y-1,z+1,3) + LIGHT(x+1,y,z+1,3)) / 75.0f;
|
||||||
|
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
if ((rot == 0) || (rot == 2)){
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
} else if (rot == 1){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v1, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u1,v2, lr3,lg3,lb3,ls3);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
} else if (rot == 3){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!IS_BLOCKED(x,y,z-1,group)){
|
if (!IS_BLOCKED(x,y,z-1,group)){
|
||||||
l = 0.8f;
|
l = 0.8f;
|
||||||
|
|
||||||
SETUP_UV(block->textureFaces[4]);
|
SETUP_UV(textureCopyFaces[4]);
|
||||||
|
|
||||||
const float lr = LIGHT(x,y,z-1, 0) / 15.0f;
|
const float lr = LIGHT(x,y,z-1, 0) / 15.0f;
|
||||||
const float lg = LIGHT(x,y,z-1, 1) / 15.0f;
|
const float lg = LIGHT(x,y,z-1, 1) / 15.0f;
|
||||||
@ -272,21 +386,39 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
float ls2 = l*(LIGHT(x+1,y+1,z-1,3) + ls*30 + LIGHT(x,y+1,z-1,3) + LIGHT(x+1,y,z-1,3)) / 75.0f;
|
float ls2 = l*(LIGHT(x+1,y+1,z-1,3) + ls*30 + LIGHT(x,y+1,z-1,3) + LIGHT(x+1,y,z-1,3)) / 75.0f;
|
||||||
float ls3 = l*(LIGHT(x+1,y-1,z-1,3) + ls*30 + LIGHT(x,y-1,z-1,3) + LIGHT(x+1,y,z-1,3)) / 75.0f;
|
float ls3 = l*(LIGHT(x+1,y-1,z-1,3) + ls*30 + LIGHT(x,y-1,z-1,3) + LIGHT(x+1,y,z-1,3)) / 75.0f;
|
||||||
|
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
if ((rot == 0) || (rot == 2)){
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
||||||
|
} else if (rot == 1){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u1,v1, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v2, lr3,lg3,lb3,ls3);
|
||||||
|
} else if (rot == 3){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void _renderBlockShadeless(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, unsigned int id, size_t& index){
|
inline void _renderBlockShadeless(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, voxel vox, size_t& index){
|
||||||
float l;
|
float l;
|
||||||
float uvsize = 1.0f/16.0f;
|
float uvsize = 1.0f/16.0f;
|
||||||
|
|
||||||
Block* block = Block::blocks[id];
|
Block* block = Block::blocks[vox.id];
|
||||||
unsigned char group = block->drawGroup;
|
unsigned char group = block->drawGroup;
|
||||||
|
|
||||||
if (!IS_BLOCKED(x,y+1,z,group)){
|
if (!IS_BLOCKED(x,y+1,z,group)){
|
||||||
@ -447,7 +579,7 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
|
|||||||
if (block->emission[0] || block->emission[1] || block->emission[2]){
|
if (block->emission[0] || block->emission[1] || block->emission[2]){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_renderBlock(buffer, x, y, z, chunks, vox.id, index);
|
_renderBlock(buffer, x, y, z, chunks, vox, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -460,7 +592,7 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
|
|||||||
continue;
|
continue;
|
||||||
Block* block = Block::blocks[vox.id];
|
Block* block = Block::blocks[vox.id];
|
||||||
if (block->emission[0] || block->emission[1] || block->emission[2]){
|
if (block->emission[0] || block->emission[1] || block->emission[2]){
|
||||||
_renderBlockShadeless(buffer, x, y, z, chunks, vox.id, index);
|
_renderBlockShadeless(buffer, x, y, z, chunks, vox, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -474,7 +606,7 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
|
|||||||
continue;
|
continue;
|
||||||
if (vox.id != 9)
|
if (vox.id != 9)
|
||||||
continue;
|
continue;
|
||||||
_renderBlock(buffer, x, y, z, chunks, vox.id, index);
|
_renderBlock(buffer, x, y, z, chunks, vox, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -500,7 +632,7 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
|
|||||||
continue;
|
continue;
|
||||||
if (vox.id != 4)
|
if (vox.id != 4)
|
||||||
continue;
|
continue;
|
||||||
_renderBlock(buffer, x, y, z, chunks, vox.id, index);
|
_renderBlock(buffer, x, y, z, chunks, vox, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -126,9 +126,17 @@ void HudRenderer::draw(Level* level, Assets* assets){
|
|||||||
int inv_hm = step*8;
|
int inv_hm = step*8;
|
||||||
int inv_w = inv_wm - (step - size);
|
int inv_w = inv_wm - (step - size);
|
||||||
int inv_h = inv_hm - (step - size);
|
int inv_h = inv_hm - (step - size);
|
||||||
|
int inv_x = (Window::width - (inv_w)) / 2;
|
||||||
|
int inv_y = (Window::height - (inv_h)) / 2;
|
||||||
int xs = (Window::width - inv_w + step)/2;
|
int xs = (Window::width - inv_w + step)/2;
|
||||||
int x = 0;
|
|
||||||
int ys = (Window::height - inv_h + step)/2;
|
int ys = (Window::height - inv_h + step)/2;
|
||||||
|
if (Window::width > inv_wm*3){
|
||||||
|
inv_x = (Window::width + (inv_w)) / 2;
|
||||||
|
inv_y = (Window::height - (inv_h)) / 2;
|
||||||
|
xs = (Window::width + inv_w + step)/2;
|
||||||
|
ys = (Window::height - inv_h + step)/2;
|
||||||
|
}
|
||||||
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
vec4 tint = vec4(1.0f);
|
vec4 tint = vec4(1.0f);
|
||||||
int mx = Events::x;
|
int mx = Events::x;
|
||||||
@ -139,11 +147,11 @@ void HudRenderer::draw(Level* level, Assets* assets){
|
|||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
batch->color = vec4(0.0f, 0.0f, 0.0f, 0.3f);
|
batch->color = vec4(0.0f, 0.0f, 0.0f, 0.3f);
|
||||||
batch->rect(0, 0, Window::width, Window::height);
|
batch->rect(0, 0, Window::width, Window::height);
|
||||||
batch->rect((Window::width - (inv_w)) / 2 - 4, (Window::height - (inv_h)) / 2 - 4, inv_w+8, inv_h+8,
|
batch->rect(inv_x - 4, inv_y - 4, inv_w+8, inv_h+8,
|
||||||
0.95f, 0.95f, 0.95f, 0.85f, 0.85f, 0.85f,
|
0.95f, 0.95f, 0.95f, 0.85f, 0.85f, 0.85f,
|
||||||
0.7f, 0.7f, 0.7f,
|
0.7f, 0.7f, 0.7f,
|
||||||
0.55f, 0.55f, 0.55f, 0.45f, 0.45f, 0.45f, 4);
|
0.55f, 0.55f, 0.55f, 0.45f, 0.45f, 0.45f, 4);
|
||||||
batch->rect((Window::width - (inv_w)) / 2, (Window::height - (inv_h)) / 2, inv_w, inv_h,
|
batch->rect(inv_x, inv_y, inv_w, inv_h,
|
||||||
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f,
|
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f,
|
||||||
0.75f, 0.75f, 0.75f,
|
0.75f, 0.75f, 0.75f,
|
||||||
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 4);
|
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 4);
|
||||||
|
|||||||
@ -176,33 +176,48 @@ void PlayerController::update_interaction(){
|
|||||||
if (vox != nullptr){
|
if (vox != nullptr){
|
||||||
selectedBlockId = vox->id;
|
selectedBlockId = vox->id;
|
||||||
selectedBlockPosition = iend;
|
selectedBlockPosition = iend;
|
||||||
|
int x = (int)iend.x;
|
||||||
|
int y = (int)iend.y;
|
||||||
|
int z = (int)iend.z;
|
||||||
|
uint8_t states;
|
||||||
|
|
||||||
|
if (Block::blocks[player->choosenBlock]->rotatable){
|
||||||
|
states = states & 0b11111100;
|
||||||
|
// if (abs(norm.x) > abs(norm.z)){
|
||||||
|
// if (abs(norm.x) > abs(norm.y)) states = states | 0b00000001;
|
||||||
|
// if (abs(norm.x) < abs(norm.y)) states = states | 0b00000010;
|
||||||
|
// }
|
||||||
|
// if (abs(norm.x) < abs(norm.z)){
|
||||||
|
// if (abs(norm.z) > abs(norm.y)) states = states | 0b00000011;
|
||||||
|
// if (abs(norm.z) < abs(norm.y)) states = states | 0b00000010;
|
||||||
|
// }
|
||||||
|
if (abs(norm.x) > abs(norm.z)){
|
||||||
|
if (abs(norm.x) > abs(norm.y)) states = 0x31;
|
||||||
|
if (abs(norm.x) < abs(norm.y)) states = 0x32;
|
||||||
|
}
|
||||||
|
if (abs(norm.x) < abs(norm.z)){
|
||||||
|
if (abs(norm.z) > abs(norm.y)) states = 0x33;
|
||||||
|
if (abs(norm.z) < abs(norm.y)) states = 0x32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Block* block = Block::blocks[vox->id];
|
Block* block = Block::blocks[vox->id];
|
||||||
if (Events::jclicked(GLFW_MOUSE_BUTTON_1) && block->breakable){
|
if (Events::jclicked(GLFW_MOUSE_BUTTON_1) && block->breakable){
|
||||||
int x = (int)iend.x;
|
chunks->set(x,y,z, 0, 0);
|
||||||
int y = (int)iend.y;
|
|
||||||
int z = (int)iend.z;
|
|
||||||
chunks->set(x,y,z, 0);
|
|
||||||
lighting->onBlockSet(x,y,z,0);
|
lighting->onBlockSet(x,y,z,0);
|
||||||
}
|
}
|
||||||
if (Events::jclicked(GLFW_MOUSE_BUTTON_2)){
|
if (Events::jclicked(GLFW_MOUSE_BUTTON_2)){
|
||||||
int x = (int)(iend.x)+(int)(norm.x);
|
if (block->model != BLOCK_MODEL_X_SPRITE){
|
||||||
int y = (int)(iend.y)+(int)(norm.y);
|
x = (int)(iend.x)+(int)(norm.x);
|
||||||
int z = (int)(iend.z)+(int)(norm.z);
|
y = (int)(iend.y)+(int)(norm.y);
|
||||||
if (block->model == BLOCK_MODEL_X_SPRITE){
|
z = (int)(iend.z)+(int)(norm.z);
|
||||||
x = (int)iend.x;
|
|
||||||
y = (int)iend.y;
|
|
||||||
z = (int)iend.z;
|
|
||||||
}
|
}
|
||||||
if (!level->physics->isBlockInside(x,y,z, player->hitbox)){
|
if (!level->physics->isBlockInside(x,y,z, player->hitbox)){
|
||||||
chunks->set(x, y, z, player->choosenBlock);
|
chunks->set(x, y, z, player->choosenBlock, states);
|
||||||
lighting->onBlockSet(x,y,z, player->choosenBlock);
|
lighting->onBlockSet(x,y,z, player->choosenBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Events::jclicked(GLFW_MOUSE_BUTTON_3)){
|
if (Events::jclicked(GLFW_MOUSE_BUTTON_3)){
|
||||||
int x = (int)iend.x;
|
|
||||||
int y = (int)iend.y;
|
|
||||||
int z = (int)iend.z;
|
|
||||||
player->choosenBlock = chunks->get(x,y,z)->id;
|
player->choosenBlock = chunks->get(x,y,z)->id;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -178,7 +178,7 @@ int main() {
|
|||||||
if (status) return status;
|
if (status) return status;
|
||||||
|
|
||||||
std::cout << "-- loading world" << std::endl;
|
std::cout << "-- loading world" << std::endl;
|
||||||
vec3 playerPosition = vec3(0,150,0);
|
vec3 playerPosition = vec3(0,64,0);
|
||||||
Camera* camera = new Camera(playerPosition, radians(90.0f));
|
Camera* camera = new Camera(playerPosition, radians(90.0f));
|
||||||
World* world = new World("world-1", "world/", 42);
|
World* world = new World("world-1", "world/", 42);
|
||||||
Player* player = new Player(playerPosition, 4.0f, camera);
|
Player* player = new Player(playerPosition, 4.0f, camera);
|
||||||
|
|||||||
@ -19,6 +19,7 @@ public:
|
|||||||
bool obstacle = true;
|
bool obstacle = true;
|
||||||
bool selectable = true;
|
bool selectable = true;
|
||||||
bool breakable = true;
|
bool breakable = true;
|
||||||
|
bool rotatable = false;
|
||||||
float hitboxScale = 1;
|
float hitboxScale = 1;
|
||||||
float hitboxY = 1;
|
float hitboxY = 1;
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
#define CHUNK_W 16
|
#define CHUNK_W 16
|
||||||
#define CHUNK_H 256
|
#define CHUNK_H 256
|
||||||
#define CHUNK_D 16
|
#define CHUNK_D 16
|
||||||
#define CHUNK_VOL (CHUNK_W * CHUNK_H * CHUNK_D)
|
#define CHUNK_VOL (CHUNK_W * CHUNK_H * CHUNK_D * 2)
|
||||||
|
|
||||||
#define CHUNK_MODIFIED 0x1
|
#define CHUNK_MODIFIED 0x1
|
||||||
#define CHUNK_READY 0x2
|
#define CHUNK_READY 0x2
|
||||||
|
|||||||
@ -123,7 +123,7 @@ Chunk* Chunks::getChunk(int x, int z){
|
|||||||
return chunks[z * w + x];
|
return chunks[z * w + x];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Chunks::set(int x, int y, int z, int id){
|
void Chunks::set(int x, int y, int z, int id, uint8_t states){
|
||||||
x -= ox * CHUNK_W;
|
x -= ox * CHUNK_W;
|
||||||
z -= oz * CHUNK_D;
|
z -= oz * CHUNK_D;
|
||||||
int cx = x / CHUNK_W;
|
int cx = x / CHUNK_W;
|
||||||
@ -140,6 +140,7 @@ void Chunks::set(int x, int y, int z, int id){
|
|||||||
int lx = x - cx * CHUNK_W;
|
int lx = x - cx * CHUNK_W;
|
||||||
int lz = z - cz * CHUNK_D;
|
int lz = z - cz * CHUNK_D;
|
||||||
chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx].id = id;
|
chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx].id = id;
|
||||||
|
chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx].states = states;
|
||||||
chunk->setUnsaved(true);
|
chunk->setUnsaved(true);
|
||||||
chunk->setModified(true);
|
chunk->setModified(true);
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,7 @@ public:
|
|||||||
voxel* get(int x, int y, int z);
|
voxel* get(int x, int y, int z);
|
||||||
unsigned short getLight(int x, int y, int z);
|
unsigned short getLight(int x, int y, int z);
|
||||||
unsigned char getLight(int x, int y, int z, int channel);
|
unsigned char getLight(int x, int y, int z, int channel);
|
||||||
void set(int x, int y, int z, int id);
|
void set(int x, int y, int z, int id, uint8_t states);
|
||||||
voxel* rayCast(vec3 start, vec3 dir, float maxLength, vec3& end, vec3& norm, vec3& iend);
|
voxel* rayCast(vec3 start, vec3 dir, float maxLength, vec3& end, vec3& norm, vec3& iend);
|
||||||
|
|
||||||
bool isObstacle(int x, int y, int z);
|
bool isObstacle(int x, int y, int z);
|
||||||
|
|||||||
@ -151,6 +151,7 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
|||||||
id = BLOCK_FLOWER;
|
id = BLOCK_FLOWER;
|
||||||
}
|
}
|
||||||
voxels[(y * CHUNK_D + z) * CHUNK_W + x].id = id;
|
voxels[(y * CHUNK_D + z) * CHUNK_W + x].id = id;
|
||||||
|
voxels[(y * CHUNK_D + z) * CHUNK_W + x].states = 0x32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
struct voxel {
|
struct voxel {
|
||||||
uint8_t id;
|
uint8_t id;
|
||||||
|
uint8_t states;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* VOXELS_VOXEL_H_ */
|
#endif /* VOXELS_VOXEL_H_ */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user