void GuiContainer::updateElementBounds(ElementInfo const & info) { Recti containerBounds = getBounds(); Coord2i containerSize = containerBounds.max - containerBounds.min + Coord2i{1, 1}; Recti elementBounds = info.element->getBounds(); Coord2i elementSize = elementBounds.max - elementBounds.min + Coord2i{1, 1}; info.element->setSize(Coord2i(info.sizeFractionOfContainer.scale(containerSize)) + info.sizeOffset); info.element->setPosition(Coord2i(info.positionFractionOfContainer.scale(containerSize) - info.positionFractionOfElement.scale(elementSize)) + info.positionOffset); }
Coord3f Ground::normalAt(Coord2i indexPoint) { // NOTE: In this function, the vertical component is i, which comes in as indexPoint.x, // and vice versa for the horizonal, j, which is indexPoint.y Coord2i p1, p2, p3; Coord3f normal; bool ignore[6] = { false, false, false, false, false, false }; float& cS = this->cellSize; if (indexPoint.x == 0) { ignore[2] = true; ignore[3] = true; ignore[4] = true; } if (indexPoint.x == (this->nRows - 1)) { ignore[0] = true; ignore[1] = true; ignore[5] = true; } if (indexPoint.y == 0) { ignore[3] = true; ignore[4] = true; ignore[5] = true; } if (indexPoint.y == (this->nCols - 1)) { ignore[0] = true; ignore[1] = true; ignore[2] = true; } vector<Coord3f> normals; p1 = Coord2i(indexPoint.x, indexPoint.y); for (int i = 0; i < 6; i++) { if (ignore[i]) continue; switch(i) { case 0: p1 = Coord2i(indexPoint.x, indexPoint.y); p2 = Coord2i(indexPoint.x+1, indexPoint.y+1); p3 = Coord2i(indexPoint.x+1, indexPoint.y); break; case 1: p1 = Coord2i(indexPoint.x, indexPoint.y); p2 = Coord2i(indexPoint.x, indexPoint.y+1); p3 = Coord2i(indexPoint.x+1, indexPoint.y+1); break; case 2: p1 = Coord2i(indexPoint.x-1, indexPoint.y); p2 = Coord2i(indexPoint.x, indexPoint.y+1); p3 = Coord2i(indexPoint.x, indexPoint.y); break; case 3: p1 = Coord2i(indexPoint.x-1, indexPoint.y-1); p2 = Coord2i(indexPoint.x-1, indexPoint.y); p3 = Coord2i(indexPoint.x, indexPoint.y); break; case 4: p1 = Coord2i(indexPoint.x-1, indexPoint.y-1); p2 = Coord2i(indexPoint.x, indexPoint.y); p3 = Coord2i(indexPoint.x, indexPoint.y-1); break; case 5: p1 = Coord2i(indexPoint.x, indexPoint.y-1); p2 = Coord2i(indexPoint.x, indexPoint.y); p3 = Coord2i(indexPoint.x+1, indexPoint.y); break; } if (i % 2 == 0) { // If i is even, then triangle is the upper half (if part of square) version normal = Coord3f(cS * (this->pointGrid[p1.x][p1.y] - this->pointGrid[p3.x][p3.y]), cS * cS, cS * (this->pointGrid[p3.x][p3.y] - this->pointGrid[p2.x][p2.y])); } else { // Otherwise, i is odd and the lower half normal = Coord3f(cS * (this->pointGrid[p2.x][p2.y] - this->pointGrid[p3.x][p3.y]), cS * cS, cS * (this->pointGrid[p1.x][p1.y] - this->pointGrid[p2.x][p2.y])); } normals.push_back(normal); } Coord3f sumNormal; for (vector<Coord3f>::iterator it = normals.begin(); it != normals.end(); ++it) { sumNormal = sumNormal + (*it); } return this->normalize(sumNormal); }