Add routines to draw a vector font (public domain Hershey Simplex

font, not bad). Use that to label the planes now.

[git-p4: depot-paths = "//depot/solvespace/": change = 1660]
solver
Jonathan Westhues 2008-04-11 03:13:47 -08:00
parent 3357446278
commit 181e50f1d9
11 changed files with 1884 additions and 25 deletions

View File

@ -15,6 +15,7 @@ SSOBJS = $(OBJDIR)\solvespace.obj \
$(OBJDIR)\util.obj \ $(OBJDIR)\util.obj \
$(OBJDIR)\entity.obj \ $(OBJDIR)\entity.obj \
$(OBJDIR)\sketch.obj \ $(OBJDIR)\sketch.obj \
$(OBJDIR)\glhelper.obj \
LIBS = user32.lib gdi32.lib comctl32.lib advapi32.lib opengl32.lib glu32.lib LIBS = user32.lib gdi32.lib comctl32.lib advapi32.lib opengl32.lib glu32.lib

2
dsc.h
View File

@ -27,8 +27,6 @@ public:
static Vector RotationU(double a, double b, double c, double d); static Vector RotationU(double a, double b, double c, double d);
static Vector RotationV(double a, double b, double c, double d); static Vector RotationV(double a, double b, double c, double d);
}; };
void glVertex3v(Vector u);
class Point2d { class Point2d {
public: public:

View File

@ -1,5 +1,12 @@
#include "solvespace.h" #include "solvespace.h"
void Entity::LineDrawHitTest(Vector a, Vector b) {
glBegin(GL_LINE_STRIP);
glxVertex3v(a);
glxVertex3v(b);
glEnd();
}
void Entity::Draw(void) { void Entity::Draw(void) {
switch(type) { switch(type) {
case CSYS_2D: { case CSYS_2D: {
@ -17,15 +24,27 @@ void Entity::Draw(void) {
double s = (min(SS.GW.width, SS.GW.height))*0.4; double s = (min(SS.GW.width, SS.GW.height))*0.4;
u = u.ScaledBy(s); Vector pp = (p.Plus(u)).Plus(v);
v = v.ScaledBy(s); Vector pm = (p.Plus(u)).Minus(v);
Vector mm = (p.Minus(u)).Minus(v);
Vector mp = (p.Minus(u)).Plus(v);
pp = pp.ScaledBy(s);
pm = pm.ScaledBy(s);
mm = mm.ScaledBy(s);
mp = mp.ScaledBy(s);
LineDrawHitTest(pp, pm);
LineDrawHitTest(pm, mm);
LineDrawHitTest(mm, mp);
LineDrawHitTest(mp, pp);
Request *r = SS.request.FindById(this->request());
glPushMatrix();
glxTranslatev(mm);
glxOntoCsys(u, v);
glxWriteText(r->name.str);
glPopMatrix();
Vector r;
glBegin(GL_LINE_LOOP);
r = p; r = r.Minus(v); r = r.Minus(u); glVertex3v(r);
r = p; r = r.Plus(v); r = r.Minus(u); glVertex3v(r);
r = p; r = r.Plus(v); r = r.Plus(u); glVertex3v(r);
r = p; r = r.Minus(v); r = r.Plus(u); glVertex3v(r);
glEnd(); glEnd();
break; break;
} }

1774
font.table Normal file

File diff suppressed because it is too large Load Diff

56
glhelper.cpp Normal file
View File

@ -0,0 +1,56 @@
#include "solvespace.h"
// A public-domain Hershey vector font ("Simplex").
#include "font.table"
void glxWriteText(char *str)
{
double scale = 0.7/SS.GW.scale;
int xo = 5;
int yo = 5;
for(; *str; str++) {
int c = *str;
if(c < 32 || c > 126) c = 32;
c -= 32;
glBegin(GL_LINE_STRIP);
int j;
for(j = 0; j < Font[c].points; j++) {
int x = Font[c].coord[j*2];
int y = Font[c].coord[j*2+1];
if(x == PEN_UP && y == PEN_UP) {
glEnd();
glBegin(GL_LINE_STRIP);
} else {
glVertex3d((xo + x)*scale, (yo + y)*scale, 0);
}
}
glEnd();
xo += Font[c].width;
}
}
void glxVertex3v(Vector u)
{
glVertex3f((GLfloat)u.x, (GLfloat)u.y, (GLfloat)u.z);
}
void glxTranslatev(Vector u)
{
glTranslated((GLdouble)u.x, (GLdouble)u.y, (GLdouble)u.z);
}
void glxOntoCsys(Vector u, Vector v)
{
double mat[16];
Vector n = u.Cross(v);
MakeMatrix(mat, u.x, v.x, n.x, 0,
u.y, v.y, n.y, 0,
u.z, v.z, n.z, 0,
0, 0, 0, 1);
glMultMatrixd(mat);
}

View File

@ -76,13 +76,14 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
projDown = orig.projDown.RotatedAbout(orig.projRight, s*dy); projDown = orig.projDown.RotatedAbout(orig.projRight, s*dy);
NormalizeProjectionVectors(); NormalizeProjectionVectors();
orig.projRight = projRight;
orig.projDown = projDown;
orig.mouse.x = x;
orig.mouse.y = y;
} }
orig.projRight = projRight;
orig.projDown = projDown;
orig.offset = offset;
orig.mouse.x = x;
orig.mouse.y = y;
Invalidate(); Invalidate();
} }
} }
@ -142,7 +143,11 @@ void GraphicsWindow::Paint(int w, int h) {
0, 0, 0, 1); 0, 0, 0, 1);
glMultMatrixd(mat); glMultMatrixd(mat);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glClearIndex((GLfloat)0); glClearIndex((GLfloat)0);
glClearDepth(1.0); glClearDepth(1.0);

