void FlyingModeManipulator::dragMiddle( const Vector2i& to, const Vector2i& from ) { Viewport& viewport = _window.getViewPort(); const float x = ( to.x() - from.x( )) * _window.getMotionSpeed(); const float y = ( to.y() - from.y( )) * _window.getMotionSpeed(); viewport.translate( Vector3f( x, y , 0.f ), true ); }
void FlyingModeManipulator::dragLeft( const Vector2i& to, const Vector2i& from ) { const float du = ( to.x() - from.x( )) * _window.getRotateSpeed(); const float dv = ( to.y() - from.y( )) * _window.getRotateSpeed(); Viewport& viewport = _window.getViewPort(); viewport.rotate( viewport.getPosition(), du, dv, true ); }
void FlyingModeManipulator::dragRight( const Vector2i& to, const Vector2i& from ) { const float fwd = -( to.y() - from.y( )) * _window.getMotionSpeed(); Viewport& viewport = _window.getViewPort(); const Vector3f dir( 0.f, 0.f , 1.f ); viewport.translate( dir*fwd, false ); }
bool Font::FontTexture::findEmpty(const Vector2i& size, Vector2i& cursor_out) { if(size.x() >= textureSize.x() || size.y() >= textureSize.y()) return false; if(writePos.x() + size.x() >= textureSize.x() && writePos.y() + rowHeight + size.y() + 1 < textureSize.y()) { // row full, but it should fit on the next row // move cursor to next row writePos = Vector2i(0, writePos.y() + rowHeight + 1); // leave 1px of space between glyphs rowHeight = 0; } if(writePos.x() + size.x() >= textureSize.x() || writePos.y() + size.y() >= textureSize.y()) { // nope, still won't fit return false; } cursor_out = writePos; writePos[0] += size.x() + 1; // leave 1px of space between glyphs if(size.y() > rowHeight) rowHeight = size.y(); return true; }
void KisColorSelectorRing::paintCache() { QImage cache(m_cachedSize, m_cachedSize, QImage::Format_ARGB32_Premultiplied); Vector2i center(cache.width()/2., cache.height()/2.); for(int x=0; x<cache.width(); x++) { for(int y=0; y<cache.height(); y++) { Vector2i currentPoint((float)x, (float)y); Vector2i relativeVector = currentPoint-center; qreal currentRadius = relativeVector.squaredNorm(); currentRadius=sqrt(currentRadius); if(currentRadius < outerRadius()+1 && currentRadius > innerRadius()-1) { float angle = std::atan2((float)relativeVector.y(), (float)relativeVector.x())+((float)M_PI); angle/=2*((float)M_PI); angle*=359.f; if(currentRadius < outerRadius() && currentRadius > innerRadius()) { cache.setPixel(x, y, m_cachedColors.at(angle)); } else { // draw antialiased border qreal coef=1.; if(currentRadius > outerRadius()) { // outer border coef-=currentRadius; coef+=outerRadius(); } else { // inner border coef+=currentRadius; coef-=innerRadius(); } coef=qBound(qreal(0.), coef, qreal(1.)); int red=qRed(m_cachedColors.at(angle)); int green=qGreen(m_cachedColors.at(angle)); int blue=qBlue(m_cachedColors.at(angle)); // the format is premultiplied, so we have to take care of that QRgb color = qRgba(red*coef, green*coef, blue*coef, 255*coef); cache.setPixel(x, y, color); } } else { cache.setPixel(x, y, qRgba(0,0,0,0)); } } } m_pixelCache = cache; }
Vector2i Window::preferredSize(NVGcontext *ctx) const { Vector2i result = Widget::preferredSize(ctx); nvgFontSize(ctx, 18.0f); nvgFontFace(ctx, "sans-bold"); float bounds[4]; nvgTextBounds(ctx, 0, 0, mTitle.c_str(), nullptr, bounds); return result.cwiseMax(Vector2i( bounds[2]-bounds[0] + 20, bounds[3]-bounds[1] )); }
void AbstractTexture::storageImplementationDefault(GLenum target, GLsizei levels, AbstractTexture::InternalFormat internalFormat, const Vector2i& size) { bindInternal(); /** @todo Re-enable when extension wrangler is available for ES2 */ #ifndef MAGNUM_TARGET_GLES2 glTexStorage2D(target, levels, GLenum(internalFormat), size.x(), size.y()); #else //glTexStorage2DEXT(target, levels, GLenum(internalFormat), size.x(), size.y()); static_cast<void>(target); static_cast<void>(levels); static_cast<void>(internalFormat); static_cast<void>(size); #endif }
void GridManager::LinkToMyself(Vector2i p, sep::Axis mirror_axis) { Cell* cell = grid_->GetInitCell(p)->m_pCell; int coord = mirror_axis == sep::X ? p.x() : p.y(); if (coord < 2) { if (cell->m_pPrev[mirror_axis] != nullptr) throw("Next is already not emty"); cell->m_pPrev[mirror_axis] = cell; // cell->m_vNext[mirror_axis][0] } else { if (cell->m_pNext[mirror_axis] != nullptr) throw("Next is already not emty"); cell->m_pNext[mirror_axis] = cell; // cell->m_vPrev[mirror_axis][0] } }
template<UnsignedInt dimensions, class T> typename DimensionTraits<dimensions, T>::MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2<T>& projectionScale, const Vector2i& viewport) { /* Don't divide by zero / don't preserve anything */ if(projectionScale.x() == 0 || projectionScale.y() == 0 || viewport.x() == 0 || viewport.y() == 0 || aspectRatioPolicy == AspectRatioPolicy::NotPreserved) return {}; Math::Vector2<T> relativeAspectRatio = Math::Vector2<T>(viewport)*projectionScale; /* Extend on larger side = scale larger side down Clip on smaller side = scale smaller side up */ return Camera<dimensions, T>::aspectRatioScale( (relativeAspectRatio.x() > relativeAspectRatio.y()) == (aspectRatioPolicy == AspectRatioPolicy::Extend) ? Vector2(relativeAspectRatio.y()/relativeAspectRatio.x(), T(1.0)) : Vector2(T(1.0), relativeAspectRatio.x()/relativeAspectRatio.y())); }
template<UnsignedInt dimensions, class T> MatrixTypeFor<dimensions, T> aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2<T>& projectionScale, const Vector2i& viewport) { /* Don't divide by zero / don't preserve anything */ if(projectionScale.x() == 0 || projectionScale.y() == 0 || viewport.x() == 0 || viewport.y() == 0 || aspectRatioPolicy == AspectRatioPolicy::NotPreserved) return {}; CORRADE_INTERNAL_ASSERT((projectionScale > Math::Vector2<T>(0)).all() && (viewport > Vector2i(0)).all()); Math::Vector2<T> relativeAspectRatio = Math::Vector2<T>(viewport)*projectionScale; /* Extend on larger side = scale larger side down Clip on smaller side = scale smaller side up */ return MatrixTypeFor<dimensions, T>::scaling(Math::Vector<dimensions, T>::pad( (relativeAspectRatio.x() > relativeAspectRatio.y()) == (aspectRatioPolicy == AspectRatioPolicy::Extend) ? Math::Vector2<T>(relativeAspectRatio.y()/relativeAspectRatio.x(), T(1)) : Math::Vector2<T>(T(1), relativeAspectRatio.x()/relativeAspectRatio.y()), T(1))); }
Vector2i CubeMapTexture::getImageSizeImplementationDefault(const Int level) { Vector2i size; bindInternal(); glGetTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, GL_TEXTURE_WIDTH, &size.x()); glGetTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, GL_TEXTURE_HEIGHT, &size.y()); return size; }
Vector2i CubeMapTexture::getImageSizeImplementationDSAEXT(const Int level) { _created = true; Vector2i size; glGetTextureLevelParameterivEXT(_id, GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, GL_TEXTURE_WIDTH, &size.x()); glGetTextureLevelParameterivEXT(_id, GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, GL_TEXTURE_HEIGHT, &size.y()); return size; }
void Application::toggleFullScreen () { if (fullscreen) { #ifdef _WIN32 SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE); SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_FRAMECHANGED | SWP_SHOWWINDOW); // ShowWindow(hWnd, SW_SHOWNORMAL); #endif } else { #ifdef _WIN32 SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP | WS_VISIBLE); SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_FRAMECHANGED | SWP_SHOWWINDOW); // ShowWindow(hWnd, SW_SHOWMAXIMIZED); #endif } fullscreen = !fullscreen; // Set the size. #ifdef _WIN32 RECT rect; GetClientRect(hWnd, &rect); size.set(rect.right, rect.bottom); // left and top are always 0. #endif screenToNDC = Transform::screenToNDC<float>(size); if (widget != 0) { widget->setBounds(Box2i::minSize(Vector2i::zero(), size)); } }
LRESULT WINAPI wndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CREATE: ::hWnd = hWnd; break; case WM_CLOSE: onClose(); break; case WM_SIZE: { int newWidth = LOWORD(lParam); int newHeight = HIWORD(lParam); size.set(newWidth, newHeight); screenToNDC = Transform::screenToNDC<float>(size); if (widget != 0) { widget->setBounds(Box2i::minSize(Vector2i::zero(), size)); } } break; case WM_SYSKEYDOWN: case WM_KEYDOWN: if (wParam == VK_RETURN && (lParam & 0xffff) == 1 && GetKeyState(VK_MENU) < 0) // alt-enter { Application::toggleFullScreen(); } break; default: return DefWindowProc(hWnd, msg, wParam, lParam); } return 0; }
void GridManager::GridGeometryToInitialCells() { if (!boxes_stack_.size()) throw("no grid boxes"); // determine grid size Vector2i vMin(boxes_stack_[0]->p), vMax; std::for_each(boxes_stack_.begin(), boxes_stack_.end(), [&](GridBox* box) { if (box->p.x() < vMin.x()) vMin.x() = box->p.x(); if (box->p.y() < vMin.y()) vMin.y() = box->p.y(); if (box->p.x() + box->size.x() > vMax.x()) vMax.x() = box->p.x() + box->size.x(); if (box->p.y() + box->size.y() > vMax.y()) vMax.y() = box->p.y() + box->size.y(); }); Vector2i size = vMax - vMin + Vector2i(2, 2); // size += 2 for fake cells Config::vGridSize = Vector3i(size.x(), size.y(), 1); vMin -= Vector2i(1, 1); // min_p -= 1 for fake cells grid_->AllocateInitData(); std::for_each(boxes_stack_.begin(), boxes_stack_.end(), [&](GridBox* box) { for (int x = 0; x < box->size.x(); x++) { for (int y = 0; y < box->size.y(); y++) { Vector2i tmp_pos = box->p + Vector2i(x, y) - vMin; InitCellData* init_cell = grid_->GetInitCell(tmp_pos); init_cell->m_eType = sep::NORMAL_CELL; } } for (int x = -1; x < box->size.x() + 1; x++) { for (int y = -1; y < box->size.y() + 1; y++) { Vector2i tmp_pos = box->p + Vector2i(x, y) - vMin; InitCellData* init_cell = grid_->GetInitCell(tmp_pos); GasesConfigsMap& init_conds = init_cell->m_mInitConds; for (int gas = 0; gas < Config::iGasesNumber; gas++) { init_conds[gas] = box->def_config; } Vector2i size_with_fakes(box->size); size_with_fakes += Vector2i(2, 2); box->config(x + 1, y + 1, init_conds, size_with_fakes, box->p); } } }); }
Eigen::Vector3f unproject(const Eigen::Vector3f &win, const Eigen::Matrix4f &model, const Eigen::Matrix4f &proj, const Vector2i &viewportSize) { Eigen::Matrix4f Inverse = (proj * model).inverse(); Eigen::Vector4f tmp; tmp << win, 1; tmp(0) = tmp(0) / viewportSize.x(); tmp(1) = tmp(1) / viewportSize.y(); tmp = tmp.array() * 2.0f - 1.0f; Eigen::Vector4f obj = Inverse * tmp; obj /= obj(3); return obj.head(3); }
Matrix3f NNUtilities::calcInverseTransformation(const Vector2i& center, const Vector2i& inSize, const Vector2i& outSize, const Angle rotation) { const Vector2i upperLeft = (center.array() - inSize.array() / 2).matrix(); const Vector2f transformationFactor = (inSize.cast<float>().array() / outSize.cast<float>().array()).matrix(); //float sin = std::sin(rotation); //float cos = std::cos(rotation); Matrix3f inverseTransformation; //TODO check rotation inverseTransformation(0, 0) = transformationFactor.x();// *cos; inverseTransformation(0, 1) = 0;// transformationFactor.x() * (-sin); inverseTransformation(1, 0) = 0;// transformationFactor.y() * sin; inverseTransformation(1, 1) = transformationFactor.y();// *cos; inverseTransformation(0, 2) = upperLeft.x();// +outSize.x() * (1 - cos + sin) / 2 * transformationFactor.x(); inverseTransformation(1, 2) = upperLeft.y();// +outSize.y() * (1 - sin - cos) / 2 * transformationFactor.y(); return inverseTransformation; }
void CompoundUpdateOutputVisitor::_generateTiles(TileQueue* queue, Compound* compound) { const Vector2i& tileSize = queue->getTileSize(); const PixelViewport& pvp = compound->getInheritPixelViewport(); if (!pvp.hasArea()) return; const Vector2i dim(pvp.w / tileSize.x() + ((pvp.w % tileSize.x()) ? 1 : 0), pvp.h / tileSize.y() + ((pvp.h % tileSize.y()) ? 1 : 0)); std::vector<Vector2i> tiles; tiles.reserve(dim.x() * dim.y()); tiles::generateZigzag(tiles, dim); _addTilesToQueue(queue, compound, tiles); }
bool Slider::mouseDragEvent(const Vector2i &p, const Vector2i & /* rel */, int /* button */, int /* modifiers */) { if (!mEnabled) return false; mValue = std::min(std::max((p.x() - mPos.x()) / (float) mSize.x(), (float) 0.0f), (float) 1.0f); if (mCallback) mCallback(mValue); return true; }
Layout LayoutStack::PutSpace(Vector2i size) { auto& b = stack.back(); Layout l = b.getNext(b.grow); if (l.fill == Dir::Down || l.fill == Dir::Up) { l.across = size.x(); l.maxFill = size.y(); } else { l.across = size.y(); l.maxFill = size.x(); } b.putNext(l); return l; }
Eigen::Vector3f project(const Eigen::Vector3f &obj, const Eigen::Matrix4f &model, const Eigen::Matrix4f &proj, const Vector2i &viewportSize) { Eigen::Vector4f tmp; tmp << obj, 1; tmp = model * tmp; tmp = proj * tmp; tmp = tmp.array() / tmp(3); tmp = tmp.array() * 0.5f + 0.5f; tmp(0) = tmp(0) * viewportSize.x(); tmp(1) = tmp(1) * viewportSize.y(); return tmp.head(3); }
bool Window::mouseButtonEvent(const Vector2i &p, int button, bool down, int modifiers) { if (Widget::mouseButtonEvent(p, button, down, modifiers)) return true; if (button == GLFW_MOUSE_BUTTON_1) { mDrag = down && (p.y() - mPos.y()) < mTheme->mWindowHeaderHeight; return true; } return false; }
bool ShaderProgram::setUniformValue(const std::string& name, const Vector2i& v) { GLint location = static_cast<GLint>(findUniform(name)); if (location == -1) { m_error = "Could not set uniform " + name + ". No such uniform."; return false; } glUniform2iv(location, 1, v.data()); return true; }
void AutomaticCameraCalibratorHandlerInsertion::deliverPoint(const Vector2i& point, bool upper, bool deletionRequired) { if(!deletionRequired) { std::stringstream line1; line1 << "set module:AutomaticCameraCalibrator:insertionCurrentCamera " << (upper ? "upper;" : "lower;"); robotConsole->handleConsole(line1.str()); std::stringstream line2; line2 << "set module:AutomaticCameraCalibrator:insertionPoint x = "; line2 << point.x(); line2 << "; y = "; line2 << point.y(); line2 << ";"; robotConsole->handleConsole(line2.str()); std::stringstream line3; line3 << "dr module:AutomaticCameraCalibrator:insertPoint"; robotConsole->handleConsole(line3.str()); } }
bool Slider::mouseButtonEvent(const Vector2i &p, int /* button */, bool down, int /* modifiers */) { if (!mEnabled) return false; mValue = std::min(std::max((p.x() - mPos.x()) / (float) mSize.x(), (float) 0.0f), (float) 1.0f); if (mCallback) mCallback(mValue); if (mFinalCallback && !down) mFinalCallback(mValue); return true; }
void NNUtilities::getInterpolatedImageSection(const Vector2i& center, const Vector2i& inSize, const Vector2i& outSize, const GrayscaledImage& src, OutType* output, const Angle rotation) { Matrix3f inverseTransformation = calcInverseTransformation(center,inSize,outSize, rotation); if (std::is_same<OutType, float>::value) ImageTransform::transform(src, (float*)output, outSize.x(), outSize.y(), inverseTransformation, Vector2f(0.f, 0.f), 128.f); else { MatrixXf dest(outSize.x(), outSize.y()); ImageTransform::transform(src, dest.data(), outSize.x(), outSize.y(), inverseTransformation, Vector2f(0.f, 0.f), 128.f); Eigen::Matrix<OutType, Eigen::Dynamic, Eigen::Dynamic> dest_ = dest.cast<OutType>(); memcpy(output, dest_.data(), outSize.x()* outSize.y() * sizeof(OutType)); } }
void MotionBlurCamera::setViewport(const Vector2i& size) { SceneGraph::Camera3D::setViewport(size); /* Initialize previous frames with black color */ std::size_t textureSize = size.product()*framebuffer.pixelSize(); Containers::Array<UnsignedByte> texture{Containers::ValueInit, textureSize}; framebuffer.setData(PixelFormat::RGB8Unorm, size, texture, GL::BufferUsage::DynamicDraw); for(Int i = 0; i != FrameCount; ++i) frames[i]->setImage(0, GL::TextureFormat::RGB8, framebuffer); }
bool VScrollPanel::mouseDragEvent (const Vector2i &, const Vector2i & rel, int, int) { if (mChildren.empty()) return false; float scrollh = height() * std::min (1.0f, height() / (float)mChildPreferredHeight); mScroll = std::max ((float) 0.0f, std::min ((float) 1.0f, mScroll + rel.y() / (float) (mSize.y() - 8 - scrollh))); return true; }
void AutomaticCameraCalibrator::insertSample(Vector2i point, CameraInfo::Camera camera) { if(insertionOnCamera != theCameraInfo.camera) return; Sample sample; if(!Transformation::imageToRobot(point.x(), point.y(), theCameraMatrix, theCameraInfo, sample.pointOnField)) { OUTPUT_TEXT("MEEEK! Point not on field!" << (theCameraInfo.camera == CameraInfo::upper ? " Upper " : " Lower ")); return; } sample.pointInImage = point; sample.torsoMatrix = theTorsoMatrix; sample.headYaw = theJointAngles.angles[Joints::headYaw]; sample.headPitch = theJointAngles.angles[Joints::headPitch]; sample.cameraInfo = theCameraInfo; samples.push_back(sample); lastInsertedSample = sample; lastActionWasInsertion = true; alreadyRevertedInsertion = false; insertionValueExistant = false; }
Layout Layout::Top(AlignedBox2i box, Dir dir) { Vector2i size = box.sizes(); switch (dir) { case Dir::Right: return{ dir, Dir::Up, 0, size.x(), size.y(), box.corner(AlignedBox2i::BottomLeft) }; case Dir::Left: return{ dir, Dir::Up, 0, size.x(), size.y(), box.corner(AlignedBox2i::BottomRight) }; case Dir::Down: return{ dir, Dir::Right, 0, size.y(), size.x(), box.corner(AlignedBox2i::TopLeft) }; case Dir::Up: return{ dir, Dir::Right, 0, size.y(), size.x(), box.corner(AlignedBox2i::BottomLeft) }; default: assert(false && "Layout broken"); return{}; } }