MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / DrawColoredRing

Function DrawColoredRing

Descent3/fireball.cpp:2073–2149  ·  view source on GitHub ↗

Draws a colored alpha ring...useful for cool lighting effects

Source from the content-addressed store, hash-verified

2071
2072// Draws a colored alpha ring...useful for cool lighting effects
2073void DrawColoredRing(vector *pos, float r, float g, float b, float inner_alpha, float outer_alpha, float size,
2074 float inner_ring_ratio, uint8_t saturate, uint8_t lod) {
2075 static vector circleVecs[3][32];
2076 static int lodSegments[3] = {32, 16, 8};
2077 static bool firstCall = true;
2078
2079 if (firstCall) {
2080 // initialize the circleVecs
2081 firstCall = false;
2082 int lodi;
2083 for (lodi = 0; lodi < 3; ++lodi) {
2084 int numSegments = lodSegments[lodi];
2085 int ringIncrement = 65536 / numSegments;
2086 int ringAngle = 0;
2087 int i;
2088 for (i = 0; i < numSegments; ++i, ringAngle += ringIncrement) {
2089 float ringSin = FixSin(ringAngle);
2090 float ringCos = FixCos(ringAngle);
2091 circleVecs[lodi][i].x = ringCos;
2092 circleVecs[lodi][i].y = ringSin;
2093 circleVecs[lodi][i].z = 0.0f;
2094 }
2095 }
2096 }
2097
2098 // setup renderer
2099 rend_SetLighting(LS_GOURAUD);
2100 rend_SetTextureType(TT_FLAT);
2101 rend_SetOverlayType(OT_NONE);
2102 rend_SetColorModel(CM_RGB);
2103 rend_SetFlatColor(GR_RGB(r * 255, g * 255, b * 255));
2104 rend_SetAlphaType((saturate) ? AT_SATURATE_VERTEX : AT_VERTEX);
2105
2106 // check LOD level
2107 ASSERT(lod >= 0 && lod <= 2);
2108 int i, numSegments = lodSegments[lod];
2109
2110 // get the view matrix
2111 matrix viewOrient;
2112 g3_GetUnscaledMatrix(&viewOrient);
2113 viewOrient = ~viewOrient;
2114
2115 // setup the points
2116 g3Point innerPoints[32], outerPoints[32];
2117 float innerRingSize = size * inner_ring_ratio;
2118 float outerRingSize = size;
2119 for (i = 0; i < numSegments; ++i) {
2120 vector worldSpaceCircleVec = circleVecs[lod][i] * viewOrient;
2121 vector innerPos = (*pos) + (worldSpaceCircleVec * innerRingSize);
2122 vector outerPos = (*pos) + (worldSpaceCircleVec * outerRingSize);
2123
2124 g3_RotatePoint(&innerPoints[i], &innerPos);
2125 innerPoints[i].p3_flags |= PF_RGBA;
2126 innerPoints[i].p3_a = inner_alpha;
2127 innerPoints[i].p3_r = r;
2128 innerPoints[i].p3_g = g;
2129 innerPoints[i].p3_b = b;
2130

Callers 2

DrawSkyFunction · 0.85
DrawColoredDiskFunction · 0.85

Calls 12

g3_GetUnscaledMatrixFunction · 0.85
g3_RotatePointFunction · 0.85
g3_DrawPolyFunction · 0.85
FixSinFunction · 0.50
FixCosFunction · 0.50
rend_SetLightingFunction · 0.50
rend_SetTextureTypeFunction · 0.50
rend_SetOverlayTypeFunction · 0.50
rend_SetColorModelFunction · 0.50
rend_SetFlatColorFunction · 0.50
GR_RGBFunction · 0.50
rend_SetAlphaTypeFunction · 0.50

Tested by

no test coverage detected