// sets direction void Turret::lookAt(const float3 &pos, bool at_once) { //TODO: rounding float3 center = boundingBox().center(); float2 dir(pos.x - center.x, pos.z - center.z); float len = length(dir); if(len < constant::epsilon) return; dir = dir / len; m_target_angle = vectorToAngle(dir); if(at_once) setDirAngle(m_target_angle); }
void JvSprite::updatePosToJvGame() { CCRect boundingrect = boundingBox(); float cocospointX = (float)boundingrect.getMinX(); float cocospointY = (float)boundingrect.getMaxY(); JvPoint cocospoint(cocospointX,cocospointY); JvPoint jvgamePoint = JvU::cocos2dPoint_to_JvGamePoint(cocospoint,JvG::stateP->getStateLayer()->getContentSize().height); mJvObject->x = jvgamePoint.x; mJvObject->y = jvgamePoint.y; mJvObject->width = boundingrect.size.width; mJvObject->height = boundingrect.size.height; }
MonsterDisplay::MonsterDisplay(int i, int x, int y, float r) : i_(i), CCSprite(), Display(), p_(nullptr) { initWithFile("Test_zone.png"); setPosition(ccp(x,y)); setRotation(r); CCSize size = boundingBox().size; label_ = CCLabelTTF::create("empty", "Thonburi", 32 ); label_->setPosition(ccp(size.width/2, size.height/2)); //addChild(label_); }
bool CCtrlPage::isTouchInside( cocos2d::CCTouch * touch ) { CCNode* pParent = this->getParent(); if (NULL == pParent) { return false; } CHECKF(touch); CCPoint touchLocation = touch->getLocation(); // Get the touch position touchLocation = pParent->convertToNodeSpace(touchLocation); CCRect bBox=boundingBox(); return bBox.containsPoint(touchLocation); }
bool VEScrollView::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { CCPoint localPoint = (CCPoint)pTouch->getLocation(); CCRect box = boundingBox(); if(box.containsPoint(localPoint)) { m_fTouchOffset = 0; m_fIntensity = 0.f; m_bTouching=true; makeScrollBar(); return false; } return true; }
void ItemFireString::collision() { if (_mario->_dead) return; // »ñÈ¡fireStringÏ߶Πstruct Line { CCPoint pt1; CCPoint pt2; } lineFireString; CCRect rcItem = boundingBox(); int angle = getRotation(); angle %= 360; if (angle > 270) { lineFireString.pt1 = ccp(rcItem.getMinX(), rcItem.getMinY()); lineFireString.pt2 = ccp(rcItem.getMaxX(), rcItem.getMaxY()); } else if (angle > 180) { lineFireString.pt1 = ccp(rcItem.getMinX(), rcItem.getMaxY()); lineFireString.pt2 = ccp(rcItem.getMaxX(), rcItem.getMinY()); } else if (angle > 90) { lineFireString.pt1 = ccp(rcItem.getMinX(), rcItem.getMinY()); lineFireString.pt2 = ccp(rcItem.getMaxX(), rcItem.getMaxY()); } else { lineFireString.pt1 = ccp(rcItem.getMinX(), rcItem.getMaxY()); lineFireString.pt2 = ccp(rcItem.getMaxX(), rcItem.getMinY()); } // MarioÏ߶ΠLine lineMario[2]; CCRect rcMario = _mario->boundingBox(); lineMario[0].pt1 = ccp(rcMario.getMinX(), rcMario.getMinY()); lineMario[0].pt2 = ccp(rcMario.getMaxX(), rcMario.getMaxY()); lineMario[1].pt1 = ccp(rcMario.getMaxX(), rcMario.getMinY()); lineMario[1].pt2 = ccp(rcMario.getMinX(), rcMario.getMaxY()); for (int i = 0; i < 2; ++i) { if (ccpSegmentIntersect(lineMario[i].pt1, lineMario[i].pt2, lineFireString.pt1, lineFireString.pt2)) _mario->Die(false); } }
void testGlyphConstructor() { setUpFreetype(); FTBBox boundingBox( face->glyph); CPPUNIT_ASSERT_DOUBLES_EQUAL( 2, boundingBox.lowerX, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, boundingBox.lowerY, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox.lowerZ, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( 35, boundingBox.upperX, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( 38, boundingBox.upperY, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox.upperZ, 0.01); tearDownFreetype(); }
void ItemTortoiseFly::collision() { if (_bGodMode || _mario->_status == Mario::DEAD || _mario->_bGodMode) { return; } CCRect rcItem = boundingBox(); CCRect rcMario = _mario->boundingBox(); if (rcItem.intersectsRect(rcMario)) { if (_status == NORMAL) { if (_mario->_status == Mario::FLY && _mario->_speedUp <= 0 && rcMario.getMinY() > rcItem.getMaxY() - rcItem.size.height / 2) { _status = DROPPING; updateStatus(); } else { _mario->die(false); } } else if (_status == DROPPING) { // ... nothing to do // 设计中,乌龟下降的速度应该大于mario下降的速度,所以不应该有碰撞 } else if (_status == ONLAND) { if (_mario->_status == Mario::FLY && _mario->_speedUp <= 0 && rcMario.getMinY() > rcItem.getMaxY() - rcItem.size.height / 2) { _status = SLEEP; updateStatus(); } else { _mario->die(false); } } else if (_status == SLEEP) { if (_bGodMode) return; _status = CRAZY; updateStatus(); } } }
ShapeList & ShapeList::append(const Shape & shape, ShapeList::Direction direction, ShapeList::Alignment alignment, double margin, LineWidthFlag lineWidthFlag) { if ( _shapes.size() == 0 ) { (*this) << shape; return *this; } Rect box = boundingBox(lineWidthFlag); Point c = box.center(); Rect shapeBox = shape.boundingBox(lineWidthFlag); const double shapeHalfWidth = shapeBox.width / 2.0; const double shapeHalfHeight = shapeBox.height / 2.0; double x = c.x; double y = c.y; Shape * s = shape.clone(); if ( direction == Right || direction == Left ) { x = (direction==Right) ? (box.right() + shapeHalfWidth + margin) : (box.left - (margin + shapeHalfWidth)); switch(alignment) { case AlignCenter: y = c.y; break; case AlignTop: y = box.top - shapeBox.height/2.0; break; case AlignBottom: y = (box.top - box.height) + shapeBox.height/2.0; break; case AlignLeft: case AlignRight: Tools::error << "ShapeList::append(): bad alignement\n"; break; } } else { y = (direction==Top) ? (box.top + shapeHalfHeight + margin) : (box.bottom() - (shapeHalfHeight + margin)); switch(alignment) { case AlignCenter: x = c.x; break; case AlignLeft: x = box.left + shapeBox.width/2.0; break; case AlignRight: x = (box.left + box.width) - shapeBox.width/2.0; break; case AlignTop: case AlignBottom: Tools::error << "ShapeList::append(): bad alignement\n"; break; } } s->moveCenter(x,y); (*this) << (*s); delete s; return *this; }
void UIScrollView::UpdateBounding() { CCRect kRect = boundingBox(); if(m_kChildren.Size()) { m_f32MinX = VE_MAXFLOAT_F; m_f32MaxX = -VE_MAXFLOAT_F; m_f32MinY = VE_MAXFLOAT_F; m_f32MaxY = -VE_MAXFLOAT_F; m_kChildren.BeginIterator(); while(!m_kChildren.IsEnd()) { UIWidget* pkWidget = m_kChildren.GetIterNode()->m_tContent; m_kChildren.Next(); VE_ASSERT(pkWidget); if(pkWidget->GetVisible()) { CCRect kRectWidget = pkWidget->boundingBox(); kRectWidget.origin.x -= kRectWidget.size.width * pkWidget->GetTouchAnchorPoint().x; kRectWidget.origin.y -= kRectWidget.size.height * pkWidget->GetTouchAnchorPoint().y; m_f32MinX = VE_MIN(kRectWidget.getMinX(), m_f32MinX); m_f32MaxX = VE_MAX(kRectWidget.getMaxX(), m_f32MaxX); m_f32MinY = VE_MIN(kRectWidget.getMinY(), m_f32MinY); m_f32MaxY = VE_MAX(kRectWidget.getMaxY(), m_f32MaxY); } } m_f32MinY = VE_MIN(m_f32MinY, m_f32MaxY - kRect.size.height); } else { m_f32MinX = 0; m_f32MaxX = kRect.size.width; m_f32MinY = 0; m_f32MaxY = kRect.size.height; } m_f32MoveLeft = m_f32MinX; m_f32MoveRight = m_f32MaxX - kRect.size.width; m_f32MoveBottom = m_f32MinY; m_f32MoveTop = m_f32MaxY - kRect.size.height; VeFloat32 f32Rate = m_f32MaxY > m_f32MinY ? kRect.size.height / (m_f32MaxY - m_f32MinY) : 1.0f; f32Rate = VE_MIN(f32Rate, 1.0f); m_f32ScrollBarLen = VeFloorf(VeFloat32(kRect.size.height) * f32Rate); m_bCanScroll = f32Rate < 1.0f; UpdateScrollBar(); }
void NativeRenderDialog::render(QPainter& P, QRect theR, RendererOptions opt) { P.setClipRect(theR); P.setClipping(true); P.setRenderHint(QPainter::Antialiasing); mapview->setGeometry(theR); mapview->setViewport(boundingBox(), theR); mapview->setRenderOptions(opt); mapview->invalidate(true, true, false); mapview->drawFeaturesSync(P); if (opt.options & RendererOptions::ScaleVisible) mapview->drawScale(P); if (opt.options & RendererOptions::LatLonGridVisible) mapview->drawLatLonGrid(P); }
void Group::flushFIG( std::ostream & stream, const TransformFIG & transform, std::map<DGtal::Color,int> & colormap ) const { Rect box = boundingBox(); stream << "# Begin group\n"; stream << "6 " << transform.mapX( box.left ) << " " << transform.mapY( box.top ) << " " << transform.mapX( box.left + box.width ) << " " << transform.mapY( box.top - box.height ) << "\n"; ShapeList::flushFIG( stream, transform, colormap ); stream << "-6\n"; stream << "# End Group\n"; }
void CCheckBox::onTouchMoved(CCTouch* pTouch, float fDuration) { CC_WIDGET_LONGCLICK_ONTOUCHMOVED; CCPoint tPoint = m_pParent->convertToNodeSpace(pTouch->getLocation()); if( boundingBox().containsPoint(tPoint) ) { if( isChecked() ) { if( m_pCheckedPress ) { SAFE_SET_VISIBLE(m_pCheckedPress, true); SAFE_SET_VISIBLE(m_pChecked, false); } else { SAFE_SET_VISIBLE(m_pChecked, true); } } else { if( m_pNormalPress ) { SAFE_SET_VISIBLE(m_pNormalPress, true); SAFE_SET_VISIBLE(m_pNormal, false); } else { SAFE_SET_VISIBLE(m_pNormal, true); } } } else { if( isChecked() ) { SAFE_SET_VISIBLE(m_pCheckedPress, false); SAFE_SET_VISIBLE(m_pChecked, true); } else { SAFE_SET_VISIBLE(m_pNormalPress, false); SAFE_SET_VISIBLE(m_pNormal, true); } } }
bool ruiMenuManager::PickMenuItem(const rPoint& position){ if (m_handler){ rRect boundingBox(m_position, m_menuSize); if (boundingBox.ContainsPoint(position)){ int item = (position.y - boundingBox.y) / m_rowHeight; ruiMenuItem* menuItem = m_menu->GetItem(item); ruiMenuEvent event(m_menu, menuItem->Id()); m_handler->Trigger(ruiEVT_MENU,event); return true; } } return false; }
// Copy index list in a vector for Vertex Array Use void GLC_Mesh::finish() { boundingBox(); m_MeshData.finishLod(); if (GLC_State::vboUsed()) { finishVbo(); } else { finishNonVbo(); } //qDebug() << "Mesh mem size= " << memmorySize(); }
// Copy index list in a vector for Vertex Array Use void GLC_Mesh::finish() { if (m_MeshData.lodCount() > 0) { boundingBox(); m_MeshData.finishLod(); moveIndexToMeshDataLod(); } else { clear(); } //qDebug() << "Mesh mem size= " << memmorySize(); }
void Board::drawBoundingBox( int depth /* = -1 */ ) { int d = (depth!=-1) ? depth : _nextDepth--; Rect bbox = boundingBox(); _shapes.push_back( new Rectangle( _state.unit(bbox.left), _state.unit(bbox.top), _state.unit(bbox.width), _state.unit(bbox.height), _state.penColor, _state.fillColor, _state.lineWidth, _state.lineStyle, _state.lineCap, _state.lineJoin, d ) ); }
void MapGraphicItem::resize(const QRectF &rect) { Q_UNUSED(rect); { this->prepareGeometryChange(); maprect=boundingBox(scene()->sceneRect(),rotation); this->setTransform(QTransform().translate(-(maprect.width()-scene()->width())/2,-(maprect.height()-scene()->height())/2)); this->setTransformOriginPoint(maprect.center().x(),maprect.center().y()); this->setRotation(rotation); } core->OnMapSizeChanged(maprect.width(),maprect.height()); core->SetCurrentRegion(internals::Rectangle(0, 0, maprect.width(), maprect.height())); if(isVisible()) { core->GoToCurrentPosition(); } }
void FinishTile::update(float delta) { if (timer != nullptr && ball != nullptr && !gameFinished) { const Vec2& position = this->getPosition(); const Size& size = this->getContentSize(); Rect boundingBox(position.x, position.y, size.width, size.height); if (timer->getTimer() <= 0 || boundingBox.intersectsCircle(ball->getPosition(), ball->getContentSize().width / 2)) { auto gameOverLayer = GameOverLayer::create(); this->getParent()->addChild(gameOverLayer, 1); gameOverLayer->show(timer->getTimer() <= 0 ? false : true); finishCallback(); gameFinished = true; // auto gameOverScene = GameOverScene::createScene(); // Director::getInstance()->pushScene(TransitionFade::create(0.5, gameOverScene, Color3B(0,0,0))); } } }
bool Turret::canSee(EntityRef target_ref, bool simple_test) { const Entity *target = refEntity(target_ref); if(!target || isDead()) return false; const FBox &box = boundingBox(); const FBox &target_box = target->boundingBox(); float dist = distance(box, target_box); float3 eye_pos = asXZY(box.center().xz(), box.min.y + box.height() * 0.75f); if(dist > max_distance) return false; if(simple_test) return true; //TODO: move to ThinkingEntity? return world()->isVisible(eye_pos, target_ref, ref(), target->typeId() == EntityId::actor? 4 : 3); }
bool DrawingLayer::toXML(QXmlStreamWriter& stream, bool asTemplate, QProgressDialog * progress) { bool OK = true; stream.writeStartElement(metaObject()->className()); Layer::toXML(stream, asTemplate, progress); if (!asTemplate) { stream.writeStartElement("osm"); stream.writeAttribute("version", "0.6"); stream.writeAttribute("generator", QString("%1 %2").arg(STRINGIFY(PRODUCT)).arg(STRINGIFY(VERSION))); if (p->Features.size()) { stream.writeStartElement("bound"); CoordBox layBB = boundingBox(); QString S = QString().number(layBB.bottomLeft().y(),'f',6) + ","; S += QString().number(layBB.bottomLeft().x(),'f',6) + ","; S += QString().number(layBB.topRight().y(),'f',6) + ","; S += QString().number(layBB.topRight().x(),'f',6); stream.writeAttribute("box", S); stream.writeAttribute("origin", QString("http://www.openstreetmap.org/api/%1").arg(M_PREFS->apiVersion())); stream.writeEndElement(); } QList<MapFeaturePtr>::iterator it; for(it = p->Features.begin(); it != p->Features.end(); it++) (*it)->toXML(stream, progress); stream.writeEndElement(); QList<CoordBox> downloadBoxes = p->theDocument->getDownloadBoxes(this); if (downloadBoxes.size() && p->theDocument->getLastDownloadLayerTime().secsTo(QDateTime::currentDateTime()) < 12*3600) { // Do not export downloaded areas if older than 12h stream.writeStartElement("DownloadedAreas"); QListIterator<CoordBox>it(downloadBoxes); while(it.hasNext()) { it.next().toXML("DownloadedBoundingBox", stream); } stream.writeEndElement(); } } stream.writeEndElement(); return OK; }
//============================================================= //============================================================= void CCScrollLayer::onTouchEnded(Touch *pTouch, Event *pEvent) { Touch* touch = pTouch; Point endPoint = touch->getLocation(); Node* parent = getParent(); if(!parent) { return; } Point localPoint = parent->convertToNodeSpace(endPoint); Rect boundRect = boundingBox(); if(boundRect.containsPoint(localPoint) && m_containBeginTouchPointFlag) //结束点是否在区域内 { if(m_pagingEnable == true) { nextPageAction(localPoint); } else { beginDeclerate(); //开始减速 } sendSelector(SSTE_TOUCH_CANCEL); } else { if(m_pagingEnable == true) { if(m_containBeginTouchPointFlag) { nextPageAction(localPoint); } // setPageRowCount(m_pageRowIndex+1,true); // setPageColumnsCount(m_pageColumnsIndex+1,true); } else { moveToEndPosition(true, m_contentLayer->getPosition()); } } }
//============================================================= //============================================================= bool CCCutTouchLayer::onTouchBegan(Touch* touch, Event* event) //截住touch { if(!m_bPreventTouch) return false; if(!isVisible()) { return false; } Node* fatherNode = getParent(); if(!fatherNode) return false; Point touchPointInWorld = touch->getLocation(); Rect selfRect = boundingBox(); Point selfOriginInWorld = fatherNode->convertToWorldSpace(selfRect.origin); Rect selfRectInWorld = Rect(selfOriginInWorld.x,selfOriginInWorld.y,selfRect.size.width,selfRect.size.height); if(selfRectInWorld.containsPoint(touchPointInWorld) == false) { return false; } for (Node *c = this->_parent; c != NULL; c = c->getParent()) { if (c->isVisible() == false) //若父亲有不可见的则不处理touch { return false; } Rect rect = c->boundingBox(); Node* parentNode = c->getParent(); if(parentNode) { Point originInWorld = parentNode->convertToWorldSpace(rect.origin); Rect rectInWorld = Rect(originInWorld.x,originInWorld.y,rect.size.width,rect.size.height); if(rectInWorld.containsPoint(touchPointInWorld) == false) // 不在父视图区域内 { return false; } } } return true; }
bool SGFirstSubLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { if (SGGuideManager::shareManager()->isGuide) { return false; } CCPoint touchLocation = pTouch->getLocation(); // Get the touch position touchLocation = this->getParent()->convertToNodeSpace(touchLocation); CCRect bBox=boundingBox(); bool istouchIn = bBox.containsPoint(touchLocation); if (istouchIn && iscantouch) { ((CCScrollView*)getParent()->getParent())->ccTouchBegan(pTouch, pEvent); touchBeginLocation = pTouch->getLocationInView(); isMove = false; } return (istouchIn && iscantouch); }
Path2D GeometricRecognizer::scaleToSquare(Path2D points) { //--- Figure out the smallest box that can contain the path DollarRecognizer::Rectangle box = boundingBox(points); Path2D newPoints; for (Path2DIterator i = points.begin(); i != points.end(); i++) { Point2D point = *i; //--- Scale the points to fit the main box //--- So if we wanted everything 100x100 and this was 50x50, //--- we'd multiply every point by 2 double scaledX = point.x * (this->squareSize / box.width); double scaledY = point.y * (this->squareSize / box.height); //--- Why are we adding them to a new list rather than //--- just scaling them in-place? // TODO: try scaling in place (once you know this way works) newPoints.push_back(Point2D(scaledX, scaledY)); } return newPoints; }
void BattleManagerScreen::spawnEnemy() { CCSize screen = boundingBox().size; EntityPair enemy; enemy.model = new GameEntity("Giant Rat"); enemy.model->addAbility( m_abilities["Bite"] ); //enemy.enemyModel->incProperty("hp_curr", -90); enemy.model->setProperty("hp_base", 50, NULL); enemy.model->setProperty("xp_curr", 10, NULL); enemy.view = new GameEntityView( enemy.model ); enemy.view->setBackground("rat.png"); int offY = (rand()%100) - 50; enemy.view->setPosition( screen.width, 220 + offY ); addChild(enemy.view); m_enemies.push_back(enemy); m_allEntities.push_back(enemy); }
void pupiltracker::cvx::getROI(const cv::Mat& src, cv::Mat& dst, const cv::Rect& roi, int borderType) { cv::Rect bbSrc = boundingBox(src); cv::Rect validROI = roi & bbSrc; if (validROI == roi) { dst = cv::Mat(src, validROI); } else { // Figure out how much to add on for top, left, right and bottom cv::Point tl = roi.tl() - bbSrc.tl(); cv::Point br = roi.br() - bbSrc.br(); int top = std::max(-tl.y, 0); // Top and left are negated because adding a border int left = std::max(-tl.x, 0); // goes "the wrong way" int right = std::max(br.x, 0); int bottom = std::max(br.y, 0); cv::Mat tmp(src, validROI); cv::copyMakeBorder(tmp, dst, top, bottom, left, right, borderType); } }
void Board::saveTikZ( const char * filename, double pageWidth, double pageHeight, double margin ) const { std::ofstream file( filename ); TransformTikZ transform; Rect box = boundingBox(); bool clipping = _clippingPath.size() > 2; if ( clipping ) box = box && _clippingPath.boundingBox(); transform.setBoundingBox( box, pageWidth, pageHeight, margin ); file << "\\begin{tikzpicture}[anchor=south west,text depth=0,x={(1pt,0pt)},y={(0pt,-1pt)}]" << std::endl; if ( clipping ) { file << "\\clip "; _clippingPath.flushTikZPoints( file, transform ); file << "\n"; } // Draw the background color if needed. if ( _backgroundColor != Color::None ) { Rectangle r( box, Color::None, _backgroundColor, 0.0 ); r.flushTikZ( file, transform ); } // Draw the shapes. std::vector< Shape* > shapes = _shapes; stable_sort( shapes.begin(), shapes.end(), shapeGreaterDepth ); std::vector< Shape* >::const_iterator i = shapes.begin(); std::vector< Shape* >::const_iterator end = shapes.end(); while ( i != end ) { (*i)->flushTikZ( file, transform ); ++i; } file << "\\end{tikzpicture}" << std::endl; file.close(); }
bool GuideLayer::onTouchBegan(Touch *touch, Event *event) { if (isFixed) { auto stencil = clippingNode->getStencil(); auto rect = stencil->boundingBox(); auto point = touch->getLocation(); if (rect.containsPoint(point)) { this->removeFromParent(); return false; } } else { this->removeFromParent(); return false; } return true; }
bool UIScrollView::IsIn(VeFloat32 x, VeFloat32 y) { CCRect kRect = boundingBox(); return kRect.containsPoint(ccp(x,y)); }