示例#1
0
bool Rock::CheckMove(Coordinate currentPosition, Coordinate movePosition, bool allowDoCornerStep){
	if (currentPosition.GetX() == movePosition.GetX() || currentPosition.GetY() == movePosition.GetY())
		return true;


	return false;
}
示例#2
0
/*
 * Das ist die Standart Bresenham-Algorithmus.
 * Die Lage der Punkte wird nicht geprüft, sondern davon ausgegangen, dass dies schon passiert ist.
 * Die Angabe des Orthanden und der Basis dient der Translation der Koordinaten.
 */
void PrimitiveLine::DrawLineBresenham(ImageBase *img, const Coordinate &to,const char orthant, const Coordinate &offset) const {
    int deltaX = to.GetX();
    int deltaY = to.GetY();
    int e= 2*deltaY - deltaX;
    int x = 0;
    int y = 0;
    Coordinate coord;
    while( x <= deltaX ) {
        /* Ruecktransformation der Koordinaten */
        coord = DrawLineTranslateCoordinates(offset,x,y,orthant);

        /* Pixel zeichnen (wenn Koordinaten im Bild) */
        if(coord.GetX() >= 0 && (unsigned)coord.GetX() < img->GetWidth()
                && coord.GetY() >= 0 && (unsigned)coord.GetY() < img->GetHeight()) {
            img->SetPixel(coord.GetX(),coord.GetY(),0,GetColor().GetR());
            img->SetPixel(coord.GetX(),coord.GetY(),1,GetColor().GetG());
            img->SetPixel(coord.GetX(),coord.GetY(),2,GetColor().GetB());
        }

        /* Gemaess Bresenham-Algorithmus bestimmen, ob das Pixel rechts vom
         * vorigen Pixel oder rechtsoben vom vorigen Pixel gesetzt werden muss */
        if( e > 0 ) {
            y++;
            e += 2*(deltaY - deltaX);
        } else {
            e += 2*deltaY;
        }
        x++;
    }
}
示例#3
0
文件: hud.cpp 项目: moses7/Epiar
void Radar::WorldToBlip( Coordinate &w, Coordinate &b ) {
	Player *p = Player::Instance();
	Coordinate player = p->GetWorldPosition();
	
	b.SetX( ( ( w.GetX() - player.GetX() ) / float(visibility) ) * ( RADAR_WIDTH / 2.0 ) );
	b.SetY( ( ( w.GetY() - player.GetY() ) / float(visibility) ) * ( RADAR_HEIGHT / 2.0 ) );
}
示例#4
0
bool QuadTree::Contains(Coordinate point){
	bool insideLeftBorder = (center.GetX()-radius) <= point.GetX();
	bool insideRightBorder = (center.GetX()+radius) >= point.GetX();
	bool insideTopBorder = (center.GetY()+radius) >= point.GetY();
	bool insideBottomBorder = (center.GetY()-radius) <= point.GetY();
	return insideLeftBorder && insideRightBorder && insideTopBorder && insideBottomBorder;
}
示例#5
0
文件: ai.cpp 项目: bellinat0r/Epiar
/**\brief checks if a potential target is within targeting range
 *
 */
