void EffectBoil::incrementBubbles() { for (int i = 0; i < NUM_BUBBLES; i++) { if (!bubbles[i].alive) { if (frand() < boilingDensity) { bubbles[i].alive = true; bubbles[i].x = minx + scalex*frand(); bubbles[i].y = miny + scaley*frand(); bubbles[i].size = 0.0f; bubbles[i].speed = 0.05f + 0.1f*frand(); } } else { bubbles[i].size += bubbles[i].speed; for (int j = 0; j < i; j++) { if (bubbles[j].alive && bubblesTooClose(&bubbles[i],&bubbles[j])) combineBubbles(&bubbles[i],&bubbles[j]); } if (bubbles[i].size > 2.0 && frand() < 0.2) popBubble(&bubbles[i]); else if (bubbles[i].size > 4.0) popBubble(&bubbles[i]); } } }
void EffectBoil::combineBubbles(Bubble * bubbleA, Bubble * bubbleB) { Bubble * dst = bubbleB, * src = bubbleA; if (bubbleA->size > bubbleB->size) { dst = bubbleA; src = bubbleB; } if (src->size == 0) { src->alive = false; return; } float ratio = dst->size / (dst->size + src->size); dst->size = (float)pow((double)(dst->size*dst->size*dst->size+ src->size*src->size*src->size),0.33333); dst->x = dst->x * ratio + src->x*(1-ratio); dst->y = dst->y * ratio + src->y*(1-ratio); popBubble(src); }
//------------------------------------------------------------------------------ void GuiBubbleTextCtrl::onMouseDown(const GuiEvent &event) { if (mInAction) { popBubble(); return; } mDlg = new GuiControl(); AssertFatal(mDlg, "Failed to create the GuiControl for the BubbleTextCtrl"); mDlg->setDataField( StringTable->insert("profile"), NULL, "GuiModelessDialogProfile"); mDlg->setField("horizSizing", "width"); mDlg->setField("vertSizing", "height"); mDlg->setField("extent", "640 480"); mPopup = new GuiControl(); AssertFatal(mPopup, "Failed to create the GuiControl for the BubbleTextCtrl"); mPopup->setDataField( StringTable->insert("profile"), NULL, "GuiBubblePopupProfile"); mMLText = new GuiMLTextCtrl(); AssertFatal(mMLText, "Failed to create the GuiMLTextCtrl for the BubbleTextCtrl"); mMLText->setDataField( StringTable->insert("profile"), NULL, "GuiBubbleTextProfile"); mMLText->setField("position", "2 2"); mMLText->setField("extent", "296 51"); mMLText->setText((char*)mText,dStrlen(mText)); mMLText->registerObject(); mPopup->registerObject(); mDlg->registerObject(); mPopup->addObject(mMLText); mDlg->addObject(mPopup); mPopup->resize(event.mousePoint,Point2I(300,55)); getRoot()->pushDialogControl(mDlg,0); mouseLock(); mInAction = true; }
void EffectBoil::start() { boilingDensity = 0.016f; for (int i = 0; i < NUM_BUBBLES; i++) popBubble(&bubbles[i]); }