// // Draw wireframe sphere // void CClientColSphere::DebugRender ( const CVector& vecPosition, float fDrawRadius ) { SColorARGB color ( 64, 255, 0, 0 ); float fLineWidth = 4.f + pow ( m_fRadius, 0.5f ); CGraphicsInterface* pGraphics = g_pCore->GetGraphics (); uint iterations = Clamp ( 1, Round ( pow ( m_fRadius, 0.25f ) * 0.75f ), 4 ); const SWireModel& model = GetSphereWireModel ( iterations ); for ( uint i = 0 ; i < model.vertexList.size () ; i += 2 ) { const CVector& vecBegin = model.vertexList[ i ] * m_fRadius + m_vecPosition; const CVector& vecEnd = model.vertexList[ i + 1 ] * m_fRadius + m_vecPosition; pGraphics->DrawLine3DQueued ( vecBegin, vecEnd, fLineWidth, color, false ); } }
// // Draw wireframe polygon // void CClientColPolygon::DebugRender ( const CVector& vecPosition, float fDrawRadius ) { const uint uiNumPoints = m_Points.size(); SColorARGB color ( 128, 255, 255, 0 ); float fLineWidth = 4.f + pow ( m_fRadius, 0.5f ); CGraphicsInterface* pGraphics = g_pCore->GetGraphics (); // Don't draw a few end slices to show it goes on for ever int iSkipEndSlices = 4; // Calc required detail level uint uiNumSlices = std::max ( 2 + iSkipEndSlices * 2, Round ( sqrt ( fDrawRadius * 2.0f ) * 2.0f ) ); // Draw Slices { for ( uint s = iSkipEndSlices ; s < uiNumSlices - iSkipEndSlices ; s++ ) { float fZ = vecPosition.fZ - fDrawRadius + fDrawRadius * 2.0f * ( s / (float)( uiNumSlices - 1 ) ); fZ += 4; // Extra bit so a slice is on the same Z coord as the camera for ( uint i = 0 ; i < uiNumPoints ; i++ ) { const CVector2D& vecPointBegin = m_Points [ i ]; const CVector2D& vecPointEnd = m_Points [ ( i + 1 ) % uiNumPoints ]; CVector vecBegin ( vecPointBegin.fX, vecPointBegin.fY, fZ ); CVector vecEnd ( vecPointEnd.fX, vecPointEnd.fY, fZ ); pGraphics->DrawLine3DQueued ( vecBegin, vecEnd, fLineWidth, color, false ); } } } // Draw lines from bottom to top { for ( uint i = 0 ; i < uiNumPoints ; i++ ) { const CVector2D& vecPoint = m_Points [ i ]; CVector vecBegin ( vecPoint.fX, vecPoint.fY, vecPosition.fZ - fDrawRadius ); CVector vecEnd ( vecPoint.fX, vecPoint.fY, vecPosition.fZ + fDrawRadius ); pGraphics->DrawLine3DQueued ( vecBegin, vecEnd, fLineWidth, color, false ); } } }
/////////////////////////////////////////////////////////////// // // CGraphStats::Draw // // // /////////////////////////////////////////////////////////////// void CGraphStats::Draw ( void ) { if ( !m_bEnabled ) return; CGraphicsInterface* pGraphics = g_pCore->GetGraphics(); uint uiViewportHeight = pGraphics->GetViewportHeight(); uint uiOriginX = 10; uint uiOriginY = Min < int > ( 500, uiViewportHeight - 10 ); uint uiSizeX = GRAPHSTAT_HISTORY_SIZE; uint uiSizeY = 150; uint uiRangeY = 100; // 100ms float fLineScale = 1/1000.f / uiRangeY * uiSizeY; // Backgrounf box pGraphics->DrawRectQueued( uiOriginX, uiOriginY - uiSizeY, uiSizeX, uiSizeY, SColorRGBA( 0, 0, 0, 128 ), true ); // Draw data line. for ( std::map < SString, SGraphStatLine >::iterator iter = m_LineList.begin() ; iter != m_LineList.end() ; ++iter ) { SGraphStatLine& line = iter->second; int iDataPos = line.iDataPos; int iDataPosPrev = iDataPos; if ( iDataPos == -1 ) iDataPos = GRAPHSTAT_HISTORY_SIZE - 1; for ( int i = uiSizeX - 1 ; i > 0 ; i-- ) { float fY0 = line.dataHistory[ iDataPos ] * fLineScale; float fY1 = line.dataHistory[ iDataPosPrev ] * fLineScale; iDataPosPrev = iDataPos; iDataPos--; if ( iDataPos == -1 ) iDataPos = GRAPHSTAT_HISTORY_SIZE - 1; pGraphics->DrawLineQueued( uiOriginX + i - 1, uiOriginY - fY0, uiOriginX + i, uiOriginY - fY1, 1, line.color, true ); } } }
/////////////////////////////////////////////////////////////// // // CGraphStats::Draw // // // /////////////////////////////////////////////////////////////// void CGraphStats::Draw(void) { if (!m_bEnabled) return; CGraphicsInterface* pGraphics = g_pCore->GetGraphics(); uint uiViewportHeight = pGraphics->GetViewportHeight(); uint uiOriginX = 10; uint uiOriginY = std::min<int>(500, uiViewportHeight - 10); uint uiSizeX = GRAPHSTAT_HISTORY_SIZE; uint uiSizeY = 150; uint uiRangeY = 100; // 100ms float fLineScale = 1 / 1000.f / uiRangeY * uiSizeY; float fHalfLineHeight = pGraphics->GetDXFontHeight() / 2; // Backgroung box pGraphics->DrawRectQueued(uiOriginX, uiOriginY - uiSizeY, uiSizeX, uiSizeY, SColorRGBA(0, 0, 0, 128), true); // Draw data line. for (const auto& dataLine : m_LineList) { const SGraphStatLine& line = dataLine.second; int iDataPos = line.iDataPos; int iDataPosPrev = iDataPos; for (int i = uiSizeX - 1; i > 0; i--) { float fY0 = line.dataHistory[iDataPos] * fLineScale; float fY1 = line.dataHistory[iDataPosPrev] * fLineScale; iDataPosPrev = iDataPos; iDataPos--; if (iDataPos == -1) iDataPos = GRAPHSTAT_HISTORY_SIZE - 1; pGraphics->DrawLineQueued(uiOriginX + i - 1, uiOriginY - fY0, uiOriginX + i, uiOriginY - fY1, 1, line.color, true); } float fX = uiOriginX + uiSizeX + 2; float fY = uiOriginY - line.dataHistory[line.iDataPos] * fLineScale - fHalfLineHeight; pGraphics->DrawStringQueued(fX, fY, fX, fY, line.color, line.strName.c_str(), 1.0f, 1.0f, DT_NOCLIP, nullptr, true); } }
// // Draw wireframe rectangle // void CClientColRectangle::DebugRender ( const CVector& vecPosition, float fDrawRadius ) { CVector vecBase ( m_vecPosition.fX, m_vecPosition.fY, vecPosition.fZ - fDrawRadius ); CVector vecOrigin ( m_vecPosition.fX + m_vecSize.fX * 0.5f, m_vecPosition.fY + m_vecSize.fY * 0.5f, vecPosition.fZ ); CVector vecSize ( m_vecSize.fX, m_vecSize.fY, fDrawRadius * 2.f ); SColorARGB color ( 128, 255, 0, 255 ); float fLineWidth = 4.f + pow ( Max ( m_vecSize.fX, m_vecSize.fY ) * 0.5f, 0.5f ); CGraphicsInterface* pGraphics = g_pCore->GetGraphics (); // Don't draw a few end slices to show it goes on for ever int iSkipEndSlicesZ = 4; // Calc required detail level uint uiNumSlicesX = Max ( 2, Round ( sqrt ( vecSize.fX ) * 1.5f ) ); uint uiNumSlicesY = Max ( 2, Round ( sqrt ( vecSize.fY ) * 1.5f ) ); uint uiNumSlicesZ = Max ( 2 + iSkipEndSlicesZ * 2, Round ( sqrt ( vecSize.fZ ) * 2.0f ) ); // Draw Slices Z { static const CVector cornerPoints[] = { CVector( 0, 0, 1 ), CVector( 1, 0, 1 ), CVector( 1, 1, 1 ), CVector( 0, 1, 1 ) }; CVector vecMult = vecSize; CVector vecAdd = vecBase + CVector ( 0, 0, 4 ); // Extra bit so a slice is on the same Z coord as the camera for ( uint s = iSkipEndSlicesZ ; s < uiNumSlicesZ - iSkipEndSlicesZ ; s++ ) { vecMult.fZ = vecSize.fZ * ( s / (float)( uiNumSlicesZ - 1 ) ); for ( uint i = 0 ; i < NUMELMS( cornerPoints ) ; i++ ) { const CVector& vecBegin = cornerPoints [ i ] * vecMult + vecAdd; const CVector& vecEnd = cornerPoints [ ( i + 1 ) % 4 ] * vecMult + vecAdd; pGraphics->DrawLine3DQueued ( vecBegin, vecEnd, fLineWidth, color, false ); } } } // Draw Slices Y { static const CVector cornerPoints[] = { CVector( 0, 1, 0 ), CVector( 1, 1, 0 ), CVector( 1, 1, 1 ), CVector( 0, 1, 1 ) }; CVector vecMult = vecSize; CVector vecAdd = vecBase; for ( uint s = 0 ; s < uiNumSlicesY ; s++ ) { vecMult.fY = vecSize.fY * ( s / (float)( uiNumSlicesY - 1 ) ); for ( uint i = 0 ; i < NUMELMS( cornerPoints ) ; i++ ) { if ( !(i & 1) ) continue; // No end cap const CVector& vecBegin = cornerPoints [ i ] * vecMult + vecAdd; const CVector& vecEnd = cornerPoints [ ( i + 1 ) % 4 ] * vecMult + vecAdd; pGraphics->DrawLine3DQueued ( vecBegin, vecEnd, fLineWidth, color, false ); } } } // Draw Slices X { static const CVector cornerPoints[] = { CVector( 1, 0, 0 ), CVector( 1, 1, 0 ), CVector( 1, 1, 1 ), CVector( 1, 0, 1 ) }; CVector vecMult = vecSize; CVector vecAdd = vecBase; for ( uint s = 0 ; s < uiNumSlicesX ; s++ ) { vecMult.fX = vecSize.fX * ( s / (float)( uiNumSlicesX - 1 ) ); for ( uint i = 0 ; i < NUMELMS( cornerPoints ) ; i++ ) { if ( !(i & 1) ) continue; // No end cap const CVector& vecBegin = cornerPoints [ i ] * vecMult + vecAdd; const CVector& vecEnd = cornerPoints [ ( i + 1 ) % 4 ] * vecMult + vecAdd; pGraphics->DrawLine3DQueued ( vecBegin, vecEnd, fLineWidth, color, false ); } } } }
void CNametags::DrawTagForPlayer(CClientPlayer* pPlayer, unsigned char ucAlpha) { // If they aren't in the same dimension, dont draw if (pPlayer->GetDimension() != m_usDimension || !pPlayer->IsNametagShowing()) return; // Grab the resolution width and height CGraphicsInterface* pGraphics = g_pCore->GetGraphics(); static float fResWidth = static_cast<float>(pGraphics->GetViewportWidth()); static float fResHeight = static_cast<float>(pGraphics->GetViewportHeight()); // Get the position CVector vecPosition; pPlayer->GetBonePosition(BONE_PELVIS, vecPosition); // Calculate where the player is on our screen CVector vecScreenPosition; vecPosition.fZ += 0.3f; pGraphics->CalcScreenCoors(&vecPosition, &vecScreenPosition); // Grab health and max health float fMaxHealth = pPlayer->GetMaxHealth(); float fHealth = pPlayer->GetHealth(); float fArmor = pPlayer->GetArmor(); // Recalculate that to be within 0-100 fHealth = fHealth / fMaxHealth * 100; if (fHealth > 100.0f) fHealth = 100.0f; // Some multiplier heh... fHealth *= 7.52f; // Allow up to 50 pixels off screen to avoid nametags suddenly disappearing if (fHealth > 0 && vecScreenPosition.fX > -50.0f && vecScreenPosition.fX < fResWidth + 50.f && vecScreenPosition.fY > -50.0f && vecScreenPosition.fY < fResHeight + 50.f && vecScreenPosition.fZ > 0.1f) { // Grab the nick to show const char* szNick = pPlayer->GetNametagText(); if (!szNick || !szNick[0]) szNick = pPlayer->GetNick(); // Draw his name unsigned char ucR, ucG, ucB; pPlayer->GetNametagColor(ucR, ucG, ucB); // Draw shadow first int iScreenPosX = static_cast<int>(vecScreenPosition.fX); int iScreenPosY = static_cast<int>(vecScreenPosition.fY); pGraphics->DrawString(iScreenPosX + 1, iScreenPosY + 1, iScreenPosX + 1, iScreenPosY + 1, COLOR_ARGB(255, 0, 0, 0), szNick, 1.0f, 1.0f, DT_NOCLIP | DT_CENTER); pGraphics->DrawString(iScreenPosX, iScreenPosY, iScreenPosX, iScreenPosY, COLOR_ARGB(255, ucR, ucG, ucB), szNick, 1.0f, 1.0f, DT_NOCLIP | DT_CENTER); // We need to draw health tags? if (m_bDrawHealth) { fHealth = fHealth / (750.0f / 510.0f); long lRed = 0; long lGreen = 0; if (fHealth > 255) { lRed = static_cast<long>(512.0f - fHealth); if (lRed > 255) lRed = 255; lGreen = 255; } else if (fHealth <= 255) { lRed = 255; lGreen = static_cast<long>(fHealth); } long lRedBlack = static_cast<long>(lRed * 0.33f); long lGreenBlack = static_cast<long>(lGreen * 0.33f); // TR - TL - BR - BL float fHeight = fResHeight * 0.011f; float fWidth = fResWidth * 0.060f; float fTopOffset = fResHeight * 0.025f; float fSizeIncreaseBorder = fResWidth * 0.003f; float fRemovedWidth = fWidth - (fHealth / 512.0f * fWidth); float fTopArmorOffset = fTopOffset + fHeight - 0.01f * fResWidth; float fMaxArmor = 100.0f; float fArmorAlpha = (fArmor / fMaxArmor) * (ucAlpha / 255.0f); // 0->1 unsigned char ucArmorAlpha = (unsigned char)(255.0f * fArmorAlpha); #define ARMOR_BORDER_COLOR COLOR_ABGR(ucArmorAlpha,167,177,179) // Base rectangle CVector vecTopLeftBase(vecScreenPosition.fX - fWidth * 0.5f, vecScreenPosition.fY + fTopOffset, 0); CVector vecBotRightBase(vecScreenPosition.fX + fWidth * 0.5f, vecScreenPosition.fY + fTopOffset + fHeight, 0); // background CVector vecTopLeft = vecTopLeftBase + CVector(-fSizeIncreaseBorder, -fSizeIncreaseBorder, 0); CVector vecBotRight = vecBotRightBase + CVector(+fSizeIncreaseBorder, +fSizeIncreaseBorder, 0); pGraphics->DrawRectangle(vecTopLeft.fX, vecTopLeft.fY, vecBotRight.fX - vecTopLeft.fX, vecBotRight.fY - vecTopLeft.fY, COLOR_ABGR(ucAlpha, 0, 0, 0), true); if (fArmor > 0.0f) { // Left side of armor indicator vecTopLeft = vecTopLeftBase + CVector(-fSizeIncreaseBorder, -fSizeIncreaseBorder, 0); vecBotRight = vecBotRightBase + CVector(-fWidth, +fSizeIncreaseBorder, 0); pGraphics->DrawRectangle(vecTopLeft.fX, vecTopLeft.fY, vecBotRight.fX - vecTopLeft.fX, vecBotRight.fY - vecTopLeft.fY, ARMOR_BORDER_COLOR, true); // Right side of armor indicator vecTopLeft = vecTopLeftBase + CVector(+fWidth, -fSizeIncreaseBorder, 0); vecBotRight = vecBotRightBase + CVector(+fSizeIncreaseBorder, +fSizeIncreaseBorder, 0); pGraphics->DrawRectangle(vecTopLeft.fX, vecTopLeft.fY, vecBotRight.fX - vecTopLeft.fX, vecBotRight.fY - vecTopLeft.fY, ARMOR_BORDER_COLOR, true); // Top armor indicator vecTopLeft = vecTopLeftBase + CVector(+0, -fSizeIncreaseBorder, 0); vecBotRight = vecBotRightBase + CVector(+0, -fHeight, 0); pGraphics->DrawRectangle(vecTopLeft.fX, vecTopLeft.fY, vecBotRight.fX - vecTopLeft.fX, vecBotRight.fY - vecTopLeft.fY, ARMOR_BORDER_COLOR, true); // Bottom armor indicator vecTopLeft = vecTopLeftBase + CVector(+0, +fHeight, 0); vecBotRight = vecBotRightBase + CVector(+0, +fSizeIncreaseBorder, 0); pGraphics->DrawRectangle(vecTopLeft.fX, vecTopLeft.fY, vecBotRight.fX - vecTopLeft.fX, vecBotRight.fY - vecTopLeft.fY, ARMOR_BORDER_COLOR, true); } // the colored bit vecTopLeft = vecTopLeftBase + CVector(+0, +0, 0); vecBotRight = vecBotRightBase + CVector(-fRemovedWidth, +0, 0); pGraphics->DrawRectangle(vecTopLeft.fX, vecTopLeft.fY, vecBotRight.fX - vecTopLeft.fX, vecBotRight.fY - vecTopLeft.fY, COLOR_ABGR(ucAlpha, 0, static_cast<unsigned char>(lGreen), static_cast<unsigned char>(lRed)), true); // the black bit vecTopLeft = vecTopLeftBase + CVector(+fWidth - fRemovedWidth, +0, 0); vecBotRight = vecBotRightBase + CVector(+0, +0, 0); pGraphics->DrawRectangle(vecTopLeft.fX, vecTopLeft.fY, vecBotRight.fX - vecTopLeft.fX, vecBotRight.fY - vecTopLeft.fY, COLOR_ABGR(ucAlpha, 0, static_cast<unsigned char>(lGreenBlack), static_cast<unsigned char>(lRedBlack)), true); // Draw the player status icon if (pPlayer->HasConnectionTrouble()) { pGraphics->DrawTexture(m_pConnectionTroubleIcon, vecScreenPosition.fX - 20, vecScreenPosition.fY + 20); } } } }
// // Draw wireframe cuboid // void CClientColCuboid::DebugRender ( const CVector& vecPosition, float fDrawRadius ) { CVector vecBase = m_vecPosition; CVector vecOrigin = m_vecPosition + m_vecSize * 0.5f; CVector vecSize = m_vecSize; SColorARGB color ( 128, 0, 255, 0 ); float fLineWidth = 4.f + pow ( Max ( Max ( m_vecSize.fX, m_vecSize.fY ), m_vecSize.fZ ) * 0.5f, 0.5f ); CGraphicsInterface* pGraphics = g_pCore->GetGraphics (); // Calc required detail level uint uiNumSlicesX = Max ( 2, Round ( sqrt ( vecSize.fX ) * 1.5f ) ); uint uiNumSlicesY = Max ( 2, Round ( sqrt ( vecSize.fY ) * 1.5f ) ); uint uiNumSlicesZ = Max ( 2, Round ( sqrt ( vecSize.fZ ) * 2.0f ) ); // Draw Slices Z { static const CVector cornerPoints[] = { CVector( 0, 0, 1 ), CVector( 1, 0, 1 ), CVector( 1, 1, 1 ), CVector( 0, 1, 1 ) }; CVector vecMult ( vecSize.fX, vecSize.fY, vecSize.fZ ); CVector vecAdd ( vecBase.fX, vecBase.fY, vecBase.fZ ); for ( uint s = 0 ; s < uiNumSlicesZ ; s++ ) { vecMult.fZ = vecSize.fZ * ( s / (float)( uiNumSlicesZ - 1 ) ); for ( uint i = 0 ; i < NUMELMS( cornerPoints ) ; i++ ) { const CVector& vecBegin = cornerPoints [ i ] * vecMult + vecAdd; const CVector& vecEnd = cornerPoints [ ( i + 1 ) % 4 ] * vecMult + vecAdd; pGraphics->DrawLine3DQueued ( vecBegin, vecEnd, fLineWidth, color, false ); } } } // Draw Slices Y { static const CVector cornerPoints[] = { CVector( 0, 1, 0 ), CVector( 1, 1, 0 ), CVector( 1, 1, 1 ), CVector( 0, 1, 1 ) }; CVector vecMult ( vecSize.fX, vecSize.fY, vecSize.fZ ); CVector vecAdd ( vecBase.fX, vecBase.fY, vecBase.fZ ); for ( uint s = 0 ; s < uiNumSlicesY ; s++ ) { vecMult.fY = vecSize.fY * ( s / (float)( uiNumSlicesY - 1 ) ); for ( uint i = 0 ; i < NUMELMS( cornerPoints ) ; i++ ) { const CVector& vecBegin = cornerPoints [ i ] * vecMult + vecAdd; const CVector& vecEnd = cornerPoints [ ( i + 1 ) % 4 ] * vecMult + vecAdd; pGraphics->DrawLine3DQueued ( vecBegin, vecEnd, fLineWidth, color, false ); } } } // Draw Slices X { static const CVector cornerPoints[] = { CVector( 1, 0, 0 ), CVector( 1, 1, 0 ), CVector( 1, 1, 1 ), CVector( 1, 0, 1 ) }; CVector vecMult ( vecSize.fX, vecSize.fY, vecSize.fZ ); CVector vecAdd ( vecBase.fX, vecBase.fY, vecBase.fZ ); for ( uint s = 0 ; s < uiNumSlicesX ; s++ ) { vecMult.fX = vecSize.fX * ( s / (float)( uiNumSlicesX - 1 ) ); for ( uint i = 0 ; i < NUMELMS( cornerPoints ) ; i++ ) { const CVector& vecBegin = cornerPoints [ i ] * vecMult + vecAdd; const CVector& vecEnd = cornerPoints [ ( i + 1 ) % 4 ] * vecMult + vecAdd; pGraphics->DrawLine3DQueued ( vecBegin, vecEnd, fLineWidth, color, false ); } } } }