void CMoltenBoltEffectCreator::Paint (CG16bitImage &Dest, int x, int y, SViewportPaintCtx &Ctx) // Paint // // Paint effect { // Compute the length of the bolt based on the time int iLength = m_iLength + (m_iGrowth * (Min(8, Ctx.iTick))); // Create the outer shape SPoint Poly[SHAPE_COUNT]; CreateBoltShape(Ctx.iRotation, iLength, m_iWidth, Poly); // Paint CG16bitRegion Region; WORD wColor = CG16bitImage::BlendPixel(Ctx.wSpaceColor, m_wSecondaryColor, 200); Region.CreateFromConvexPolygon(SHAPE_COUNT, Poly); Region.Fill(Dest, x, y, wColor); // Create the inner shape CreateBoltShape(Ctx.iRotation, Max(16, iLength * 7 / 8), Max(2, m_iWidth * 7 / 8), Poly); // Paint Region.CreateFromConvexPolygon(SHAPE_COUNT, Poly); Region.Fill(Dest, x, y, m_wPrimaryColor); }
void CShapeEffectPainter::Paint (CG16bitImage &Dest, int x, int y, SViewportPaintCtx &Ctx) // Paint // // Paint effect { // Compute the desired rotation, length, and width int iLength = m_pCreator->GetLength() + Ctx.iTick * m_pCreator->GetLengthInc(); int iWidth = m_pCreator->GetWidth() + Ctx.iTick * m_pCreator->GetWidthInc(); int iRotation = (m_pCreator->IsDirectional() ? Ctx.iRotation : 0); // Generate the shape CacheShapeRegion(iRotation, iLength, iWidth); // Paint DWORD byOpacity = m_pCreator->GetOpacity(); WORD wColor = m_pCreator->GetColor(); if (byOpacity == 255) m_CachedRegion.Fill(Dest, x, y, wColor); else m_CachedRegion.FillTrans(Dest, x, y, wColor, byOpacity); }
void CBeamEffectCreator::DrawBeamHeavyBlaster (CG16bitImage &Dest, SLineDesc &Line, SViewportPaintCtx &Ctx) // DrawBeamHeavyBlaster // // Draws the appropriate beam { // Convert to an angle relative to xTo, yTo CVector vVec(Line.xFrom - Line.xTo, Line.yFrom - Line.yTo); Metric rRadius; int iAngle = VectorToPolar(vVec, &rRadius); int iRadius = (int)rRadius; // Can't deal with 0 sized lines if (iRadius == 0) return; CG16bitRegion Region; SPoint Poly[8]; // Compute some metrics int iLengthUnit = iRadius * (10 + m_iIntensity) / 40; int iWidthUnit = Max(1, iRadius * m_iIntensity / 60); // Paint the outer-most glow WORD wColor = CG16bitImage::BlendPixel(Ctx.wSpaceColor, m_wSecondaryColor, 100); CreateBlasterShape(iAngle, 4 * iLengthUnit, 3 * iWidthUnit / 2, Poly); Region.CreateFromConvexPolygon(8, Poly); Region.Fill(Dest, Line.xTo, Line.yTo, wColor); // Paint the inner transition wColor = CG16bitImage::BlendPixel(m_wSecondaryColor, m_wPrimaryColor, 128); wColor = CG16bitImage::BlendPixel(Ctx.wSpaceColor, wColor, 200); CreateBlasterShape(iAngle, 3 * iLengthUnit, iWidthUnit, Poly); Region.CreateFromConvexPolygon(8, Poly); Region.Fill(Dest, Line.xTo, Line.yTo, wColor); // Paint the inner core CreateBlasterShape(iAngle, iLengthUnit, iWidthUnit - 1, Poly); Region.CreateFromConvexPolygon(8, Poly); Region.Fill(Dest, Line.xTo, Line.yTo, m_wPrimaryColor); }
void CBeamEffectCreator::DrawBeamLightningBolt (CG16bitImage &Dest, SLineDesc &Line, SViewportPaintCtx &Ctx) // DrawBeamLightningBolt // // Draws the appropriate beam { int i; // Compute a set of points for the lightning int iPointCount = LIGHTNING_POINT_COUNT; CVector *pPoints = new CVector [iPointCount]; pPoints[0] = CVector(Line.xFrom, Line.yFrom); pPoints[iPointCount - 1] = CVector(Line.xTo, Line.yTo); ComputeLightningPoints(iPointCount, pPoints, 0.3); // Draw based on intensity switch (m_iIntensity) { // Draw nothing case 0: break; // At intensity 1 or 2 just draw a lightning line with the primary color case 1: case 2: { for (i = 0; i < iPointCount-1; i++) { const CVector &vFrom = pPoints[i]; const CVector &vTo = pPoints[i + 1]; Dest.DrawLine((int)vFrom.GetX(), (int)vFrom.GetY(), (int)vTo.GetX(), (int)vTo.GetY(), m_iIntensity, m_wPrimaryColor); } break; } // At intensity 3 or 4 draw secondary color around primary. case 3: case 4: { for (i = 0; i < iPointCount-1; i++) { const CVector &vFrom = pPoints[i]; const CVector &vTo = pPoints[i + 1]; Dest.DrawLine((int)vFrom.GetX(), (int)vFrom.GetY(), (int)vTo.GetX(), (int)vTo.GetY(), m_iIntensity, m_wSecondaryColor); } for (i = 0; i < iPointCount-1; i++) { const CVector &vFrom = pPoints[i]; const CVector &vTo = pPoints[i + 1]; Dest.DrawLine((int)vFrom.GetX(), (int)vFrom.GetY(), (int)vTo.GetX(), (int)vTo.GetY(), m_iIntensity - 2, m_wPrimaryColor); } break; } // At intensity 5-10 we draw a glow around the beam case 5: case 6: case 7: case 8: case 9: case 10: { // Create a polygon for the glow shaped like a wide version of the // lightning bolt. CG16bitRegion GlowRegion; CreateLightningGlow(Line, iPointCount, pPoints, m_iIntensity, &GlowRegion); // Paint the glow GlowRegion.FillTrans(Dest, 0, 0, m_wSecondaryColor, 128); // Paint the main bolt for (i = 0; i < iPointCount-1; i++) { const CVector &vFrom = pPoints[i]; const CVector &vTo = pPoints[i + 1]; Dest.DrawLine((int)vFrom.GetX(), (int)vFrom.GetY(), (int)vTo.GetX(), (int)vTo.GetY(), 4, m_wSecondaryColor); } for (i = 0; i < iPointCount-1; i++) { const CVector &vFrom = pPoints[i]; const CVector &vTo = pPoints[i + 1]; Dest.DrawLine((int)vFrom.GetX(), (int)vFrom.GetY(), (int)vTo.GetX(), (int)vTo.GetY(), 2, m_wPrimaryColor); } break; } // For even larger beams we do a double glow default: { // Create a polygon for the glow shaped like a wide version of the // lightning bolt. CG16bitRegion GlowRegion1; CreateLightningGlow(Line, iPointCount, pPoints, m_iIntensity, &GlowRegion1); CG16bitRegion GlowRegion2; CreateLightningGlow(Line, iPointCount, pPoints, 10, &GlowRegion2); // Paint the glow GlowRegion1.FillTrans(Dest, 0, 0, m_wSecondaryColor, 48); GlowRegion2.FillTrans(Dest, 0, 0, m_wSecondaryColor, 96); // Paint the main bolt for (i = 0; i < iPointCount-1; i++) { const CVector &vFrom = pPoints[i]; const CVector &vTo = pPoints[i + 1]; Dest.DrawLine((int)vFrom.GetX(), (int)vFrom.GetY(), (int)vTo.GetX(), (int)vTo.GetY(), 4, m_wSecondaryColor); } for (i = 0; i < iPointCount-1; i++) { const CVector &vFrom = pPoints[i]; const CVector &vTo = pPoints[i + 1]; Dest.DrawLine((int)vFrom.GetX(), (int)vFrom.GetY(), (int)vTo.GetX(), (int)vTo.GetY(), 2, m_wPrimaryColor); } break; } } // Done delete [] pPoints; }
void CBeamEffectCreator::DrawBeamLightning (CG16bitImage &Dest, SLineDesc &Line, SViewportPaintCtx &Ctx) // DrawBeamLightning // // Draws the appropriate beam { // The central part of the beam is different depending on the // intensity. if (m_iIntensity < 4) { WORD wStart = CG16bitImage::BlendPixel(Ctx.wSpaceColor, m_wPrimaryColor, 128); Dest.DrawBiColorLine(Line.xFrom, Line.yFrom, Line.xTo, Line.yTo, 3, Ctx.wSpaceColor, wStart); WORD wEnd = CG16bitImage::BlendPixel(Ctx.wSpaceColor, m_wPrimaryColor, 155); Dest.DrawBiColorLine(Line.xFrom, Line.yFrom, Line.xTo, Line.yTo, 1, wEnd, m_wPrimaryColor); } else if (m_iIntensity < 10) { WORD wStart = CG16bitImage::BlendPixel(Ctx.wSpaceColor, m_wSecondaryColor, 155); Dest.DrawBiColorLine(Line.xFrom, Line.yFrom, Line.xTo, Line.yTo, 5, Ctx.wSpaceColor, wStart); Dest.DrawBiColorLine(Line.xFrom, Line.yFrom, Line.xTo, Line.yTo, 3, Ctx.wSpaceColor, m_wSecondaryColor); WORD wEnd = CG16bitImage::BlendPixel(Ctx.wSpaceColor, m_wPrimaryColor, 155); Dest.DrawBiColorLine(Line.xFrom, Line.yFrom, Line.xTo, Line.yTo, 1, wEnd, m_wPrimaryColor); } else { // Convert to an angle relative to xTo, yTo CVector vVec(Line.xFrom - Line.xTo, Line.yFrom - Line.yTo); Metric rRadius; int iAngle = VectorToPolar(vVec, &rRadius); int iRadius = (int)rRadius; // Can't deal with 0 sized lines if (iRadius == 0) return; CG16bitRegion Region; SPoint Poly[8]; // Paint the outer-most glow WORD wColor = CG16bitImage::BlendPixel(Ctx.wSpaceColor, m_wSecondaryColor, 100); CreateBlasterShape(iAngle, iRadius, iRadius / 6, Poly); Region.CreateFromConvexPolygon(8, Poly); Region.Fill(Dest, Line.xTo, Line.yTo, wColor); // Paint the inner transition wColor = CG16bitImage::BlendPixel(m_wSecondaryColor, m_wPrimaryColor, 128); wColor = CG16bitImage::BlendPixel(Ctx.wSpaceColor, wColor, 200); CreateBlasterShape(iAngle, iRadius * 2 / 3, iRadius / 7, Poly); Region.CreateFromConvexPolygon(8, Poly); Region.Fill(Dest, Line.xTo, Line.yTo, wColor); // Paint the inner core CreateBlasterShape(iAngle, iRadius / 2, iRadius / 8, Poly); Region.CreateFromConvexPolygon(8, Poly); Region.Fill(Dest, Line.xTo, Line.yTo, m_wPrimaryColor); } // Compute the half-way point int xHalf = (Line.xFrom + Line.xTo) / 2; int yHalf = (Line.yFrom + Line.yTo) / 2; // Draw lightning int iCount = m_iIntensity + mathRandom(0, 2); for (int j = 0; j < iCount; j++) if (mathRandom(1, 2) == 1) DrawLightning(Dest, xHalf, yHalf, Line.xTo, Line.yTo, m_wPrimaryColor, LIGHTNING_POINT_COUNT, 0.5); else DrawLightning(Dest, Line.xFrom, Line.yFrom, Line.xTo, Line.yTo, m_wSecondaryColor, LIGHTNING_POINT_COUNT, 0.3); }
void CFlarePainter::Paint (CG16bitImage &Dest, int x, int y, SViewportPaintCtx &Ctx) // Paint // // Paint { int i; COLORREF wPrimaryColor = m_pCreator->GetPrimaryColor(); switch (m_pCreator->GetStyle()) { case CFlareEffectCreator::styleFadingBlast: { // Radius shrinks proportionally each tick int iRadius; if (m_iTick < m_pCreator->GetLifetime()) iRadius = (int)(m_pCreator->GetRadius() * ((Metric)(m_pCreator->GetLifetime() - m_iTick) / (Metric)m_pCreator->GetLifetime())); else iRadius = 0; // Paint if (iRadius) { // Paint each of the spikes first int iAngle = 360 / MAIN_SPIKE_COUNT; for (i = 0; i < MAIN_SPIKE_COUNT; i++) { SPoint Spike[4]; m_pCreator->CreateFlareSpike(i * iAngle, iRadius, iRadius / MAIN_SPIKE_WIDTH_RATIO, Spike); CG16bitRegion Region; Region.CreateFromConvexPolygon(4, Spike); Region.FillTrans(Dest, x, y, wPrimaryColor, 128); } // Paint central glow #if 0 DrawAlphaGradientCircle(Dest, x, y, iRadius / 8, wPrimaryColor); #endif // Paint the extended glow DrawAlphaGradientCircle(Dest, x, y, iRadius, wPrimaryColor); } break; } } }
void CFlarePainter::Paint (CG16bitImage &Dest, int x, int y, SViewportPaintCtx &Ctx) // Paint // // Paint { int i; // Safety checks int iTotalLifetime = m_pCreator->GetLifetime(); if (iTotalLifetime <= 0) return; switch (m_pCreator->GetStyle()) { case CFlareEffectCreator::styleFadingBlast: { // Radius shrinks proportionally each tick int iRadius; if (m_iTick < m_pCreator->GetLifetime()) iRadius = (int)(m_pCreator->GetRadius() * ((Metric)(m_pCreator->GetLifetime() - m_iTick) / (Metric)iTotalLifetime)); else iRadius = 0; // Color moves from primary to secondary WORD wColor; if (m_pCreator->GetPrimaryColor() != m_pCreator->GetSecondaryColor()) wColor = CG16bitImage::FadeColor(m_pCreator->GetPrimaryColor(), m_pCreator->GetSecondaryColor(), 100 * m_iTick / iTotalLifetime); else wColor = m_pCreator->GetPrimaryColor(); // Paint if (iRadius) { // Paint each of the spikes first int iAngle = 360 / MAIN_SPIKE_COUNT; for (i = 0; i < MAIN_SPIKE_COUNT; i++) { SPoint Spike[4]; m_pCreator->CreateFlareSpike(i * iAngle, iRadius, iRadius / MAIN_SPIKE_WIDTH_RATIO, Spike); CG16bitRegion Region; Region.CreateFromSimplePolygon(4, Spike); Region.FillTrans(Dest, x, y, wColor, MAIN_SPIKE_OPACITY); } // Paint the extended glow DrawAlphaGradientCircle(Dest, x, y, iRadius, wColor); } break; } } }