Пример #1
0
//子弹和怪物碰撞
bool GameLayer:: iscollision(Sprite *sprite1, Sprite *sprite2){
    auto rect1 = sprite1->getBoundingBox();//子弹
    auto rect2 = sprite2->getBoundingBox();//怪物

   return !(rect1.getMaxX() < rect2.getMinX() ||
            rect2.getMaxX() <  rect1.getMinX() ||
            rect1.getMaxY() < rect2.getMinY() ||
            rect2.getMaxY() <rect1.getMinY());
}
Пример #2
0
 bool isOverlapping(const Rectangle& rect) const
 {
   /* Ugly, but correct. FIXME */
   return
     (insideInterval(rect.getMinX(), getMinX(), getMaxX()) ||
      insideInterval(rect.getMaxX(), getMinX(), getMaxX()) ||
      insideInterval(getMinX(), rect.getMinX(), rect.getMaxX()) ||
      insideInterval(getMaxX(), rect.getMinX(), rect.getMaxX())) &&
     (insideInterval(rect.getMinY(), getMinY(), getMaxY()) ||
      insideInterval(rect.getMaxY(), getMinY(), getMaxY()) ||
      insideInterval(getMinY(), rect.getMinY(), rect.getMaxY()) ||
      insideInterval(getMaxY(), rect.getMinY(), rect.getMaxY()));
 }
