void percentAdd(Pixel *pix, Pixel addition, byteFraction percent) { static Pixel white = {0xFFFFFF}; //calculate the total percentage uint16_t totalPercent = pix->color.p + percent; //get the overflow (signed arithmetic) byteFraction overflow = max(0, (int)totalPercent-255); if (overflow > 0) { //calculate fractions for the old and new parts byteFraction oldFract = fract1(pix->color.p, totalPercent); byteFraction newFract = fract1(percent, totalPercent); //calculate the percentaged pixels and add nMultiply(pix, oldFract); nMultiply(&addition, newFract); nAdd(pix, addition); //lerp to white nMix(pix, white, overflow, 255); pix->color.p = 255; } else { nAdd(pix, addition); pix->color.p = totalPercent; } }
void RenderSpring(cloth *clothItem, node cur, node step) { node adj; int index = 0; adj = nAdd(cur, step); if(!( (adj.x>clothItem->width-1) || (adj.x<0) || (adj.y>clothItem->height-1) || (adj.y<0) )) { index = FindIndexInArray(cur.y, cur.x, clothItem->width); glVertex3f(clothItem->positions[index].x, clothItem->positions[index].y, clothItem->positions[index].z); index = FindIndexInArray(adj.y, adj.x, clothItem->width); glVertex3f(clothItem->positions[index].x, clothItem->positions[index].y, clothItem->positions[index].z); } }
Pixel add(Pixel pix, Pixel addition) { nAdd(&pix, addition); return pix; }