bool Robot::checkCollision(bool pointBased) { for (auto& bullet : Game::instance->bullets) { BBox other = bullet->getBBox(); if (!bullet->shotByPlayer) continue; if (other.Intersects(getBBox()) && !(pointBased && !other.Contains(getWorldPos()))) { bullet->flaggedForRemoval = true; if (--health <= 0) { if (!flaggedForRemoval) { Game::instance->kills++; } flaggedForRemoval = true; return true; } break; } } for (auto& robot : Game::instance->robots) { BBox other = robot->getBBox(); if (robot != this && other.Intersects(getBBox()) && !(pointBased && !other.Contains(getWorldPos()))) { return false; } } return CubeMesh::checkCollision(pointBased); }
DT_BBoxNode::DT_BBoxNode(int first, int last, int& node, DT_BBoxNode *free_nodes, const DT_CBox *boxes, DT_Index *indices, const DT_CBox& bbox) { assert(last - first >= 2); int axis = bbox.longestAxis(); MT_Scalar abscissa = bbox.getCenter()[axis]; int i = first, mid = last; while (i < mid) { if (boxes[indices[i]].getCenter()[axis] < abscissa) { ++i; } else { --mid; std::swap(indices[i], indices[mid]); } } if (mid == first || mid == last) { mid = (first + last) / 2; } m_lbox = getBBox(first, mid, boxes, indices); m_rbox = getBBox(mid, last, boxes, indices); m_flags = 0x0; if (mid - first == 1) { m_flags |= LLEAF; m_lchild = indices[first]; } else { m_lchild = node++; new(&free_nodes[m_lchild]) DT_BBoxNode(first, mid, node, free_nodes, boxes, indices, m_lbox); } if (last - mid == 1) { m_flags |= RLEAF; m_rchild = indices[mid]; } else { m_rchild = node++; new(&free_nodes[m_rchild]) DT_BBoxNode(mid, last, node, free_nodes, boxes, indices, m_rbox); } }
TRegion *TRegion::findRegion(const TRegion &r) const { if (areAlmostEqual(r.getBBox(), getBBox(), 1e-3)) return (TRegion *)this; if (!getBBox().contains(r.getBBox())) return 0; TRegion *ret; for (UINT i = 0; i < m_imp->m_includedRegionArray.size(); i++) if ((ret = m_imp->m_includedRegionArray[i]->findRegion(r)) != 0) return ret; return 0; }
void TextBase :: fontInfo(void) { if(!m_font) { return; } std::vector<gem::any>atoms; gem::any value; value = m_font->Ascender(); atoms.clear(); atoms.push_back(value); m_infoOut.send("ascender", atoms); value = m_font->Descender(); atoms.clear(); atoms.push_back(value); m_infoOut.send("descender", atoms); value = m_font->LineHeight(); atoms.clear(); atoms.push_back(value); m_infoOut.send("height", atoms); if(!m_theText.empty()) { getBBox(); } }
bool TRegion::Imp::isSubRegionOf(const TRegion::Imp &r) const { if (!r.getBBox().contains(getBBox())) return false; for (UINT i = 0; i < m_edge.size(); i++) { for (UINT j = 0; j < r.m_edge.size(); j++) { TEdge *e = r.m_edge[j]; TEdge *subE = m_edge[i]; if (subE->m_index == e->m_index && (subE->m_w0 < m_edge[i]->m_w1) == (e->m_w0 < e->m_w1)) { bool forward = (e->m_w0 < e->m_w1); if (forward && (subE->m_w0 >= e->m_w0 || areAlmostEqual(subE->m_w0, e->m_w0, 1e-3)) && (subE->m_w1 <= e->m_w1 || areAlmostEqual(subE->m_w1, e->m_w1, 1e-3))) return true; if (!forward && (subE->m_w0 <= e->m_w0 || areAlmostEqual(subE->m_w0, e->m_w0, 1e-3)) && (subE->m_w1 >= e->m_w1 || areAlmostEqual(subE->m_w1, e->m_w1, 1e-3))) return true; } } } return false; }
void TextBase :: fontInfo(void) { if(!m_font)return; std::vector<gem::any>atoms; gem::any value; value = m_font->Ascender(); atoms.clear(); atoms.push_back(value); m_infoOut.send("ascender", atoms); value = m_font->Descender(); atoms.clear(); atoms.push_back(value); m_infoOut.send("descender", atoms); value = m_font->LineHeight(); atoms.clear(); atoms.push_back(value); m_infoOut.send("height", atoms); if(!m_theText.empty()) { float x0, y0, z0, x1, y1, z1; x0=y0=z0=0; x1=y1=z1=0; getBBox(x0, y0, z0, x1, y1, z1); atoms.clear(); atoms.push_back(x0); atoms.push_back(y0); atoms.push_back(z0); atoms.push_back(x1); atoms.push_back(y1); atoms.push_back(z1); m_infoOut.send("bbox", atoms); } }
bool SVGSVGElement::checkEnclosure(SVGElement* element, const FloatRect& rect) { // TODO : take into account pointer-events? // FIXME: Why is element ignored?? // FIXME: Implement me (see bug 11274) return rect.contains(getBBox()); }
bool TRegion::Imp::contains(const TRegion::Imp &r) const { if (!getBBox().contains(r.getBBox())) return false; for (UINT i = 0; i < r.m_edge.size(); i++) for (UINT j = 0; j < m_edge.size(); j++) if (*r.m_edge[i] == *m_edge[j]) return false; // nessuno stroke in comune!! /* for ( i=0; i<r.m_edge.size(); i++) { TEdge *e = r.m_edge[i]; if (!contains(e->m_s->getThickPoint(e->m_w0))) return false; if (!contains(e->m_s->getThickPoint((e->m_w0+e->m_w1)/2.0))) return false; if (!contains(e->m_s->getThickPoint(e->m_w1))) return false; } */ TEdge *e = r.m_edge[0]; return contains(e->m_s->getThickPoint((e->m_w0 + e->m_w1) / 2.0)); }
void QRangeSlider::showValueTooltip() { QPoint pos; range_t myRange = range(); const QStyleRangeSlider* style = styleRangeSlider(); QRect bbox = getBBox(); pos.setX(style->sliderValueFromPosition( style->getGrooveX(bbox), style->getGrooveX(bbox) + style->getGrooveWidth(bbox), int(0.5*(myRange.first + myRange.second)), cutoffRange().second-cutoffRange().first)); QVariant first, second; if (unitConverter_) { first = unitConverter_->convertFromBase(myRange.first); second = unitConverter_->convertFromBase(myRange.second); } else { first = myRange.first; second = myRange.second; } QString text = QString("(%1, %2)").arg(first.toString()).arg(second.toString()); QToolTip::showText(mapToGlobal(pos), text, this, QRect()); }
bool SVGSVGElement::checkIntersection(SVGElement*, const FloatRect& rect) { // TODO : take into account pointer-events? // FIXME: Why is element ignored?? // FIXME: Implement me (see bug 11274) return rect.intersects(getBBox()); }
void KdCluster::create() { TreeProperty::BuildProfile bf; bf._maxLeafPrims = 128; bf._maxLevel = 8; KdTree::create(&bf); KdTreeNode * root = getRoot(); if(!root) return; m_groupGeometries = new GeometryArray *[numNoEmptyLeaves()]; m_nodeGroupInd.clear(); m_currentGroup = 0; const BoundingBox b = getBBox(); recursiveFindGroup(root, b); unsigned totalNGeo = 0; unsigned minN = 1<<20; unsigned maxN = 0; unsigned n; unsigned i=0; for(; i < m_currentGroup; i++) { n = m_groupGeometries[i]->numGeometries(); totalNGeo += n; if(n < minN) minN = n; if(n > maxN) maxN = n; } std::cout<<" total n geometries "<<totalNGeo<<"\n" <<" kd clustering to n groups "<<m_currentGroup<<"\n" <<" min/max geometry count in group "<<minN<<"/"<<maxN<<"\n"; }
void CPattern::optimalizeSize() { SRECT bb; getBBox(bb); if (bb.x0 <= bb.x1 && bb.y0 <= bb.y1) { int nLX = bb.x1 - bb.x0 + 1; int nLY = bb.y1 - bb.y0 + 1; std::unique_ptr<UC_PIXEL[]> nPat(new UC_PIXEL[nLX * nLY]); if (!nPat) { char s[200]; sprintf(s, "in Pattern Optimalization \n"); throw SMemAllocError(s); } for (int y = bb.y0; y <= bb.y1; y++) for (int x = bb.x0; x <= bb.x1; x++) { UC_PIXEL *pPat = m_pat.get() + y * m_lX + x; UC_PIXEL *pNPat = nPat.get() + (y - bb.y0) * nLX + x - bb.x0; pNPat->r = pPat->r; pNPat->g = pPat->g; pNPat->b = pPat->b; pNPat->m = pPat->m; } m_lX = nLX; m_lY = nLY; m_pat = std::move(nPat); } }
// get bbox transformed to top CBBox2D CQIllustratorShape:: getFlatBBox() const { CBBox2D bbox = getBBox(); if (! bbox.isSet()) return bbox; if (! parent_) return bbox; // if parent transform pby parent flat matric const CMatrix2D &m = parent_->getFlatMatrix(); CPoint2D p1 = m*bbox.getLL(); CPoint2D p2 = m*bbox.getLR(); CPoint2D p3 = m*bbox.getUL(); CPoint2D p4 = m*bbox.getUR(); CBBox2D bbox1(p1, p2); bbox1 += p3; bbox1 += p4; return bbox1; }
void EntityCreatorCreationInstance::scaleNode() { if (mModelMount) { mModelMount->rescale(hasBBox() ? &getBBox() : 0); } else { S_LOG_WARNING("Tried to scale node without there being a valid model mount."); } }
void ModelPreviewWorker::scaleNode() { if (mModelMount) { mModelMount->rescale(hasBBox() ? &getBBox() : 0); } else { S_LOG_WARNING("Tried to scale node without there being a valid model mount."); } }
bool TRegion::Imp::contains(const TStroke &s, bool mayIntersect) const { if (!getBBox().contains(s.getBBox())) return false; if (mayIntersect && thereAreintersections(s)) return false; return contains(s.getThickPoint(0.5)); }
bool KdCluster::intersectRay(const Ray * eyeRay) { if(!getRoot()) return false; float hitt0, hitt1; BoundingBox b = getBBox(); if(!b.intersect(*eyeRay, &hitt0, &hitt1)) return false; return recursiveIntersectRay(getRoot(), eyeRay, b); }
QRectF CQIllustratorShape:: getQRect() const { CBBox2D bbox = getBBox(); if (bbox.isSet()) return CQUtil::toQRect(bbox); else return QRectF(); }
bool KdIntersection::intersectBox(const BoundingBox & box) { KdTreeNode * root = getRoot(); if(!root) return false; BoundingBox b = getBBox(); m_testBox = box; return recursiveIntersectBox(root, b); }
/*! \reimp */ void QRangeSlider::paintEvent(QPaintEvent*) { QPainter p(this); QRect bbox = getBBox(); styleRangeSlider()->drawComplexControl(QStyle::CC_CustomBase, &styleOptionRangeSlider_, &p, this); }
bool BaseTransform::intersect(const Ray & ray) const { Matrix44F s = worldSpace(); s.inverse(); Vector3F a = ray.m_origin + ray.m_dir * ray.m_tmin; a = s.transform(a); Vector3F b = ray.m_origin + ray.m_dir * ray.m_tmax; b = s.transform(b); Ray objR(a, b); float hit0, hit1; return getBBox().intersect(objR, &hit0, &hit1); }
void CQIllustratorShape:: drawGaussian(CQIllustratorShapeDrawer *drawer) const { CQIllustratorFilterShapeDrawer drawer1(drawer, this); drawShape(&drawer1); const CBBox2D &bbox = getBBox(); //QTransform transform = drawer->getPainter()->worldTransform(); QTransform transform = drawer->getPainter()->transform(); QPointF p1 = transform.map(QPointF(bbox.getXMin(), bbox.getYMin())); QPointF p2 = transform.map(QPointF(bbox.getXMax(), bbox.getYMax())); int px1 = std::min(p1.x(), p2.x()) - 4; int py1 = std::min(p1.y(), p2.y()) - 4; int px2 = std::max(p1.x(), p2.x()) + 4; int py2 = std::max(p1.y(), p2.y()) + 4; //----- int w = px2 - px1 + 1; int h = py2 - py1 + 1; const QImage &qimage = drawer1.getImage().copy(px1, py1, w, h); QImage qimage1(w, h, QImage::Format_ARGB32); qimage1.fill(qRgba(0,0,0,0)); //------ double bx = 2.0; double by = 2.0; int nx = 0; int ny = 0; //------ CQImageGaussianBlur blur(qimage); blur.blur(qimage1, bx, by, nx, ny); //------ drawer->drawImage(px1, py1, qimage1); }
bool TRegion::selectFill(const TRectD &selArea, int styleId) { bool hitSomeRegions = false; if (selArea.contains(getBBox())) { hitSomeRegions = true; setStyle(styleId); } int regNum = m_imp->m_includedRegionArray.size(); for (int i = 0; i < regNum; i++) hitSomeRegions |= m_imp->m_includedRegionArray[i]->selectFill(selArea, styleId); return hitSomeRegions; }
void TRegion::Imp::computeScanlineIntersections(double y, vector<double> &intersections) const { TRectD bbox = getBBox(); if (y <= bbox.y0 || y >= bbox.y1) return; assert(intersections.empty()); UINT i, firstSide = 0; vector<int> sides; for (i = 0; i < m_edge.size(); i++) { TEdge *e = m_edge[i]; TStroke *s = e->m_s; if (s->getBBox().y0 > y || s->getBBox().y1 < y) continue; int chunkIndex0, chunkIndex1; double t0, t1; s->getChunkAndT(e->m_w0, chunkIndex0, t0); s->getChunkAndT(e->m_w1, chunkIndex1, t1); if (chunkIndex0 > chunkIndex1) { findIntersections(y, *s->getChunk(chunkIndex0), t0, 0, intersections, sides); for (int j = chunkIndex0 - 1; j > chunkIndex1; j--) findIntersections(y, *s->getChunk(j), 1, 0, intersections, sides); findIntersections(y, *s->getChunk(chunkIndex1), 1, t1, intersections, sides); } else if (chunkIndex0 < chunkIndex1) { findIntersections(y, *s->getChunk(chunkIndex0), t0, 1, intersections, sides); for (int j = chunkIndex0 + 1; j < chunkIndex1; j++) findIntersections(y, *s->getChunk(j), 0, 1, intersections, sides); findIntersections(y, *s->getChunk(chunkIndex1), 0, t1, intersections, sides); } else { findIntersections(y, *s->getChunk(chunkIndex0), t0, t1, intersections, sides); } } if (intersections.size() > 0 && intersections.front() == intersections.back()) { intersections.pop_back(); if (!sides.empty() && sides.front() == sides.back() && intersections.size() > 0) intersections.erase(intersections.begin()); } std::sort(intersections.begin(), intersections.end()); assert(intersections.size() % 2 == 0); }
bool KdIntersection::intersectTetrahedron(const Vector3F * tet) { KdTreeNode * root = getRoot(); if(!root) return false; m_testTetrahedron[0] = tet[0]; m_testTetrahedron[1] = tet[1]; m_testTetrahedron[2] = tet[2]; m_testTetrahedron[3] = tet[3]; m_testBox.reset(); m_testBox.expandBy(tet[0]); m_testBox.expandBy(tet[1]); m_testBox.expandBy(tet[2]); m_testBox.expandBy(tet[3]); BoundingBox b = getBBox(); return recursiveIntersectTetrahedron(root, b); }
/*! \reimp */ void QRangeSlider::mouseMoveEvent(QMouseEvent* ev) { if (tracking != QStyle::SC_None) { ev->accept(); if (cutoffRange().second == cutoffRange().first) return; const QStyleRangeSlider* style = styleRangeSlider(); QRect bbox = getBBox(); int x = ev->pos().x(); int min = style->getGrooveX(bbox); int max = min + style->getGrooveWidth(bbox); if (x > max) x = max; int val = style->sliderPositionFromValue( min, max, x, cutoffRange().second-cutoffRange().first); if (val < cutoffRange().first) val = cutoffRange().first; if (val > cutoffRange().second) val = cutoffRange().second; range_t newRange = range(); if (tracking == QStyle::SC_SliderHandle) { newRange.first = val; if (val > newRange.second) newRange.second = val; } else if(tracking == QStyleRangeSlider::SC_SliderHandle2) { newRange.second = val; if (val < newRange.first) newRange.first = val; } setRange(newRange); showValueTooltip(); } }
QUrl MapAdapterWMS::tileQuery(const int& x, const int& y, const int& controller_zoom) const { // Get the url's query details. QUrlQuery url_query(getBaseUrl()); // Calculate the number of coordinates per tile. const int coord_per_tile_x = 360.0 / projection::get().tilesX(controller_zoom); const int coord_per_tile_y = 180.0 / projection::get().tilesY(controller_zoom); // Set BBOX (x1,y1,x2,y2). url_query.removeQueryItem("BBOX"); url_query.addQueryItem("BBOX", getBBox(-180 + x * coord_per_tile_x, 90 - (y + 1) * coord_per_tile_y, (-180 + x * coord_per_tile_x) + coord_per_tile_x, (90 - (y + 1) * coord_per_tile_y) + coord_per_tile_y)); // Create a new url with the modified url query. QUrl modified_url(getBaseUrl()); modified_url.setQuery(url_query); // Return the modified url. return QUrl(modified_url); }
void MainWindow::on_pushButton_released() { QFile file("rule.file"); if(file.open(QIODevice::WriteOnly | QIODevice::Truncate)){ QTextStream out(&file); out << ui->textEdit->toPlainText(); out.flush(); file.close(); } Model new_m; material_map.clear(); readMtl("default.mtl", true); errors.clear(); parseFile("rule.file", new_m); //printf("Errors : %ld\n", errors.size()); if(errors.size() > 0){ new_m.faces.clear(); std::string all; for(size_t i = 0; i < errors.size(); i++){ all += errors[i]; all += "\n"; } QString str = QString::fromStdString(all); text->setText(str); err->show(); } BBox scope; getBBox(new_m, scope); translate(new_m, -(scope.max.x + scope.min.x)/2.0, -(scope.max.x + scope.min.x)/2.0, -(scope.max.x + scope.min.x)/2.0); model_size = std::max(std::max(scope.max.y - scope.min.y, scope.max.x - scope.min.x), scope.max.z - scope.min.z); //scale(new_m, 1.0/model_size, 1.0/model_size, 1.0/model_size); //scaleTextures(new_m); sortFacesByMaterial(new_m); m = new_m; update_model = true; }
int Sphere::intersectBBox(const BBox &box) const { return getBBox().intersectBBox(box); }
int main(int argc, char *argv[]) { logger.setLogLevel(Logging::Debug); struct args a; setArgs(a, argc, argv); GU_Detail gdp; bool binary = false; bool bbox = false; if( a.b ) binary = true; // convert all files in directory from hsff to geo or bgeo if (a.cd || a.c) { logger.debug("Found argument -cd or -c, trying to convert files in a directory."); std::vector<std::string> filesToConvert; if( a.cd ) { logger.debug("Found argument -cd trying to convert files in a directory."); std::string info("Directory: "); info += a.cdDir; logger.debug(info); if( binary ) logger.debug("Exporting binary bgeo files"); else logger.debug("Exporting ascii geo files"); //dirname.harden(argv[1]); // what does this mean, harden??? fs::path p(a.cdDir); getHsffFiles(p, filesToConvert, binary); }else{ logger.debug("Found argument -c trying to convert exactly one file."); //filename = UT_String(args.argp('c')); std::string info("Filename."); info += a.cFile; logger.debug(info); filesToConvert.push_back(a.cFile); } // export geo loop for( uint fId = 0; fId < filesToConvert.size(); fId++) { Hsff inFile(filesToConvert[fId]); if(!inFile.good) { logger.error(std::string("Error: problems reading file ") + filesToConvert[fId]); //cerr << "Error: problems reading file " << filesToConvert[fId] << "\n"; inFile.close(); continue; } logger.debug(std::string("Converting file ") + filesToConvert[fId]); //cout << "Converting " << filesToConvert[fId] << "\n"; inFile.doBinary = binary; unsigned int geoType = inFile.readGeoType(); switch(geoType) { case PARTICLE: //cout << "Detected particle file.\n"; createParticleGeo(inFile); break; case FLUID: //cout << "Detected fluid file.\n"; createFluidGeo(inFile); break; case MESH: //cout << "Detected mesh file.\n"; createMeshGeo(inFile); break; case CURVE: //cout << "Detected curve file.\n"; createCurveGeo(inFile); break; case NURBS: //cout << "Detected nurbs file.\n"; createNurbsGeo(inFile); break; } inFile.close(); } return 0; } // get bbox from 1st argument if (a.bbox) { std::string info("Getting BBox of "); info += a.bboxfile; logger.debug(info); if( !isValid(fs::path(a.bboxfile))) { logger.error("Could not read file."); return 1; } UT_BoundingBox bbox; getBBox(a.bboxfile, bbox); cout << "BBox: " << bbox.xmin() << " " << bbox.ymin() << " " << bbox.zmin() << " " << bbox.xmax() << " " << bbox.ymax() << " " << bbox.zmax() << "\n"; } if (a.ptc) { std::string info("Getting pointcloud of "); info += a.ptcfile; logger.debug(info); std::string outFile = pystring::replace(a.ptcfile, ".geo", ".hsffp"); // add a 'p' to show that it is a point cloud file from this tool if( pystring::endswith(a.ptcfile, "bgeo")) outFile = pystring::replace(a.ptcfile, ".bgeo", ".hsffp"); // add a 'p' to show that it is a point cloud file from this tool UT_BoundingBox bbox; readPtc(a.ptcfile, outFile, a.ptcdv, bbox); cout << "BBox: " << bbox.xmin() << " " << bbox.ymin() << " " << bbox.zmin() << " " << bbox.xmax() << " " << bbox.ymax() << " " << bbox.zmax() << "\n"; } //cout << "numargs: " << args.argc() << "\n"; // if (args.argc() == 3) //{ // UT_String dobin; // // dobin.harden(argv[2]); // if(dobin.isInteger()) // { // if( dobin.toInt() == 0) // binary = true; // else // binary = false; // } //} //if(binary) // cout << "Writing from source dir " << dirname << " as binary\n"; //else // cout << "Writing from source dir " << dirname << " as ascii\n"; return 0; }