Пример #3
0
PreconditionWidget::PreconditionWidget(UMLScene * scene, ObjectWidget* a, Uml::IDType id )
    : UMLWidget(scene, WidgetBase::wt_Precondition, id)
{
    init();
    m_pOw = a;
    int y = getY();
    m_nY = y;
    //updateResizability();
    // calculateWidget();
    y = y < getMinY() ? getMinY() : y;
    y = y > getMaxY() ? getMaxY() : y;
    m_nY = y;
    this->activate();
}
Пример #4
0
PreconditionWidget::PreconditionWidget(UMLView * view, ObjectWidget* a, Uml::IDType id )
  : UMLWidget(view, id)
{
    init();
    m_pOw = a;
    int y = getY();
    m_nY = y;
    //updateResizability();
    updateComponentSize();
   // calculateWidget();
    y = y < getMinY() ? getMinY() : y;
    y = y > getMaxY() ? getMaxY() : y;
    m_nY = y;
    this->activate();
}
Пример #5
0
bool Bonus::isCollidePlayer()
{
	auto player = GameScene::getTankM()->getPlayerTank();
	if (player == nullptr)
	{
		return false;
	}
	auto boundingBox1 = player->getBoundingBox();
	auto boundingBox2 = this->getBoundingBox();
	/* 不使用intersectsRect,因为边缘重合的时候并不算 */
	return !(boundingBox1.getMaxX() <= boundingBox2.getMinX() ||
		boundingBox2.getMaxX() <= boundingBox1.getMinX() ||
		boundingBox1.getMaxY() <= boundingBox2.getMinY() ||
		boundingBox2.getMaxY() <= boundingBox1.getMinY());
}
Пример #6
0
/*** This should be called when Objects colided. If 1/2 of the object height is > the other objects minY
it will hurt the other object with damage dmg.***/
void EnemyObject::simpleWalkerHurt(GameObject* pPlayer, const uint32_t otherType) {
    auto player = pPlayer->getHitbox();
    auto rThis = getHitbox();
    if (rThis->getMidY() > player->getMinY()) {
      pPlayer->hurt(dmg, Vec2(getVelocityX(), fSimpleHurtForce));
    }
}
Пример #7
0
/*public*/
void
Envelope::translate(double transX, double transY)
{
	if (isNull()) return;
	init(getMinX() + transX, getMaxX() + transX,
		getMinY() + transY, getMaxY() + transY);
}
Пример #8
0
bool OctreeProjectedPolygon::pointInside(const glm::vec2& point, bool* matchesVertex) const {

    OctreeProjectedPolygon::pointInside_calls++;

    // first check the bounding boxes, the point must be fully within the boounding box of this polygon
    if ((point.x > getMaxX()) ||
            (point.y > getMaxY()) ||
            (point.x < getMinX()) ||
            (point.y < getMinY())) {
        return false;
    }

    // consider each edge of this polygon as a potential separating axis
    // check the point against each edge
    for (int i = 0; i < getVertexCount(); i++) {
        glm::vec2 start = getVertex(i);
        glm::vec2 end   = getVertex((i + 1) % getVertexCount());
        float a = start.y - end.y;
        float b = end.x - start.x;
        float c = a * start.x + b * start.y;
        if (a * point.x + b * point.y < c) {
            return false;
        }
    }

    return true;
}
Пример #9
0
bool DRect::intersectsRect(const DRect& rect) const
{
    return !(   getMaxX() < rect.getMinX()
             || rect.getMaxX() < getMinX()
             || getMaxY() < rect.getMinY()
             || rect.getMaxY() < getMinY());
}
Пример #10
0
bool VoxelProjectedPolygon::pointInside(const glm::vec2& point) const {
    // first check the bounding boxes, the point must be fully within the boounding box of this shadow
    if ((point.x > getMaxX()) ||
        (point.y > getMaxY()) ||
        (point.x < getMinX()) ||
        (point.y < getMinY())) {
        return false;
    }

    float e = (getMaxX() - getMinX()) / 100.0f; // some epsilon
    
    // We need to have one ray that goes from a known outside position to the point in question. We'll pick a
    // start point just outside of our min X
    glm::vec2 r1p1(getMinX() - e, point.y);
    glm::vec2 r1p2(point);

    glm::vec2 r2p1(getVertex(getVertexCount()-1)); // start with last vertex to first vertex
    glm::vec2 r2p2;
    
    // Test the ray against all sides
    int intersections = 0;
    for (int i = 0; i < getVertexCount(); i++) {
        r2p2 = getVertex(i);
        if (doLineSegmentsIntersect(r1p1, r1p2, r2p1, r2p2)) {
            intersections++;
        }
        r2p1 = r2p2; // set up for next side
    }

    // If odd number of intersections, we're inside    
    return ((intersections & 1) == 1);
}
Пример #11
0
bool VoxelProjectedPolygon::occludes(const VoxelProjectedPolygon& occludee, bool checkAllInView) const {
    
    // if we are completely out of view, then we definitely don't occlude!
    // if the occludee is completely out of view, then we also don't occlude it
    //
    // this is true, but unfortunately, we're not quite handling projects in the
    // case when SOME points are in view and others are not. So, we will not consider
    // occlusion for any shadows that are partially in view.
    if (checkAllInView && (!getAllInView() || !occludee.getAllInView())) {
        return false;
    }

    // first check the bounding boxes, the occludee must be fully within the boounding box of this shadow
    if ((occludee.getMaxX() > getMaxX()) ||
        (occludee.getMaxY() > getMaxY()) ||
        (occludee.getMinX() < getMinX()) ||
        (occludee.getMinY() < getMinY())) {
        return false;
    }
    
    // if we got this far, then check each vertex of the occludee, if all those points
    // are inside our polygon, then the tested occludee is fully occluded
    for(int i = 0; i < occludee.getVertexCount(); i++) {
        if (!pointInside(occludee.getVertex(i))) {
            return false;
        }
    }
    
    // if we got this far, then indeed the occludee is fully occluded by us
    return true;
}
bool Boundingbox::CollideBox(Boundingbox* _Box)
{
	if (getMinX() > _Box->getMaxX()) return false;
	if (getMaxX() < _Box->getMinX()) return false;
	if (getMinY() > _Box->getMaxY()) return false;
	if (getMaxY() < _Box->getMinY()) return false;
	return true;
}
Пример #13
0
/*public*/
bool
Envelope::centre(Coordinate& centre) const
{
	if (isNull()) return false;
	centre.x=(getMinX() + getMaxX()) / 2.0;
	centre.y=(getMinY() + getMaxY()) / 2.0;
	return true;
}
Пример #14
0
 /* Get the rectangle which is big enough to hold both rectangles */
 Rectangle getUnion(const Rectangle& rect) const
 {
   return Rectangle(
     std::min(getMinX(), rect.getMinX()),
     std::max(getMaxX(), rect.getMaxX()),
     std::min(getMinY(), rect.getMinY()),
     std::max(getMaxY(), rect.getMaxY()));  
 }
