예제 #1
0
/**
 * Draws a single tile onto the screen
 * Also changes the status from VISIBLE to 
 */
void drawtile(struct tile* tile)
{
	if(tile->texture.data == NULL)
		return;
		
	struct point topleft = world2screen(tile->left, tile->top);
	struct point bottomright = world2screen(tile->right, tile->bottom);
	float width = bottomright.x - topleft.x;
	float height = bottomright.y - topleft.y;
	
	DrawImg(topleft.x, topleft.y, width, height, tile->texture, tile->opacity);
	
	//Draw extra copies of this tile to the left and to the right
	//Should only happed if the view is so zoomed out that the world can be seen multiple times
	
	//Draw copies to the left
	float extratilesx = topleft.x - world_width;
	while(extratilesx + width > 0)
	{
		DrawImg(extratilesx, topleft.y, width, height, tile->texture, tile->opacity);
		extratilesx -= world_width;
	}
	
	//Draw copies to the right
	extratilesx = topleft.x + world_width;
	while(extratilesx < SCREEN_WIDTH) {
		DrawImg(extratilesx, topleft.y, width, height, tile->texture, tile->opacity);
		extratilesx += world_width;
	}
}
예제 #2
0
 bool VisObj::select_vertex(const CGLA::Vec2i& pos)
 {
     float d;
     if(depth_pick(pos[0], pos[1], d))
     {
         Vec3d c;
         float r;
         bsphere(mani, c, r);
         VertexID closest = InvalidVertexID;
         double min_dist = DBL_MAX;
         for(auto vid : mani.vertices())
         {
             Vec3d wp = world2screen(mani.pos(vid));
             if(sqr_length(Vec2d(wp[0],wp[1])-Vec2d(pos))<100)
             {
                 double dist = sqr_length(screen2world(pos[0], pos[1], d)-mani.pos(vid));
                 if(dist < min_dist)
                 {
                     min_dist = dist;
                     closest = vid;
                 }
             }
         }
         if(closest != InvalidVertexID) {
             vertex_selection.resize(mani.allocated_vertices(),0);
             vertex_selection[closest] = !vertex_selection[closest];
             active_selection = true;
             post_create_display_list();
             return true;
         }
     }
     return false;
     
 }