void WobbleNodeAnimator::buildQuadVertex(MyGUI::VectorQuadData& _data) { int count_w = getCountX(); int count_h = getCountY(); for (int rx=0; rx<count_w+1; rx++) { for (int ry=0; ry<count_h+1; ry++) { MyGUI::FloatPoint point((float)rx / (float)count_w, (float)ry / (float)count_h); float drageffect = 0; if (mInertiaMode) { float drageffect1 = squaredDistance(point, MyGUI::FloatPoint(0, 0)) * mResizeStrength; float drageffect2 = squaredDistance(point, MyGUI::FloatPoint(1, 1)) * mResizeStrength; drageffect = std::min(drageffect1, drageffect2); } else { drageffect = squaredDistance(mInertiaPoint, point) * mDragStrength; } float fx = getLeft() + getWidth() * point.left; float fy = getTop() + getHeight() * point.top; MyGUI::FloatPoint vert(fx + (-mDragOffset.left) * drageffect, fy + mDragOffset.top * drageffect); if (rx < count_w && ry < count_h) { _data[rx + ry*count_w].vertex[MyGUI::QuadData::CornerLT].x = vert.left; _data[rx + ry*count_w].vertex[MyGUI::QuadData::CornerLT].y = vert.top; } if (rx > 0 && ry > 0) { _data[(rx-1) + (ry-1)*count_w].vertex[MyGUI::QuadData::CornerRB].x = vert.left; _data[(rx-1) + (ry-1)*count_w].vertex[MyGUI::QuadData::CornerRB].y = vert.top; } if (rx > 0 && ry < count_h) { _data[(rx-1) + ry*count_w].vertex[MyGUI::QuadData::CornerRT].x = vert.left; _data[(rx-1) + ry*count_w].vertex[MyGUI::QuadData::CornerRT].y = vert.top; } if (rx < count_w && ry > 0) { _data[rx + (ry-1)*count_w].vertex[MyGUI::QuadData::CornerLB].x = vert.left; _data[rx + (ry-1)*count_w].vertex[MyGUI::QuadData::CornerLB].y = vert.top; } } } }
REAL d_dem::getMeanValue(REAL x_from, REAL x_to, REAL y_from, REAL y_to) const { size_t i_from, i_to; size_t j_from, j_to; i_from = get_i(x_from); i_from = MAX(0, i_from); i_to = get_i(x_to); i_to = MIN(i_to, getCountX()-1); j_from = get_j(y_from); j_from = MAX(0, j_from); j_to = get_j(y_to); j_to = MIN(j_to, getCountY()-1); size_t NN = getCountX(); size_t i,j; size_t cnt = 0; REAL sum_value = 0; REAL value; for (j = j_from; j <= j_to; j++) { for (i = i_from; i <= i_to; i++) { size_t pos = i + j*NN; value = (*coeff)(pos); if (value == this->undef_value) continue; sum_value += value; cnt++; }; }; if (cnt == 0) return this->undef_value; REAL res = sum_value/REAL(cnt); return res; };
size_t FadeNodeAnimator::animate( bool _update, size_t _quad_count, MyGUI::VectorQuadData& _data, float _time, MyGUI::IVertexBuffer* _buffer, MyGUI::ITexture* _texture, const MyGUI::RenderTargetInfo& _info, const MyGUI::IntCoord& _coord, bool& _isAnimate ) { addTime(_time); if (mDestroy && mAlpha == 0) { return _quad_count; } _isAnimate = true; _quad_count = tesselation( _quad_count, _data, _texture, _info, _coord); size_t index = 0; switch (mFadeType) { case 0: // random squares for (; index < _quad_count; ++index) { float alpha = pow(mAlpha, mSpeed[index]); unsigned int colour = 0xFFFFFF | ((unsigned int)(alpha * 255.0f) << 24); _data[index].vertex[MyGUI::QuadData::CornerLT].colour = colour; _data[index].vertex[MyGUI::QuadData::CornerRT].colour = colour; _data[index].vertex[MyGUI::QuadData::CornerLB].colour = colour; _data[index].vertex[MyGUI::QuadData::CornerRB].colour = colour; } break; case 1: // random not-squares case 2: // from center case 3: // TV for (int y = 0; y < getCountY() + 1; ++y) { for (int x = 0; x < getCountX() + 1; ++x) { index = x + y * getCountX(); float speed = 1.0f; if (mFadeType == 1) // random not-squares { speed = (float)mSpeed[index % (getCountX() * getCountY())]; } if (mFadeType == 2) // from center { float x1 = float(x - getCountX() / 2) / getCountX() * 2; float y1 = float(y - getCountY() / 2) / getCountY() * 2; speed = sqrt(x1 * x1 + y1 * y1); } if (mFadeType == 3) // TV { float x1 = float(x - getCountX() / 2) / getCountX() * 2; float y1 = float(y - getCountY() / 2) / getCountY() * 2; speed = sqrt(x1 * x1 * x1 * x1 + y1 * y1); } float alpha = pow(mAlpha, speed); unsigned int colour = 0xFFFFFF | ((unsigned int)(alpha * 255.0f) << 24); if ( x < getCountX() && y < getCountY() ) _data[index].vertex[MyGUI::QuadData::CornerLT].colour = colour; if ( x > 0 && y < getCountY() ) _data[index - 1].vertex[MyGUI::QuadData::CornerRT].colour = colour; if ( x < getCountX() && y > 0 ) _data[index - getCountX()].vertex[MyGUI::QuadData::CornerLB].colour = colour; if ( x > 0 && y > 0 ) _data[index - getCountX() - 1].vertex[MyGUI::QuadData::CornerRB].colour = colour; } } break; } return _quad_count; }
REAL d_dem::getInterpValue(REAL x, REAL y) const { REAL value = 0; size_t I0, J0, I1, J1; size_t func_sizeX = getCountX(); size_t func_sizeY = getCountY(); REAL z0, z1, z2, z3; REAL x0, y0; REAL delta_x, delta_y; REAL hX = grd->stepX; REAL hY = grd->stepY; const d_grid * g = grd; I0 = (size_t)MAX(0,floor( (x - g->startX)/g->stepX )); J0 = (size_t)MAX(0,floor( (y - g->startY)/g->stepY )); I1 = I0+1; J1 = J0+1; I0 = MIN(MAX( 0, I0 ), func_sizeX-1); I1 = MIN(MAX( 0, I1 ), func_sizeX-1); J0 = MIN(MAX( 0, J0 ), func_sizeY-1); J1 = MIN(MAX( 0, J1 ), func_sizeY-1); getCoordNode(I0, J0, x0, y0); z0 = (*(coeff))(I0 + func_sizeX*J0); z1 = (*(coeff))(I1 + func_sizeX*J0); z2 = (*(coeff))(I1 + func_sizeX*J1); z3 = (*(coeff))(I0 + func_sizeX*J1); if ( (z0 == this->undef_value) || (z1 == this->undef_value) || (z2 == this->undef_value) || (z3 == this->undef_value) ) { REAL sum = REAL(0); size_t cnt = 0; if (z0 != this->undef_value) { sum += z0; cnt++; } if (z1 != this->undef_value) { sum += z1; cnt++; } if (z2 != this->undef_value) { sum += z2; cnt++; } if (z3 != this->undef_value) { sum += z3; cnt++; } if (cnt == 0) { return this->undef_value; } REAL mean_z = sum/REAL(cnt); if (z0 == this->undef_value) z0 = mean_z; if (z1 == this->undef_value) z1 = mean_z; if (z2 == this->undef_value) z2 = mean_z; if (z3 == this->undef_value) z3 = mean_z; } delta_x = x - x0; delta_y = y - y0; // первый шаг линейной интерпол¤ции REAL z11 = (z2-z1)*delta_y/hY+z1; REAL z22 = (z3-z0)*delta_y/hY+z0; // второй шаг линейной интерпол¤ции REAL res = (z11-z22)*delta_x/hX+z22; return res; };