From 181e50f1d9c0291b4aec7c39572a95859bc5f281 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Fri, 11 Apr 2008 03:13:47 -0800 Subject: [PATCH] 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] --- Makefile | 1 + dsc.h | 2 - entity.cpp | 35 +- font.table | 1774 +++++++++++++++++++++++++++++++++++++++++++++ glhelper.cpp | 56 ++ graphicswin.cpp | 15 +- sketch.h | 3 + solvespace.cpp | 10 +- solvespace.h | 6 + util.cpp | 5 +- win32/w32main.cpp | 2 +- 11 files changed, 1884 insertions(+), 25 deletions(-) create mode 100644 font.table create mode 100644 glhelper.cpp diff --git a/Makefile b/Makefile index 87f43d2d..8e4737fe 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ SSOBJS = $(OBJDIR)\solvespace.obj \ $(OBJDIR)\util.obj \ $(OBJDIR)\entity.obj \ $(OBJDIR)\sketch.obj \ + $(OBJDIR)\glhelper.obj \ LIBS = user32.lib gdi32.lib comctl32.lib advapi32.lib opengl32.lib glu32.lib diff --git a/dsc.h b/dsc.h index b9fb180d..91d91da4 100644 --- a/dsc.h +++ b/dsc.h @@ -27,8 +27,6 @@ public: static Vector RotationU(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 { public: diff --git a/entity.cpp b/entity.cpp index 4d6a1180..8e8d3294 100644 --- a/entity.cpp +++ b/entity.cpp @@ -1,5 +1,12 @@ #include "solvespace.h" +void Entity::LineDrawHitTest(Vector a, Vector b) { + glBegin(GL_LINE_STRIP); + glxVertex3v(a); + glxVertex3v(b); + glEnd(); +} + void Entity::Draw(void) { switch(type) { case CSYS_2D: { @@ -17,15 +24,27 @@ void Entity::Draw(void) { double s = (min(SS.GW.width, SS.GW.height))*0.4; - u = u.ScaledBy(s); - v = v.ScaledBy(s); + 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); + 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(); break; } diff --git a/font.table b/font.table new file mode 100644 index 00000000..2bfc93d8 --- /dev/null +++ b/font.table @@ -0,0 +1,1774 @@ + + +#define PEN_UP 127 + +static const struct { + int points; + int width; + signed char coord[120]; +} Font[] = { + // character 32 (' ') + { 0, 16, + { 1 + } + }, + + // character 33 ('!') + { 8, 10, + { + 5, 21, + 5, 7, + PEN_UP, PEN_UP, + 5, 2, + 4, 1, + 5, 0, + 6, 1, + 5, 2, + } + }, + + // character 34 ('"') + { 5, 16, + { + 4, 21, + 4, 14, + PEN_UP, PEN_UP, + 12, 21, + 12, 14, + } + }, + + // character 35 ('#') + { 11, 21, + { + 11, 25, + 4, -7, + PEN_UP, PEN_UP, + 17, 25, + 10, -7, + PEN_UP, PEN_UP, + 4, 12, + 18, 12, + PEN_UP, PEN_UP, + 3, 6, + 17, 6, + } + }, + + // character 36 ('$') + { 26, 20, + { + 8, 25, + 8, -4, + PEN_UP, PEN_UP, + 12, 25, + 12, -4, + PEN_UP, PEN_UP, + 17, 18, + 15, 20, + 12, 21, + 8, 21, + 5, 20, + 3, 18, + 3, 16, + 4, 14, + 5, 13, + 7, 12, + 13, 10, + 15, 9, + 16, 8, + 17, 6, + 17, 3, + 15, 1, + 12, 0, + 8, 0, + 5, 1, + 3, 3, + } + }, + + // character 37 ('%') + { 31, 24, + { + 21, 21, + 3, 0, + PEN_UP, PEN_UP, + 8, 21, + 10, 19, + 10, 17, + 9, 15, + 7, 14, + 5, 14, + 3, 16, + 3, 18, + 4, 20, + 6, 21, + 8, 21, + 10, 20, + 13, 19, + 16, 19, + 19, 20, + 21, 21, + PEN_UP, PEN_UP, + 17, 7, + 15, 6, + 14, 4, + 14, 2, + 16, 0, + 18, 0, + 20, 1, + 21, 3, + 21, 5, + 19, 7, + 17, 7, + } + }, + + // character 38 ('&') + { 34, 26, + { + 23, 12, + 23, 13, + 22, 14, + 21, 14, + 20, 13, + 19, 11, + 17, 6, + 15, 3, + 13, 1, + 11, 0, + 7, 0, + 5, 1, + 4, 2, + 3, 4, + 3, 6, + 4, 8, + 5, 9, + 12, 13, + 13, 14, + 14, 16, + 14, 18, + 13, 20, + 11, 21, + 9, 20, + 8, 18, + 8, 16, + 9, 13, + 11, 10, + 16, 3, + 18, 1, + 20, 0, + 22, 0, + 23, 1, + 23, 2, + } + }, + + // character 39 (''') + { 7, 10, + { + 5, 19, + 4, 20, + 5, 21, + 6, 20, + 6, 18, + 5, 16, + 4, 15, + } + }, + + // character 40 ('(') + { 10, 14, + { + 11, 25, + 9, 23, + 7, 20, + 5, 16, + 4, 11, + 4, 7, + 5, 2, + 7, -2, + 9, -5, + 11, -7, + } + }, + + // character 41 (')') + { 10, 14, + { + 3, 25, + 5, 23, + 7, 20, + 9, 16, + 10, 11, + 10, 7, + 9, 2, + 7, -2, + 5, -5, + 3, -7, + } + }, + + // character 42 ('*') + { 8, 16, + { + 8, 21, + 8, 9, + PEN_UP, PEN_UP, + 3, 18, + 13, 12, + PEN_UP, PEN_UP, + 13, 18, + 3, 12, + } + }, + + // character 43 ('+') + { 5, 26, + { + 13, 18, + 13, 0, + PEN_UP, PEN_UP, + 4, 9, + 22, 9, + } + }, + + // character 44 (',') + { 8, 10, + { + 6, 1, + 5, 0, + 4, 1, + 5, 2, + 6, 1, + 6, -1, + 5, -3, + 4, -4, + } + }, + + // character 45 ('-') + { 2, 26, + { + 4, 9, + 22, 9, + } + }, + + // character 46 ('.') + { 5, 10, + { + 5, 2, + 4, 1, + 5, 0, + 6, 1, + 5, 2, + } + }, + + // character 47 ('/') + { 2, 22, + { + 20, 25, + 2, -7, + } + }, + + // character 48 ('0') + { 17, 20, + { + 9, 21, + 6, 20, + 4, 17, + 3, 12, + 3, 9, + 4, 4, + 6, 1, + 9, 0, + 11, 0, + 14, 1, + 16, 4, + 17, 9, + 17, 12, + 16, 17, + 14, 20, + 11, 21, + 9, 21, + } + }, + + // character 49 ('1') + { 4, 20, + { + 6, 17, + 8, 18, + 11, 21, + 11, 0, + } + }, + + // character 50 ('2') + { 14, 20, + { + 4, 16, + 4, 17, + 5, 19, + 6, 20, + 8, 21, + 12, 21, + 14, 20, + 15, 19, + 16, 17, + 16, 15, + 15, 13, + 13, 10, + 3, 0, + 17, 0, + } + }, + + // character 51 ('3') + { 15, 20, + { + 5, 21, + 16, 21, + 10, 13, + 13, 13, + 15, 12, + 16, 11, + 17, 8, + 17, 6, + 16, 3, + 14, 1, + 11, 0, + 8, 0, + 5, 1, + 4, 2, + 3, 4, + } + }, + + // character 52 ('4') + { 6, 20, + { + 13, 21, + 3, 7, + 18, 7, + PEN_UP, PEN_UP, + 13, 21, + 13, 0, + } + }, + + // character 53 ('5') + { 17, 20, + { + 15, 21, + 5, 21, + 4, 12, + 5, 13, + 8, 14, + 11, 14, + 14, 13, + 16, 11, + 17, 8, + 17, 6, + 16, 3, + 14, 1, + 11, 0, + 8, 0, + 5, 1, + 4, 2, + 3, 4, + } + }, + + // character 54 ('6') + { 23, 20, + { + 16, 18, + 15, 20, + 12, 21, + 10, 21, + 7, 20, + 5, 17, + 4, 12, + 4, 7, + 5, 3, + 7, 1, + 10, 0, + 11, 0, + 14, 1, + 16, 3, + 17, 6, + 17, 7, + 16, 10, + 14, 12, + 11, 13, + 10, 13, + 7, 12, + 5, 10, + 4, 7, + } + }, + + // character 55 ('7') + { 5, 20, + { + 17, 21, + 7, 0, + PEN_UP, PEN_UP, + 3, 21, + 17, 21, + } + }, + + // character 56 ('8') + { 29, 20, + { + 8, 21, + 5, 20, + 4, 18, + 4, 16, + 5, 14, + 7, 13, + 11, 12, + 14, 11, + 16, 9, + 17, 7, + 17, 4, + 16, 2, + 15, 1, + 12, 0, + 8, 0, + 5, 1, + 4, 2, + 3, 4, + 3, 7, + 4, 9, + 6, 11, + 9, 12, + 13, 13, + 15, 14, + 16, 16, + 16, 18, + 15, 20, + 12, 21, + 8, 21, + } + }, + + // character 57 ('9') + { 23, 20, + { + 16, 14, + 15, 11, + 13, 9, + 10, 8, + 9, 8, + 6, 9, + 4, 11, + 3, 14, + 3, 15, + 4, 18, + 6, 20, + 9, 21, + 10, 21, + 13, 20, + 15, 18, + 16, 14, + 16, 9, + 15, 4, + 13, 1, + 10, 0, + 8, 0, + 5, 1, + 4, 3, + } + }, + + // character 58 (':') + { 11, 10, + { + 5, 14, + 4, 13, + 5, 12, + 6, 13, + 5, 14, + PEN_UP, PEN_UP, + 5, 2, + 4, 1, + 5, 0, + 6, 1, + 5, 2, + } + }, + + // character 59 (';') + { 14, 10, + { + 5, 14, + 4, 13, + 5, 12, + 6, 13, + 5, 14, + PEN_UP, PEN_UP, + 6, 1, + 5, 0, + 4, 1, + 5, 2, + 6, 1, + 6, -1, + 5, -3, + 4, -4, + } + }, + + // character 60 ('<') + { 3, 24, + { + 20, 18, + 4, 9, + 20, 0, + } + }, + + // character 61 ('=') + { 5, 26, + { + 4, 12, + 22, 12, + PEN_UP, PEN_UP, + 4, 6, + 22, 6, + } + }, + + // character 62 ('>') + { 3, 24, + { + 4, 18, + 20, 9, + 4, 0, + } + }, + + // character 63 ('?') + { 20, 18, + { + 3, 16, + 3, 17, + 4, 19, + 5, 20, + 7, 21, + 11, 21, + 13, 20, + 14, 19, + 15, 17, + 15, 15, + 14, 13, + 13, 12, + 9, 10, + 9, 7, + PEN_UP, PEN_UP, + 9, 2, + 8, 1, + 9, 0, + 10, 1, + 9, 2, + } + }, + + // character 64 ('@') + { 55, 27, + { + 18, 13, + 17, 15, + 15, 16, + 12, 16, + 10, 15, + 9, 14, + 8, 11, + 8, 8, + 9, 6, + 11, 5, + 14, 5, + 16, 6, + 17, 8, + PEN_UP, PEN_UP, + 12, 16, + 10, 14, + 9, 11, + 9, 8, + 10, 6, + 11, 5, + PEN_UP, PEN_UP, + 18, 16, + 17, 8, + 17, 6, + 19, 5, + 21, 5, + 23, 7, + 24, 10, + 24, 12, + 23, 15, + 22, 17, + 20, 19, + 18, 20, + 15, 21, + 12, 21, + 9, 20, + 7, 19, + 5, 17, + 4, 15, + 3, 12, + 3, 9, + 4, 6, + 5, 4, + 7, 2, + 9, 1, + 12, 0, + 15, 0, + 18, 1, + 20, 2, + 21, 3, + PEN_UP, PEN_UP, + 19, 16, + 18, 8, + 18, 6, + 19, 5, + } + }, + + // character 65 ('A') + { 8, 18, + { + 9, 21, + 1, 0, + PEN_UP, PEN_UP, + 9, 21, + 17, 0, + PEN_UP, PEN_UP, + 4, 7, + 14, 7, + } + }, + + // character 66 ('B') + { 23, 21, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 4, 21, + 13, 21, + 16, 20, + 17, 19, + 18, 17, + 18, 15, + 17, 13, + 16, 12, + 13, 11, + PEN_UP, PEN_UP, + 4, 11, + 13, 11, + 16, 10, + 17, 9, + 18, 7, + 18, 4, + 17, 2, + 16, 1, + 13, 0, + 4, 0, + } + }, + + // character 67 ('C') + { 18, 21, + { + 18, 16, + 17, 18, + 15, 20, + 13, 21, + 9, 21, + 7, 20, + 5, 18, + 4, 16, + 3, 13, + 3, 8, + 4, 5, + 5, 3, + 7, 1, + 9, 0, + 13, 0, + 15, 1, + 17, 3, + 18, 5, + } + }, + + // character 68 ('D') + { 15, 21, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 4, 21, + 11, 21, + 14, 20, + 16, 18, + 17, 16, + 18, 13, + 18, 8, + 17, 5, + 16, 3, + 14, 1, + 11, 0, + 4, 0, + } + }, + + // character 69 ('E') + { 11, 19, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 4, 21, + 17, 21, + PEN_UP, PEN_UP, + 4, 11, + 12, 11, + PEN_UP, PEN_UP, + 4, 0, + 17, 0, + } + }, + + // character 70 ('F') + { 8, 18, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 4, 21, + 17, 21, + PEN_UP, PEN_UP, + 4, 11, + 12, 11, + } + }, + + // character 71 ('G') + { 22, 21, + { + 18, 16, + 17, 18, + 15, 20, + 13, 21, + 9, 21, + 7, 20, + 5, 18, + 4, 16, + 3, 13, + 3, 8, + 4, 5, + 5, 3, + 7, 1, + 9, 0, + 13, 0, + 15, 1, + 17, 3, + 18, 5, + 18, 8, + PEN_UP, PEN_UP, + 13, 8, + 18, 8, + } + }, + + // character 72 ('H') + { 8, 22, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 18, 21, + 18, 0, + PEN_UP, PEN_UP, + 4, 11, + 18, 11, + } + }, + + // character 73 ('I') + { 2, 8, + { + 4, 21, + 4, 0, + } + }, + + // character 74 ('J') + { 10, 16, + { + 12, 21, + 12, 5, + 11, 2, + 10, 1, + 8, 0, + 6, 0, + 4, 1, + 3, 2, + 2, 5, + 2, 7, + } + }, + + // character 75 ('K') + { 8, 21, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 18, 21, + 4, 7, + PEN_UP, PEN_UP, + 9, 12, + 18, 0, + } + }, + + // character 76 ('L') + { 5, 17, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 4, 0, + 16, 0, + } + }, + + // character 77 ('M') + { 11, 24, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 4, 21, + 12, 0, + PEN_UP, PEN_UP, + 20, 21, + 12, 0, + PEN_UP, PEN_UP, + 20, 21, + 20, 0, + } + }, + + // character 78 ('N') + { 8, 22, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 4, 21, + 18, 0, + PEN_UP, PEN_UP, + 18, 21, + 18, 0, + } + }, + + // character 79 ('O') + { 21, 22, + { + 9, 21, + 7, 20, + 5, 18, + 4, 16, + 3, 13, + 3, 8, + 4, 5, + 5, 3, + 7, 1, + 9, 0, + 13, 0, + 15, 1, + 17, 3, + 18, 5, + 19, 8, + 19, 13, + 18, 16, + 17, 18, + 15, 20, + 13, 21, + 9, 21, + } + }, + + // character 80 ('P') + { 13, 21, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 4, 21, + 13, 21, + 16, 20, + 17, 19, + 18, 17, + 18, 14, + 17, 12, + 16, 11, + 13, 10, + 4, 10, + } + }, + + // character 81 ('Q') + { 24, 22, + { + 9, 21, + 7, 20, + 5, 18, + 4, 16, + 3, 13, + 3, 8, + 4, 5, + 5, 3, + 7, 1, + 9, 0, + 13, 0, + 15, 1, + 17, 3, + 18, 5, + 19, 8, + 19, 13, + 18, 16, + 17, 18, + 15, 20, + 13, 21, + 9, 21, + PEN_UP, PEN_UP, + 12, 4, + 18, -2, + } + }, + + // character 82 ('R') + { 16, 21, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 4, 21, + 13, 21, + 16, 20, + 17, 19, + 18, 17, + 18, 15, + 17, 13, + 16, 12, + 13, 11, + 4, 11, + PEN_UP, PEN_UP, + 11, 11, + 18, 0, + } + }, + + // character 83 ('S') + { 20, 20, + { + 17, 18, + 15, 20, + 12, 21, + 8, 21, + 5, 20, + 3, 18, + 3, 16, + 4, 14, + 5, 13, + 7, 12, + 13, 10, + 15, 9, + 16, 8, + 17, 6, + 17, 3, + 15, 1, + 12, 0, + 8, 0, + 5, 1, + 3, 3, + } + }, + + // character 84 ('T') + { 5, 16, + { + 8, 21, + 8, 0, + PEN_UP, PEN_UP, + 1, 21, + 15, 21, + } + }, + + // character 85 ('U') + { 10, 22, + { + 4, 21, + 4, 6, + 5, 3, + 7, 1, + 10, 0, + 12, 0, + 15, 1, + 17, 3, + 18, 6, + 18, 21, + } + }, + + // character 86 ('V') + { 5, 18, + { + 1, 21, + 9, 0, + PEN_UP, PEN_UP, + 17, 21, + 9, 0, + } + }, + + // character 87 ('W') + { 11, 24, + { + 2, 21, + 7, 0, + PEN_UP, PEN_UP, + 12, 21, + 7, 0, + PEN_UP, PEN_UP, + 12, 21, + 17, 0, + PEN_UP, PEN_UP, + 22, 21, + 17, 0, + } + }, + + // character 88 ('X') + { 5, 20, + { + 3, 21, + 17, 0, + PEN_UP, PEN_UP, + 17, 21, + 3, 0, + } + }, + + // character 89 ('Y') + { 6, 18, + { + 1, 21, + 9, 11, + 9, 0, + PEN_UP, PEN_UP, + 17, 21, + 9, 11, + } + }, + + // character 90 ('Z') + { 8, 20, + { + 17, 21, + 3, 0, + PEN_UP, PEN_UP, + 3, 21, + 17, 21, + PEN_UP, PEN_UP, + 3, 0, + 17, 0, + } + }, + + // character 91 ('[') + { 11, 14, + { + 4, 25, + 4, -7, + PEN_UP, PEN_UP, + 5, 25, + 5, -7, + PEN_UP, PEN_UP, + 4, 25, + 11, 25, + PEN_UP, PEN_UP, + 4, -7, + 11, -7, + } + }, + + // character 92 ('\') + { 2, 14, + { + 0, 21, + 14, -3, + } + }, + + // character 93 (']') + { 11, 14, + { + 9, 25, + 9, -7, + PEN_UP, PEN_UP, + 10, 25, + 10, -7, + PEN_UP, PEN_UP, + 3, 25, + 10, 25, + PEN_UP, PEN_UP, + 3, -7, + 10, -7, + } + }, + + // character 94 ('^') + { 10, 16, + { + 6, 15, + 8, 18, + 10, 15, + PEN_UP, PEN_UP, + 3, 12, + 8, 17, + 13, 12, + PEN_UP, PEN_UP, + 8, 17, + 8, 0, + } + }, + + // character 95 ('_') + { 2, 16, + { + 0, -2, + 16, -2, + } + }, + + // character 96 ('`') + { 7, 10, + { + 6, 21, + 5, 20, + 4, 18, + 4, 16, + 5, 15, + 6, 16, + 5, 17, + } + }, + + // character 97 ('a') + { 17, 19, + { + 15, 14, + 15, 0, + PEN_UP, PEN_UP, + 15, 11, + 13, 13, + 11, 14, + 8, 14, + 6, 13, + 4, 11, + 3, 8, + 3, 6, + 4, 3, + 6, 1, + 8, 0, + 11, 0, + 13, 1, + 15, 3, + } + }, + + // character 98 ('b') + { 17, 19, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 4, 11, + 6, 13, + 8, 14, + 11, 14, + 13, 13, + 15, 11, + 16, 8, + 16, 6, + 15, 3, + 13, 1, + 11, 0, + 8, 0, + 6, 1, + 4, 3, + } + }, + + // character 99 ('c') + { 14, 18, + { + 15, 11, + 13, 13, + 11, 14, + 8, 14, + 6, 13, + 4, 11, + 3, 8, + 3, 6, + 4, 3, + 6, 1, + 8, 0, + 11, 0, + 13, 1, + 15, 3, + } + }, + + // character 100 ('d') + { 17, 19, + { + 15, 21, + 15, 0, + PEN_UP, PEN_UP, + 15, 11, + 13, 13, + 11, 14, + 8, 14, + 6, 13, + 4, 11, + 3, 8, + 3, 6, + 4, 3, + 6, 1, + 8, 0, + 11, 0, + 13, 1, + 15, 3, + } + }, + + // character 101 ('e') + { 17, 18, + { + 3, 8, + 15, 8, + 15, 10, + 14, 12, + 13, 13, + 11, 14, + 8, 14, + 6, 13, + 4, 11, + 3, 8, + 3, 6, + 4, 3, + 6, 1, + 8, 0, + 11, 0, + 13, 1, + 15, 3, + } + }, + + // character 102 ('f') + { 8, 12, + { + 10, 21, + 8, 21, + 6, 20, + 5, 17, + 5, 0, + PEN_UP, PEN_UP, + 2, 14, + 9, 14, + } + }, + + // character 103 ('g') + { 22, 19, + { + 15, 14, + 15, -2, + 14, -5, + 13, -6, + 11, -7, + 8, -7, + 6, -6, + PEN_UP, PEN_UP, + 15, 11, + 13, 13, + 11, 14, + 8, 14, + 6, 13, + 4, 11, + 3, 8, + 3, 6, + 4, 3, + 6, 1, + 8, 0, + 11, 0, + 13, 1, + 15, 3, + } + }, + + // character 104 ('h') + { 10, 19, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 4, 10, + 7, 13, + 9, 14, + 12, 14, + 14, 13, + 15, 10, + 15, 0, + } + }, + + // character 105 ('i') + { 8, 8, + { + 3, 21, + 4, 20, + 5, 21, + 4, 22, + 3, 21, + PEN_UP, PEN_UP, + 4, 14, + 4, 0, + } + }, + + // character 106 ('j') + { 11, 10, + { + 5, 21, + 6, 20, + 7, 21, + 6, 22, + 5, 21, + PEN_UP, PEN_UP, + 6, 14, + 6, -3, + 5, -6, + 3, -7, + 1, -7, + } + }, + + // character 107 ('k') + { 8, 17, + { + 4, 21, + 4, 0, + PEN_UP, PEN_UP, + 14, 14, + 4, 4, + PEN_UP, PEN_UP, + 8, 8, + 15, 0, + } + }, + + // character 108 ('l') + { 2, 8, + { + 4, 21, + 4, 0, + } + }, + + // character 109 ('m') + { 18, 30, + { + 4, 14, + 4, 0, + PEN_UP, PEN_UP, + 4, 10, + 7, 13, + 9, 14, + 12, 14, + 14, 13, + 15, 10, + 15, 0, + PEN_UP, PEN_UP, + 15, 10, + 18, 13, + 20, 14, + 23, 14, + 25, 13, + 26, 10, + 26, 0, + } + }, + + // character 110 ('n') + { 10, 19, + { + 4, 14, + 4, 0, + PEN_UP, PEN_UP, + 4, 10, + 7, 13, + 9, 14, + 12, 14, + 14, 13, + 15, 10, + 15, 0, + } + }, + + // character 111 ('o') + { 17, 19, + { + 8, 14, + 6, 13, + 4, 11, + 3, 8, + 3, 6, + 4, 3, + 6, 1, + 8, 0, + 11, 0, + 13, 1, + 15, 3, + 16, 6, + 16, 8, + 15, 11, + 13, 13, + 11, 14, + 8, 14, + } + }, + + // character 112 ('p') + { 17, 19, + { + 4, 14, + 4, -7, + PEN_UP, PEN_UP, + 4, 11, + 6, 13, + 8, 14, + 11, 14, + 13, 13, + 15, 11, + 16, 8, + 16, 6, + 15, 3, + 13, 1, + 11, 0, + 8, 0, + 6, 1, + 4, 3, + } + }, + + // character 113 ('q') + { 17, 19, + { + 15, 14, + 15, -7, + PEN_UP, PEN_UP, + 15, 11, + 13, 13, + 11, 14, + 8, 14, + 6, 13, + 4, 11, + 3, 8, + 3, 6, + 4, 3, + 6, 1, + 8, 0, + 11, 0, + 13, 1, + 15, 3, + } + }, + + // character 114 ('r') + { 8, 13, + { + 4, 14, + 4, 0, + PEN_UP, PEN_UP, + 4, 8, + 5, 11, + 7, 13, + 9, 14, + 12, 14, + } + }, + + // character 115 ('s') + { 17, 17, + { + 14, 11, + 13, 13, + 10, 14, + 7, 14, + 4, 13, + 3, 11, + 4, 9, + 6, 8, + 11, 7, + 13, 6, + 14, 4, + 14, 3, + 13, 1, + 10, 0, + 7, 0, + 4, 1, + 3, 3, + } + }, + + // character 116 ('t') + { 8, 12, + { + 5, 21, + 5, 4, + 6, 1, + 8, 0, + 10, 0, + PEN_UP, PEN_UP, + 2, 14, + 9, 14, + } + }, + + // character 117 ('u') + { 10, 19, + { + 4, 14, + 4, 4, + 5, 1, + 7, 0, + 10, 0, + 12, 1, + 15, 4, + PEN_UP, PEN_UP, + 15, 14, + 15, 0, + } + }, + + // character 118 ('v') + { 5, 16, + { + 2, 14, + 8, 0, + PEN_UP, PEN_UP, + 14, 14, + 8, 0, + } + }, + + // character 119 ('w') + { 11, 22, + { + 3, 14, + 7, 0, + PEN_UP, PEN_UP, + 11, 14, + 7, 0, + PEN_UP, PEN_UP, + 11, 14, + 15, 0, + PEN_UP, PEN_UP, + 19, 14, + 15, 0, + } + }, + + // character 120 ('x') + { 5, 17, + { + 3, 14, + 14, 0, + PEN_UP, PEN_UP, + 14, 14, + 3, 0, + } + }, + + // character 121 ('y') + { 9, 16, + { + 2, 14, + 8, 0, + PEN_UP, PEN_UP, + 14, 14, + 8, 0, + 6, -4, + 4, -6, + 2, -7, + 1, -7, + } + }, + + // character 122 ('z') + { 8, 17, + { + 14, 14, + 3, 0, + PEN_UP, PEN_UP, + 3, 14, + 14, 14, + PEN_UP, PEN_UP, + 3, 0, + 14, 0, + } + }, + + // character 123 ('{') + { 39, 14, + { + 9, 25, + 7, 24, + 6, 23, + 5, 21, + 5, 19, + 6, 17, + 7, 16, + 8, 14, + 8, 12, + 6, 10, + PEN_UP, PEN_UP, + 7, 24, + 6, 22, + 6, 20, + 7, 18, + 8, 17, + 9, 15, + 9, 13, + 8, 11, + 4, 9, + 8, 7, + 9, 5, + 9, 3, + 8, 1, + 7, 0, + 6, -2, + 6, -4, + 7, -6, + PEN_UP, PEN_UP, + 6, 8, + 8, 6, + 8, 4, + 7, 2, + 6, 1, + 5, -1, + 5, -3, + 6, -5, + 7, -6, + 9, -7, + } + }, + + // character 124 ('|') + { 2, 8, + { + 4, 25, + 4, -7, + } + }, + + // character 125 ('}') + { 39, 14, + { + 5, 25, + 7, 24, + 8, 23, + 9, 21, + 9, 19, + 8, 17, + 7, 16, + 6, 14, + 6, 12, + 8, 10, + PEN_UP, PEN_UP, + 7, 24, + 8, 22, + 8, 20, + 7, 18, + 6, 17, + 5, 15, + 5, 13, + 6, 11, + 10, 9, + 6, 7, + 5, 5, + 5, 3, + 6, 1, + 7, 0, + 8, -2, + 8, -4, + 7, -6, + PEN_UP, PEN_UP, + 8, 8, + 6, 6, + 6, 4, + 7, 2, + 8, 1, + 9, -1, + 9, -3, + 8, -5, + 7, -6, + 5, -7, + } + }, + + // character 126 ('~') + { 23, 24, + { + 3, 6, + 3, 8, + 4, 11, + 6, 12, + 8, 12, + 10, 11, + 14, 8, + 16, 7, + 18, 7, + 20, 8, + 21, 10, + PEN_UP, PEN_UP, + 3, 8, + 4, 10, + 6, 11, + 8, 11, + 10, 10, + 14, 7, + 16, 6, + 18, 6, + 20, 7, + 21, 10, + 21, 12, + } + }, +}; + diff --git a/glhelper.cpp b/glhelper.cpp new file mode 100644 index 00000000..1b77e53f --- /dev/null +++ b/glhelper.cpp @@ -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); +} diff --git a/graphicswin.cpp b/graphicswin.cpp index cd754b98..3390677b 100644 --- a/graphicswin.cpp +++ b/graphicswin.cpp @@ -76,13 +76,14 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown, projDown = orig.projDown.RotatedAbout(orig.projRight, s*dy); 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(); } } @@ -142,7 +143,11 @@ void GraphicsWindow::Paint(int w, int h) { 0, 0, 0, 1); glMultMatrixd(mat); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glEnable(GL_LINE_SMOOTH); glEnable(GL_DEPTH_TEST); + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glClearIndex((GLfloat)0); glClearDepth(1.0); diff --git a/sketch.h b/sketch.h index e16a55a7..2a5fdfce 100644 --- a/sketch.h +++ b/sketch.h @@ -97,11 +97,14 @@ public: Expr *expr[16]; + inline hRequest request(void) + { hRequest r; r.v = (this->h.v >> 11); return r; } inline hParam param(int i) { hParam r; r.v = ((this->h.v) << 8) | i; return r; } inline hPoint point(int i) { hPoint r; r.v = ((this->h.v) << 8) | i; return r; } + void LineDrawHitTest(Vector a, Vector b); void Draw(void); }; diff --git a/solvespace.cpp b/solvespace.cpp index 014b734e..c143b08d 100644 --- a/solvespace.cpp +++ b/solvespace.cpp @@ -36,15 +36,15 @@ void SolveSpace::Init(void) { r.type = Request::CSYS_2D; r.group = Group::HGROUP_REFERENCES; - r.name.strcpy("__xy_plane"); + r.name.strcpy("#xy-plane"); r.h = Request::HREQUEST_REFERENCE_XY; request.Add(&r); - r.name.strcpy("__yz_plane"); + r.name.strcpy("#yz-plane"); r.h = Request::HREQUEST_REFERENCE_YZ; request.Add(&r); - r.name.strcpy("__zx_plane"); + r.name.strcpy("#zx-plane"); r.h = Request::HREQUEST_REFERENCE_ZX; request.Add(&r); @@ -69,8 +69,8 @@ void SolveSpace::Solve(void) { double a, b, c, d; } Quat[] = { { Request::HREQUEST_REFERENCE_XY, 1, 0, 0, 0, }, - { 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_YZ, 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++) { hEntity he; diff --git a/solvespace.h b/solvespace.h index 95199bd7..280ef941 100644 --- a/solvespace.h +++ b/solvespace.h @@ -27,8 +27,14 @@ class Expr; #include "sketch.h" #include "expr.h" +// From the platform-specific code. 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])) diff --git a/util.cpp b/util.cpp index 81d72a98..6b3a6c93 100644 --- a/util.cpp +++ b/util.cpp @@ -160,7 +160,4 @@ Vector Vector::ScaledBy(double v) { return r; } -void glVertex3v(Vector u) -{ - glVertex3f((GLfloat)u.x, (GLfloat)u.y, (GLfloat)u.z); -} + diff --git a/win32/w32main.cpp b/win32/w32main.cpp index cacb450b..849aed03 100644 --- a/win32/w32main.cpp +++ b/win32/w32main.cpp @@ -247,7 +247,7 @@ static HGLRC CreateGlContext(HDC hdc) pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.dwLayerMask = PFD_MAIN_PLANE; - pfd.iPixelType = PFD_TYPE_COLORINDEX; + pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 8; pfd.cDepthBits = 16; pfd.cAccumBits = 0;