本文整理汇总了C++中Line函数的典型用法代码示例。如果您正苦于以下问题:C++ Line函数的具体用法?C++ Line怎么用?C++ Line使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Line函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Line
Line Line::operator/(float factor)
{
return Line(axisProjections / factor);
}
示例2: endPaintingR
void
endPaintingR(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
{
switch (activeTool)
{
case TOOL_RUBBER:
Replace(hdc, last.x, last.y, x, y, fg, bg, rubberRadius);
break;
case TOOL_PEN:
Line(hdc, last.x, last.y, x, y, bg, 1);
SetPixel(hdc, x, y, bg);
break;
case TOOL_LINE:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
roundTo8Directions(start.x, start.y, &x, &y);
Line(hdc, start.x, start.y, x, y, bg, lineWidth);
break;
case TOOL_BEZIER:
pointSP++;
if (pointSP == 4)
pointSP = 0;
break;
case TOOL_RECT:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(start.x, start.y, &x, &y);
Rect(hdc, start.x, start.y, x, y, bg, fg, lineWidth, shapeStyle);
break;
case TOOL_SHAPE:
resetToU1();
pointStack[pointSP].x = x;
pointStack[pointSP].y = y;
if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0))
roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y,
&pointStack[pointSP].x, &pointStack[pointSP].y);
pointSP++;
if (pointSP >= 2)
{
if ((pointStack[0].x - x) * (pointStack[0].x - x) +
(pointStack[0].y - y) * (pointStack[0].y - y) <= lineWidth * lineWidth + 1)
{
Poly(hdc, pointStack, pointSP, bg, fg, lineWidth, shapeStyle, TRUE);
pointSP = 0;
}
else
{
Poly(hdc, pointStack, pointSP, bg, fg, lineWidth, shapeStyle, FALSE);
}
}
if (pointSP == 255)
pointSP--;
break;
case TOOL_ELLIPSE:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(start.x, start.y, &x, &y);
Ellp(hdc, start.x, start.y, x, y, bg, fg, lineWidth, shapeStyle);
break;
case TOOL_RRECT:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(start.x, start.y, &x, &y);
RRect(hdc, start.x, start.y, x, y, bg, fg, lineWidth, shapeStyle);
break;
}
}
示例3: pos
bool Collision::AABB_vs_Line(const AABB& a, const Line& b, Vector *v)
{
// Fast AABB check first
if(!AABB_vs_AABB(a, b.getAABB(), v))
return false;
/* (u)
+-------+
| |
(l)| |(r)
| |
+-------+
(d)
*/
const Vector bstart = b.startpos();
const Vector pos(a.getPosition());
const Vector upleftr(a.upleftRel());
const Vector downrightr(a.downrightRel());
const Vector uprightr(downrightr.x, upleftr.y);
const Vector downleftr(upleftr.x, downrightr.y);
Vector vtmp;
Vector *vp = v ? &vtmp : NULL;
float mindiff = b.lenSq();
float diff = mindiff;
bool hit = false;
// (u)
if(Line_vs_Line(b, Line(pos, upleftr, uprightr), vp))
{
if(v)
{
diff = (vtmp - bstart).getLength2DSq();
if(diff < mindiff)
{
mindiff = diff;
*v = vtmp;
}
}
hit = true;
}
// (l)
if(Line_vs_Line(b, Line(pos, upleftr, downleftr), vp))
{
if(v)
{
diff = (vtmp - bstart).getLength2DSq();
if(diff < mindiff)
{
mindiff = diff;
*v = vtmp;
}
}
hit = true;
}
// (r)
if(Line_vs_Line(b, Line(pos, uprightr, downrightr), vp))
{
if(v)
{
diff = (vtmp - bstart).getLength2DSq();
if(diff < mindiff)
{
mindiff = diff;
*v = vtmp;
}
}
hit = true;
}
// (d)
if(Line_vs_Line(b, Line(pos, downleftr, downrightr), vp))
{
if(v)
{
diff = (vtmp - bstart).getLength2DSq();
if(diff < mindiff)
{
mindiff = diff;
*v = vtmp;
}
}
hit = true;
}
return hit;
}
示例4: Line
void MDrawContextR2::VLine(int x, int y, int len)
{
Line(x, y, x, y+len);
}
示例5: endPaintingL
void
endPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
{
switch (activeTool)
{
case TOOL_FREESEL:
{
POINT *ptStackCopy;
int i;
rectSel_src[0] = rectSel_src[1] = 0x7fffffff;
rectSel_src[2] = rectSel_src[3] = 0;
for (i = 0; i <= ptSP; i++)
{
if (ptStack[i].x < rectSel_src[0])
rectSel_src[0] = ptStack[i].x;
if (ptStack[i].y < rectSel_src[1])
rectSel_src[1] = ptStack[i].y;
if (ptStack[i].x > rectSel_src[2])
rectSel_src[2] = ptStack[i].x;
if (ptStack[i].y > rectSel_src[3])
rectSel_src[3] = ptStack[i].y;
}
rectSel_src[2] += 1 - rectSel_src[0];
rectSel_src[3] += 1 - rectSel_src[1];
rectSel_dest[0] = rectSel_src[0];
rectSel_dest[1] = rectSel_src[1];
rectSel_dest[2] = rectSel_src[2];
rectSel_dest[3] = rectSel_src[3];
if (ptSP != 0)
{
DeleteObject(hSelMask);
hSelMask = CreateBitmap(rectSel_src[2], rectSel_src[3], 1, 1, NULL);
DeleteObject(SelectObject(hSelDC, hSelMask));
ptStackCopy = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(POINT) * (ptSP + 1));
for (i = 0; i <= ptSP; i++)
{
ptStackCopy[i].x = ptStack[i].x - rectSel_src[0];
ptStackCopy[i].y = ptStack[i].y - rectSel_src[1];
}
Poly(hSelDC, ptStackCopy, ptSP + 1, 0x00ffffff, 0x00ffffff, 1, 2, TRUE);
HeapFree(GetProcessHeap(), 0, ptStackCopy);
SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(rectSel_src[2], rectSel_src[3]));
resetToU1();
MaskBlt(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], hDrawingDC, rectSel_src[0],
rectSel_src[1], hSelMask, 0, 0, MAKEROP4(SRCCOPY, WHITENESS));
Poly(hdc, ptStack, ptSP + 1, bg, bg, 1, 2, TRUE);
newReversible();
MaskBlt(hDrawingDC, rectSel_src[0], rectSel_src[1], rectSel_src[2], rectSel_src[3], hSelDC, 0,
0, hSelMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND));
placeSelWin();
ShowWindow(hSelection, SW_SHOW);
/* force refresh of selection contents */
SendMessage(hSelection, WM_LBUTTONDOWN, 0, 0);
SendMessage(hSelection, WM_MOUSEMOVE, 0, 0);
SendMessage(hSelection, WM_LBUTTONUP, 0, 0);
}
HeapFree(GetProcessHeap(), 0, ptStack);
ptStack = NULL;
break;
}
case TOOL_RECTSEL:
resetToU1();
if ((rectSel_src[2] != 0) && (rectSel_src[3] != 0))
{
DeleteObject(hSelMask);
hSelMask = CreateBitmap(rectSel_src[2], rectSel_src[3], 1, 1, NULL);
DeleteObject(SelectObject(hSelDC, hSelMask));
Rect(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], 0x00ffffff, 0x00ffffff, 1, 2);
SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(rectSel_src[2], rectSel_src[3]));
resetToU1();
BitBlt(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], hDrawingDC, rectSel_src[0],
rectSel_src[1], SRCCOPY);
Rect(hdc, rectSel_src[0], rectSel_src[1], rectSel_src[0] + rectSel_src[2],
rectSel_src[1] + rectSel_src[3], bgColor, bgColor, 0, TRUE);
newReversible();
BitBlt(hDrawingDC, rectSel_src[0], rectSel_src[1], rectSel_src[2], rectSel_src[3], hSelDC, 0,
0, SRCCOPY);
placeSelWin();
ShowWindow(hSelection, SW_SHOW);
/* force refresh of selection contents */
SendMessage(hSelection, WM_LBUTTONDOWN, 0, 0);
SendMessage(hSelection, WM_MOUSEMOVE, 0, 0);
SendMessage(hSelection, WM_LBUTTONUP, 0, 0);
}
break;
case TOOL_RUBBER:
Erase(hdc, last.x, last.y, x, y, bg, rubberRadius);
break;
case TOOL_PEN:
Line(hdc, last.x, last.y, x, y, fg, 1);
SetPixel(hdc, x, y, fg);
break;
case TOOL_LINE:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
roundTo8Directions(start.x, start.y, &x, &y);
//.........这里部分代码省略.........
示例6: main
int main(int argc,char **argv) {
if(argc<2) return 0;
count=atoi(argv[1]);
Line("template <class AccStruct> template <class Output>");
Line("void BIHTree<AccStruct>:: [email protected](const Vec3q *rOrigin,const Vec3q *tDir,floatq *out,i32x4 *object,TreeStats *tstats,int dirMask) const {");
List(" floatq maxD[@]={#};","out[#]");
Line(" ");
Line(" TreeStats stats;");
Line(" ");
Line(" stats.TracingPacket(4*@);");
Line("");
Line(" Vec3q invDir[@]={");
Blck(" VInv(Vec3q(tDir[#].x+0.000000000001f,tDir[#].y+0.000000000001f,tDir[#].z+0.000000000001f)),");
Line(" };");
Line(" floatq tinv[3][@]={");
List(" {#},","invDir[#].x");
List(" {#},","invDir[#].y");
List(" {#} };","invDir[#].z");
Line(" floatq torig[3][@]={");
List(" {#},", "rOrigin[#].x");
List(" {#},", "rOrigin[#].y");
List(" {#} };","rOrigin[#].z");
Line("");
Line(" int dSign[3]; FillDSignArray(dirMask,dSign);");
List(" floatq minRet[@]={#},tMin[@],tMax[@];","maxD[#]");
Blck(" tMin[#]=ConstEpsilon<floatq>(); tMax[#]=Min(maxD[#],minRet[#]);");
Line("");
Line(" floatq fStackBegin[@*2*(maxLevel+2)],*fStack=fStackBegin;");
Line(" u32 nStackBegin[maxLevel+2],*nStack=nStackBegin;");
Line("");
Line(" {");
List(" Vec3q ttMin[@]={#};","(Vec3q(pMin)-rOrigin[#])*invDir[#]");
List(" Vec3q ttMax[@]={#};","(Vec3q(pMax)-rOrigin[#])*invDir[#]");
Line("");
List(" if(dSign[0]) {#;}","Swap(ttMin[#].x,ttMax[#].x)");
List(" if(dSign[1]) {#;}","Swap(ttMin[#].y,ttMax[#].y)");
List(" if(dSign[2]) {#;}","Swap(ttMin[#].z,ttMax[#].z)");
Line("");
Blck(" tMax[#]=Min(Min(ttMax[#].x,ttMax[#].y),tMax[#]);");
Blck(" tMax[#]=Min(ttMax[#].z,tMax[#]);");
Line(" ");
Blck(" tMin[#]=Max(Max(ttMin[#].x,ttMin[#].y),tMin[#]);");
Blck(" tMin[#]=Max(ttMin[#].z,tMin[#]);");
Line(" }");
Line(" ObjectIdxBuffer<4> mailbox;");
Line("");
Line(" const BIHNode *node0=&nodes[0];");
Line(" int idx=0;");
Line("");
Line(" while(true) {");
Line(" stats.LoopIteration();");
Line("");
Line(" if(idx&BIHNode::leafMask) {");
Line(" idx&=BIHNode::idxMask;");
Line("");
Line(" if(!mailbox.Find(idx)) {");
Line(" mailbox.Insert(idx);");
Line(" stats.Intersection(@);");
Line("");
Line(" const Element &obj=objects[idx];");
Line("");
Line(" Vec3q tvec[@]; {");
Line(" Vec3q a(obj.a.x,obj.a.y,obj.a.z);");
Blck(" tvec[#]=rOrigin[#]-a;");
Line(" }");
Line(" floatq u[@],v[@]; {");
Line(" Vec3q ba(obj.ba.x,obj.ba.y,obj.ba.z),ca(obj.ca.x,obj.ca.y,obj.ca.z);");
Blck(" u[#]=tDir[#]|(ba^tvec[#]); v[#]=tDir[#]|(tvec[#]^ca);");
Line(" }");
Line("");
Line(" Vec3p nrm=obj.Nrm();");
Line(" floatq nrmLen=floatq( ((float*)&obj.ca)[3] );");
{ int tCount=count; for(count=0;count<tCount;count++) {
Line(" {");
Line(" floatq det=tDir[@]|nrm;");
Line(" f32x4b mask=Min(u[@],v[@])>=0.0f&&u[@]+v[@]<=det*nrmLen;");
Line(" if(ForAny(mask)) {");
Line(" floatq dist=Condition(mask,-(tvec[@]|nrm)/det,minRet[@]);");
Line(" mask=dist<minRet[@]&&dist>0.0f;");
Line(" minRet[@]=Condition(mask,Output::type==otShadow?0.00001f:dist,minRet[@]);");
Line(" if(Output::objectIndexes) {");
Line(" object[@]=Condition(i32x4b(mask),i32x4(objectId),object[@]);");
Line(" element[@]=Condition(i32x4b(mask),i32x4(idx),element[@]);");
Line(" }");
Line(" stats.IntersectPass();");
Line(" } else stats.IntersectFail();");
Line(" }");
} }
Line(" }");
Line("");
Line(" POP_STACK:");
Line(" if(fStack==fStackBegin) break;");
Line("");
Line(" fStack-=2*@;");
Blck(" tMin[#]=fStack[#];");
Blck(" tMax[#]=Min(fStack[@+#],minRet[#]);");
Line(" --nStack;");
//.........这里部分代码省略.........
示例7: usePoint
/*!
\param points Series of data points
\return Curve points
*/
QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const
{
QStack<Line> stack;
stack.reserve( 500 );
const QPointF *p = points.data();
const int nPoints = points.size();
QVector<bool> usePoint( nPoints, false );
double distToSegment;
stack.push( Line( 0, nPoints - 1 ) );
while ( !stack.isEmpty() )
{
const Line r = stack.pop();
// initialize line segment
const double vecX = p[r.to].x() - p[r.from].x();
const double vecY = p[r.to].y() - p[r.from].y();
const double vecLength = qSqrt( vecX * vecX + vecY * vecY );
const double unitVecX = ( vecLength != 0.0 ) ? vecX / vecLength : 0.0;
const double unitVecY = ( vecLength != 0.0 ) ? vecY / vecLength : 0.0;
double maxDist = 0.0;
int nVertexIndexMaxDistance = r.from + 1;
for ( int i = r.from + 1; i < r.to; i++ )
{
//compare to anchor
const double fromVecX = p[i].x() - p[r.from].x();
const double fromVecY = p[i].y() - p[r.from].y();
const double fromVecLength =
qSqrt( fromVecX * fromVecX + fromVecY * fromVecY );
if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 )
{
distToSegment = fromVecLength;
}
if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 )
{
distToSegment = fromVecLength;
}
else
{
const double toVecX = p[i].x() - p[r.to].x();
const double toVecY = p[i].y() - p[r.to].y();
const double toVecLength = qSqrt( toVecX * toVecX + toVecY * toVecY );
const double s = toVecX * ( -unitVecX ) + toVecY * ( -unitVecY );
if ( s < 0.0 )
distToSegment = toVecLength;
else
{
distToSegment = qSqrt( qFabs( toVecLength * toVecLength - s * s ) );
}
}
if ( maxDist < distToSegment )
{
maxDist = distToSegment;
nVertexIndexMaxDistance = i;
}
}
if ( maxDist <= d_data->tolerance )
{
usePoint[r.from] = true;
usePoint[r.to] = true;
}
else
{
stack.push( Line( r.from, nVertexIndexMaxDistance ) );
stack.push( Line( nVertexIndexMaxDistance, r.to ) );
}
}
int cnt = 0;
QPolygonF stripped( nPoints );
for ( int i = 0; i < nPoints; i++ )
{
if ( usePoint[i] )
stripped[cnt++] = p[i];
}
stripped.resize( cnt );
return stripped;
}
示例8: Line
void GlyphPainter::LineOp(const Pointf& p, bool)
{
Line(p);
}
示例9: Lines
Lines() : space_advance(0), lines(1, Line()) {}
示例10: addLine
void CrossFadeAnimation::addLine(Part was, Part now) {
_lines.push_back(Line(std::move(was), std::move(now)));
}
示例11: append_to_db
void Tracker::append_to_db(int last_block, unsigned int time_len) {
*db << Line(first_block, last_block, reboot_id, time_len) << flush;
}
示例12: Rectangle
void CList::Draw(HDC dc)
{
activated&=focused;
{ // Rahmen malen
HPEN pen=CreatePen(PS_SOLID,1,focused?RGB(255,255,255):RGB(128,128,128)),oldpen;
oldpen=(HPEN)SelectObject(dc,pen);
HBRUSH brush=CreateSolidBrush(focused?RGB(32,32+12,32+24):RGB(8,16,32)),oldbrush;
oldbrush=(HBRUSH)SelectObject(dc,brush);
Rectangle(dc,0,0,w,h);
SelectObject(dc,GetStockObject(BLACK_BRUSH));
Rectangle(dc,w-listscrollbar_width,0,w,h);
Line(dc,w-listscrollbar_width,0,w-listscrollbar_width,h);
SelectObject(dc,oldpen);
DeleteObject(pen);
SelectObject(dc,oldbrush);
DeleteObject(brush);
}
if (numstrings>0)
{ // Scrollbar malen
SelectObject(dc,GetStockObject(WHITE_PEN));
HBRUSH brush=CreateSolidBrush((activated||scrolling)?RGB(64,192,214):RGB(64,92,128)),oldbrush;
oldbrush=(HBRUSH)SelectObject(dc,brush);
float hoehe=(h-2.0f)*(float)VisibleLines()/(float)numstrings;
if (VisibleLines()>numstrings)
hoehe=(h-2.0f);
float y=1.0f;
if (numstrings!=VisibleLines()+1)y=1.0f+starty*(float(h-hoehe-2.0f)/float(numstrings-VisibleLines()-1));
Rectangle(dc,w-listscrollbar_width+1,(int)y,w-1,int(y+hoehe));
SelectObject(dc,oldbrush);
DeleteObject(brush);
}
if (strings)
{ // Listenelemente anzeigen
int y=5;
HFONT font=CreateFont(listitem_height-1,0,0,0,FW_THIN,0,0,0,0,0,0,0,0,"Arial"),oldfont;
oldfont=(HFONT)SelectObject(dc,font);
SetBkMode(dc,TRANSPARENT);
HBRUSH brush=CreateSolidBrush(activated?RGB(64,192,214):RGB(64,92,128));
SelectObject(dc,GetStockObject(NULL_PEN));
SetTextColor(dc,RGB(0,192,255));
for (int i=starty;i<numstrings;i++)
{
RECT r={1,y,w-listscrollbar_width,y+listitem_height};
if (i==selected)
{ // Aktueller Eintrag ist der Auserwählte
SetTextColor(dc,RGB(255,255,255));
FillRect(dc,&r,brush);
Sleep(1);
}
r.left+=5;
DrawText(dc,strings[i],strlen(strings[i]),&r,DT_VCENTER);
if (i==selected)
{
SetTextColor(dc,RGB(0,192,255));
}
y+=listitem_height;
if (i>=starty+VisibleLines())break;
}
SelectObject(dc,oldfont);
DeleteObject(brush);
DeleteObject(font);
}
}
示例13: Line
Polyline::operator Line() const
{
if (this->points.size() > 2) CONFESS("Can't convert polyline with more than two points to a line");
return Line(this->points.front(), this->points.back());
}
示例14: SelectObject
void CSlider::Draw(HDC dc)
{
CWnd::Draw(dc);
activated&=focused;
MouseButtonDown&=focused;
int h2=h/2;
// Hintergrund
{
HBRUSH brush=CreateSolidBrush(focused?RGB(0,64,92):(canfocus?RGB(0,0,0):RGB(64,64,64)))
,oldbrush=(HBRUSH)SelectObject(dc,brush);
SelectObject(dc,GetStockObject(NULL_PEN));
Rectangle(dc,0,0,w,h2+1);
SelectObject(dc,oldbrush);
DeleteObject(brush);
HPEN pen=CreatePen(PS_SOLID,1,RGB(64,64,64)),oldpen=(HPEN)SelectObject(dc,pen);
Line(dc,0,0,w-1,0);
Line(dc,0,0,0,h2-1);
SelectObject(dc,oldpen);
DeleteObject(pen);
pen=CreatePen(PS_SOLID,1,RGB(192,192,192));
SelectObject(dc,pen);
Line(dc,w-1,0,w-1,h2-1);
Line(dc,0,h2-1,w-1,h2-1);
SelectObject(dc,oldpen);
DeleteObject(pen);
}
// Beschriftung
{
HFONT font=CreateFont(h-h2-2,0,0,0,0,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"MS SansSerif"),oldfont=(HFONT)SelectObject(dc,font);
SetTextColor(dc,focused?RGB(255,255,255):RGB(192,192,192));
RECT r={0,0+h2-1,w-1,h-1};
SetBkMode(dc,TRANSPARENT);
CHAR c[10];
sprintf(&c[0],"%.2f",iLeft);
DrawText(dc,&c[0],strlen(&c[0]),&r,DT_LEFT);
sprintf(&c[0],"%.2f",iRight);
DrawText(dc,&c[0],strlen(&c[0]),&r,DT_RIGHT);
SetTextColor(dc,focused?RGB(64,192,255):RGB(192,192,192));
sprintf(&c[0],"%.2f",Position);
DrawText(dc,&c[0],strlen(&c[0]),&r,DT_CENTER|DT_SINGLELINE);
SelectObject(dc,oldfont);
DeleteObject(font);
}
// Knopf
{
HPEN pen=CreatePen(PS_SOLID,1,focused?RGB(255,255,255):canfocus?RGB(0,192,255):RGB(160,160,160)),oldpen=(HPEN)SelectObject(dc,pen);
HBRUSH brush=CreateSolidBrush(canfocus?focused?activated?RGB(0,255,192):RGB(0,192,255):RGB(0,128,192):RGB(192,192,192)),oldbrush=(HBRUSH)SelectObject(dc,brush);
const int breite=h2-2;
const int hoehe=h2-2;
int links=int(2+((w-2-breite)*(Position-iLeft))/(iRight-iLeft));
Rectangle(dc,links-1,1,links+breite-1,hoehe+1);
if (activated)
{
const int x1=links+1;
const int x2=links+breite-4;
const int xm=(x2-x1)/2+x1;
const int y1=3+1;
const int y2=hoehe-2-1;
const int ym=(y2-y1)/2+y1;
HPEN pen=CreatePen(PS_SOLID,2,RGB(255,0,0)),oldpen=(HPEN)SelectObject(dc,pen);
Line(dc,xm-1,y1,x1,ym);
Line(dc,x1,ym,xm-1,y2);
Line(dc,xm+1,y1,x2,ym);
Line(dc,x2,ym,xm+1,y2);
SelectObject(dc,oldpen);
DeleteObject(pen);
}
SelectObject(dc,oldbrush);
SelectObject(dc,oldpen);
DeleteObject(brush);
DeleteObject(pen);
//.........这里部分代码省略.........
示例15: sqrtl
void CMainWnd::OnPaint()
{
Object A{ 2.680795435464e+20, -1.531367579292792e+12, 0.0, 0.0, -1.923828617202e+3 * M_PI / 1.581035760 * sqrtl(5.1/19.9), 0.0, 0.0, 1.40491e+9 };
Object B{ 1.2979296712296e+20, 3.19134145606896e+12, 0.0, 0.0, 4.009222934760e+3 * M_PI / 1.581035760 * sqrtl(5.1 / 19.9), 0.0, 0.0, 5.8422e+7 };
CPaintDC dc(this);
RECT rect;
GetClientRect(&rect);
long double x = rect.right; //Ширина окна
long double y = rect.bottom; //Высота окна
dc.FillSolidRect(0, 0, lrintl(x), lrintl(y), RGB(0, 0, 0));
CPen Line(PS_SOLID, 1, RGB(255, 255, 255));
CBrush Star1(RGB(255,255,255));
CBrush Star2(RGB(0, 0, 0));
CBrush BPlanetoid(RGB(0, 127, 127));
CPen Planetoid(PS_SOLID, 1, RGB(0, 127, 127));
CPen Background(PS_SOLID, 1, RGB(0, 0, 0));
dc.SetTextColor(RGB(255, 255, 255));
dc.TextOutW(5, 5, "Координаты планеты, а.е.");
dc.TextOutW(5, 65, "Скорость планеты, км/с");
long double h = 5.0e+4;
long double max = 3.2e+12;
dc.MoveTo(lrintl(x / 2 + y / 2.0*A.x / max), lrintl(y / 2.0*(1.0 - A.y / max)));
for (long double t = 0; t < T; t += h){
long double dx = B.x - A.x, dy = B.y - A.y;
long double R = hypotl(dx, dy);
long double cosinus = dx / R, sinus = dy / R;
R *= R;
// Сириус А
A.ax = B.GM / R * cosinus;
A.ay = B.GM / R * sinus;
A.vx += h*A.ax;
A.vy += h*A.ay;
// Сириус Б
B.ax = -A.GM / R * cosinus;
B.ay = -A.GM / R * sinus;
B.vx += h*B.ax;
B.vy += h*B.ay;
dx = Planet.x - A.x, dy = Planet.y - A.y;
R = hypotl(dx, dy);
cosinus = dx / R; sinus = dy / R;
R *= R;
Planet.ax = -A.GM / R * cosinus;
Planet.ay = -A.GM / R * sinus;
dx = Planet.x - B.x; dy = Planet.y - B.y;
R = hypotl(dx, dy);
cosinus = dx / R; sinus = dy / R;
R *= R;
Planet.ax += -B.GM / R * cosinus;
Planet.ay += -B.GM / R * sinus;
Planet.vx += h*Planet.ax;
Planet.vy += h*Planet.ay;
bool k = (llrintl(t) % 1000 == 0);
if (k){
dc.SelectObject(Line);
dc.MoveTo(0, lrintl(y / 2));
dc.LineTo(lrintl(x), lrintl(y / 2));
dc.MoveTo(lrintl(x / 2), 0);
dc.LineTo(lrintl(x / 2), lrintl(y));
};
if (k){
dc.SelectObject(Background);
dc.SelectObject(Star2);
dc.Ellipse(lrintl(x / 2 + y / 2.0*A.x / max) - 7, lrintl(y / 2.0*(1.0 - A.y / max)) - 7, lrintl(x / 2 + y / 2.0*A.x / max) + 7, lrintl(y / 2.0*(1.0 - A.y / max)) + 7);
};
A.x += h*A.vx;
A.y += h*A.vy;
if (k){
dc.SelectObject(Star1);
dc.Ellipse(lrintl(x / 2 + y / 2.0*A.x / max) - 7, lrintl(y / 2.0*(1.0 - A.y / max)) - 7, lrintl(x / 2 + y / 2.0*A.x / max) + 7, lrintl(y / 2.0*(1.0 - A.y / max)) + 7);
};
//dc.LineTo(lrintl(x / 2 + y / 2.0*A.x / max), lrintl(y / 2.0*(1.0 - A.y / max)));
//dc.MoveTo(lrintl(x / 2 + y / 2.0*B.x / max), lrintl(y / 2.0*(1.0 - B.y / max)));
if (k){
dc.SelectObject(Background);
dc.SelectObject(Star2);
dc.Ellipse(lrintl(x / 2 + y / 2.0*B.x / max) - 5, lrintl(y / 2.0*(1.0 - B.y / max)) - 5, lrintl(x / 2 + y / 2.0*B.x / max) + 5, lrintl(y / 2.0*(1.0 - B.y / max)) + 5);
};
B.x += h*B.vx;
B.y += h*B.vy;
if (k){
dc.SelectObject(Star1);
dc.Ellipse(lrintl(x / 2 + y / 2.0*B.x / max) - 5, lrintl(y / 2.0*(1.0 - B.y / max)) - 5, lrintl(x / 2 + y / 2.0*B.x / max) + 5, lrintl(y / 2.0*(1.0 - B.y / max)) + 5);
};
if (k){
dc.SelectObject(Background);
dc.SelectObject(Star2);
dc.Ellipse(lrintl(x / 2 + y / 2.0*Planet.x / max) - 3, lrintl(y / 2.0*(1.0 - Planet.y / max)) - 3, lrintl(x / 2 + y / 2.0*Planet.x / max) + 3, lrintl(y / 2.0*(1.0 - Planet.y / max)) + 3);
};
Planet.x += h*Planet.vx;
Planet.y += h*Planet.vy;
if (k){
dc.SelectObject(BPlanetoid);
dc.Ellipse(lrintl(x / 2 + y / 2.0*Planet.x / max) - 3, lrintl(y / 2.0*(1.0 - Planet.y / max)) - 3, lrintl(x / 2 + y / 2.0*Planet.x / max) + 3, lrintl(y / 2.0*(1.0 - Planet.y / max)) + 3);
//.........这里部分代码省略.........