bool AI::InRange(Coordinate a, Coordinate b){
	//printf("InRange check\n");
	int x=a.GetX() - b.GetX();
	int y=a.GetY() - b.GetY();
	//printf("finished InRange check\n");
	return(x*x + y*y <=COMBAT_RANGE_SQUARED);
}
示例#6
0
void PrimitiveBox::Init(const Coordinate &c1, const Coordinate &c2, const Color &c) {

	points_.clear();

	// construct rectangle
	points_.push_back(c1);
	points_.push_back(Coordinate(c1.GetX(), c2.GetY()));
	points_.push_back(c2);
	points_.push_back(Coordinate(c2.GetX(), c1.GetY()));
	points_.push_back(c1);
	SetColor(c);
}
示例#7
0
文件: Segmentation.cpp 项目: fry/emiv
int Segmentation::GetFreemanCode(const int label, const Coordinate &firstPoint, std::vector<int> &freemanCode) {
  int cx = firstPoint.GetX();
  int cy = firstPoint.GetY();
  
  const int width = labelImage_.GetWidth();
  const int height = labelImage_.GetHeight();
  
  const Color color = Color::red();
  
  // initial direction is south
  int cb = 6;
  // continue until we're at the starting pixel again
  while (true) {
    int ck, dx, dy;
    // test pixels from right to left in the general direction
    for (ck = cb - 1; ck <= cb + 1; ck++) {
      // translate freeman code to direction and apply it
      get_fm(ck, dx, dy);
      const int px = cx + dx;
      const int py = cy + dy;
      // ensure bounds
      if (px >= 0 && py >= 0 && px <= width && py <= height) {
        // if a pixel matches the label, move to that pixel and abort
        if (labelImage_.GetPixel(px, py, 0) == label) {
          cx = px; cy = py;
          break;
        }
      }
    }
    
    ck = fmc(ck);
    
    if (ck == cb || ck == fmc(cb + 1)) {
      // matched pixel is forward or right, nothing needs to change
      freemanCode.push_back(ck);
    } else if (ck == fmc(cb - 1)) {
      // pixel is left, turn left in addition to marking this pixel
      cb -= 2;
      freemanCode.push_back(ck);
    } else {
      // no pixel found, turn right
      cb += 2;
    }
    
    cb = ((cb + 8) % 8);
    
    // abort if we reached the start
    if (cx == firstPoint.GetX() && cy == firstPoint.GetY())
      break;
  }
}
示例#8
0
bool Pown::CheckMove(Coordinate currentPosition, Coordinate movePosition, bool allowDoCornerStep){
	
	if (allowDoCornerStep)
	{
		if (abs(currentPosition.GetY() - movePosition.GetY()) == SQUARESIZE && abs(currentPosition.GetX() - movePosition.GetX()) == SQUARESIZE)
			return true;
	}
	if (currentPosition.GetX() == movePosition.GetX())
	{
		return isMoved ? (abs(currentPosition.GetY() - movePosition.GetY()) == SQUARESIZE) : (abs(currentPosition.GetY() - movePosition.GetY()) <= 2 * SQUARESIZE);
	}

	return false;
}
示例#9
0
/** Adjust the Edges based on the locations of the populated QuadTrees
 */
void SpriteManager::AdjustBoundaries()
{
	Coordinate c;
	map<Coordinate,QuadTree*>::iterator iter;

	northEdge = southEdge = eastEdge = westEdge = 0;
	for ( iter = trees.begin(); iter != trees.end(); ++iter ) { 
		c = iter->first;
		if( c.GetY() > northEdge) northEdge = c.GetY();
		if( c.GetY() < southEdge) southEdge = c.GetY();
		if( c.GetX() > eastEdge)  eastEdge  = c.GetX();
		if( c.GetX() < westEdge)  westEdge  = c.GetX();
	}
}
示例#10
0
void QuadTree::Draw(Coordinate root){
	// The QuadTree is scaled so that it always fits on the screen.
	float scale = (Video::GetHalfHeight() > Video::GetHalfWidth() ?
		static_cast<float>(Video::GetHalfWidth()) : static_cast<float>(Video::GetHalfHeight()) -5);
	float r = scale* radius / QUADRANTSIZE;
	float x = (scale* static_cast<float>((center-root).GetX()) / QUADRANTSIZE)
		+ static_cast<float>(Video::GetHalfWidth())  -r;
	float y = (scale* static_cast<float>((center-root).GetY()) / QUADRANTSIZE)
		+ static_cast<float>(Video::GetHalfHeight()) -r;
	Video::DrawRect( static_cast<int>(x),static_cast<int>(y),
		static_cast<int>(2*r),static_cast<int>(2*r), 0,255.f,0.f, .1f);

	if(!isLeaf){ // Node
		for(int t=0;t<4;t++){
			if(NULL != (subtrees[t])) subtrees[t]->Draw(root);
		}
	} else { // Leaf
		list<Sprite *>::iterator i;
		for( i = objects->begin(); i != objects->end(); ++i ) {
			Coordinate pos = (*i)->GetWorldPosition() - root;
			int posx = static_cast<int>((scale* (float)pos.GetX() / QUADRANTSIZE) + (float)Video::GetHalfWidth());
			int posy = static_cast<int>((scale* (float)pos.GetY() / QUADRANTSIZE) + (float)Video::GetHalfHeight());
			Color col = (*i)->GetRadarColor();
			// The 17 is here because it looks nice.  I can't explain why.
			Video::DrawCircle( posx, posy, static_cast<int>(17.f*(*i)->GetRadarSize()/scale),2, col.r,col.g,col.b );
		}
	}
}
示例#11
0
文件: testFeatures.cpp 项目: fry/emiv
void test_image(const std::string name) {
  std::cout << name.substr(name.find_last_of("/") + 1, std::string::npos) << ":" << std::endl;
  Image image;
  image.LoadPPM(name);
  image.SetColorModel(ImageBase::cm_Grey);
  
  const int label = 255;
  Segmentation seg(image);
  Coordinate center; 
  int area;
  seg.GetCenterAndArea(label, center, area);
  std::cout << "  Object has its center at: " << center.GetX() << "," << center.GetY() << " with area: " << area << " pixel." << std::endl;
  
  Coordinate topleft(seg.GetLabelTopLeft(label));
  std::vector<int> fmc;
  seg.GetFreemanCode(label, topleft, fmc);

  const float circumference = seg.GetCircumference(fmc);
  const float roundness = seg.GetRoundness(area, circumference);
  std::cout << "  Object has roundness of " << roundness << std::endl;
  
  if (rint(roundness) >= 16) {
    std::cout << "  Object is a rectangle" << std::endl;
  } else {
    std::cout << "  Object is a circle" << std::endl;
  }
}
示例#12
0
文件: hud.cpp 项目: cthielen/epiar
/**\brief Draws the target.
 */
