本文整理汇总了C++中Point2d::DistanceTo方法的典型用法代码示例。如果您正苦于以下问题:C++ Point2d::DistanceTo方法的具体用法?C++ Point2d::DistanceTo怎么用?C++ Point2d::DistanceTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point2d
的用法示例。
在下文中一共展示了Point2d::DistanceTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawOrGetDistance
//.........这里部分代码省略.........
// Draw the diameter symbol
Vector dc = topLeft;
dc = dc.Plus(gu.WithMagnitude(5/SS.GW.scale));
dc = dc.Plus(gr.WithMagnitude(9/SS.GW.scale));
double dr = 5/SS.GW.scale;
double theta, dtheta = (2*PI)/12;
for(theta = 0; theta < 2*PI-0.01; theta += dtheta) {
LineDrawOrGetDistance(
dc.Plus(gu.WithMagnitude(cos(theta)*dr)).Plus(
gr.WithMagnitude(sin(theta)*dr)),
dc.Plus(gu.WithMagnitude(cos(theta+dtheta)*dr)).Plus(
gr.WithMagnitude(sin(theta+dtheta)*dr)));
}
theta = 25*(PI/180);
dr *= 1.7;
dtheta = PI;
LineDrawOrGetDistance(
dc.Plus(gu.WithMagnitude(cos(theta)*dr)).Plus(
gr.WithMagnitude(sin(theta)*dr)),
dc.Plus(gu.WithMagnitude(cos(theta+dtheta)*dr)).Plus(
gr.WithMagnitude(sin(theta+dtheta)*dr)));
}
break;
}
case POINTS_COINCIDENT: {
if(!dogd.drawing) {
for(int i = 0; i < 2; i++) {
Vector p = SK.GetEntity(i == 0 ? ptA : ptB)-> PointGetNum();
Point2d pp = SS.GW.ProjectPoint(p);
// The point is selected within a radius of 7, from the
// same center; so if the point is visible, then this
// constraint cannot be selected. But that's okay.
dogd.dmin = min(dogd.dmin, pp.DistanceTo(dogd.mp) - 3);
dogd.refp = p;
}
break;
}
if(dogd.drawing) {
// Let's adjust the color of this constraint to have the same
// rough luma as the point color, so that the constraint does not
// stand out in an ugly way.
RgbaColor cd = Style::Color(Style::DATUM),
cc = Style::Color(Style::CONSTRAINT);
// convert from 8-bit color to a vector
Vector vd = Vector::From(cd.redF(), cd.greenF(), cd.blueF()),
vc = Vector::From(cc.redF(), cc.greenF(), cc.blueF());
// and scale the constraint color to have the same magnitude as
// the datum color, maybe a bit dimmer
vc = vc.WithMagnitude(vd.Magnitude()*0.9);
// and set the color to that.
ssglColorRGB(RGBf(vc.x, vc.y, vc.z));
for(int a = 0; a < 2; a++) {
Vector r = SS.GW.projRight.ScaledBy((a+1)/SS.GW.scale);
Vector d = SS.GW.projUp.ScaledBy((2-a)/SS.GW.scale);
for(int i = 0; i < 2; i++) {
Vector p = SK.GetEntity(i == 0 ? ptA : ptB)-> PointGetNum();
glBegin(GL_QUADS);
ssglVertex3v(p.Plus (r).Plus (d));
ssglVertex3v(p.Plus (r).Minus(d));
ssglVertex3v(p.Minus(r).Minus(d));
ssglVertex3v(p.Minus(r).Plus (d));
glEnd();
}
示例2: MouseMoved
void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
bool middleDown, bool rightDown, bool shiftDown, bool ctrlDown)
{
if(GraphicsEditControlIsVisible()) return;
if(context.active) return;
SS.extraLine.draw = false;
if(!orig.mouseDown) {
// If someone drags the mouse into our window with the left button
// already depressed, then we don't have our starting point; so
// don't try.
leftDown = false;
}
if(rightDown) {
middleDown = true;
shiftDown = !shiftDown;
}
if(SS.showToolbar) {
if(ToolbarMouseMoved((int)x, (int)y)) {
hover.Clear();
return;
}
}
if(!leftDown && (pending.operation == DRAGGING_POINTS ||
pending.operation == DRAGGING_MARQUEE))
{
ClearPending();
InvalidateGraphics();
}
Point2d mp = Point2d::From(x, y);
currentMousePosition = mp;
if(rightDown && orig.mouse.DistanceTo(mp) < 5 && !orig.startedMoving) {
// Avoid accidentally panning (or rotating if shift is down) if the
// user wants a context menu.
return;
}
orig.startedMoving = true;
// If the middle button is down, then mouse movement is used to pan and
// rotate our view. This wins over everything else.
if(middleDown) {
hover.Clear();
double dx = (x - orig.mouse.x) / scale;
double dy = (y - orig.mouse.y) / scale;
if(!(shiftDown || ctrlDown)) {
double s = 0.3*(PI/180)*scale; // degrees per pixel
projRight = orig.projRight.RotatedAbout(orig.projUp, -s*dx);
projUp = orig.projUp.RotatedAbout(orig.projRight, s*dy);
NormalizeProjectionVectors();
} else if(ctrlDown) {
double theta = atan2(orig.mouse.y, orig.mouse.x);
theta -= atan2(y, x);
SS.extraLine.draw = true;
SS.extraLine.ptA = UnProjectPoint(Point2d::From(0, 0));
SS.extraLine.ptB = UnProjectPoint(mp);
Vector normal = orig.projRight.Cross(orig.projUp);
projRight = orig.projRight.RotatedAbout(normal, theta);
projUp = orig.projUp.RotatedAbout(normal, theta);
NormalizeProjectionVectors();
} else {
offset.x = orig.offset.x + dx*projRight.x + dy*projUp.x;
offset.y = orig.offset.y + dx*projRight.y + dy*projUp.y;
offset.z = orig.offset.z + dx*projRight.z + dy*projUp.z;
}
orig.projRight = projRight;
orig.projUp = projUp;
orig.offset = offset;
orig.mouse.x = x;
orig.mouse.y = y;
if(SS.TW.shown.screen == TextWindow::SCREEN_EDIT_VIEW) {
if(havePainted) {
SS.ScheduleShowTW();
}
}
InvalidateGraphics();
havePainted = false;
return;
}
if(pending.operation == 0) {
double dm = orig.mouse.DistanceTo(mp);
// If we're currently not doing anything, then see if we should
// start dragging something.
if(leftDown && dm > 3) {
Entity *e = NULL;
if(hover.entity.v) e = SK.GetEntity(hover.entity);
if(e && e->type != Entity::WORKPLANE) {
//.........这里部分代码省略.........
示例3: DrawOrGetDistance
void Entity::DrawOrGetDistance(void) {
if(!IsVisible()) return;
Group *g = SK.GetGroup(group);
switch(type) {
case POINT_N_COPY:
case POINT_N_TRANS:
case POINT_N_ROT_TRANS:
case POINT_N_ROT_AA:
case POINT_IN_3D:
case POINT_IN_2D: {
Vector v = PointGetNum();
dogd.refp = v;
if(dogd.drawing) {
double s = 3.5;
Vector r = SS.GW.projRight.ScaledBy(s/SS.GW.scale);
Vector d = SS.GW.projUp.ScaledBy(s/SS.GW.scale);
ssglColorRGB(Style::Color(Style::DATUM));
ssglDepthRangeOffset(6);
glBegin(GL_QUADS);
ssglVertex3v(v.Plus (r).Plus (d));
ssglVertex3v(v.Plus (r).Minus(d));
ssglVertex3v(v.Minus(r).Minus(d));
ssglVertex3v(v.Minus(r).Plus (d));
glEnd();
ssglDepthRangeOffset(0);
} else {
Point2d pp = SS.GW.ProjectPoint(v);
dogd.dmin = pp.DistanceTo(dogd.mp) - 6;
}
break;
}
case NORMAL_N_COPY:
case NORMAL_N_ROT:
case NORMAL_N_ROT_AA:
case NORMAL_IN_3D:
case NORMAL_IN_2D: {
int i;
for(i = 0; i < 2; i++) {
if(i == 0 && !SS.GW.showNormals) {
// When the normals are hidden, we will continue to show
// the coordinate axes at the bottom left corner, but
// not at the origin.
continue;
}
hRequest hr = h.request();
// Always draw the x, y, and z axes in red, green, and blue;
// brighter for the ones at the bottom left of the screen,
// dimmer for the ones at the model origin.
int f = (i == 0 ? 100 : 255);
if(hr.v == Request::HREQUEST_REFERENCE_XY.v) {
ssglColorRGB(RGBi(0, 0, f));
} else if(hr.v == Request::HREQUEST_REFERENCE_YZ.v) {
ssglColorRGB(RGBi(f, 0, 0));
} else if(hr.v == Request::HREQUEST_REFERENCE_ZX.v) {
ssglColorRGB(RGBi(0, f, 0));
} else {
ssglColorRGB(Style::Color(Style::NORMALS));
if(i > 0) break;
}
Quaternion q = NormalGetNum();
Vector tail;
if(i == 0) {
tail = SK.GetEntity(point[0])->PointGetNum();
glLineWidth(1);
} else {
// Draw an extra copy of the x, y, and z axes, that's
// always in the corner of the view and at the front.
// So those are always available, perhaps useful.
double s = SS.GW.scale;
double h = 60 - SS.GW.height/2;
double w = 60 - SS.GW.width/2;
tail = SS.GW.projRight.ScaledBy(w/s).Plus(
SS.GW.projUp. ScaledBy(h/s)).Minus(SS.GW.offset);
ssglDepthRangeLockToFront(true);
glLineWidth(2);
}
Vector v = (q.RotationN()).WithMagnitude(50/SS.GW.scale);
Vector tip = tail.Plus(v);
LineDrawOrGetDistance(tail, tip);
v = v.WithMagnitude(12/SS.GW.scale);
Vector axis = q.RotationV();
LineDrawOrGetDistance(tip,tip.Minus(v.RotatedAbout(axis, 0.6)));
LineDrawOrGetDistance(tip,tip.Minus(v.RotatedAbout(axis,-0.6)));
}
ssglDepthRangeLockToFront(false);
break;
}
case DISTANCE:
case DISTANCE_N_COPY:
// These are used only as data structures, nothing to display.
//.........这里部分代码省略.........