示例#1
0
static void	curve(const POINT& p0, const POINT& p1, const POINT& p2)
// Recursive routine to generate bezier curve within tolerance.
{
#ifdef SWF_DEBUG
	static int	recursion_count = 0;
	recursion_count++;
	if (recursion_count > 256)
		SWF_ASSERT(0);	// probably a bug!
#endif//SWF_DEBUG

	// Midpoint on line between two endpoints.
	POINT mid = (p0 + p2) * 0.5f;
	// Midpoint on the curve.
	POINT sample = (mid + p1) * 0.5f;

	mid -= sample;
	if (mid.magnitude() < SWF::curve_error_tolerance) {
		add_line_segment(p2);
	} else {
		// Error is too large; subdivide.
		curve(p0,  (p0 + p1) * 0.5f, sample);
		curve(sample, (p1 + p2) * 0.5f, p2);
	}

#ifdef SWF_DEBUG
	recursion_count--;
#endif//SWF_DEBUG
}
示例#2
0
void main()
{
	char cKey = 0;
	Object stateMap[gStageWidth * gStageHeight] = {};
	POINT tower = { 9, 9, 5 };
	POINT enemy = { 2, 2, 0 };

	while (cKey != 27)
	{
		drowingGuide();

		initObject(&tower, &enemy, stateMap);

		if (tower.isinRange(&enemy))
		{
			printf("발사!\n");
		}
		
		// 입력받은 키값을 key변수에 대입
		cKey = getch();
		if (_kbhit())
		{
			cKey = getch();
			enemyUpdate(cKey, &enemy, stateMap);
		}


		system("cls");
	}
}
示例#3
0
	void get() {
		p1.get();
		p2.get();
		p3.get();
		if (p2 < p1) swap(p1, p2);
		if (p3 < p2) swap(p2, p3);
		if (p2 < p1) swap(p1, p2);
	}