void Hud::DrawTarget( SpriteManager* sprites ) {
	Sprite* target = sprites->GetSpriteByID( targetID );

	if(target != NULL) {
		int edge = (target->GetImage())->GetWidth() / 6;
		Coordinate targetScreenPosition = target->GetScreenPosition();
		if(edge > 25) edge = 25;
		int x = targetScreenPosition.GetX();
		int y = targetScreenPosition.GetY();
		int r = target->GetRadarSize();
		Color c = target->GetRadarColor();

		if( (Timer::GetTicks() - timeTargeted) < OPTION(Uint32, "options/timing/target-zoom")) {
			r += Video::GetHalfHeight() - Video::GetHalfHeight()*(Timer::GetTicks()-timeTargeted)/OPTION(Uint32,"options/timing/target-zoom");
			for( int i = 0; i < RETICLE_BLUR; i++ ) {
				c = c * .9f;
				edge += 3;
				r *= 1.1f;
				Video::DrawTarget(x,y,r,r,edge,c.r,c.g,c.b);
			}
		} else {
			Video::DrawTarget(x,y,r,r,edge,c.r,c.g,c.b);
		}
	}
}
inline int Coordinate::operator<(const Coordinate &rhs) const
{
    if (x == rhs.GetX())
        return y < rhs.GetY();
    else
        return x < rhs.GetX();
}
示例#14
0
QuadPosition QuadTree::SubTreeThatContains(Coordinate point){
	bool rightOfCenter = point.GetX() > center.GetX();
	bool aboveCenter = point.GetY() > center.GetY();
	int pos =  (aboveCenter?0:2) | (rightOfCenter?1:0);
	assert(this->Contains(point)); // Ensure that this point is in this region
	return QuadPosition(pos);
}
示例#15
0
bool Bishop::CheckMove(Coordinate currentPosition, Coordinate movePosition, bool allowDoCornerStep){
	
	if (abs(currentPosition.GetX() - movePosition.GetX()) == abs(currentPosition.GetY() - movePosition.GetY()))
		return true;


	return false;
}
示例#16
0
/**\brief Returns QuadTree center.
 * \param point Coordinate
 * \return Coordinate of centerpointer
 */
Coordinate SpriteManager::GetQuadrantCenter(Coordinate point){
	// Figure out where the new Tree should go.
	// Quadrants are tiled adjacent to the central Quadrant centered at (0,0).
	double cx, cy;
	cx = float(floor( (point.GetX()+QUADRANTSIZE)/(QUADRANTSIZE*2.0f)) * QUADRANTSIZE*2.f);
	cy = float(floor( (point.GetY()+QUADRANTSIZE)/(QUADRANTSIZE*2.0f)) * QUADRANTSIZE*2.f);
	return Coordinate(cx,cy);
}
示例#17
0
/**\brief Get the min/max planet positions. Useful when generating traffic.
 * \note Returns the values through the pointer arguments.
 */
