static FLOATaabbox3D CalculateAABBoxFromRect(CTerrain *ptrTerrain, Rect rcExtract) { ASSERT(ptrTerrain!=NULL); ASSERT(ptrTerrain->tr_penEntity!=NULL); // Get entity that holds this terrain //CEntity *penEntity = ptrTerrain->tr_penEntity; FLOATaabbox3D bboxExtract; FLOATaabbox3D bboxAllTerrain; ptrTerrain->GetAllTerrainBBox(bboxAllTerrain); FLOAT fMinY = bboxAllTerrain.minvect(2); FLOAT fMaxY = bboxAllTerrain.maxvect(2); bboxExtract.minvect = FLOAT3D(rcExtract.rc_iLeft * ptrTerrain->tr_vStretch(1),fMinY,rcExtract.rc_iTop * ptrTerrain->tr_vStretch(3)); bboxExtract.maxvect = FLOAT3D(rcExtract.rc_iRight * ptrTerrain->tr_vStretch(1),fMaxY,rcExtract.rc_iBottom * ptrTerrain->tr_vStretch(3)); return bboxExtract; }
void ShowSelectionInternal(CTerrain *ptrTerrain, Rect &rcExtract, CTextureData *ptdBrush, GFXColor colSelection, FLOAT fStrenght, SelectionFill sfFill) { ASSERT(ptrTerrain!=NULL); ASSERT(ptdBrush!=NULL); Rect rcSelection; FLOATaabbox3D bboxSelection; // Clamp rect used for extraction rcSelection.rc_iLeft = Clamp(rcExtract.rc_iLeft , 0, ptrTerrain->tr_pixHeightMapWidth); rcSelection.rc_iTop = Clamp(rcExtract.rc_iTop , 0, ptrTerrain->tr_pixHeightMapHeight); rcSelection.rc_iRight = Clamp(rcExtract.rc_iRight , 0, ptrTerrain->tr_pixHeightMapWidth); rcSelection.rc_iBottom = Clamp(rcExtract.rc_iBottom , 0, ptrTerrain->tr_pixHeightMapHeight); // Prepare box for vertex selection bboxSelection = FLOAT3D(rcSelection.rc_iLeft, 0, rcSelection.rc_iTop); bboxSelection |= FLOAT3D(rcSelection.rc_iRight, 0, rcSelection.rc_iBottom); // Stretch selection box bboxSelection.minvect(1) *= ptrTerrain->tr_vStretch(1); bboxSelection.minvect(3) *= ptrTerrain->tr_vStretch(3); bboxSelection.maxvect(1) *= ptrTerrain->tr_vStretch(1); bboxSelection.maxvect(3) *= ptrTerrain->tr_vStretch(3); // Set selection box height FLOATaabbox3D bboxAllTerrain; ptrTerrain->GetAllTerrainBBox(bboxAllTerrain); bboxSelection.minvect(2) = bboxAllTerrain.minvect(2); bboxSelection.maxvect(2) = bboxAllTerrain.maxvect(2); GFXVertex *pavVertices; INDEX *paiIndices; INDEX ctVertices; INDEX ctIndices; // Extract vertices in selection rect ExtractVerticesInRect(ptrTerrain, rcSelection, &pavVertices, &paiIndices, ctVertices, ctIndices); if(ctVertices!=rcSelection.Width()*rcSelection.Height()) { ASSERT(FALSE); return; } // if no vertices if(ctVertices==0) { return; } // Prepare vertex colors for selection preview PIX pixWidth = rcSelection.Width(); PIX pixHeight = rcSelection.Height(); INDEX iStepX = ptdBrush->GetWidth() - pixWidth; INDEX iFirst = 0; if(rcExtract.rc_iTop<0) { iFirst += -rcExtract.rc_iTop*ptdBrush->GetWidth(); } if(rcExtract.rc_iLeft<0) { iFirst += -rcExtract.rc_iLeft; } _aiExtColors.Push(ctVertices); GFXColor *pacolColor = (GFXColor*)&_aiExtColors[0]; GFXColor *pacolBrush = (GFXColor*)&ptdBrush->td_pulFrames[iFirst]; // Fill vertex colors for selection preview SLONG slStrength = (SLONG) (Clamp(Abs(fStrenght),0.0f,1.0f) * 256.0f); // for each row for(INDEX iy=0;iy<pixHeight;iy++) { // for each col for(INDEX ix=0;ix<pixWidth;ix++) { pacolColor->ul.abgr = colSelection.ul.abgr; pacolColor->ub.a = (pacolBrush->ub.r*slStrength)>>8; pacolColor++; pacolBrush++; } pacolBrush+=iStepX; } // Render selected polygons for selection preview if(sfFill == SF_WIREFRAME) { gfxPolygonMode(GFX_LINE); gfxEnableDepthBias(); } if(sfFill != SF_POINTS) { // Draw selection gfxDisableTexture(); gfxDisableAlphaTest(); gfxEnableBlend(); gfxBlendFunc(GFX_SRC_ALPHA, GFX_INV_SRC_ALPHA); gfxSetVertexArray(pavVertices,ctVertices); gfxSetColorArray(&_aiExtColors[0]); gfxLockArrays(); gfxDrawElements(ctIndices,paiIndices); gfxUnlockArrays(); gfxDisableBlend(); } if(sfFill == SF_WIREFRAME) { gfxDisableDepthBias(); gfxPolygonMode(GFX_FILL); } if(sfFill == SF_POINTS) { DrawSelectedVertices(pavVertices,&_aiExtColors[0],ctVertices); } }