Пример #15
0
// can be optimized with new pointInside()
bool OctreeProjectedPolygon::occludes(const OctreeProjectedPolygon& occludee, bool checkAllInView) const {

    OctreeProjectedPolygon::occludes_calls++;

    // if we are completely out of view, then we definitely don't occlude!
    // if the occludee is completely out of view, then we also don't occlude it
    //
    // this is true, but unfortunately, we're not quite handling projects in the
    // case when SOME points are in view and others are not. So, we will not consider
    // occlusion for any shadows that are partially in view.
    if (checkAllInView && (!getAllInView() || !occludee.getAllInView())) {
        return false;
    }

    // first check the bounding boxes, the occludee must be fully within the boounding box of this shadow
    if ((occludee.getMaxX() > getMaxX()) ||
            (occludee.getMaxY() > getMaxY()) ||
            (occludee.getMinX() < getMinX()) ||
            (occludee.getMinY() < getMinY())) {
        return false;
    }

    // we need to test for identity as well, because in the case of identity, none of the points
    // will be "inside" but we don't want to bail early on the first non-inside point
    bool potentialIdenity = false;
    if ((occludee.getVertexCount() == getVertexCount()) && (getBoundingBox().contains(occludee.getBoundingBox())) ) {
        potentialIdenity = true;
    }
    // if we got this far, then check each vertex of the occludee, if all those points
    // are inside our polygon, then the tested occludee is fully occluded
    int pointsInside = 0;
    for(int i = 0; i < occludee.getVertexCount(); i++) {
        bool vertexMatched = false;
        if (!pointInside(occludee.getVertex(i), &vertexMatched)) {

            // so the point we just tested isn't inside, but it might have matched a vertex
            // if it didn't match a vertext, then we bail because we can't be an identity
            // or if we're not expecting identity, then we also bail early, no matter what
            if (!potentialIdenity || !vertexMatched) {
                return false;
            }
        } else {
            pointsInside++;
        }
    }

    // we're only here if all points are inside matched and/or we had a potentialIdentity we need to check
    if (pointsInside == occludee.getVertexCount()) {
        return true;
    }

    // If we have the potential for identity, then test to see if we match, if we match, we occlude
    if (potentialIdenity) {
        return matches(occludee);
    }

    return false; // if we got this far, then we're not occluded
}
Пример #16
0
//----------------------------------------------------------
void ofRectangle::growToInclude(const ofRectangle& rect){
    float x0 = MIN(getMinX(),rect.getMinX());
    float x1 = MAX(getMaxX(),rect.getMaxX());
    float y0 = MIN(getMinY(),rect.getMinY());
    float y1 = MAX(getMaxY(),rect.getMaxY());
    float w = x1 - x0;
    float h = y1 - y0;
    set(x0,y0,w,h);
}
Пример #17
0
//----------------------------------------------------------
void ofRectangle::growToInclude(const ofPoint& p){
    float x0 = MIN(getMinX(),p.x);
    float x1 = MAX(getMaxX(),p.x);
    float y0 = MIN(getMinY(),p.y);
    float y1 = MAX(getMaxY(),p.y);
    float w = x1 - x0;
    float h = y1 - y0;
    set(x0,y0,w,h);
}
Пример #18
0
void PreconditionWidget::slotWidgetMoved(Uml::IDType id)
{
    const Uml::IDType idA = m_pOw->localID();
    if (idA != id ) {
        uDebug() << "id=" << ID2STR(id) << ": ignoring for idA=" << ID2STR(idA);
        return;
    }
    m_nY = getY();
    if (m_nY < getMinY())
        m_nY = getMinY();
    if (m_nY > getMaxY())
        m_nY = getMaxY();

    calculateDimensions();
    if (m_scene->getSelectCount(true) > 1)
        return;

}
Пример #19
0
bool EnemyPlane::isStillOnScreen()
{
    auto boundings = getParent()->getBoundingBox();
    bool planeIsOnScreen = ( this->getPositionX()-19 < boundings.getMaxX() && this->getPositionX()-19 > boundings.getMinX() &&
    this->getPositionY()-19 < boundings.getMaxY() && this->getPositionY()-19  > boundings.getMinY());
    

    return planeIsOnScreen;
}
Пример #20
0
void VoxelProjectedPolygon::printDebugDetails() const {
    printf("VoxelProjectedPolygon...");
    printf("    minX=%f maxX=%f minY=%f maxY=%f\n", getMinX(), getMaxX(), getMinY(), getMaxY());
    printf("    vertex count=%d distance=%f\n", getVertexCount(), getDistance());
    for (int i = 0; i < getVertexCount(); i++) {
        glm::vec2 point = getVertex(i);
        printf("    vertex[%d] = %f, %f \n", i, point.x, point.y);
    }
}
Пример #21
0
bool Sphere::isIntersects(Vec3 p)
{
	if (getMaxX() > p.getX() && getMinX() < p.getX())
		return true;
	if (getMaxY() > p.getY() && getMinY() < p.getY())
		return true;
	if (getMaxZ() > p.getZ() && getMinZ() < p.getZ())
		return true;
	return false;
}
Пример #22
0
bool CCRect::containsPoint(const CCPoint& point) const
{
    bool bRet = false;

    if (point.x >= getMinX() && point.x <= getMaxX()
        && point.y >= getMinY() && point.y <= getMaxY())
    {
        bRet = true;
    }

    return bRet;
}
Пример #23
0
/**
 * Constructs a MessageWidget.
 *
 * This method is used for creation, synchronous and synchronous message types.
 *
 * @param scene   The parent to this class.
 * @param a       The role A widget for this message.
 * @param b       The role B widget for this message.
 * @param y       The vertical position to display this message.
 * @param sequenceMessageType Whether synchronous or asynchronous
 * @param id      A unique id used for deleting this object cleanly.
 *                The default (-1) will prompt generation of a new ID.
 */
