// Recalc ball image void CVectorCtl::BuildImage (LPDRAWITEMSTRUCT lpDrawItemStruct) { int xf, yf; for (int x=0; x<m_iWidth; x++) // Scan all columns for (int y=0; y<m_iHeight; y++) { // Scan all rows xf = x-m_iXCenter; // Find distance from center yf = y-m_iYCenter; if (xf*xf + yf*yf <= m_iSqrRadius) { // Point on ball surface double vx = double(xf) / double(m_iRadius), vy = double(yf) / double(m_iRadius), vz = sqrt (1.0 - vx*vx - vy*vy); // Find ball's normal m_dcMem.SetPixelV (x,y, CalcLight (vx,vy,vz)); } } }
void cLightingThread::LightChunk(cLightingChunkStay & a_Item) { cChunkDef::BlockNibbles BlockLight, SkyLight; ReadChunks(a_Item.m_ChunkX, a_Item.m_ChunkZ); PrepareBlockLight(); CalcLight(m_BlockLight); PrepareSkyLight(); /* // DEBUG: Save chunk data with highlighted seeds for visual inspection: cFile f4; if ( f4.Open(Printf("Chunk_%d_%d_seeds.grab", a_Item.x, a_Item.z), cFile::fmWrite) ) { for (int z = 0; z < cChunkDef::Width * 3; z++) { for (int y = cChunkDef::Height / 2; y >= 0; y--) { unsigned char Seeds [cChunkDef::Width * 3]; memcpy(Seeds, m_BlockTypes + y * BlocksPerYLayer + z * cChunkDef::Width * 3, cChunkDef::Width * 3); for (int x = 0; x < cChunkDef::Width * 3; x++) { if (m_IsSeed1[y * BlocksPerYLayer + z * cChunkDef::Width * 3 + x]) { Seeds[x] = E_BLOCK_DIAMOND_BLOCK; } } f4.Write(Seeds, cChunkDef::Width * 3); } } } //*/ CalcLight(m_SkyLight); /* // DEBUG: Save XY slices of the chunk data and lighting for visual inspection: cFile f1, f2, f3; if ( f1.Open(Printf("Chunk_%d_%d_data.grab", a_Item.x, a_Item.z), cFile::fmWrite) && f2.Open(Printf("Chunk_%d_%d_sky.grab", a_Item.x, a_Item.z), cFile::fmWrite) && f3.Open(Printf("Chunk_%d_%d_glow.grab", a_Item.x, a_Item.z), cFile::fmWrite) ) { for (int z = 0; z < cChunkDef::Width * 3; z++) { for (int y = cChunkDef::Height / 2; y >= 0; y--) { f1.Write(m_BlockTypes + y * BlocksPerYLayer + z * cChunkDef::Width * 3, cChunkDef::Width * 3); unsigned char SkyLight [cChunkDef::Width * 3]; unsigned char BlockLight[cChunkDef::Width * 3]; for (int x = 0; x < cChunkDef::Width * 3; x++) { SkyLight[x] = m_SkyLight [y * BlocksPerYLayer + z * cChunkDef::Width * 3 + x] << 4; BlockLight[x] = m_BlockLight[y * BlocksPerYLayer + z * cChunkDef::Width * 3 + x] << 4; } f2.Write(SkyLight, cChunkDef::Width * 3); f3.Write(BlockLight, cChunkDef::Width * 3); } } } //*/ CompressLight(m_BlockLight, BlockLight); CompressLight(m_SkyLight, SkyLight); m_World->ChunkLighted(a_Item.m_ChunkX, a_Item.m_ChunkZ, BlockLight, SkyLight); if (a_Item.m_CallbackAfter != NULL) { a_Item.m_CallbackAfter->Call(a_Item.m_ChunkX, a_Item.m_ChunkZ); } a_Item.Disable(); delete &a_Item; }