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);
}
Beispiel #2
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());
}
Beispiel #3
0
    float Field::getDistanceToFieldX(float x)
    {
        float distance = 0;

        if (x < getMinX())
            distance = getMinX() - x;

        else if (x > getMaxX())
            distance = x - getMaxX();

        return distance;
    }
 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()));
 }
Beispiel #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());
}
Beispiel #6
0
Datei: Ball.cpp Projekt: Zaka/yap
void Ball::move(float delta) {
    this->setPosition(getPosition() + getVelocity() * delta);

    auto bBox = getBoundingBox();
    auto ballRight = bBox.getMaxX();
    auto ballLeft = bBox.getMinX();
    
    if (ballRight > VisibleRect::right().x) {
        setPosition(Point(VisibleRect::right().x - radius(),
                          getPosition().y) );
        _velocity.x *= -1;
    } else if (ballLeft < VisibleRect::left().x) {
        setPosition(Point(VisibleRect::left().x + radius(),
                          getPosition().y) );
        _velocity.x *= -1;
    }
    
    if (getPosition().y > VisibleRect::top().y - radius()) {
        setPosition(Point(getPosition().x,
                          VisibleRect::top().y - radius()));
        _velocity.y *= -1;
    } else if (getPosition().y < VisibleRect::bottom().y + radius()) {
        setPosition(Point(getPosition().x,
                          VisibleRect::bottom().y + radius()));
        _velocity.y *= -1;
    }
}
Beispiel #7
0
void GFXST_LineType(
	     void (*GFX_OSFunc)(
				struct Tracker_Windows *window,
				enum ColorNums color,
				int x,int y,int x2,int y2,
                                int where
				),
	     struct Tracker_Windows *window,
	     enum ColorNums color,
	     int x,int y,int x2,int y2,
             int where
	     )
{
  int minx=getMinX(window);

  if(x<minx){
    if(x2<minx){
      return;
    }

    y=y2-(((y2-y)*(x2-minx))/(x2-x));
    x=minx;
  }

  if(x2<minx){
    y2=y+(((y2-y)*(minx-x2))/(x-x2));

    x2=minx;
  }


  GFXS_LineType(GFX_OSFunc,window,color,x,y,x2,y2,where);

}
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;
}
Beispiel #9
0
double DLibshuff::dCalculate(int x, int y){
	
	double sum = 0;
	
	minX = getMinX(x);
	
	if (m->control_pressed) { return sum; }
	
	minXY = getMinXY(x, y);
	
	if (m->control_pressed) { return sum; }
	
	vector<int> nx = calcN(minX);
	
	if (m->control_pressed) { return sum; }
	
	vector<int> nxy = calcN(minXY);
	
	if (m->control_pressed) { return sum; }

	for(int i=0;i<numDXs;i++){
		float h = (nx[i] - nxy[i]) / (float) groupSizes[x];
		sum += h * h * stepSize;
	}

	return sum;
}
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;
}
Beispiel #11
0
/*public*/
void
Envelope::translate(double transX, double transY)
{
	if (isNull()) return;
	init(getMinX() + transX, getMaxX() + transX,
		getMinY() + transY, getMaxY() + transY);
}
Beispiel #12
0
bool DRect::intersectsRect(const DRect& rect) const
{
    return !(   getMaxX() < rect.getMinX()
             || rect.getMaxX() < getMinX()
             || getMaxY() < rect.getMinY()
             || rect.getMaxY() < getMinY());
}
 /* 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()));  
 }
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;
}
Beispiel #15
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;
}
// 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
}
void CubeProjectedPolygon::printDebugDetails() const {
    qCDebug(shared, "CubeProjectedPolygon..."
            "    minX=%f maxX=%f minY=%f maxY=%f", (double)getMinX(), (double)getMaxX(), (double)getMinY(), (double)getMaxY());
    qCDebug(shared, "    vertex count=%d distance=%f", getVertexCount(), (double)getDistance());
    for (int i = 0; i < getVertexCount(); i++) {
        glm::vec2 point = getVertex(i);
        qCDebug(shared, "    vertex[%d] = %f, %f ", i, (double)point.x, (double)point.y);
    }
}
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);
    }
}
//----------------------------------------------------------
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);
}
//----------------------------------------------------------
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);
}
Beispiel #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;
}
Beispiel #22
0
void GFXST_TextType(
	     void (*GFX_OSFunc)(
				struct Tracker_Windows *window,
				enum ColorNums color,const char *text,
				int x,int y,
                                int width,
                                int flags,
                                int where
				),
	     struct Tracker_Windows *window,
	     enum ColorNums color,const char *text,
	     int x,int y,
             int width,
             int flags,
             int where
	     )
{
  if(flags & TEXT_NOTEXT){
    int minx=getMinX(window);
    GFXS_TextType(GFX_OSFunc,window,color,text,R_MAX(minx,x),y,width,flags,where);
  }else{
    int minx=getMinX(window);

    if(GFX_OSFunc==QUEUE_GFX_Text){
      if(x<minx){
        x=minx;
        //char temp[600];
        //sprintf(temp,"<--%s",text);
        //GFXS_TextType(GFX_OSFunc,window,color,temp,x,y,width,flags,where);
      }else
        GFXS_TextType(GFX_OSFunc,window,color,text,x,y,width,flags,where);
    }else{
      if(x<minx){
        if((strlen(text)+1)*window->fontwidth<minx) return;
        text+=(minx-x)/window->fontwidth;
        x=minx;
      }
      GFXS_TextType(GFX_OSFunc,window,color,text,x,y,width,flags,where);
    }
  }
}
Beispiel #23
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;
}
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));
    }
}
Beispiel #25
0
/**
 * @brief AddKeyFrameImageCoverPolicy
 * add a keyframe taking into account the percentage of image free of features matched
 * @param frame
 * @return
 */