MessageWidget::MessageWidget(UMLScene * scene, ObjectWidget* a, ObjectWidget* b,
                             int y, Uml::SequenceMessage::Enum sequenceMessageType,
                             Uml::ID::Type id /* = Uml::id_None */)
  : UMLWidget(scene, WidgetBase::wt_Message, id)
{
    init();
    m_pOw[Uml::RoleType::A] = a;
    m_pOw[Uml::RoleType::B] = b;
    m_sequenceMessageType = sequenceMessageType;
    if (m_sequenceMessageType == Uml::SequenceMessage::Creation) {
        y -= m_pOw[Uml::RoleType::B]->height() / 2;
        m_pOw[Uml::RoleType::B]->setY(y);
    }
    updateResizability();
    calculateWidget();
    y = y < getMinY() ? getMinY() : y;
    y = y > getMaxY() ? getMaxY() : y;
    setY(y);

    this->activate();
}
Пример #24
0
void HexaGridMap::updateTrajectory() {
    ((DrawNode*)this->trajectoryCanvas)->clear();
    Point* ptsToDraw = new Point[this->trajectory.size()];
    for (int i = 0; i < this->trajectory.size(); i++) {
        auto name = Utils::generateNameByPoint(this->trajectory.at(i));
        auto box = this->getChildByName<HexaGridMapUnit*>(name)->getBoundingBox();
        ptsToDraw[i] = Point(box.getMinX()+box.getMaxX(), box.getMinY()+box.getMaxY())/2;
    }
    for (int i = 1; i < this->trajectory.size(); i++) {
        ((DrawNode*)this->trajectoryCanvas)->drawSegment(ptsToDraw[i-1], ptsToDraw[i], 4, Color4F(.5, .25, .25, 1));
    }
}
Пример #25
0
/**
 * Constrains the FloatingTextWidget X and Y values supplied.
 * Overrides operation from LinkWidget.
 *
 * @param textX        candidate X value (may be modified by the constraint)
 * @param textY        candidate Y value (may be modified by the constraint)
 * @param textWidth    width of the text
 * @param textHeight   height of the text
 * @param tr           Uml::TextRole::Enum of the text
 */
