91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 126KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2021-06-10
  • 語言: C/C++
  • 標(biāo)簽: 直線裁剪??

資源簡介

用C語言實(shí)現(xiàn)的直線裁剪算法,初學(xué)計(jì)算機(jī)圖形學(xué)的童鞋可以參考參考

資源截圖

代碼片段和文件信息

#include?“ggltools.h“

void?gltRasterText(double?x?double?y?const?char?*text?void?*font)
{
????if(text?==?NULL)?return?;
????
????glRasterPos2d(x?y);
????for(int?i=0;?text[i]?!=?‘\0‘;?i++)
????{
????????glutBitmapCharacter(font?text[i]);
????}?
}

void?gltLine2d(double?x0?double?y0?double?x1?double?y1)
{
????glBegin(GL_LINES);
????????glVertex2d(x0?y0);
????????glVertex2d(x1?y1);
????glEnd();
}

void?gltRect2d(double?x0?double?y0?double?x1?double?y1)
{
????glBegin(GL_LINE_STRIP);
????????glVertex2d(x0?y0);
????????glVertex2d(x1?y0);
????????
????????glVertex2d(x1?y1);
????????
????????glVertex2d(x0?y1);
????????
????????glVertex2d(x0?y0);
????glEnd();
}

char?gltClipCode(const?GPoint2d?&pt?const?GPoint2d?&top?const?GPoint2d?&bottom)//
{
????char?code?=?0;
????
????if(pt.y()?>?top.y())?code?|=?0x01;
????else?if(pt.y()?????
????if(pt.x()?>?bottom.x())?code?|=?0x04;
????else?if(pt.x()?????
????return?code;
}

template
void?swap(T&aT&b)
{
T?t=a;
a=b;
b=t;
}

//直線的裁剪

bool?gltLineClip2d(GPoint2d?&pt0?GPoint2d?&pt1?
???????????????????const?GPoint2d?&top?const?GPoint2d?&bottom)
{
bool?isSwap=false;
char?c0c1;//全部被接受,c0和c1?按位與?為0
while(true)
{
c0=gltClipCode(pt0topbottom);
c1=gltClipCode(pt1topbottom);

if((c0?|?c1)==0)?
{
if(isSwap)?swap(pt0pt1);
return?true;
}
if((c0?&?c1)!=0)
{
return?false;
}
if(c0==0)
{
swap(pt0pt1);
swap(c0c1);
}

if(c0?&?0x01)//在yt之上
{
pt0.mX=pt0.x()+(pt1.x()-pt0.x())*(top.y()-pt0.y())/(pt1.y()-pt0.y());
pt0.mY=top.y();
}
else?if(c0?&?0x02)//在yt之下
{

pt0.mX=pt0.x()+(pt1.x()-pt0.x())*(bottom.y()-pt0.y())/(pt1.y()-pt0.y());
pt0.mY=bottom.y();

}
else?if(c0?&?0x04)//在yt?之右
{

pt0.mY=pt0.y()+(pt1.y()-pt0.y())*(bottom.x()-pt0.x())/(pt1.x()-pt0.x());
pt0.mX=bottom.x();

}
else?if(c0?&?0x08)//在yt之左
{

????????????pt0.mY=pt0.y()+(pt1.y()-pt0.y())*(top.x()-pt0.x())/(pt1.x()-pt0.x());
pt0.mX=top.x();

}


}

????return?false;
}

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2011-12-05?10:49??clip\
?????文件????????3955??2010-08-29?22:31??clip\Clip.dsp
?????文件?????????533??2010-08-29?22:29??clip\Clip.dsw
?????文件???????82944??2011-12-05?10:49??clip\Clip.ncb
?????文件???????93184??2011-12-05?10:49??clip\Clip.opt
?????文件????????1167??2011-12-05?10:47??clip\Clip.plg
?????文件????????2202??2011-12-05?09:26??clip\ggltools.cpp
?????文件?????????514??2006-04-18?20:29??clip\ggltools.h
?????文件?????????335??2005-12-19?21:13??clip\gpoint2d.cpp
?????文件?????????514??2006-04-18?20:18??clip\gpoint2d.h
?????文件????????3677??2010-08-29?22:31??clip\main.cpp
?????目錄???????????0??2011-12-05?10:47??clip\Release\
?????文件???????49152??2011-12-05?10:47??clip\Release\Clip.exe
?????文件??????335912??2011-12-05?10:47??clip\Release\Clip.pch
?????文件????????2472??2011-12-05?10:47??clip\Release\ggltools.obj
?????文件????????1410??2011-12-05?08:27??clip\Release\gpoint2d.obj
?????文件????????8282??2011-12-05?08:27??clip\Release\main.obj
?????文件???????33792??2011-12-05?10:48??clip\Release\vc60.idb

評論

共有 條評論