void SpriteManager::GetBoundaries(float *north, float *south, float *east, float *west)
{
	*north = *south = *east = *west = 0;

	list<Sprite *>::iterator i;

	for( i = spritelist->begin(); i != spritelist->end(); ++i ) {
		Sprite *s = (*i);

		if( s->GetDrawOrder() == DRAW_ORDER_PLANET ) {
			Coordinate c = s->GetWorldPosition();

			if(c.GetY() < *north) *north = c.GetY();
			if(c.GetY() > *south) *south = c.GetY();
			if(c.GetX() < *west) *west = c.GetX();
			if(c.GetX() > *east) *east = c.GetX();
		}
	}
}
示例#18
0
void PrimitivePoint::Draw(ImageBase *img) const {
	
	Coordinate c = points_.front();
	int x = c.GetX();
	int y = c.GetY();

	if(x >= 0 && y >= 0 && x < img->GetWidth() && y < img->GetHeight()) {
		img->SetPixel(x, y, 0, color_.GetR());
		img->SetPixel(x, y, 1, color_.GetG());
		img->SetPixel(x, y, 2, color_.GetB());
	}
}
示例#19
0
文件: hud.cpp 项目: cthielen/epiar
/**\brief Draws the radar.
 */
void Radar::Draw( Camera* camera, SpriteManager* sprites ) {
	short int radar_mid_x = RADAR_MIDDLE_X + Video::GetWidth() - 129;
	short int radar_mid_y = RADAR_MIDDLE_Y + 5;
	int radarSize;
	Coordinate focus = camera->GetFocusCoordinate();

	/*if(largeMode) {
		if( visibility <= QUADRANTSIZE )
		{
			Map* map = (Map*)UI::Search( "/Map/" );
			assert(map); // large mode should only be on when there is a map.
			if(map) {
				map->SetCenter( focus );
				map->SetScale( 300.0 / (2*visibility) );
			}
		}
		return;
	}*/

	list<Sprite*> *spriteList = sprites->GetSpritesNear(camera->GetFocusCoordinate(), (float)visibility);
	for( list<Sprite*>::const_iterator iter = spriteList->begin(); iter != spriteList->end(); iter++)
	{
		Coordinate blip;
		Sprite *sprite = *iter;

		// Calculate the blip coordinate for this sprite
		Coordinate wpos = sprite->GetWorldPosition();
		WorldToBlip( focus, wpos, blip );

		// Use the OpenGL Crop Rectangle to ensure that the blip is on the radar

		/* Convert to screen coords */
		blip.SetX( blip.GetX() + radar_mid_x );
		blip.SetY( blip.GetY() + radar_mid_y );

		radarSize = int((sprite->GetRadarSize() / float(visibility)) * (RADAR_HEIGHT / 4.0));

		if( radarSize >= 1 ) {
			if(sprite->GetID() == Hud::GetTarget() && Timer::GetTicks() % 1000 < 100)
				Video::DrawCircle( blip, radarSize, 2, WHITE );
			else
				Video::DrawCircle( blip, radarSize, 1, sprite->GetRadarColor() );
		} else {
			if(sprite->GetID() == Hud::GetTarget() && Timer::GetTicks() % 1000 < 100)
				Video::DrawCircle( blip, 1, 2, WHITE );
			else
				Video::DrawPoint( blip, sprite->GetRadarColor() );
		}
	}

	delete spriteList;
}
示例#20
0
/*
 * Diese Funktion bereitet die Parameter für die Bresenhamfunktion vor.
 */