void MessageWidget::constrainTextPos(qreal &textX, qreal &textY, qreal textWidth, qreal textHeight,
                                     Uml::TextRole::Enum tr)
{
    textX = constrainX(textX, textWidth, tr);
    // Constrain Y.
    const qreal minTextY = getMinY();
    const qreal maxTextY = getMaxY() - textHeight - 5;
    if (textY < minTextY)
        textY = minTextY;
    else if (textY > maxTextY)
        textY = maxTextY;
//     setY(textY + textHeight);   // NB: side effect
}
Пример #26
0
void MessageWidget::slotWidgetMoved(Uml::ID::Type id)
{
    const Uml::ID::Type idA = m_pOw[Uml::RoleType::A]->localID();
    const Uml::ID::Type idB = m_pOw[Uml::RoleType::B]->localID();
    if (idA != id && idB != id) {
        DEBUG(DBG_SRC) << "id=" << Uml::ID::toString(id) << ": ignoring for idA=" << Uml::ID::toString(idA)
            << ", idB=" << Uml::ID::toString(idB);
        return;
    }
    qreal y = this->y();
    if (y < getMinY())
        y = getMinY();
    if (y > getMaxY())
        y = getMaxY();
    setPos(x(), y);
    calculateWidget();
    if(!m_pFText)
        return;
    if (m_scene->selectedCount(true) > 1)
        return;
    setTextPosition();
}
Пример #27
0
/**
 * Constructs a Lost or Found MessageWidget.
 *
 * @param scene  The parent to this class.
 * @param a      The role A widget for this message.
 * @param xclick The horizontal position clicked by the user
 * @param yclick The vertical position clicked by the user
 * @param sequenceMessageType Whether lost or found
 * @param id     The ID to assign (-1 will prompt a new ID.)
 */
MessageWidget::MessageWidget(UMLScene * scene, ObjectWidget* a, int xclick, int yclick,
                             Uml::SequenceMessage::Enum sequenceMessageType,
                             Uml::ID::Type id /*= Uml::id_None*/)
  : UMLWidget(scene, WidgetBase::wt_Message, id)
{
    init();
    m_pOw[Uml::RoleType::A] = a;
    m_pOw[Uml::RoleType::B] = a;

    m_sequenceMessageType = sequenceMessageType;

    m_xclicked = xclick;
    m_yclicked = yclick;

    updateResizability();
    calculateWidget();
    yclick = yclick < getMinY() ? getMinY() : yclick;
    yclick = yclick > getMaxY() ? getMaxY() : yclick;
    setY(yclick);
    m_yclicked = yclick;

    this->activate();
}
Пример #28
0
bool KeyboardPaddle::collideWithBall(Ball* ball) {
        auto paddleBBox = getBoundingBox();
        auto ballBBox = ball->getBoundingBox();

        float bLeft = ballBBox.getMinX();
        float bHigh = ballBBox.getMaxY();
        float bLow = ballBBox.getMinY();

        float pRight = paddleBBox.getMaxX();
        float pHigh = paddleBBox.getMaxY();
        float pLow = paddleBBox.getMinY();

        if (bLeft <= pRight) {
                if (bHigh <= pHigh
                    && bHigh >= pLow) {
                        return true;
                } else if (bLow <= pHigh
                           && bLow >= pLow) {
                        return true;
                }
        }

        return false;
}
Пример #29
0
/**
 * Constrains the vertical position of the message widget so it doesn't go
 * upper than the bottom side of the lower object.
 * The height of the floating text widget in the message is taken in account
 * if there is any and isn't empty.
 *
 * @param diffY The difference between current Y position and new Y position.
 * @return The new Y position, constrained.
 */
qreal MessageWidget::constrainPositionY(qreal diffY)
{
    qreal newY = y() + diffY;

    qreal minY = getMinY();
    if (m_pFText && !m_pFText->displayText().isEmpty()) {
        minY += m_pFText->height();
    }

    if (newY < minY) {
        newY = minY;
    }

    return newY;
}
bool ZoneImplementation::isWithinBoundaries(const Vector3& position) {
	//Remove 1/16th of the size to match client limits. NOTE: it has not been verified to work like this in the client.
	//Normal zone size is 8192, 1/16th of that is 512 resulting in 7680 as the boundary value.
	float maxX = getMaxX() * 15 / 16;
	float minX = getMinX() * 15 / 16;
	float maxY = getMaxY() * 15 / 16;
	float minY = getMinY() * 15 / 16;

	if (maxX >= position.getX() && minX <= position.getX() &&
			maxY >= position.getY() && minY <= position.getY()) {
		return true;
	} else {
		return false;
	}
}