View File

@ -97,11 +97,14 @@ public:
Expr *expr[16]; Expr *expr[16];
inline hRequest request(void)
{ hRequest r; r.v = (this->h.v >> 11); return r; }
inline hParam param(int i) inline hParam param(int i)
{ hParam r; r.v = ((this->h.v) << 8) | i; return r; } { hParam r; r.v = ((this->h.v) << 8) | i; return r; }
inline hPoint point(int i) inline hPoint point(int i)
{ hPoint r; r.v = ((this->h.v) << 8) | i; return r; } { hPoint r; r.v = ((this->h.v) << 8) | i; return r; }
void LineDrawHitTest(Vector a, Vector b);
void Draw(void); void Draw(void);
}; };

View File

@ -36,15 +36,15 @@ void SolveSpace::Init(void) {
r.type = Request::CSYS_2D; r.type = Request::CSYS_2D;
r.group = Group::HGROUP_REFERENCES; r.group = Group::HGROUP_REFERENCES;
r.name.strcpy("__xy_plane"); r.name.strcpy("#xy-plane");
r.h = Request::HREQUEST_REFERENCE_XY; r.h = Request::HREQUEST_REFERENCE_XY;
request.Add(&r); request.Add(&r);
r.name.strcpy("__yz_plane"); r.name.strcpy("#yz-plane");
r.h = Request::HREQUEST_REFERENCE_YZ; r.h = Request::HREQUEST_REFERENCE_YZ;
request.Add(&r); request.Add(&r);
r.name.strcpy("__zx_plane"); r.name.strcpy("#zx-plane");
r.h = Request::HREQUEST_REFERENCE_ZX; r.h = Request::HREQUEST_REFERENCE_ZX;
request.Add(&r); request.Add(&r);
@ -69,8 +69,8 @@ void SolveSpace::Solve(void) {
double a, b, c, d; double a, b, c, d;
} Quat[] = { } Quat[] = {
{ Request::HREQUEST_REFERENCE_XY, 1, 0, 0, 0, }, { Request::HREQUEST_REFERENCE_XY, 1, 0, 0, 0, },
{ Request::HREQUEST_REFERENCE_YZ, 0.5, 0.5, 0.5, 0.5, }, { Request::HREQUEST_REFERENCE_YZ, 0.5, -0.5, -0.5, -0.5, },
{ Request::HREQUEST_REFERENCE_ZX, 0.5, -0.5, -0.5, -0.5, }, { Request::HREQUEST_REFERENCE_ZX, 0.5, 0.5, 0.5, 0.5, },
}; };
for(i = 0; i < 3; i++) { for(i = 0; i < 3; i++) {
hEntity he; hEntity he;

View File

@ -27,8 +27,14 @@ class Expr;
#include "sketch.h" #include "sketch.h"
#include "expr.h" #include "expr.h"
// From the platform-specific code.
void Invalidate(void); void Invalidate(void);
// Utility functions that are provided in the platform-independent code.
void glxVertex3v(Vector u);
void glxWriteText(char *str);
void glxTranslatev(Vector u);
void glxOntoCsys(Vector u, Vector v);
#define arraylen(x) (sizeof((x))/sizeof((x)[0])) #define arraylen(x) (sizeof((x))/sizeof((x)[0]))

View File

@ -160,7 +160,4 @@ Vector Vector::ScaledBy(double v) {
return r; return r;
} }
void glVertex3v(Vector u)
{
glVertex3f((GLfloat)u.x, (GLfloat)u.y, (GLfloat)u.z);
}

View File

@ -247,7 +247,7 @@ static HGLRC CreateGlContext(HDC hdc)
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER; PFD_DOUBLEBUFFER;
pfd.dwLayerMask = PFD_MAIN_PLANE; pfd.dwLayerMask = PFD_MAIN_PLANE;
pfd.iPixelType = PFD_TYPE_COLORINDEX; pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 8; pfd.cColorBits = 8;
pfd.cDepthBits = 16; pfd.cDepthBits = 16;
pfd.cAccumBits = 0; pfd.cAccumBits = 0;