Exemplo n.º 1
0
void Win32Graphics::drawGraphics( const OSGraphics &rGraphics, int xSrc,
                                  int ySrc, int xDest, int yDest, int width,
                                  int height )
{
    // check and adapt to source if needed
    if( !checkBoundaries( 0, 0, rGraphics.getWidth(), rGraphics.getHeight(),
                          xSrc, ySrc, width, height ) )
    {
        msg_Err( getIntf(), "nothing to draw from graphics source" );
        return;
    }

    // check destination
    if( !checkBoundaries( 0, 0, m_width, m_height,
                          xDest, yDest, width, height ) )
    {
        msg_Err( getIntf(), "out of reach destination! pls, debug your skin" );
        return;
    }

    // Create the mask for transparency
    HRGN mask = CreateRectRgn( xSrc, ySrc, xSrc + width, ySrc + height );
    CombineRgn( mask, ((Win32Graphics&)rGraphics).getMask(), mask, RGN_AND );
    OffsetRgn( mask, xDest - xSrc, yDest - ySrc );

    // Copy the image
    HDC srcDC = ((Win32Graphics&)rGraphics).getDC();
    SelectClipRgn( m_hDC, mask );
    BitBlt( m_hDC, xDest, yDest, width, height, srcDC, xSrc, ySrc, SRCCOPY );

    // Add the source mask to the mask of the graphics
    CombineRgn( m_mask, mask, m_mask, RGN_OR );
    DeleteObject( mask );
}
Exemplo n.º 2
0
void X11Graphics::drawGraphics( const OSGraphics &rGraphics, int xSrc,
                                int ySrc, int xDest, int yDest, int width,
                                int height )
{
    const X11Graphics& rGraph = (X11Graphics&)rGraphics;

    // check and adapt to source if needed
    if( !checkBoundaries( 0, 0, rGraph.getWidth(), rGraph.getHeight(),
                          xSrc, ySrc, width, height ) )
    {
        msg_Err( getIntf(), "nothing to draw from graphics source" );
        return;
    }

    // check destination
    if( !checkBoundaries( 0, 0, m_width, m_height,
                          xDest, yDest, width, height ) )
    {
        msg_Err( getIntf(), "out of reach destination! pls, debug your skin" );
        return;
    }

    // Source drawable
    Drawable src = rGraph.getDrawable();

    // Create the mask for transparency
    Region voidMask = XCreateRegion();
    XRectangle rect;
    rect.x = xSrc;
    rect.y = ySrc;
    rect.width = width;
    rect.height = height;
    Region clipMask = XCreateRegion();
    XUnionRectWithRegion( &rect, voidMask, clipMask );
    Region mask = XCreateRegion();
    XIntersectRegion( rGraph.getMask(), clipMask, mask );
    XDestroyRegion( clipMask );
    XDestroyRegion( voidMask );
    XOffsetRegion( mask, xDest - xSrc, yDest - ySrc );

    // Copy the pixmap
    XSetRegion( XDISPLAY, m_gc, mask );
    XCopyArea( XDISPLAY, src, m_pixmap, m_gc, xSrc, ySrc, width, height,
               xDest, yDest );

    // Add the source mask to the mask of the graphics
    Region newMask = XCreateRegion();
    XUnionRegion( m_mask, mask, newMask );
    XDestroyRegion( mask );
    XDestroyRegion( m_mask );
    m_mask = newMask;
}
Exemplo n.º 3
0
void PingPong::update()
{
    QByteArray size;
    // Server is only updating the coordinates
    //! [Updating coordinates]
    if (m_role == 1) {
        checkBoundaries();
        m_ballPreviousX = m_ballX;
        m_ballPreviousY = m_ballY;
        m_ballY = m_direction*(m_ballX+interval) - m_direction*m_ballX + m_ballY;
        m_ballX = m_ballX + interval;

        size.setNum(m_ballX);
        size.append(' ');
        QByteArray size1;
        size1.setNum(m_ballY);
        size.append(size1);
        size.append(' ');
        size1.setNum(m_leftBlockY);
        size.append(size1);
        size.append(" \n");
        socket->write(size.constData());
        Q_EMIT ballChanged();
    }
    else if (m_role == 2) {
        size.setNum(m_rightBlockY);
        size.append(" \n");
        socket->write(size.constData());
    }
    //! [Updating coordinates]
}
Exemplo n.º 4
0
//the game loop, calls all of the supplemental
//methods of the application to continuously
//update and maintain the functionality of the
//game
void Application::gameLoop()
{
    while(gameRunning)
    {
        handleEnvironment();

        updateMonsters();

        handleEvents();

        updatePlayer();

        handleArrows();

        handlePhysics();

        delta.start();

        checkBoundaries();
        updateFPS();
        updatePoints();
        drawSurface();

        if(finished)
        {
            showFinal();
        }

    }
}
Exemplo n.º 5
0
void TileMap::loadFromFile(std::string filename)
{
	std::ifstream file(filename.c_str());

	//Read in the texture filename
	file >> tInfo.textureFile;
	
	// Set the texture
	sprite.setTexture(*texture);

	// Read in the number of tiles in the texture
	file >> tInfo.nTiles;

	// Read in the tile size
	file >> tInfo.tileSize;

	// Read in the tiles per row in the texture
	file >> tInfo.tpr;

	// Read in the map size
	file >> tInfo.mapSize.x;
	file >> tInfo.mapSize.y;

	// Use map size to determine max scroll values
	minScroll.x = (float)TileNS::SIZE;
	minScroll.y = (float)TileNS::SIZE;
	maxScroll.x = (float)(tInfo.mapSize.x - 1) * (float)TileNS::SIZE - SCREEN_WIDTH;
	maxScroll.y = (float)(tInfo.mapSize.y - 1) * (float)TileNS::SIZE - SCREEN_HEIGHT;

	// Allocate space for the map
	tiles = new Tile[tInfo.mapSize.x * tInfo.mapSize.y];

	// Read in the tiles
	for (int i = 0; i < tInfo.mapSize.x * tInfo.mapSize.y; i++)
		file >> tiles[i];

	file.close();


	scrollX = minScroll.x;
	scrollY = minScroll.y;

	checkBoundaries();


	// Calculate the minimum and maximum visible tiles
	minTiles.y = (int)(scrollY / tInfo.tileSize);
	maxTiles.y = (int)((scrollY + SCREEN_HEIGHT) / tInfo.tileSize);

	minTiles.x = (int)(scrollX / tInfo.tileSize);
	maxTiles.x = (int)((scrollX + SCREEN_WIDTH) / tInfo.tileSize);
}
Exemplo n.º 6
0
//====================================================================================
// scroll(float)
// Scrolls the TileMap by adding the given values to the map's x and y scroll values.
// Checks to see if the map has scrolled to any of its edges, and triggers a scroll
// event with the amounts by which the map scrolled.
//====================================================================================
void TileMap::scroll(float x, float y)
{
	scrollX += x;
	scrollY += y;

	checkBoundaries();

	Event::Data e;
	e.type = Event::SCROLL;
	e.scrollX = x;
	e.scrollY = y;
	EventManager::triggerEvent(e);
}
Exemplo n.º 7
0
//=======================================================================================
// TileMap::enter(sf::Vector2i, sf::Vector2i)
// This method is called when entering a new tile map. The reference tile is the tile
// that should appear at the top right corner of the screen upon entering. The reference
// tile is used to compute x and y scroll values, which in turn are used to compute the
// minimum and maximum visible tiles.
//=======================================================================================
void TileMap::enter(sf::Vector2i ref)
{
	// Set the scroll values based on reference tile
	scrollX = (float)ref.x * (float)TileNS::SIZE;
	scrollY = (float)ref.y * (float)TileNS::SIZE;

	checkBoundaries();

	// Calculate the minimum and maximum visible tiles
	minTiles.y = (int)(scrollY / tInfo.tileSize);
	maxTiles.y = (int)((scrollY + SCREEN_HEIGHT) / tInfo.tileSize);

	minTiles.x = (int)(scrollX / tInfo.tileSize);
	maxTiles.x = (int)((scrollX + SCREEN_WIDTH) / tInfo.tileSize);
}
Exemplo n.º 8
0
bool Emitter::updateEmitter(sf::Vector2f &location)
{
	setLocation(location);
	createParticle();
	for (std::list<Particle>::iterator it = particles.begin(); it != particles.end();)
	{
		it->update(0.01);
		/*if (it->getLife() < 1)
			particles.erase(it);
		else*/
			++it;
	}

	if (checkBoundaries())
		return true;
	else
		return false;
};
Exemplo n.º 9
0
//Updates position of ship based on accelerations, called from timer.c critical zone
void applyAccelerations(Ship *ship, iArgs input, FILE *sketch) {
    eraseShip(ship, sketch);

    double oldX = ship -> centerPos[0];
    double oldY = ship -> centerPos[1];

    if (rotationBuffer != ship -> rotationAngle) {
        rotationBuffer = ship -> rotationAngle;
    }

    double oldxV = ship -> xspeed;
    double oldyV = ship -> yspeed;
    double deltat = 0.05;
    double thrust;
    double ar = rotationBuffer * PI / 180.0;

    if (ship -> thrustOn) {
        thrust = input.thrust;
    } else {
        thrust = 0;
    }

    ship -> xA = thrust*cos(ar);
    ship -> yA = -(input.gravity) + thrust*sin(ar);

    ship -> centerPos[0] = oldX + oldxV*deltat + (1/2)*(ship -> xA)*deltat*deltat;
    ship -> centerPos[1] = oldY + oldyV*deltat + (1/2)*(ship -> yA)*deltat*deltat;
    ship -> xspeed = oldxV - (ship -> xA)*deltat;
    ship -> yspeed = oldyV - (ship -> yA)*deltat;

    checkBoundaries(ship);
    recreateShip(ship);

    if (rotationBuffer != ship -> rotationAngle) {
        rotateShip(ship, rotationBuffer - 90);
    }


    drawShip(ship, sketch);
    //
}
Exemplo n.º 10
0
void Ball::update(){
//    cout << "Called update: " << pos << endl;
    pos += vel;
    checkBoundaries();
}
Exemplo n.º 11
0
uchar PathFinding::getTileAt(const iPoint& pos) const
{
	if (checkBoundaries(pos))
		return map_data[pos.y * width + pos.x];
	return INVALID_WALKABILTY_CODE;
}
Exemplo n.º 12
0
bool PathFinding::isWalkable(const iPoint& pos) const
{
	if (checkBoundaries(pos) && map_data[pos.y * width + pos.x] != 0)
		return true;
	return false;
}
Exemplo n.º 13
0
void Win32Graphics::drawBitmap( const GenericBitmap &rBitmap,
                                int xSrc, int ySrc, int xDest, int yDest,
                                int width, int height, bool blend )
{
    (void)blend;

    // check and adapt to source if needed
    if( !checkBoundaries( 0, 0, rBitmap.getWidth(), rBitmap.getHeight(),
                          xSrc, ySrc, width, height ) )
    {
        msg_Err( getIntf(), "empty source! pls, debug your skin" );
        return;
    }

    // check destination
    if( !checkBoundaries( 0, 0, m_width, m_height,
                          xDest, yDest, width, height ) )
    {
        msg_Err( getIntf(), "out of reach destination! pls, debug your skin" );
        return;
    }

    // Get a buffer on the image data
    uint8_t *pBmpData = rBitmap.getData();
    if( pBmpData == NULL )
    {
        // Nothing to draw
        return;
    }

    void *pBits;     // pointer to DIB section
    // Fill a BITMAPINFO structure
    BITMAPINFO bmpInfo;
    memset( &bmpInfo, 0, sizeof( bmpInfo ) );
    bmpInfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
    bmpInfo.bmiHeader.biWidth = width;
    bmpInfo.bmiHeader.biHeight = -height;
    bmpInfo.bmiHeader.biPlanes = 1;
    bmpInfo.bmiHeader.biBitCount = 32;
    bmpInfo.bmiHeader.biCompression = BI_RGB;
    bmpInfo.bmiHeader.biSizeImage = width * height * 4;

    // Create a DIB (Device Independent Bitmap) and associate it with
    // a temporary DC
    HDC hDC = CreateCompatibleDC( m_hDC );
    HBITMAP hBmp = CreateDIBSection( hDC, &bmpInfo, DIB_RGB_COLORS,
                                     &pBits, NULL, 0 );
    SelectObject( hDC, hBmp );

    // Mask for transparency
    HRGN mask = CreateRectRgn( 0, 0, 0, 0 );

    // Skip the first lines of the image
    pBmpData += 4 * ySrc * rBitmap.getWidth();

    // Copy the bitmap on the image and compute the mask
    for( int y = 0; y < height; y++ )
    {
        // Skip uninteresting bytes at the beginning of the line
        pBmpData += 4 * xSrc;
        // Flag to say whether the previous pixel on the line was visible
        bool wasVisible = false;
        // Beginning of the current visible segment on the line
        int visibleSegmentStart = 0;
        for( int x = 0; x < width; x++ )
        {
            uint8_t b = *(pBmpData++);
            uint8_t g = *(pBmpData++);
            uint8_t r = *(pBmpData++);
            uint8_t a = *(pBmpData++);

            // Draw the pixel
            ((UINT32 *)pBits)[x + y * width] =
                (a << 24) | (r << 16) | (g << 8) | b;

            if( a > 0 )
            {
                // Pixel is visible
                if( ! wasVisible )
                {
                    // Beginning of a visible segment
                    visibleSegmentStart = x;
                }
                wasVisible = true;
            }
            else
            {
                // Pixel is transparent
                if( wasVisible )
                {
                    // End of a visible segment: add it to the mask
                    addSegmentInRegion( mask, visibleSegmentStart, x, y );
                }
                wasVisible = false;
            }
        }
        if( wasVisible )
        {
            // End of a visible segment: add it to the mask
            addSegmentInRegion( mask, visibleSegmentStart, width, y );
        }
        // Skip uninteresting bytes at the end of the line
        pBmpData += 4 * (rBitmap.getWidth() - width - xSrc);
    }

    // Apply the mask to the internal DC
    OffsetRgn( mask, xDest, yDest );
    SelectClipRgn( m_hDC, mask );

    BLENDFUNCTION bf;      // structure for alpha blending
    bf.BlendOp = AC_SRC_OVER;
    bf.BlendFlags = 0;
    bf.SourceConstantAlpha = 0xff;  // don't use constant alpha
    bf.AlphaFormat = AC_SRC_ALPHA;

    // Blend the image onto the internal DC
    if( !AlphaBlend( m_hDC, xDest, yDest, width, height, hDC, 0, 0,
                     width, height, bf ) )
    {
        msg_Err( getIntf(), "AlphaBlend() failed" );
    }

    // Add the bitmap mask to the global graphics mask
    CombineRgn( m_mask, m_mask, mask, RGN_OR );

    // Do cleanup
    DeleteObject( hBmp );
    DeleteObject( mask );
    DeleteDC( hDC );
}
Exemplo n.º 14
0
void check_for_pole(){
  int num_scans = (int)((cur_scan.angle_max-cur_scan.angle_min)/cur_scan.angle_increment);

  std::vector<std::vector<double> > point_vector;
  std::vector<double> temp_point(2,0);

  //loop through each scan
  for(int i = 0; i < num_scans; i++){
    if(cur_scan.ranges[i]==INFINITY ||
       std::isnan(cur_scan.ranges[i])){
      continue;
    }
    //ROS_INFO("looping through scans %d", i);
    
    double current_range = cur_scan.ranges[i];
    int good = 1;
    int bad = 0;
    int j = i+1;
    
    while(1){
      //check for end of array
      if(j>=(num_scans-1)){
	if(good >= POLE_HITS){
	  //ROS_INFO("pole hits: %d", good);
	  temp_point[0] = current_range;
	  temp_point[1] = cur_scan.angle_min + (cur_scan.angle_increment*((j+i)/2));
	  point_vector.push_back(temp_point);
	}
	break;
      }else if(fabs(cur_scan.ranges[j]-current_range) > RANGE_THRESH){
	bad++;
	if(bad <= BAD_HITS){
	  continue;
	}else{
	  if(good >= POLE_HITS){
	    temp_point[0] = current_range;
	    temp_point[1] = cur_scan.angle_min + (cur_scan.angle_increment*((j+i)/2));
	    point_vector.push_back(temp_point);
	    //ROS_INFO("pole hits: %d", good);
	    //ROS_INFO("Object Position: range->%f\tangle->%f", temp_point[0], temp_point[1]);
	    i = j;
	  }
	  break;
	}
      }else if(fabs(cur_scan.ranges[j]-current_range) < RANGE_THRESH){
	good++;
      }
      j++;
    }
  }

  
  //check each object to see if it's a pole
  for(int i = 0; i < point_vector.size(); i++){
    double range = point_vector[i][0];
    double theta = point_vector[i][1];
    double temp_x, temp_y;
    
    //first add the laser offset
    temp_x = cos(theta)*range + LASER_OFFSET;
    temp_y = sin(theta)*range;
    theta = atan2(temp_y, temp_x);
    range = sqrt(pow(temp_x,2)+pow(temp_y,2));
    
    
    if(checkBoundaries(range,theta)){
      //publish
      //geometry_msgs::Pose2D laserPoint;
      geometry_msgs::PointStamped laserPoint;
      
      laserPoint.point.x = cur_pos.x + range*cos(theta+cur_pos.theta);
      laserPoint.point.y = cur_pos.y + range*sin(theta+cur_pos.theta);
      
      //add to average and filter point
      if(moving_avg_filter.size() < 10){
      	moving_avg_filter.push_back(laserPoint);
      }else{
      	moving_avg_filter[filter_index%9] = laserPoint;
      	filter_index++;
      }
      laserPoint.point.x =0;
      laserPoint.point.y =0;
      for(int i = 0; i < moving_avg_filter.size(); i++){
      	laserPoint.point.x += moving_avg_filter[i].point.x;
      	laserPoint.point.y += moving_avg_filter[i].point.y;
      }
      
      laserPoint.point.x /= moving_avg_filter.size();
      laserPoint.point.y /= moving_avg_filter.size();
      pole_pub.publish(laserPoint);
      
      break;
    }
  }
    
}
Exemplo n.º 15
0
void X11Graphics::drawBitmap( const GenericBitmap &rBitmap, int xSrc,
                              int ySrc, int xDest, int yDest, int width,
                              int height, bool blend )
{
    // check and adapt to source if needed
    if( !checkBoundaries( 0, 0, rBitmap.getWidth(), rBitmap.getHeight(),
                          xSrc, ySrc, width, height ) )
    {
        msg_Err( getIntf(), "empty source! pls, debug your skin" );
        return;
    }

    // check destination
    if( !checkBoundaries( 0, 0, m_width, m_height,
                          xDest, yDest, width, height ) )
    {
        msg_Err( getIntf(), "out of reach destination! pls, debug your skin" );
        return;
    }

    // Get a buffer on the image data
    uint8_t *pBmpData = rBitmap.getData();
    if( pBmpData == NULL )
    {
        // Nothing to draw
        return;
    }

    // Force pending XCopyArea to be sent to the X Server
    // before issuing an XGetImage.
    XSync( XDISPLAY, False );

    // Get the image from the pixmap
    XImage *pImage = XGetImage( XDISPLAY, m_pixmap, xDest, yDest, width,
                                height, AllPlanes, ZPixmap );
    if( pImage == NULL )
    {
        msg_Dbg( getIntf(), "XGetImage returned NULL" );
        return;
    }
    char *pData = pImage->data;

    // Get the padding of this image
    int pad = pImage->bitmap_pad >> 3;
    int shift = ( pad - ( (width * XPIXELSIZE) % pad ) ) % pad;

    // Mask for transparency
    Region mask = XCreateRegion();

    // Get a pointer on the right X11Display::makePixel method
    X11Display::MakePixelFunc_t makePixelFunc = ( blend ?
        m_rDisplay.getBlendPixel() : m_rDisplay.getPutPixel() );

    // Skip the first lines of the image
    pBmpData += 4 * ySrc * rBitmap.getWidth();

    // Copy the bitmap on the image and compute the mask
    for( int y = 0; y < height; y++ )
    {
        // Skip uninteresting bytes at the beginning of the line
        pBmpData += 4 * xSrc;
        // Flag to say whether the previous pixel on the line was visible
        bool wasVisible = false;
        // Beginning of the current visible segment on the line
        int visibleSegmentStart = 0;
        for( int x = 0; x < width; x++ )
        {
            uint8_t b = *(pBmpData++);
            uint8_t g = *(pBmpData++);
            uint8_t r = *(pBmpData++);
            uint8_t a = *(pBmpData++);
            // Draw the pixel
            (m_rDisplay.*makePixelFunc)( (uint8_t*)pData, r, g, b, a );
            pData += XPIXELSIZE;
            if( a > 0 )
            {
                // Pixel is visible
                if( ! wasVisible )
                {
                    // Beginning of a visible segment
                    visibleSegmentStart = x;
                }
                wasVisible = true;
            }
            else
            {
                // Pixel is transparent
                if( wasVisible )
                {
                    // End of a visible segment: add it to the mask
                    addHSegmentInRegion( mask, visibleSegmentStart, x, y );
                }
                wasVisible = false;
            }
        }
        if( wasVisible )
        {
            // End of a visible segment: add it to the mask
            addHSegmentInRegion( mask, visibleSegmentStart, width, y );
        }
        pData += shift;
        // Skip uninteresting bytes at the end of the line
        pBmpData += 4 * (rBitmap.getWidth() - width - xSrc);
    }

    // Apply the mask to the graphics context
    XOffsetRegion( mask, xDest, yDest );
    XSetRegion( XDISPLAY, m_gc, mask );
    // Copy the image on the pixmap
    XPutImage( XDISPLAY, m_pixmap, m_gc, pImage, 0, 0, xDest, yDest, width,
               height);
    XDestroyImage( pImage );

    // Add the bitmap mask to the global graphics mask
    Region newMask = XCreateRegion();
    XUnionRegion( mask, m_mask, newMask );
    XDestroyRegion( m_mask );
    m_mask = newMask;

    XDestroyRegion( mask );
}