2008-04-01 10:48:44 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
void Entity::LineDrawOrGetDistance(Vector a, Vector b) {
|
|
|
|
if(dogd.drawing) {
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
glxVertex3v(a);
|
|
|
|
glxVertex3v(b);
|
|
|
|
glEnd();
|
|
|
|
} else {
|
|
|
|
Point2d ap = SS.GW.ProjectPoint(a);
|
|
|
|
Point2d bp = SS.GW.ProjectPoint(b);
|
|
|
|
|
|
|
|
double d = dogd.mp.DistanceToLine(ap, bp.Minus(ap), true);
|
|
|
|
dogd.dmin = min(dogd.dmin, d);
|
|
|
|
}
|
2008-04-11 11:13:47 +00:00
|
|
|
}
|
|
|
|
|
2008-04-01 10:48:44 +00:00
|
|
|
void Entity::Draw(void) {
|
2008-04-12 14:12:26 +00:00
|
|
|
dogd.drawing = true;
|
|
|
|
DrawOrGetDistance();
|
|
|
|
}
|
|
|
|
|
|
|
|
double Entity::GetDistance(Point2d mp) {
|
|
|
|
dogd.drawing = false;
|
|
|
|
dogd.mp = mp;
|
|
|
|
dogd.dmin = 1e12;
|
|
|
|
|
|
|
|
DrawOrGetDistance();
|
|
|
|
|
|
|
|
return dogd.dmin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entity::DrawOrGetDistance(void) {
|
2008-04-12 16:28:48 +00:00
|
|
|
if(!visible) return;
|
2008-04-09 08:39:01 +00:00
|
|
|
switch(type) {
|
|
|
|
case CSYS_2D: {
|
|
|
|
Vector p;
|
2008-04-12 14:12:26 +00:00
|
|
|
p = SS.point.FindById(point(16))->GetCoords();
|
2008-04-01 10:48:44 +00:00
|
|
|
|
2008-04-12 15:17:58 +00:00
|
|
|
double q[4];
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
|
|
q[i] = SS.param.FindById(param(i))->val;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector u = Vector::RotationU(q[0], q[1], q[2], q[3]);
|
|
|
|
Vector v = Vector::RotationV(q[0], q[1], q[2], q[3]);
|
2008-04-01 10:48:44 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
double s = (min(SS.GW.width, SS.GW.height))*0.4;
|
2008-04-01 10:48:44 +00:00
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
Vector pp = p.Plus (u).Plus (v);
|
|
|
|
Vector pm = p.Plus (u).Minus(v);
|
|
|
|
Vector mm = p.Minus(u).Minus(v);
|
|
|
|
Vector mp = p.Minus(u).Plus (v);
|
2008-04-11 11:13:47 +00:00
|
|
|
pp = pp.ScaledBy(s);
|
|
|
|
pm = pm.ScaledBy(s);
|
|
|
|
mm = mm.ScaledBy(s);
|
|
|
|
mp = mp.ScaledBy(s);
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
LineDrawOrGetDistance(pp, pm);
|
|
|
|
LineDrawOrGetDistance(pm, mm);
|
|
|
|
LineDrawOrGetDistance(mm, mp);
|
|
|
|
LineDrawOrGetDistance(mp, pp);
|
2008-04-01 10:48:44 +00:00
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
if(dogd.drawing) {
|
|
|
|
Request *r = SS.request.FindById(this->request());
|
|
|
|
glPushMatrix();
|
|
|
|
glxTranslatev(mm);
|
|
|
|
glxOntoCsys(u, v);
|
|
|
|
glxWriteText(r->DescriptionString());
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
2008-04-09 08:39:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
oops();
|
2008-04-01 10:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-12 15:17:58 +00:00
|
|
|
|