// In build mode, find the block at the given screen position. Return the chunk and the // data about it to the pointers. chunk *gameDialog::FindSelectedSurface(int x, int y, ChunkOffsetCoord *coc, int *surfaceDir) { ChunkShaderPicking *pickShader = ChunkShaderPicking::Make(); pickShader->EnableProgram(); pickShader->View(gViewMatrix); pickShader->Projection(gProjectionMatrix); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Use black sky for picking glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); DrawLandscape(0, DL_Picking); pickShader->DisableProgram(); unsigned char pixel[4]; glReadPixels(x,gViewport[3] - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel[0]); if (pixel[0] == 0 && pixel[1] == 0 && pixel[2] == 0) return 0; // Click on the sky, which is drawn black. No block will have this value (facing is 1-6). PickingData coding; coding.rgb[0] = pixel[0]; coding.rgb[1] = pixel[1]; coding.rgb[2] = pixel[2]; // Compensate for transformation in shader. #if 0 gMsgWindow.Add("Pick (%d,%d,%d) facing %d, d(%d,%d,%d)", coding.bitmap.x, coding.bitmap.y, coding.bitmap.z, coding.bitmap.facing, coding.bitmap.dx-1, coding.bitmap.dy-1, coding.bitmap.dz-1); gMsgWindow.Add("RGB: %d,%d,%d", coding.rgb[0], coding.rgb[1], coding.rgb[2]); #endif ChunkCoord cc; gPlayer.GetChunkCoord(&cc); cc.x += coding.bitmap.dx-1; cc.y += coding.bitmap.dy-1; cc.z += coding.bitmap.dz-1; chunk *cp = ChunkFind(&cc, false); coc->x = coding.bitmap.x; coc->y = coding.bitmap.y; coc->z = coding.bitmap.z; if (surfaceDir) *surfaceDir = coding.bitmap.facing; checkError("gameDialog::FindSelectedSurface"); return cp; }
void LandscapeDebugNode::Draw() { if(0 == heightmap->Size()) return; BindMaterial(0); int32 index = 0; for (int32 y = 0; y < heightmap->Size(); ++y) { for (int32 x = 0; x < heightmap->Size(); ++x) { debugVertices[index].position = GetPoint(x, y, heightmap->Data()[y * heightmap->Size() + x]); debugVertices[index].texCoord = Vector2((float32)x / (float32)(heightmap->Size() - 1), (float32)y / (float32)(heightmap->Size() - 1)); index++; } } int32 step = 1; int32 indexIndex = 0; int32 quadWidth = heightmap->Size(); for(int32 y = 0; y < heightmap->Size() - 1; y += step) { for(int32 x = 0; x < heightmap->Size() - 1; x += step) { debugIndices[indexIndex++] = x + y * quadWidth; debugIndices[indexIndex++] = (x + step) + y * quadWidth; debugIndices[indexIndex++] = x + (y + step) * quadWidth; debugIndices[indexIndex++] = (x + step) + y * quadWidth; debugIndices[indexIndex++] = (x + step) + (y + step) * quadWidth; debugIndices[indexIndex++] = x + (y + step) * quadWidth; } } debugRenderDataObject->SetStream(EVF_VERTEX, TYPE_FLOAT, 3, sizeof(LandscapeVertex), &debugVertices[0].position); debugRenderDataObject->SetStream(EVF_TEXCOORD0, TYPE_FLOAT, 2, sizeof(LandscapeVertex), &debugVertices[0].texCoord); #if defined(__DAVAENGINE_OPENGL__) if (debugFlags & DEBUG_DRAW_GRID) { debugFlags &= ~DEBUG_DRAW_GRID; DrawLandscape(); debugFlags |= DEBUG_DRAW_GRID; glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); RenderManager::Instance()->SetColor(1.0f, 1.f, 1.f, 1.f); RenderManager::Instance()->SetRenderEffect(RenderManager::FLAT_COLOR); RenderManager::Instance()->SetShader(0); RenderManager::Instance()->FlushState(); } #endif //#if defined(__DAVAENGINE_OPENGL__) DrawLandscape(); #if defined(__DAVAENGINE_OPENGL__) if (debugFlags & DEBUG_DRAW_ALL) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } #endif //#if defined(__DAVAENGINE_OPENGL__) if(cursor) { RenderManager::Instance()->AppendState(RenderStateBlock::STATE_BLEND); eBlendMode src = RenderManager::Instance()->GetSrcBlend(); eBlendMode dst = RenderManager::Instance()->GetDestBlend(); RenderManager::Instance()->SetBlendMode(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA); RenderManager::Instance()->SetDepthFunc(CMP_LEQUAL); cursor->Prepare(); RenderManager::Instance()->HWDrawElements(PRIMITIVETYPE_TRIANGLELIST, (heightmap->Size() - 1) * (heightmap->Size() - 1) * 6, EIF_32, &debugIndices.front()); RenderManager::Instance()->SetDepthFunc(CMP_LESS); RenderManager::Instance()->RemoveState(RenderStateBlock::STATE_BLEND); RenderManager::Instance()->SetBlendMode(src, dst); } UnbindMaterial(); }