示例#4
0
int DirToMask(POINT dir)
{
    return
    (dir.imag()==+1)?1:
    (dir.imag()==-1)?2:
    (dir.real()==-1)?4:
    (dir.real()==+1)?8:
    0;
}
示例#5
0
文件: gl_solids.cpp 项目: harishl/bap
POINT centroid(const list<POINT>& L)
{
  POINT pi;
  NT x(0), y(0), z(0);
  
  forall(pi,L){
    x = x + pi.xcoord();
    y = y + pi.ycoord();
    z = z + pi.zcoord();
  }
示例#6
0
文件: gl_solids.cpp 项目: harishl/bap
POINT centroid(const POINT& p1, const POINT& p2, const POINT& p3)
{
  NT x = p1.xcoord() + p2.xcoord() + p3.xcoord();
  NT y = p1.ycoord() + p2.ycoord() + p3.ycoord();
  NT z = p1.zcoord() + p2.zcoord() + p3.zcoord();
  return POINT(x,y,z);
}
示例#7
0
void Bezier<POINT>::TVec( const float t, POINT &point) const
{
    XTRACE();
    float t2 = 2*t;
    float tt3 = 3*t*t;

    for( int d=0; d<point.dimension(); d++)
    {
	point.set(d, pd[d][1] + t2*pd[d][2] + tt3*pd[d][3]);
    }
}
示例#8
0
void Bezier<POINT>::Pos( const float t, POINT &point) const
{
    XTRACE();
    float tt = t*t;
    float ttt = t*tt;

    for( int d=0; d<point.dimension(); d++)
    {
	point.set(d, pd[d][0] + t*pd[d][1] + tt*pd[d][2] + ttt*pd[d][3]);
    }
}
示例#9
0
int main(){
	POINT *p;
	POINT ob1(10, 20);
	p = &ob1;
	p->PutData();

	LINE ob2(50, 60, 70, 80);
	p = &ob2;
	p->PutData();

	return 0;
}
示例#10
0
bool circle_intersect(POINT &a, POINT &b, POINT &p1, POINT &p2) {
	double d = sqr(a.x - b.x) + sqr(a.y - b.y), sina, cosa;
	if (d >= sqr(a.r + b.r)) return false;
	if (d <= sqr(a.r - b.r)) return false;
	d = sqrt(d);
	cosa = (sqr(a.r) + sqr(d) - sqr(b.r)) / 2 / d / a.r;
	sina = sqrt(1 - cosa * cosa);
	POINT v = b - a;
	v = v.to_length(a.r);
	p1 = rotate(v, sina, cosa), p2 = rotate(v, -sina, cosa);
	p1 = a + p1, p2 = a + p2;
	return true;
}
示例#11
0
void Bezier<POINT>::PVec( const float t, POINT &point) const
{
    XTRACE();
    float t2 = 2*t;
    float tt3 = 3*t*t;

    if( point.dimension() != 2) return;

    //vector perpendicular to tangent at t
    // x/y -> -(y/x)
    point.set(1,  pd[0][1] + t2*pd[0][2] + tt3*pd[0][3]);
    point.set(0,-(pd[1][1] + t2*pd[1][2] + tt3*pd[1][3]));
}
示例#12
0
文件: util.hpp 项目: WilstonOreo/GEx
      bool lineSegmentIntersection(
          const POINT& _p1, 
          const POINT& _p2, 
          const POINT& _p3, 
          const POINT& _p4, 
          POINT& _point)
      {
        typedef typename POINT::Scalar scalar_type;

        // Store the values for fast access and easy
        // equations-to-code conversion
        scalar_type x1 = _p1.x(), x2 = _p2.x(), x3 = _p3.x(), x4 = _p4.x();
        scalar_type y1 = _p1.y(), y2 = _p2.y(), y3 = _p3.y(), y4 = _p4.y();
        scalar_type d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
        // If d is zero, there is no intersection
        if (d == 0) return false;
 
        // Get the x and y
        scalar_type pre = (x1*y2 - y1*x2), post = (x3*y4 - y3*x4);

        scalar_type x = ( pre * (x3 - x4) - (x1 - x2) * post ) / d;
        scalar_type y = ( pre * (y3 - y4) - (y1 - y2) * post ) / d;
 
        // Check if the x and y coordinates are within both lines
        if ( x < std::min(x1, x2) || x > std::max(x1, x2) ||
             x < std::min(x3, x4) || x > std::max(x3, x4) ) return false;
        if ( y < std::min(y1, y2) || y > std::max(y1, y2) ||
             y < std::min(y3, y4) || y > std::max(y3, y4) ) return false;
 
        // Return the point of intersection
        _point(0) = x; _point(1) = y;
        return true;
      }
示例#13
0
double gettime(POINT ts[4], POINT tm[4]) {
	int i, j;
	double ans = INF;
	POINT v = tm[3] - ts[3], uv;
	uv = v;
	uv.unit();
	for (i = 0; i < 3; i++) {
		for (j = 0; j < 3; j++) {
			POINT p1, p2, p3, p4, it;
			p1 = tm[i], p2 = tm[i] + v, p3 = ts[j], p4 = ts[(j + 1) % 3];
			if (!line_inter(p1, p2, p3, p4, it)) continue;
			double minx = min(p3.x, p4.x), maxx = max(p3.x, p4.x);
			double miny = min(p3.y, p4.y), maxy = max(p3.y, p4.y);
			if (it.x < minx || it.x > maxx || it.y < miny || it.y > maxy) continue;
			if (sgn(dot(p1, p2, it)) < 0) continue;
			ans = min(ans, dis(p1, it) / v.abs());
		}
	}
	return ans;
}
示例#14
0
文件: util.hpp 项目: WilstonOreo/GEx
 typename POINT::Scalar determinant(
   const POINT& _a,
   const POINT& _b,
   const POINT& _c)
 {
   return (_b.x() * _c.y() + _a.x() * _b.y() + _a.y()*_c.x()) -
          (_a.y() * _b.x() + _b.y() * _c.x() + _a.x()*_c.y());
 }
 static inline
 double inner (const POINT &a, const POINT &b) {
     return CGAL::to_double (a.x()*b.x() + a.y()*b.y() + a.z()*b.z());
 }
示例#16
0
void CButtonXP::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	//从lpDrawItemStruct获取控件的相关信息
	CRect rect =  lpDrawItemStruct->rcItem;
	CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	int nSaveDC = pDC->SaveDC();
	UINT state = lpDrawItemStruct->itemState;
	POINT pt ;
	TCHAR strText[MAX_PATH + 1];
	::GetWindowText(m_hWnd, strText, MAX_PATH);

	//画按钮的外边框,它是一个半径为5的圆角矩形
	pt.x = 5;
	pt.y = 5;
	CPen* hOldPen = pDC->SelectObject(&m_BoundryPen);
	pDC->RoundRect(&rect, pt);

	//获取按钮的状态
	if (state & ODS_FOCUS)
	{
		m_bFocus = TRUE;
		m_bSelected = TRUE;
	}
	else
	{
		m_bFocus = FALSE;
		m_bSelected = FALSE;
	}

	if (state & ODS_SELECTED || state & ODS_DEFAULT)
	{
		m_bFocus = TRUE;
	}

	pDC->SelectObject(hOldPen);

	rect.DeflateRect(CSize(GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE)));

	//根据按钮的状态填充按钮的底色
	CBrush* pOldBrush;
	if (m_bOver)
	{
		pOldBrush = pDC->SelectObject(&m_FillActive);
		DoGradientFill(pDC, &rect);
	}
	else
	{
		pOldBrush = pDC->SelectObject(&m_FillInactive);
		DoGradientFill(pDC, &rect);
	}

	//根据按钮的状态绘制内边框
	if (m_bOver || m_bSelected)
		DrawInsideBorder(pDC, &rect);

	pDC->SelectObject(pOldBrush);

	//显示按钮的文本
	if (strText!=NULL)
	{
		CFont* hFont = GetFont();
		CFont* hOldFont = pDC->SelectObject(hFont);
		CSize szExtent = pDC->GetTextExtent(strText, lstrlen(strText));
		CPoint pt( rect.CenterPoint().x - szExtent.cx / 2, rect.CenterPoint().y - szExtent.cy / 2);
		if (state & ODS_SELECTED) 
			pt.Offset(1, 1);
		int nMode = pDC->SetBkMode(TRANSPARENT);
		if (state & ODS_DISABLED)
			pDC->DrawState(pt, szExtent, strText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
		else
			pDC->DrawState(pt, szExtent, strText, DSS_NORMAL, TRUE, 0, (HBRUSH)NULL);
		pDC->SelectObject(hOldFont);
		pDC->SetBkMode(nMode);
	}

	pDC->RestoreDC(nSaveDC);
}
示例#17
0
void Walk(const char*  path,POINT &pos,POINT &dir, POINT &minpt,POINT &maxpt)
{
    POINT enter_dir=dir;///enter direction for cell

    path++;
    pos+=dir;
    ///enter maze


    for(;*path;path++)
    {

        switch(*path)
        {
            case 'W':

                if(minpt.real()>pos.real())minpt.real()=pos.real();
                if(minpt.imag()>pos.imag())minpt.imag()=pos.imag();

                if(maxpt.real()<pos.real())maxpt.real()=pos.real();
                if(maxpt.imag()<pos.imag())maxpt.imag()=pos.imag();

                ///break walls in enter and exit directions
                maze[std::make_pair(pos.real(),pos.imag())]|=DirToMask(-enter_dir);
                maze[std::make_pair(pos.real(),pos.imag())]|=DirToMask(+dir);

                pos+=dir;

                enter_dir=dir;

                break;

            case 'L':
                dir*=POINT(0,1);
                break;

            case 'R':
                dir*=POINT(0,-1);
                break;
        }
    }

}
示例#18
0
文件: util.hpp 项目: WilstonOreo/GEx
 void rotatePoint(const ORIGIN& _o, ANGLE _theta, POINT& _p)
 {
   auto _d = _p - _o;
   _p.x() = cos(_theta) * _d.x() - sin(_theta) * _d.y() + _o.x();
   _p.y() = sin(_theta) * _d.x() + cos(_theta) * _d.y() + _o.x();
 }