#include "drawChunk.h" void heap(float *dist,int *index,int i,int n) { int k=i; int j=2*k; while(j<=n) { if(jdist[j+1]) { j++; } if(dist[k]>dist[j]) { invertTablefloats(dist,k,j); invertTableElems(index,k,j); k=j; j=2*k; } else { break; } } } void sortCubePos(float *cubePos,uint8_t *cubeList,int size) { int i=0; float *dist=malloc(size*sizeof(float)); int *index=malloc(size*sizeof(int)); //calculates distance of each cube for(i=0;i=0;i--) { heap(dist,index,i,size-1); } for(i=size-1;i>=1;i--) { invertTablefloats(dist,i,0); invertTableElems(index,i,0); heap(dist,index,0,i-1); } //sort cubes with given indexes float *cubePosImg=malloc(size*3*sizeof(float)); memcpy(cubePosImg,cubePos,size*3*sizeof(float)); uint8_t *cubeListImg=malloc(size*sizeof(uint8_t)); memcpy(cubeListImg,cubeList,size*sizeof(uint8_t)); for(i=0;i=0;i--) { heap(dist,indexes,i,size-1); } for(i=size-1;i>=1;i--) { invertTablefloats(dist,i,0); invertTableElems(indexes,i,0); heap(dist,indexes,0,i-1); } } int isCubeVisibleInChunk(uint8_t *chunk,int cubeX,int cubeY,int cubeZ,int index) { int visible=0; if(cubeZ>=CUBE_CHUNK_Z/2) visible+=(chunk[index-CUBE_CHUNK_X*CUBE_CHUNK_X]==0) ? 1 : 0; if(cubeZ<=CUBE_CHUNK_Z/2) visible+=(chunk[index+CUBE_CHUNK_X*CUBE_CHUNK_Y]==0) ? 1 : 0; if(cubeX>=CUBE_CHUNK_X/2) visible+=(chunk[index-CUBE_CHUNK_Y]==0) ? 1 : 0; if(cubeX<=CUBE_CHUNK_X/2) visible+=(chunk[index+CUBE_CHUNK_Y]==0) ? 1 : 0; if(cubeY>=CUBE_CHUNK_Y/2) visible+=(chunk[index-1]==0) ? 1 : 0; if(cubeY<=CUBE_CHUNK_Y/2) visible+=(chunk[index+1]==0) ? 1 : 0; return visible; } int isCubeVisibleInWorld(uint8_t *world,int cubeX,int cubeY,int cubeZ,int index,pos playerPos) { int visible=0; playerPos.x=(int)playerPos.x/2; playerPos.y=(int)playerPos.y/2; playerPos.z=(int)playerPos.z/2; if(cubeZ>=playerPos.z) visible+=(world[index-CUBE_WORLD_X*CUBE_WORLD_Y]==0) ? 1 : 0; if(cubeZ<=playerPos.z) visible+=(world[index+CUBE_WORLD_X*CUBE_WORLD_Y]==0) ? 1 : 0; if(cubeX>=playerPos.x) visible+=(world[index-CUBE_WORLD_Y]==0) ? 1 : 0; if(cubeX<=playerPos.x) visible+=(world[index+CUBE_WORLD_Y]==0) ? 1 : 0; if(cubeY>=playerPos.y) visible+=(world[index-1]==0) ? 1 : 0; if(cubeY<=playerPos.y) visible+=(world[index+1]==0) ? 1 : 0; return visible; } void computeCubeWorldChunk(uint8_t *chunk,float *cubePos,uint8_t *cubeList,int *size,float xRotation,float zRotation,pos playerPos) { int i=0,j=0,k=0; //iterators int index=0,n=0,displayed=0; //utils playerPos.x-=floor(playerPos.x/2.0)*2.0-(float)CUBE_CHUNK_X; playerPos.y-=floor(playerPos.y/2.0)*2.0-(float)CUBE_CHUNK_Y; playerPos.z-=floor(playerPos.z/2.0)*2.0-(float)CUBE_CHUNK_Z-2.0; //loop to see all cubes for(i=0;i=0 && j=0 && k