void PrimitiveLine::DrawLine(ImageBase *img, const Coordinate &c1, const Coordinate &c2) const {
    int dX = (c2.GetX() - c1.GetX());
    int dY = (c2.GetY() - c1.GetY());
    char orthant = 0;
    /* Transformationen bestimmen und Informationen darueber fuer die Ruecktransformation
     * in orthant speichern */
    if( dY < 0 ) {
        orthant |= 4;
        dY = -dY;
    }
    if( dX < 0 ) {
        orthant |= 2;
        dX = -dX;
    }
    if( dY > dX ) {
        orthant |= 1;
        int z=dX;
        dX = dY;
        dY = z;
    }
    DrawLineBresenham(img,Coordinate(dX,dY),orthant,c1);
}
示例#21
0
/* Fuehrt die Ruecktransformation von durch den Bresenham-Algorithmus bestimmten Koordinaten durch */
Coordinate PrimitiveLine::DrawLineTranslateCoordinates(const Coordinate &base, const int x , const int y ,const char orthant) const {
    Coordinate result(x,y);

    if( orthant & 1 ) {
        result.SetX(y);
        result.SetY(x);
    }
    if( orthant & 2 ) {
        result.SetX(-result.GetX());
    }
    if( orthant & 4 ) {
        result.SetY(-result.GetY());
    }
    result.SetX( result.GetX() + base.GetX() );
    result.SetY( result.GetY() + base.GetY() );
    return result;
}
示例#22
0
文件: Segmentation.cpp 项目: fry/emiv
void Segmentation::DrawContourFreeman(const Coordinate& firstPoint, const std::vector<int> &freemanCode, 
    const Color color, Image &targetImage) {
  int cx = firstPoint.GetX();
  int cy = firstPoint.GetY();
  
  std::vector<int>::const_iterator iter, end;
  end = freemanCode.end();
  
  // follow the contour code and fill the pixels with the specified color
  for (iter = freemanCode.begin(); iter != end; ++iter) {
    int dx, dy;
    get_fm(*iter, dx, dy);
    cx += dx; cy += dy;
    
    targetImage.SetPixel(cx, cy, 0, color.GetRed());
    targetImage.SetPixel(cx, cy, 1, color.GetGreen());
    targetImage.SetPixel(cx, cy, 2, color.GetBlue());
  }
}
示例#23
0
void print_area_center(Segmentation& seg, const std::string& name, int label, Image& output) {
  int area; Coordinate center;
  seg.GetCenterAndArea(label, center, area);
  std::cout << name << " is located at " << center.GetX() << ", " << center.GetY() << " with area " << area << std::endl;
  
  Coordinate point(seg.GetLabelTopLeft(label));
  std::vector<int> freeman_code;
  seg.GetFreemanCode(label, point, freeman_code);
  seg.DrawContourFreeman(point, freeman_code, Color::red(), output);

  const float circumference = seg.GetCircumference(freeman_code);
  const float roundness = seg.GetRoundness(area, circumference);
  std::cout << "  Object has roundness of " << roundness << std::endl;
  
  if (rint(roundness) >= 45) {
    std::cout << "  Object is a tree" << std::endl;
  } else if (rint(roundness) >= 16) {
    std::cout << "  Object is a rectangle" << std::endl;
  } else {
    std::cout << "  Object is a circle" << std::endl;
  }
}
示例#24
0
/**\brief Draws the radar.
 */
void Radar::Draw( void ) {
	short int radar_mid_x = RADAR_MIDDLE_X + Video::GetWidth() - 129;
	short int radar_mid_y = RADAR_MIDDLE_Y + 5;
	int radarSize;

	list<Sprite*> *spriteList = SpriteManager::Instance()->GetSpritesNear(Camera::Instance()->GetFocusCoordinate(), (float)visibility);
	for( list<Sprite*>::const_iterator iter = spriteList->begin(); iter != spriteList->end(); iter++)
	{
		Coordinate blip;
		Sprite *sprite = *iter;
		
		//if( sprite->GetDrawOrder() == DRAW_ORDER_PLAYER ) continue;
		
		// Calculate the blip coordinate for this sprite
		Coordinate wpos = sprite->GetWorldPosition();
		WorldToBlip( wpos, blip );
		
		// Use the OpenGL Crop Rectangle to ensure that the blip is on the radar
		
		/* Convert to screen coords */
		blip.SetX( blip.GetX() + radar_mid_x );
		blip.SetY( blip.GetY() + radar_mid_y );
		
		radarSize = int((sprite->GetRadarSize() / float(visibility)) * (RADAR_HEIGHT/4.0));
		
		if( radarSize >= 1 ) {
			if(sprite->GetID() == Hud::GetTarget() && Timer::GetTicks() % 1000 < 100)
				Video::DrawCircle( blip, radarSize, 2, WHITE );
			else
				Video::DrawCircle( blip, radarSize, 1, sprite->GetRadarColor() );
		} else {
			if(sprite->GetID() == Hud::GetTarget() && Timer::GetTicks() % 1000 < 100)
				Video::DrawCircle( blip, 1, 2, WHITE );
			else
				Video::DrawPoint( blip, sprite->GetRadarColor() );
		}
	}
	delete spriteList;
}
示例#25
0
文件: hud.cpp 项目: akollias/Epiar
/**\brief Draws the radar.
 */