inline bool AddKeyFrameImageCoverPolicy( const StereoFrame& frame,
                                         const double imageWidth,
                                         const double coverThreshold) {

  const std::map<MapPoint*, Measurement> &measurements = frame.GetMeasurementsLeft();

  double minX = getMinX(measurements);
  double maxX = getMaxX(measurements);

  double imageAreaMeasurementFree = (minX + (imageWidth - maxX)) / imageWidth;

  return imageAreaMeasurementFree > coverThreshold;
}
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;
	}
}
//----------------------------------------------------------
ofRectangle ofRectangle::getIntersection(const ofRectangle& rect) const {

    float x0 = MAX(getMinX(),rect.getMinX());
    float x1 = MIN(getMaxX(),rect.getMaxX());
    
    float w = x1 - x0;
    if(w < 0.0f) return ofRectangle(0,0,0,0); // short circuit if needed
    
    float y0 = MAX(getMinY(),rect.getMinY());
    float y1 = MIN(getMaxY(),rect.getMaxY());
    
    float h = y1 - y0;
    if(h < 0.0f) return ofRectangle(0,0,0,0);  // short circuit if needed
    
    return ofRectangle(x0,y0,w,h);
}
Beispiel #28
0
void GFXST_BorderType2(
		     void (*GFX_P_OSFunc)(
                                          struct Tracker_Windows *window,
                                          int x, int y, int y2,
                                          int where
                                          ),
		     struct Tracker_Windows *window,
		     int x, int y, int y2,
                     int where
		     )
{
  int minx=getMinX(window);
  if(x<minx) return;

  GFXS_BorderType2(GFX_P_OSFunc,window,x,y,y2,where);
}
Beispiel #29
0
void Rect::merge(const Rect& rect)
{
    float top1    = getMaxY();
    float left1   = getMinX();
    float right1  = getMaxX();
    float bottom1 = getMinY();
    
    float top2    = rect.getMaxY();
    float left2   = rect.getMinX();
    float right2  = rect.getMaxX();
    float bottom2 = rect.getMinY();
    origin.x = std::min(left1, left2);
    origin.y = std::min(bottom1, bottom2);
    size.width = std::max(right1, right2) - origin.x;
    size.height = std::max(top1, top2) - origin.y;
}
bool Boundingbox::CollideMouse(GameData* _GD)
{
	if ((_GD->m_mouseX > getMinX()) && (_GD->m_mouseX < getMaxX()))
	{
		if ((_GD->m_mouseY > getMinY()) && (_GD->m_mouseY < getMaxY()))
		{
			if (_GD->m_mouseState->rgbButtons[0] & 0x80)
			{
				//std::cout << m_buttonoutput << endl;
				//std::cout << numberding;
				// return numberding;

				return true;
			}
		}
	}
	return false;
}