本文整理汇总了C++中Box2D类的典型用法代码示例。如果您正苦于以下问题:C++ Box2D类的具体用法?C++ Box2D怎么用?C++ Box2D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Box2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CHECK_PARAMS
cell AMX_NATIVE_CALL Natives::CreateDynamicPolygon(AMX *amx, cell *params)
{
CHECK_PARAMS(7, "CreateDynamicPolygon");
if (core->getData()->getGlobalMaxItems(STREAMER_TYPE_AREA) == core->getData()->areas.size())
{
return 0;
}
if (static_cast<int>(params[4] >= 2 && static_cast<int>(params[4]) % 2))
{
Utility::logError("CreateDynamicPolygon: Number of points must be divisible by two");
return 0;
}
int areaID = Item::Area::identifier.get();
Item::SharedArea area(new Item::Area);
area->amx = amx;
area->areaID = areaID;
area->type = STREAMER_AREA_TYPE_POLYGON;
Utility::convertArrayToPolygon(amx, params[1], params[4], boost::get<Polygon2D>(area->position));
area->height = Eigen::Vector2f(amx_ctof(params[2]), amx_ctof(params[3]));
Box2D box = boost::geometry::return_envelope<Box2D>(boost::get<Polygon2D>(area->position));
area->size = static_cast<float>(boost::geometry::comparable_distance(box.min_corner(), box.max_corner()));
Utility::addToContainer(area->worlds, static_cast<int>(params[5]));
Utility::addToContainer(area->interiors, static_cast<int>(params[6]));
Utility::addToContainer(area->players, static_cast<int>(params[7]));
core->getGrid()->addArea(area);
core->getData()->areas.insert(std::make_pair(areaID, area));
return static_cast<cell>(areaID);
}
示例2: toString
string QuadtreeNode::toString() {
ostringstream stream;
Box2D *rect;
int size = 0;
if ( !objectVector || (size = (int)objectVector->size()) > 0 ) {
stream << "";
stream << "Obj.: ";
for (int i=0; i < size; i++) {
rect = (Box2D *)objectVector->at(i);
stream << rect->toString();
if ( i < size - 1 )
stream << ", ";
}
} else {
stream << "Empty";
}
return stream.str();
}
示例3: bulk
void LocalMultiBlockInfo2D::computePeriodicOverlaps (
SparseBlockStructure2D const& sparseBlock, plint blockId )
{
Box2D intersection; // Temporary variable.
std::vector<plint> neighbors; // Temporary variable.
SmartBulk2D bulk(sparseBlock, envelopeWidth, blockId);
for (plint dx=-1; dx<=+1; dx+=1) {
for (plint dy=-1; dy<=+1; dy+=1) {
if (dx!=0 || dy!=0) {
// The new block is shifted by the length of the full multi block in each space
// direction. Consequently, overlaps between the original multi block and the
// shifted new block are identified as periodic overlaps.
plint shiftX = dx*sparseBlock.getBoundingBox().getNx();
plint shiftY = dy*sparseBlock.getBoundingBox().getNy();
Box2D shiftedBulk(bulk.getBulk().shift(shiftX,shiftY));
Box2D shiftedEnvelope(bulk.computeEnvelope().shift(shiftX,shiftY));
// Speed optimization: perform following checks only if the shifted
// domain touches the bounding box.
Box2D dummyIntersection;
if (intersect(shiftedEnvelope, sparseBlock.getBoundingBox(), dummyIntersection)) {
neighbors.clear();
sparseBlock.findNeighbors(shiftedBulk, envelopeWidth, neighbors);
// Check overlap with each existing block in the neighborhood, including with the newly added one.
for (pluint iNeighbor=0; iNeighbor<neighbors.size(); ++iNeighbor) {
plint neighborId = neighbors[iNeighbor];
SmartBulk2D neighborBulk(sparseBlock, envelopeWidth, neighborId);
// Does the envelope of the shifted new block overlap with the bulk of a previous
// block? If yes, add an overlap, in which the previous block has the "original
// position", and the new block has the "overlap position".
if (intersect(neighborBulk.getBulk(), shiftedEnvelope, intersection)) {
PeriodicOverlap2D overlap (
Overlap2D(neighborId, blockId, intersection, shiftX, shiftY),
dx, dy );
periodicOverlaps.push_back(overlap);
periodicOverlapWithRemoteData.push_back(overlap);
}
// Does the bulk of the shifted new block overlap with the envelope of a previous
// block? If yes, add an overlap, in which the new block has the "original position",
// and the previous block has the "overlap position".
// If we are in the situation in which the newly added block is periodic with itself,
// this step must be skipped, because otherwise the overlap is counted twice.
if (!(neighborId==blockId) &&
intersect(shiftedBulk, neighborBulk.computeEnvelope(), intersection))
{
intersection = intersection.shift(-shiftX,-shiftY);
periodicOverlaps.push_back (
PeriodicOverlap2D (
Overlap2D(blockId, neighborId, intersection, -shiftX, -shiftY),
-dx, -dy ) );
}
}
}
}
}
}
}
示例4: saveFull
void saveFull( MultiBlock2D& multiBlock, FileName fName, IndexOrdering::OrderingT ordering )
{
global::profiler().start("io");
SparseBlockStructure2D blockStructure(multiBlock.getBoundingBox());
Box2D bbox = multiBlock.getBoundingBox();
if (ordering==IndexOrdering::forward) {
plint nBlocks = std::min(bbox.getNx(), (plint)global::mpi().getSize());
std::vector<std::pair<plint,plint> > ranges;
util::linearRepartition(bbox.x0, bbox.x1, nBlocks, ranges);
for (pluint iRange=0; iRange<ranges.size(); ++iRange) {
blockStructure.addBlock (
Box2D( ranges[iRange].first, ranges[iRange].second,
bbox.y0, bbox.y1 ),
iRange );
}
}
else if (ordering==IndexOrdering::backward) {
plint nBlocks = std::min(bbox.getNy(), (plint)global::mpi().getSize());
std::vector<std::pair<plint,plint> > ranges;
util::linearRepartition(bbox.y0, bbox.y1, nBlocks, ranges);
for (pluint iRange=0; iRange<ranges.size(); ++iRange) {
blockStructure.addBlock (
Box2D( bbox.x0, bbox.x1, ranges[iRange].first, ranges[iRange].second ),
iRange );
}
}
else {
// Sparse ordering not defined.
PLB_ASSERT( false );
}
plint envelopeWidth=1;
MultiBlockManagement2D adjacentMultiBlockManagement (
blockStructure, new OneToOneThreadAttribution, envelopeWidth );
MultiBlock2D* multiAdjacentBlock = multiBlock.clone(adjacentMultiBlockManagement);
std::vector<plint> offset;
std::vector<plint> myBlockIds;
std::vector<std::vector<char> > data;
bool dynamicContent = false;
dumpData(*multiAdjacentBlock, dynamicContent, offset, myBlockIds, data);
if (ordering==IndexOrdering::backward && myBlockIds.size()==1) {
PLB_ASSERT( data.size()==1 );
Box2D domain;
blockStructure.getBulk(myBlockIds[0], domain);
plint sizeOfCell = multiAdjacentBlock->sizeOfCell();
PLB_ASSERT( domain.nCells()*sizeOfCell == (plint)data[0].size() );
transposeToBackward( sizeOfCell, domain, data[0] );
}
plint totalSize = offset[offset.size()-1];
writeOneBlockXmlSpec(*multiAdjacentBlock, fName, totalSize, ordering);
writeRawData(fName, myBlockIds, offset, data);
delete multiAdjacentBlock;
global::profiler().stop("io");
}
示例5: ERROR2
Box2D<qint32> GeoReference::coord2Pixel(const Box2D<double> &box) const
{
if ( !box.isValid()) {
ERROR2(ERR_INVALID_PROPERTY_FOR_2,"size", "box");
return Box2D<qint32>();
}
Pixel p1 = coord2Pixel(box.min_corner());
Pixel p2 = coord2Pixel(box.max_corner());
return Box2D<qint32>(p1,p2);
}
示例6: addDensity
void MCnucl::addDensity(Nucleus* nucl, double** dens)
{
vector<Particle*> participant = nucl->getParticipants();
for(unsigned int ipart=0; ipart<participant.size(); ipart++)
{
Particle* part = participant[ipart];
Box2D partBox = part->getBoundingBox();
double x = part->getX();
double y = part->getY();
int x_idx_left = (int)((partBox.getXL() - Xmin)/dx);
int x_idx_right = (int)((partBox.getXR() - Xmin)/dx);
int y_idx_left = (int)((partBox.getYL() - Ymin)/dy);
int y_idx_right = (int)((partBox.getYR() - Ymin)/dy);
if(x_idx_left < 0 || y_idx_left < 0 || x_idx_left > Maxx || y_idx_left > Maxy)
{
cerr << "Wounded nucleon extends out of grid bounds " << "("<< part->getX() << "," << part->getY() << ")" << endl;
}
x_idx_left = max(0, x_idx_left);
x_idx_right = min(Maxx, x_idx_right);
y_idx_left = max(0, y_idx_left);
y_idx_right = min(Maxy, y_idx_right);
for(int ir = x_idx_left; ir < x_idx_right; ir++)
{
double xg = Xmin + ir*dx;
for(int jr = y_idx_left; jr < y_idx_right; jr++)
{
double yg = Ymin + jr*dy;
double dc = (x-xg)*(x-xg) + (y-yg)*(y-yg);
if (shape_of_entropy==1) // "Checker" nucleons:
{
if(dc>dsq)
continue;
double areai = 10.0/siginNN;
dens[ir][jr] += areai*participant[ipart]->getFluctfactor();
}
else if (shape_of_entropy>=2 && shape_of_entropy<=9) // Gaussian nucleons:
{
double density;
if (shape_of_entropy == 3)
{
density = participant[ipart]->getFluctuatedDensity(xg,yg);
}
else
{
density = participant[ipart]->getSmoothDensity(xg,yg);
}
dens[ir][jr] += density;
}
}
}
}
}
示例7:
bool Geometric2DCollection::Collides(const Box2D& box) const
{
for(size_t i=0;i<aabbs.size();i++)
if(box.intersects(aabbs[i])) return true;
for(size_t i=0;i<boxes.size();i++)
if(box.intersects(boxes[i])) return true;
for(size_t i=0;i<circles.size();i++)
if(box.intersects(circles[i])) return true;
for(size_t i=0;i<triangles.size();i++)
if(box.intersects(triangles[i])) return true;
return false;
}
示例8: setSize
bool GridCoverageGenerator::setSize(const Box2D<qint32>& box, const Box2D<double> bounds) {
Size szOut(box.width(),box.height());
if ( szOut != size()) {
CornersGeoReference *grf = new CornersGeoReference();
grf->setName("subset_" + name());
grf->setCoordinateSystem(coordinateSystem());
grf->setEnvelope(bounds);
IGeoReference georef;
georef.set(static_cast<GeoReference *>(grf));
georef->compute(szOut.toQSize());
setGeoreference(georef);
}
return true;
}
示例9: computePeriodicOverlaps
void LocalMultiBlockInfo2D::computeAllPeriodicOverlaps (
SparseBlockStructure2D const& sparseBlock )
{
for (pluint iBlock=0; iBlock<myBlocks.size(); ++iBlock) {
plint blockId = myBlocks[iBlock];
Box2D bulk;
sparseBlock.getBulk(blockId, bulk);
// Speed optimization: execute the test for periodicity
// only for bulk-domains which touch the bounding box.
if (!contained (
bulk.enlarge(1), sparseBlock.getBoundingBox() ) )
{
computePeriodicOverlaps(sparseBlock, blockId);
}
}
}
示例10: transposeToBackward
void transposeToBackward(plint sizeOfCell, Box2D const& domain, std::vector<char>& data) {
plint nx = domain.getNx();
plint ny = domain.getNy();
std::vector<char> transp(data.size());
for (plint iX=0; iX<nx; ++iX) {
for (plint iY=0; iY<ny; ++iY) {
plint iForward = sizeOfCell*(iY + ny*iX);
plint iBackward = sizeOfCell*(iX + nx*iY);
for (plint iByte=0; iByte<sizeOfCell; ++iByte) {
transp[iBackward+iByte] = data[iForward+iByte];
}
}
}
transp.swap(data);
}
示例11: ObstacleIndex
bool Geometric2DCollection::Collides(const Box2D& box,int obstacle) const
{
Type type=ObstacleType(obstacle);
int index = ObstacleIndex(obstacle);
switch(type) {
case AABB:
return box.intersects(aabbs[index]);
case Triangle:
return box.intersects(triangles[index]);
case Box:
return box.intersects(boxes[index]);
case Circle:
return box.intersects(circles[index]);
}
abort();
return false;
}
示例12: RenderLabel
void LocationView::RenderLabel()
{
if(!GetLabelBindToChart() && m_label->IsVisible() && !App::Inst().GetMouseDragging())
{
// get screen coordinates for location
Point3D winPos = App::Inst().GetMapController()->ProjectToScreen(GetPosition());
Box2D bb = m_label->GetBoundingBox();
float size = m_size * App::Inst().GetResolutionFactor();
// compensate for perspective projection
float angle = sin(App::Inst().GetViewport()->GetCamera()->GetPitch()*DEG_TO_RAD);
float perspectiveSize = size * angle;
float perspectiveTextHeight = bb.Height()*angle;
// calculate screen position of label
uint offset = 2 * App::Inst().GetResolutionFactor();
if(m_label->GetLabelPosition() == _T("Right"))
m_label->SetScreenPosition(Point3D(winPos.x+size+offset, winPos.y-bb.Height()/3, LABEL_LAYER));
else if(m_label->GetLabelPosition() == _T("Left"))
m_label->SetScreenPosition(Point3D(winPos.x-bb.Width()-size-offset, winPos.y-bb.Height()/3, LABEL_LAYER));
else if(m_label->GetLabelPosition() == _T("Top"))
m_label->SetScreenPosition(Point3D(winPos.x-bb.Width()/2, winPos.y+perspectiveSize+offset, LABEL_LAYER));
else if(m_label->GetLabelPosition() == _T("Bottom"))
m_label->SetScreenPosition(Point3D(winPos.x-bb.Width()/2, winPos.y-perspectiveTextHeight-perspectiveSize, LABEL_LAYER));
m_label->Render();
}
}
示例13:
plint Parallelizer2D::computeCost(std::vector<std::vector<Box2D> > const& originalBlocks, Box2D box){
plint totalCost = 0;
plint numLevels = originalBlocks.size();
for (plint iLevel=(plint)originalBlocks.size()-1; iLevel>=0; --iLevel){
// convert the box to the current level
Box2D levelBox = global::getDefaultMultiScaleManager().scaleBox(box,iLevel-(numLevels-1));
for (pluint iComp=0; iComp<originalBlocks[iLevel].size(); ++iComp){
Box2D currentBox;
if (intersect(originalBlocks[iLevel][iComp], levelBox, currentBox)){
plint volume = currentBox.getNx()*currentBox.getNy();
totalCost += (plint) util::twoToThePower(iLevel) * volume;
}
}
}
return totalCost;
}
示例14: getCellID
CellID Grid::getCellID(const Eigen::Vector2f &position, bool insert)
{
static Box2D box;
box.min_corner()[0] = std::floor((position[0] / cellSize)) * cellSize;
box.min_corner()[1] = std::floor((position[1] / cellSize)) * cellSize;
box.max_corner()[0] = box.min_corner()[0] + cellSize;
box.max_corner()[1] = box.min_corner()[1] + cellSize;
Eigen::Vector2f centroid = boost::geometry::return_centroid<Eigen::Vector2f>(box);
CellID cellID = std::make_pair(static_cast<int>(centroid[0]), static_cast<int>(centroid[1]));
if (insert)
{
boost::unordered_map<CellID, SharedCell>::iterator c = cells.find(cellID);
if (c == cells.end())
{
SharedCell cell(new Cell(cellID));
cells[cellID] = cell;
}
}
return cellID;
}
示例15: getHotSpots
Box2D MCnucl::getHotSpots(vector<Box2D> & hotSpots)
{
hotSpots.clear();
vector<Particle*> participants = proj->getParticipants();
for(int i = 0; i < participants.size(); i++)
hotSpots.push_back(participants[i]->getBoundingBox());
participants = targ->getParticipants();
for(int i = 0; i < participants.size(); i++)
hotSpots.push_back(participants[i]->getBoundingBox());
for(int i = 0; i < binaryCollision.size(); i++)
hotSpots.push_back(binaryCollision[i]->getBoundingBox());
Box2D hotSpot = hotSpots[0];
for(int i = 1; i < hotSpots.size(); i++)
hotSpot.overUnion(hotSpots[i]);
return hotSpot;
}