void Radar::Draw( void ) {
	short int radar_mid_x = RADAR_MIDDLE_X + Video::GetWidth() - 129;
	short int radar_mid_y = RADAR_MIDDLE_Y + 5;
	int radarSize;

	list<Sprite*> *spriteList = SpriteManager::Instance()->GetSpritesNear(Camera::Instance()->GetFocusCoordinate(), (float)visibility);
	for( list<Sprite*>::const_iterator iter = spriteList->begin(); iter != spriteList->end(); iter++)
	{
		Coordinate blip;
		Sprite *sprite = *iter;
		
		//if( sprite->GetDrawOrder() == DRAW_ORDER_PLAYER ) continue;
		
		// Calculate the blip coordinate for this sprite
		Coordinate wpos = sprite->GetWorldPosition();
		WorldToBlip( wpos, blip );
		
		if( blip.ViolatesBoundary( -(RADAR_HEIGHT / 2.0), (RADAR_WIDTH / 2.0), (RADAR_HEIGHT / 2.0), -(RADAR_WIDTH / 2.0) ) == false ) {
			/* blip is on the radar */
			
			/* Convert to screen coords */
			blip.SetX( blip.GetX() + radar_mid_x );
			blip.SetY( blip.GetY() + radar_mid_y );

			radarSize = int((sprite->GetRadarSize() / float(visibility)) * (RADAR_HEIGHT/4.0));
			
			
			if( radarSize >= 1 ) {
				Video::DrawCircle( blip, radarSize, 1, sprite->GetRadarColor() );
			} else {
				Video::DrawPoint( blip, sprite->GetRadarColor() );
			}
		}
	}
	delete spriteList;
}
示例#26
0
/**\brief Gets the radar position based on world coordinate
 * \param w Pointer to world coordinate
 * \retval b Pointer to radar coordinate
 */
void Radar::WorldToBlip( Coordinate &w, Coordinate &b ) {
	Coordinate focus = Camera::Instance()->GetFocusCoordinate();
	
	b.SetX( ( ( w.GetX() - focus.GetX() ) / float(visibility) ) * ( RADAR_WIDTH / 2.0 ) );
	b.SetY( ( ( w.GetY() - focus.GetY() ) / float(visibility) ) * ( RADAR_HEIGHT / 2.0 ) );
}
示例#27
0
文件: video.cpp 项目: Maka7879/Epiar
/**\brief Draws a circle with Color
 */
void Video::DrawCircle( Coordinate c, int radius, float line_width, Color col, float a) {
	DrawCircle( (int)c.GetX(), (int)c.GetY(), radius, line_width, col.r, col.g, col.b, a);
}
示例#28
0
文件: video.cpp 项目: Maka7879/Epiar
/**\brief Draws a circle.
 */
void Video::DrawCircle( Coordinate c, int radius, float line_width, float r, float g, float b, float a) {
	DrawCircle( (int)c.GetX(), (int)c.GetY(), radius, line_width, r, g, b, a );
}
示例#29
0
文件: video.cpp 项目: Maka7879/Epiar
/**\brief Draw a point using Coordinate and Color.
 */
void Video::DrawPoint( Coordinate c, Color col ) {
	DrawPoint( (int)c.GetX(), (int)c.GetY(), col.r, col.g, col.b );
}
示例#30
0
文件: hud.cpp 项目: cthielen/epiar
/**\brief Gets the radar position based on world coordinate
 * \param w Pointer to world coordinate
 * \retval b Pointer to radar coordinate
 */
void Radar::WorldToBlip( Coordinate focus, Coordinate &w, Coordinate &b ) {
	b.SetX( ( ( w.GetX() - focus.GetX() ) / float(visibility) ) * ( RADAR_WIDTH / 2.0 ) );
	b.SetY( ( ( w.GetY() - focus.GetY() ) / float(visibility) ) * ( RADAR_HEIGHT / 2.0 ) );
}