filled model drawing (for some models)

This commit is contained in:
Zeno Rogue 2018-11-08 16:28:17 +01:00
parent b019cfcd4f
commit 5978830e01
7 changed files with 209 additions and 151 deletions

View File

@ -908,7 +908,7 @@ color_t gradient(color_t c0, color_t c1, ld v0, ld v, ld v1) {
return c;
}
void drawCircle(int x, int y, int size, color_t color) {
void drawCircle(int x, int y, int size, color_t color, color_t fillcolor) {
if(size < 0) size = -size;
#if CAP_GL
if(vid.usingGL) {
@ -916,7 +916,6 @@ void drawCircle(int x, int y, int size, color_t color) {
glhr::be_nontextured();
glhr::id_modelview();
glcoords.clear();
glhr::color2(color);
x -= vid.xcenter; y -= vid.ycenter;
int pts = size * 4;
if(pts > 1500) pts = 1500;
@ -927,7 +926,14 @@ void drawCircle(int x, int y, int size, color_t color) {
}
glhr::vertices(glcoords);
glhr::set_depthtest(false);
glDrawArrays(GL_LINE_LOOP, 0, pts);
if(fillcolor) {
glhr::color2(fillcolor);
glDrawArrays(GL_TRIANGLE_FAN, 0, pts);
}
if(color) {
glhr::color2(color);
glDrawArrays(GL_LINE_LOOP, 0, pts);
}
return;
}
#endif
@ -935,10 +941,14 @@ void drawCircle(int x, int y, int size, color_t color) {
#if CAP_XGD
gdpush(4); gdpush(color); gdpush(x); gdpush(y); gdpush(size);
#elif CAP_SDLGFX
if(vid.stretch == 1)
((vid.antialias && AA_NOGL)?aacircleColor:circleColor) (s, x, y, size, color);
else
((vid.antialias && AA_NOGL)?aaellipseColor:ellipseColor) (s, x, y, size, size * vid.stretch, color);
if(vid.stretch == 1) {
if(fillcolor) filledCircleColor(s, x, y, size, fillcolor);
if(color) ((vid.antialias && AA_NOGL)?aacircleColor:circleColor) (s, x, y, size, color);
}
else {
if(fillcolor) filledEllipseColor(s, x, y, size, size * vid.stretch, fillcolor);
if(color) ((vid.antialias && AA_NOGL)?aaellipseColor:ellipseColor) (s, x, y, size, size * vid.stretch, color);
}
#elif CAP_SDL
int pts = size * 4;
if(pts > 1500) pts = 1500;

View File

@ -1492,6 +1492,9 @@ int read_config_args() {
else if(argis("-back")) {
PHASEFROM(2); shift(); backcolor = arghex();
}
else if(argis("-fillmodel")) {
PHASEFROM(2); shift(); fillmodel = arghex();
}
else if(argis("-ring")) {
PHASEFROM(2); shift(); ringcolor = arghex();
}
@ -1517,6 +1520,11 @@ int read_config_args() {
vsync_off = true;
if(curphase == 3) setvideomode();
}
else if(argis("-aura")) {
PHASEFROM(2);
shift(); vid.aurastr = argi();
shift(); vid.aurasmoothen = argi();
}
else if(argis("-nofps")) {
nofps = true;
}

View File

@ -93,30 +93,6 @@ namespace polygonal {
}
pair<ld, ld> compute(ld x, ld y) { return compute(x,y,deg); }
void drawBoundary(int color) {
queuereset(mdUnchanged, PPR::CIRCLE);
ld C, S;
auto& ho = conformal::model_orientation;
if(ho == 0) C = 1, S = 0;
else if(ho == 180) C = -1, S = 0;
else C = cos(ho * M_PI/180), S = sin(ho * M_PI / 180);
for(int r=0; r<=2000; r++) {
cxld z = exp(cxld(0, 2*M_PI * r / 2000.0));
pair<xld,xld> z2 = compute(real(z), imag(z), deg);
hyperpoint h;
h[0] = (z2.first * C - z2.second * S) * vid.radius;
h[1] = (z2.second * C + z2.first * S) * vid.radius;
h[2] = stereo::scrdist;
curvepoint(h);
}
queuecurve(color, 0, PPR::CIRCLE);
queuereset(pmodel, PPR::CIRCLE);
}
}
#if CAP_SDL

249
graph.cpp
View File

@ -5504,103 +5504,36 @@ function<void()> wrap_drawfullmap = drawfullmap;
bool force_sphere_outline = false;
void drawfullmap() {
void circle_around_center(ld radius, color_t linecol, color_t fillcol, PPR prio) {
if(among(pmodel, mdDisk, mdEquiarea, mdEquidistant, mdFisheye) && !(pmodel == mdDisk && hyperbolic && vid.alpha <= -1)) {
hyperpoint ret;
applymodel(xpush0(radius), ret);
ld r = hypot2(ret);
queuecircle(vid.xcenter, vid.ycenter, r * vid.radius, linecol, prio, fillcol);
return;
}
for(int i=0; i<360; i++) curvepoint(xspinpush0(i * 2 * M_PI / 360, 10));
auto& c = queuecurve(linecol, fillcol, prio);
if(pmodel == mdDisk && hyperbolic && vid.alpha <= -1)
c.flags |= POLY_FORCE_INVERTED;
if(pmodel == mdJoukowsky)
c.flags |= POLY_FORCE_INVERTED;
}
DEBB(DF_GRAPH, (debugfile,"draw full map\n"));
ptds.clear();
void draw_model_elements() {
if(elliptic || (vid.grid && sphere))
circle_around_center(M_PI/2, ringcolor, 0, PPR::CIRCLE);
if(pmodel == mdTwoPoint) {
ld a = -conformal::model_orientation * M_PI / 180;
queuechr(xspinpush0(a, +vid.twopoint_param), vid.xres / 100, 'X', 0xFF0000);
queuechr(xspinpush0(a, -vid.twopoint_param), vid.xres / 100, 'X', 0xFF0000);
}
/*
if(conformal::on) {
char ch = 'A';
for(auto& v: conformal::v) {
queuepoly(ggmatrix(v->base) * v->at, shTriangle, 0x306090C0);
queuechr(ggmatrix(v->base) * v->at * C0, 10, ch++, 0xFF0000);
}
}
*/
if(!twopoint_do_flips && !stereo::active() && sphere && pmodel == mdTwoPoint) {
queuereset(vid.usingGL ? mdDisk : mdUnchanged, PPR::CIRCLE);
for(int b=-1; b<=1; b+=2)
for(ld a=-90; a<=90+1e-6; a+=pow(.5, vid.linequality)) {
using namespace hyperpoint_vec;
ld x = sin(a * vid.twopoint_param * b / 90);
ld y = 0;
ld z = -sqrt(1 - x*x);
conformal::apply_orientation(y, x);
hyperpoint h1;
applymodel(hpxyz(x,y,z), h1);
conformal::apply_orientation(h1[0], h1[1]);
h1[1] = abs(h1[1]) * b;
conformal::apply_orientation(h1[1], h1[0]);
curvepoint(h1);
}
queuecurve(ringcolor, 0, PPR::CIRCLE);
queuereset(pmodel, PPR::CIRCLE);
}
if(!stereo::active() && sphere && pmodel == mdSinusoidal) {
queuereset(vid.usingGL ? mdDisk : mdUnchanged, PPR::CIRCLE);
for(ld a=-45; a<45+1e-6; a+=pow(.5, vid.linequality)) {
curvepoint(hpxyz(cos(a * M_PI / 90) * vid.radius, a * vid.radius / 90, 0));
}
for(ld a=45; a>=-45-1e-6; a-=pow(.5, vid.linequality)) {
curvepoint(hpxyz(-cos(a * M_PI / 90) * vid.radius, a * vid.radius / 90, 0));
}
queuecurve(ringcolor, 0, PPR::CIRCLE);
queuereset(pmodel, PPR::CIRCLE);
queuechr(xspinpush0(a, +vid.twopoint_param), vid.xres / 100, 'X', ringcolor >> 8);
queuechr(xspinpush0(a, -vid.twopoint_param), vid.xres / 100, 'X', ringcolor >> 8);
}
if(!stereo::active() && vid.grid) {
ld rad = 0;
if(pmodel == mdBand && hyperbolic) rad = vid.radius;
if(pmodel == mdBandEquidistant && sphere) rad = vid.radius / 2;
if(pmodel == mdBandEquiarea && sphere) rad = vid.radius / M_PI;
if(rad) {
queuereset(vid.usingGL ? mdDisk : mdUnchanged, PPR::CIRCLE);
curvepoint(hpxyz(-vid.xcenter, -rad, 0));
curvepoint(hpxyz(vid.xres-vid.xcenter, -rad, 0));
queuecurve(ringcolor, 0, PPR::CIRCLE);
curvepoint(hpxyz(-vid.xcenter, rad, 0));
curvepoint(hpxyz(vid.xres-vid.xcenter, rad, 0));
queuecurve(ringcolor, 0, PPR::CIRCLE);
queuereset(pmodel, PPR::CIRCLE);
}
}
if(!stereo::active() && !euclid && (pmodel == mdDisk || pmodel == mdBall || (sphere && mdAzimuthalEqui()))) {
double rad = vid.radius;
bool isbnd = true;
if(sphere) {
if(mdAzimuthalEqui())
;
else if(!vid.grid && !elliptic && !force_sphere_outline)
rad = 0;
else if(vid.alpha <= 0)
;
else if(vid.alpha <= 1 && (vid.grid || elliptic)) // mark the equator
rad = rad * 1 / vid.alpha, isbnd = false;
else if(vid.grid || force_sphere_outline) // mark the edge
rad /= sqrt(vid.alpha*vid.alpha - 1);
}
if(rad && !haveaura()) {
queuecircle(vid.xcenter, vid.ycenter, rad, ringcolor,
vid.usingGL ? PPR::CIRCLE : PPR::OUTCIRCLE, isbnd);
}
if(pmodel == mdBall) ballgeometry();
if(pmodel == mdBall) {
queuecircle(vid.xcenter, vid.ycenter, vid.radius, ringcolor, PPR::OUTCIRCLE, fillmodel);
ballgeometry();
}
if(pmodel == mdHyperboloid && hyperbolic) {
@ -5643,8 +5576,138 @@ void drawfullmap() {
#endif
}
if(pmodel == mdPolygonal || pmodel == mdPolynomial)
polygonal::drawBoundary(darkena(0xFF, 0, 0xFF));
}
void draw_boundary(int w) {
if(w == 1) return;
color_t lc = ringcolor;
color_t fc = fillmodel;
PPR p = PPR::OUTCIRCLE;
if(haveaura()) lc = 0;
if(lc == 0 && fc == 0) return;
switch(pmodel) {
case mdSinusoidal: {
if(stereo::active() || !sphere) return;
queuereset(vid.usingGL ? mdDisk : mdUnchanged, PPR::CIRCLE);
for(ld a=-45; a<45+1e-6; a+=pow(.5, vid.linequality)) {
curvepoint(hpxyz(cos(a * M_PI / 90) * vid.radius, a * vid.radius / 90, 0));
}
for(ld a=45; a>=-45-1e-6; a-=pow(.5, vid.linequality)) {
curvepoint(hpxyz(-cos(a * M_PI / 90) * vid.radius, a * vid.radius / 90, 0));
}
queuecurve(lc, fc, p);
return;
}
case mdTwoPoint: {
if(twopoint_do_flips || stereo::active() || !sphere) return;
queuereset(vid.usingGL ? mdDisk : mdUnchanged, p);
for(int b=-1; b<=1; b+=2)
for(ld a=-90; a<=90+1e-6; a+=pow(.5, vid.linequality)) {
using namespace hyperpoint_vec;
ld x = sin(a * vid.twopoint_param * b / 90);
ld y = 0;
ld z = -sqrt(1 - x*x);
conformal::apply_orientation(y, x);
hyperpoint h1;
applymodel(hpxyz(x,y,z), h1);
conformal::apply_orientation(h1[0], h1[1]);
h1[1] = abs(h1[1]) * b;
conformal::apply_orientation(h1[1], h1[0]);
curvepoint(h1);
}
queuecurve(lc, fc, p);
queuereset(pmodel, p);
return;
}
case mdBand: case mdBandEquidistant: case mdBandEquiarea: {
ld rad = 0;
if(pmodel == mdBand && hyperbolic) rad = vid.radius;
if(pmodel == mdBandEquidistant && sphere) rad = vid.radius / 2;
if(pmodel == mdBandEquiarea && sphere) rad = vid.radius / M_PI;
if(rad) {
queuereset(vid.usingGL ? mdDisk : mdUnchanged, PPR::CIRCLE);
curvepoint(hpxyz(-vid.xcenter, -rad, 0));
curvepoint(hpxyz(vid.xres-vid.xcenter, -rad, 0));
queuecurve(ringcolor, 0, PPR::CIRCLE);
curvepoint(hpxyz(-vid.xcenter, rad, 0));
curvepoint(hpxyz(vid.xres-vid.xcenter, rad, 0));
queuecurve(ringcolor, 0, PPR::CIRCLE);
queuereset(pmodel, PPR::CIRCLE);
return;
}
}
default: break;
}
/*
if(!stereo::active() && !euclid && (pmodel == mdDisk || pmodel == mdBall || (sphere && mdAzimuthalEqui()))) {
double rad = vid.radius;
bool isbnd = true;
if(sphere) {
if(mdAzimuthalEqui())
;
else if(!vid.grid && !elliptic && !force_sphere_outline)
rad = 0;
else if(vid.alpha <= 0)
;
else if(vid.grid || force_sphere_outline) // mark the edge
rad /= sqrt(vid.alpha*vid.alpha - 1);
}
if(rad)
queuecircle(vid.xcenter, vid.ycenter, rad, lc, p, fc);
return;
}
*/
if(sphere) return;
circle_around_center(hyperbolic ? 20 : exp(10), lc, fc, p);
/*
if(pmodel == mdPolygonal || pmodel == mdPolynomial)
polygonal::drawBoundary(darkena(0xFF, 0, 0xFF));
*/
}
void drawfullmap() {
DEBB(DF_GRAPH, (debugfile,"draw full map\n"));
ptds.clear();
/*
if(conformal::on) {
char ch = 'A';
for(auto& v: conformal::v) {
queuepoly(ggmatrix(v->base) * v->at, shTriangle, 0x306090C0);
queuechr(ggmatrix(v->base) * v->at * C0, 10, ch++, 0xFF0000);
}
}
*/
draw_boundary(0);
draw_boundary(1);
draw_model_elements();
if(fillmodel) {
for(int i=0; i<360; i++) curvepoint(xspinpush0(i * 2 * M_PI / 360, 10));
auto m = queuecurve(ringcolor, fillmodel, PPR::OUTCIRCLE);
}
/* if(vid.wallmode < 2 && !euclid && !patterns::whichShape) {
int ls = isize(lines);

11
hyper.h
View File

@ -945,7 +945,7 @@ bool displayfrSP(int x, int y, int sh, int b, int size, const string &s, color_t
bool outofmap(hyperpoint h);
void applymodel(hyperpoint H, hyperpoint& Hscr);
void drawCircle(int x, int y, int size, color_t color);
void drawCircle(int x, int y, int size, color_t color, color_t fillcolor = 0);
void fixcolor(int& col);
ld displayspin(cell *c, int d);
hyperpoint gethyper(ld x, ld y);
@ -1820,7 +1820,7 @@ void clearMessages();
void resetGeometry();
namespace svg {
void circle(int x, int y, int size, color_t col);
void circle(int x, int y, int size, color_t col, color_t fillcolor);
void polygon(int *polyx, int *polyy, int polyi, color_t col, color_t outline, double linewidth);
void text(int x, int y, int size, const string& str, bool frame, color_t col, int align);
extern bool in;
@ -2660,16 +2660,11 @@ struct dqi_string : drawqueueitem {
};
struct dqi_circle : drawqueueitem {
int x, y, size;
int x, y, size, fillcolor;
void draw();
virtual color_t outline_group() { return 2; }
};
struct dqi_boundary_circle : dqi_circle {
int x, y, size;
void draw_pre();
};
struct dqi_action : drawqueueitem {
reaction_t action;
dqi_action(const reaction_t& a) : action(a) {}

View File

@ -66,6 +66,9 @@ static const int POLY_BADCENTERIN = (1<<18);
// precise width calculation
static const int POLY_PRECISE_WIDE = (1<<19);
// force inverted
static const int POLY_FORCE_INVERTED = (1<<20);
vector<hyperpoint> hpc;
int prehpc;
@ -549,7 +552,7 @@ void dqi_poly::gldraw() {
glhr::color2(color);
glhr::set_depthtest(model_needs_depth());
if(flags & POLY_INVERSE) {
if(flags & (POLY_INVERSE | POLY_FORCE_INVERTED)) {
glStencilOp( GL_ZERO, GL_ZERO, GL_ZERO);
glStencilFunc( GL_NOTEQUAL, 1, 1);
GLfloat xx = vid.xres;
@ -575,6 +578,11 @@ void dqi_poly::gldraw() {
glDisable(GL_STENCIL_TEST);
}
else {
glhr::color2(color);
glhr::set_depthtest(model_needs_depth());
glDrawArrays(GL_TRIANGLE_FAN, offset, cnt);
}
}
if(outline) {
@ -1222,12 +1230,11 @@ void dqi_string::draw() {
void dqi_circle::draw() {
#if ISMOBILE==0
if(svg::in) {
if(!color) return;
svg::circle(x, y, size, color);
svg::circle(x, y, size, color, fillcolor);
}
else
#endif
drawCircle(x, y, size, color);
drawCircle(x, y, size, color, fillcolor);
}
void initquickqueue() {
@ -1287,10 +1294,6 @@ void dqi_line::draw_back() {
draw();
}
void dqi_boundary_circle::draw_pre() {
draw(), color = 0;
}
void sort_drawqueue() {
for(int a=0; a<PMAX; a++) qp[a] = 0;
@ -1387,6 +1390,9 @@ void drawqueue() {
spherephase = 0;
stereo::set_projection(0);
for(auto& ptd: ptds) if(ptd->prio == PPR::OUTCIRCLE)
ptd->draw();
// on the sphere, parts on the back are drawn first
if(two_sided_model()) {
@ -1397,9 +1403,6 @@ void drawqueue() {
ptd->draw();
}
// in SVG, draw boundary circle first
if(svg::in) for(auto& ptd: ptds) ptd->draw_pre();
spherespecial = sphereflipped() ? 1 : -1;
stereo::set_projection(0);
@ -1415,7 +1418,7 @@ void drawqueue() {
stereo::set_projection(0);
}
for(auto& ptd: ptds) {
for(auto& ptd: ptds) if(ptd->prio != PPR::OUTCIRCLE) {
dynamicval<int> ss(spherespecial, among(ptd->prio, PPR::MOBILE_ARROW, PPR::OUTCIRCLE, PPR::CIRCLE) ? 0 : spherespecial);
ptd->draw();
}
@ -2739,12 +2742,13 @@ void queuechr(int x, int y, int shift, int size, char chr, color_t col, int fram
ptd.frame = frame ? (poly_outline & ~ 255) : 0;
}
void queuecircle(int x, int y, int size, color_t color, PPR prio = PPR::CIRCLE, bool boundary = false) {
auto& ptd = boundary ? (dqi_circle&) queuea<dqi_boundary_circle>(prio) : queuea<dqi_circle>(prio);
void queuecircle(int x, int y, int size, color_t color, PPR prio = PPR::CIRCLE, color_t fillcolor = 0) {
auto& ptd = queuea<dqi_circle>(prio);
ptd.x = x;
ptd.y = y;
ptd.size = size;
ptd.color = color;
ptd.fillcolor = fillcolor;
}
void getcoord0(const hyperpoint& h, int& xc, int &yc, int &sc) {

View File

@ -71,15 +71,14 @@ namespace svg {
return buf;
}
void circle(int x, int y, int size, color_t col) {
int ba = (backcolor << 8) + 0xFF;
if(!invisible(col)) {
void circle(int x, int y, int size, color_t col, color_t fillcol) {
if(!invisible(col) && !invisible(fillcol)) {
if(vid.stretch == 1)
fprintf(f, "<circle cx='%s' cy='%s' r='%s' %s/>\n",
coord(x), coord(y), coord(size), stylestr(ba, col));
coord(x), coord(y), coord(size), stylestr(fillcol, col));
else
fprintf(f, "<ellipse cx='%s' cy='%s' rx='%s' ry='%s' %s/>\n",
coord(x), coord(y), coord(size), coord(size*vid.stretch), stylestr(ba, col));
coord(x), coord(y), coord(size), coord(size*vid.stretch), stylestr(fillcol, col));
}
}
@ -223,6 +222,8 @@ void IMAGESAVE(SDL_Surface *s, const char *fname) {
hookset<void(renderbuffer*)> *hooks_hqshot;
color_t fillmodel;
void saveHighQualityShot(const char *fname, const char *caption, int fade) {
resetbuffer rb;
@ -425,6 +426,7 @@ void reflect_view() {
}
}
void apply() {
int t = ticks - lastticks;
lastticks = ticks;