예제 #1
0
//determines whether a poly intersects a circle
int PolyInCircle(const POLY * t, const CIRCLE * c)
{
//*
   int i;
   LINE l;
//*/

   if(!t || !c)
      return 0;

   if(PointInCircle(&t->p[0], c) || PointInCircle(&t->p[1], c) || PointInCircle(&t->p[2], c))
      return 1; //if any of the points of the polygon are within the circle, it intersects

//*
   for(i = 0; i < 3; i++)
   {
      l.a.x = t->p[i].x;
      l.a.y = t->p[i].y;
      l.b.x = t->p[(i + 1) % 3].x;
      l.b.y = t->p[(i + 1) % 3].y;

      if(LineInCircle_NoEndPtCheck(&l, c)) //check each line of the polygon to see if it's in the circle
         return 1;
   }
//*/

   return 0;
}
예제 #2
0
void FizzyWindow::OnMouseButton(gxbase::GLWindow::MouseButton button, bool down)
{
	if(button == gxbase::GLWindow::MouseButton::MBLeft)
	{
		if(down)
		{
			scn.mouseDown=true;
			float2 point(scn.mx, scn.my);

			vector<SimBody*> &objects = scn.objects;

			for(int i=4;i<objects.size();++i)
			{
				if(objects[i]->owner != SimBody::whoami) continue;
				if(PointInCircle(point, Circle(objects[i]->position, objects[i]->boundingCircleRadius)))
				{
					scn.jointedBody = objects[i];
					break;
				}
			}
		}
		else
		{
			scn.mouseDown=false;
			scn.springForce.zero();
			scn.jointedBody=0;
		}
	}
};
예제 #3
0
파일: map.c 프로젝트: Gilles86/afni
/*****
* Name: 		_XmHTMLGetImagemapAnchor
* Return Type: 	XmHTMLAnchor*
* Description:  checks whether the given coordinates lie somewhere within
*				the given imagemap.
* In: 
*	html:		XmHTMLWidget
*	x,y:		point coordinates, relative to upper-left corner of the
*				html widget
*	image:		current image data, required to make x and y coordinates
*				relative to upper-left corner of the image.
*	map:		imagemap to check
* Returns:
*	anchor data if successfull, NULL otherwise
*****/
XmHTMLAnchor*
_XmHTMLGetAnchorFromMap(XmHTMLWidget html, int x, int y,
	XmHTMLImage *image, XmHTMLImageMap *map)
{
	int xs, ys;
	mapArea *area, *def_area;
	XmHTMLAnchor *anchor = NULL;
	Boolean found = False;

	/* map coordinates to upperleft corner of image */
	xs = x + html->html.scroll_x - image->owner->x;
	ys = y + html->html.scroll_y - image->owner->y;

	_XmHTMLFullDebug(10, ("map.c: _XmHTMLGetAnchorFromMap, x = %i, y = %i, "
		"relative x = %i, relative y = %i\n", x, y, xs, ys));

	area = map->areas;
	def_area = NULL;

	/*
	* We test against found instead of anchor becoming non-NULL:
	* areas with the NOHREF attribute set don't have an anchor but
	* should be taken into account as well.
	*/
	while(area && !found)
	{
		switch(area->shape)
		{
			case MAP_RECT:
				if(PointInRect(xs, ys, area->coords))
				{
					anchor = area->anchor;
					found = True;
				}
				break;
			case MAP_CIRCLE:
				if(PointInCircle(xs, ys, area->coords[0], area->coords[1],
					area->coords[2]))
				{
					anchor = area->anchor;
					found = True;
				}
				break;
			case MAP_POLY:
				if(PointInPoly(xs, ys, area->region))
				{
					anchor = area->anchor;
					found = True;
				}
				break;
			/*
			* just save default area info; it's only needed if nothing
			* else matches.
			*/
			case MAP_DEFAULT:
				def_area = area;
				break;
		}
		area = area->next;
	}
	if(!found && def_area)
		anchor = def_area->anchor;

	_XmHTMLFullDebug(10, ("map.c: _XmHTMLGetAnchorFromMap, %s anchor found\n",
		(anchor ? "an" : "no")));

	return(anchor);
}
예제 #4
0
//performs clipping each frame
void Clipping(void)
{
   LIST * cur1;
   LIST * cur2;
   LIST * next;

   for(cur1 = g_asteroid_list; cur1; cur1 = next)
   {
      next = cur1->next;

      if(g_ships
         && !g_player.wait_time
         && (((ASTEROID *)cur1->d)->region & g_player.region)
         && PolyInCircle(&g_player.clip_poly, &(((ASTEROID *)cur1->d)->clip_circle))) //if the player hits the asteroid
      {
         PlayerHit();
         AsteroidHit(cur1, 0);
         continue;
      }

      for(cur2 = g_alien_list; cur2; cur2 = cur2->next)
      {
         if((((ASTEROID *)cur1->d)->region & ((ALIEN *)cur2->d)->region)
            && (PolyInCircle(&(((ALIEN *)cur2->d)->clip_poly/*s[0]*/), &(((ASTEROID *)cur1->d)->clip_circle))
               /*|| PolyInCircle(&(((ALIEN *)cur2->d)->clip_polys[1]), &(((ASTEROID *)cur1->d)->clip_circle))
               || PolyInCircle(&(((ALIEN *)cur2->d)->clip_polys[2]), &(((ASTEROID *)cur1->d)->clip_circle))*/))
         {
            AlienHit(cur2, 0);
            AsteroidHit(cur1, 0);
            break;
         }
      }
      if(cur2) //if we broke early from the loop
         continue;

      for(cur2 = g_shot_list; cur2; cur2 = cur2->next)
      {
         if((((ASTEROID *)cur1->d)->region & ((SHOT *)cur2->d)->region)
            && PointInCircle(&(((SHOT *)cur2->d)->pos), &(((ASTEROID *)cur1->d)->clip_circle))) //if any shot hits the asteroid
         {
            AsteroidHit(cur1, ((SHOT *)cur2->d)->player_owned);
            RemoveNode(cur2, &g_shot_list);
            break;
         }
      }
      if(cur2) //if we broke early from the loop
         continue;
   }

   for(cur1 = g_shot_list; cur1; cur1 = next)
   {
      next = cur1->next;

      if(!((SHOT *)cur1->d)->player_owned
         && g_ships
         && !g_player.wait_time
         && (g_player.region & ((SHOT *)cur1->d)->region)
         && PointInPoly(&(((SHOT *)cur1->d)->pos), &g_player.clip_poly)) //if the alien shot is inside player
      {
         RemoveNode(cur1, &g_shot_list);
         PlayerHit();
         continue;
      }

      if(((SHOT *)cur1->d)->player_owned)
      {
         for(cur2 = g_alien_list; cur2; cur2 = cur2->next)
         {
            if((((SHOT *)cur1->d)->region & ((ALIEN *)cur2->d)->region)
               && (PointInPoly(&(((SHOT *)cur1->d)->pos), &(((ALIEN *)cur2->d)->clip_poly/*s[0]*/))
                  /*|| PointInPoly(&(((SHOT *)cur1->d)->pos), &(((ALIEN *)cur2->d)->clip_polys[1]))
                  || PointInPoly(&(((SHOT *)cur1->d)->pos), &(((ALIEN *)cur2->d)->clip_polys[2]))*/))
            {
               RemoveNode(cur1, &g_shot_list);
               AlienHit(cur2, 1);
               break;
            }
         }
         if(cur2)
            continue;
      }

      for(cur2 = g_powerup_list; cur2; cur2 = cur2->next)
      {
         if((((SHOT *)cur1->d)->region & ((POWERUP *)cur2->d)->region)
            && PointInCircle(&(((SHOT *)cur1->d)->pos), &(((POWERUP *)cur2->d)->clip_circle)))
         {
            PowerupHit(cur2, ((SHOT *)cur1->d)->player_owned);
            RemoveNode(cur1, &g_shot_list);
            break;
         }
      }
      if(cur2)
         continue;
   }

   if(g_ships
      && !g_player.wait_time)
   {
      for(cur1 = g_alien_list; cur1; cur1 = cur1->next)
      {
         if((g_player.region & ((ALIEN *)cur1->d)->region)
            && (PolyInPoly(&g_player.clip_poly, &(((ALIEN *)cur1->d)->clip_poly/*s[0]*/))
               /*|| PolyInPoly(&g_player.clip_poly, &(((ALIEN *)cur1->d)->clip_polys[1]))
               || PolyInPoly(&g_player.clip_poly, &(((ALIEN *)cur1->d)->clip_polys[2]))*/))
         {
            PlayerHit();
            AlienHit(cur1, 0);
            break;
         }
      }
   }

   if(g_ships)
   {
      for(cur1 = g_powerup_list; cur1; cur1 = next)
      {
         next = cur1->next;

         if((g_player.region & ((POWERUP *)cur1->d)->region)
            && PolyInCircle(&g_player.clip_poly, &(((POWERUP *)cur1->d)->clip_circle)))
         {
            GetPowerup(cur1);
            continue;
         }
      }
   }
}