2019-08-10 11:43:24 +00:00
|
|
|
// Hyperbolic Rogue -- rendering
|
2019-05-26 16:04:02 +00:00
|
|
|
// Copyright (C) 2011-2019 Zeno Rogue, see 'hyper.cpp' for details
|
|
|
|
|
2019-08-10 11:43:24 +00:00
|
|
|
/** \file drawing.cpp
|
|
|
|
* \brief Rendering shapes (dqi_draw), queue of shapes to render (ptds), etc.
|
|
|
|
*/
|
|
|
|
|
2019-09-05 07:15:40 +00:00
|
|
|
#include "hyper.h"
|
2019-05-26 16:04:02 +00:00
|
|
|
namespace hr {
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
#if HDR
|
2024-10-05 11:07:21 +00:00
|
|
|
static constexpr flagtype POLY_DRAWLINES = 1; // draw the lines
|
|
|
|
static constexpr flagtype POLY_DRAWAREA = 2; // draw the area
|
|
|
|
static constexpr flagtype POLY_INVERSE = 4; // draw the inverse -- useful in stereographic projection
|
|
|
|
static constexpr flagtype POLY_ISSIDE = 8; // never draw in inverse
|
|
|
|
static constexpr flagtype POLY_BEHIND = 16; // there are points behind the camera
|
|
|
|
static constexpr flagtype POLY_TOOLARGE = 32; // some coordinates are too large -- best not to draw to avoid glitches
|
|
|
|
static constexpr flagtype POLY_INFRONT = 64; // on the sphere (orthogonal projection), do not draw without any points in front
|
|
|
|
static constexpr flagtype POLY_HASWALLS = 128; // floor shapes which have their sidewalls
|
|
|
|
static constexpr flagtype POLY_PLAIN = 256; // plain floors
|
|
|
|
static constexpr flagtype POLY_FULL = 512; // full floors
|
|
|
|
static constexpr flagtype POLY_HASSHADOW = 1024; // floor shapes which have their shadows, or can use shFloorShadow
|
|
|
|
static constexpr flagtype POLY_GP = 2048; // Goldberg shapes
|
|
|
|
static constexpr flagtype POLY_VCONVEX = 4096; // Convex shape (vertex)
|
|
|
|
static constexpr flagtype POLY_CCONVEX = 8192; // Convex shape (central)
|
|
|
|
static constexpr flagtype POLY_CENTERIN = 16384; // new system of side checking
|
|
|
|
static constexpr flagtype POLY_FORCEWIDE = Flag(15); // force wide lines
|
|
|
|
static constexpr flagtype POLY_NOTINFRONT = Flag(16); // points not in front
|
|
|
|
static constexpr flagtype POLY_NIF_ERROR = Flag(17); // points moved to the outline cross the image, disable
|
|
|
|
static constexpr flagtype POLY_BADCENTERIN = Flag(18); // new system of side checking
|
|
|
|
static constexpr flagtype POLY_PRECISE_WIDE = Flag(19); // precise width calculation
|
|
|
|
static constexpr flagtype POLY_FORCE_INVERTED = Flag(20); // force inverted
|
|
|
|
static constexpr flagtype POLY_ALWAYS_IN = Flag(21); // always draw this
|
|
|
|
static constexpr flagtype POLY_TRIANGLES = Flag(22); // made of TRIANGLES, not TRIANGLE_FAN
|
|
|
|
static constexpr flagtype POLY_INTENSE = Flag(23); // extra intense colors
|
|
|
|
static constexpr flagtype POLY_DEBUG = Flag(24); // debug this shape
|
|
|
|
static constexpr flagtype POLY_PRINTABLE = Flag(25); // these walls are printable
|
|
|
|
static constexpr flagtype POLY_FAT = Flag(26); // fatten this model in WRL export (used for Rug)
|
|
|
|
static constexpr flagtype POLY_SHADE_TEXTURE = Flag(27); // texture has 'z' coordinate for shading
|
|
|
|
static constexpr flagtype POLY_ONE_LEVEL = Flag(28); // only one level of the universal cover in SL(2,R)
|
|
|
|
static constexpr flagtype POLY_APEIROGONAL = Flag(29); // only vertices indexed up to she are drawn as the boundary
|
|
|
|
static constexpr flagtype POLY_NO_FOG = Flag(30); // disable fog for this
|
|
|
|
static constexpr flagtype POLY_FORCE_DEPTH = Flag(31); // always depth test
|
2019-08-09 23:56:00 +00:00
|
|
|
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief A graphical element that can be drawn. Objects are not drawn immediately but rather queued.
|
|
|
|
*
|
|
|
|
* HyperRogue map rendering functions do not draw its data immediately; instead, they call the 'queue' functions
|
2020-03-27 20:32:43 +00:00
|
|
|
* which store the data to draw in hr::ptds. This approach lets us draw the elements in the correct order.
|
|
|
|
*/
|
|
|
|
|
2019-08-09 23:56:00 +00:00
|
|
|
struct drawqueueitem {
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief The higher the priority, the earlier we should draw this object. */
|
2019-08-09 23:56:00 +00:00
|
|
|
PPR prio;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief Color of this object. */
|
2019-08-09 23:56:00 +00:00
|
|
|
color_t color;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief Some priorities need extra sorting inside the given class. This attribute is used to specify the inner sorting priority. */
|
2019-08-09 23:56:00 +00:00
|
|
|
int subprio;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief Draw the object. */
|
2019-08-09 23:56:00 +00:00
|
|
|
virtual void draw() = 0;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief Draw the object as background. */
|
2019-08-09 23:56:00 +00:00
|
|
|
virtual void draw_back() {}
|
2021-07-11 22:03:08 +00:00
|
|
|
virtual ~drawqueueitem() = default;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief When minimizing OpenGL calls, we need to group items of the same color, etc. together. This value is used as an extra sorting key. */
|
2019-08-09 23:56:00 +00:00
|
|
|
virtual color_t outline_group() = 0;
|
2024-10-05 11:11:23 +00:00
|
|
|
virtual dqi_poly* as_poly() { return nullptr; }
|
2019-08-09 23:56:00 +00:00
|
|
|
};
|
|
|
|
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief Drawqueueitem used to draw polygons. The majority of drawqueueitems fall here. */
|
2019-08-09 23:56:00 +00:00
|
|
|
struct dqi_poly : drawqueueitem {
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief matrix used to transform the model */
|
2020-07-27 16:49:04 +00:00
|
|
|
shiftmatrix V;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief a vector of GL vertices where the model is stored */
|
2019-08-09 23:56:00 +00:00
|
|
|
const vector<glvertex> *tab;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief the where does the model start */
|
2020-03-27 20:32:43 +00:00
|
|
|
int offset;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief how many vertices in the model */
|
2020-03-27 20:32:43 +00:00
|
|
|
int cnt;
|
2022-04-22 22:57:04 +00:00
|
|
|
/** cnt for POLY_APEIROGONAL */
|
|
|
|
int apeiro_cnt;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief the offset in the texture vertices */
|
2020-03-27 20:32:43 +00:00
|
|
|
int offset_texture;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief outline color */
|
2019-08-09 23:56:00 +00:00
|
|
|
color_t outline;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief width of boundary lines */
|
2019-08-09 23:56:00 +00:00
|
|
|
double linewidth;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief various flags */
|
2024-10-05 11:07:21 +00:00
|
|
|
flagtype flags;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief Texture data for textured polygons. Requires POLY_TRIANGLES flag */
|
2019-08-09 23:56:00 +00:00
|
|
|
struct basic_textureinfo *tinf;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief used to find the correct side to draw in spherical geometries */
|
2019-08-09 23:56:00 +00:00
|
|
|
hyperpoint intester;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief temporarily cached data */
|
2020-03-07 23:33:18 +00:00
|
|
|
float cache;
|
2021-07-11 22:03:08 +00:00
|
|
|
void draw() override;
|
2021-05-21 23:24:28 +00:00
|
|
|
#if CAP_GL
|
2019-08-09 23:56:00 +00:00
|
|
|
void gldraw();
|
2021-05-21 23:24:28 +00:00
|
|
|
#endif
|
2021-07-11 22:03:08 +00:00
|
|
|
void draw_back() override;
|
|
|
|
color_t outline_group() override { return outline; }
|
2024-10-11 07:29:19 +00:00
|
|
|
virtual dqi_poly* as_poly() override { return this; }
|
2019-08-09 23:56:00 +00:00
|
|
|
};
|
|
|
|
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief Drawqueueitem used to draw lines */
|
2019-08-09 23:56:00 +00:00
|
|
|
struct dqi_line : drawqueueitem {
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief starting and ending point */
|
2020-07-27 16:49:04 +00:00
|
|
|
shiftpoint H1, H2;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief how accurately to render the line */
|
2019-08-09 23:56:00 +00:00
|
|
|
int prf;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief width of this line */
|
2019-08-09 23:56:00 +00:00
|
|
|
double width;
|
2021-07-11 22:03:08 +00:00
|
|
|
void draw() override;
|
|
|
|
void draw_back() override;
|
|
|
|
color_t outline_group() override { return color; }
|
2019-08-09 23:56:00 +00:00
|
|
|
};
|
2020-03-27 20:32:43 +00:00
|
|
|
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief Drawqueueitem used to draw strings, using sccreen coodinates */
|
2019-08-09 23:56:00 +00:00
|
|
|
struct dqi_string : drawqueueitem {
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief text */
|
2019-08-09 23:56:00 +00:00
|
|
|
string str;
|
2020-03-27 20:32:43 +00:00
|
|
|
/** onscreen position */
|
|
|
|
int x, y;
|
|
|
|
/** shift in anaglyph mode */
|
|
|
|
int shift;
|
|
|
|
/** font size */
|
|
|
|
int size;
|
|
|
|
/** frame color */
|
|
|
|
int frame;
|
|
|
|
/** alignment (0-8-16) */
|
2019-08-09 23:56:00 +00:00
|
|
|
int align;
|
2024-10-05 11:03:29 +00:00
|
|
|
/** current font */
|
|
|
|
fontdata *font;
|
2021-07-11 22:03:08 +00:00
|
|
|
void draw() override;
|
|
|
|
color_t outline_group() override { return 1; }
|
2019-08-09 23:56:00 +00:00
|
|
|
};
|
|
|
|
|
2020-03-27 20:32:43 +00:00
|
|
|
/** Drawqueueitem used to draw circles, using screen coordinates */
|
2019-08-09 23:56:00 +00:00
|
|
|
struct dqi_circle : drawqueueitem {
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief onscreen position */
|
2020-03-27 20:32:43 +00:00
|
|
|
int x, y;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief circle size */
|
2020-03-27 20:32:43 +00:00
|
|
|
int size;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief which color should it be filled with */
|
2020-03-27 20:32:43 +00:00
|
|
|
color_t fillcolor;
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief width of the circle */
|
2019-08-09 23:56:00 +00:00
|
|
|
double linewidth;
|
2021-07-11 22:03:08 +00:00
|
|
|
void draw() override;
|
|
|
|
color_t outline_group() override { return 2; }
|
2019-08-09 23:56:00 +00:00
|
|
|
};
|
|
|
|
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief Perform an arbitrary action. May temporarily change the model, etc. */
|
2019-08-09 23:56:00 +00:00
|
|
|
struct dqi_action : drawqueueitem {
|
|
|
|
reaction_t action;
|
2021-07-11 22:03:08 +00:00
|
|
|
explicit dqi_action(const reaction_t& a) : action(a) {}
|
|
|
|
void draw() override { action(); }
|
|
|
|
color_t outline_group() override { return 2; }
|
2019-08-09 23:56:00 +00:00
|
|
|
};
|
2019-08-09 19:00:52 +00:00
|
|
|
#endif
|
|
|
|
|
2020-12-30 18:35:15 +00:00
|
|
|
EX bool in_vr_sphere;
|
2020-12-29 01:51:43 +00:00
|
|
|
hyperpoint vr_sphere_center;
|
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
bool fatborder;
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX color_t poly_outline;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX vector<unique_ptr<drawqueueitem>> ptds;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
#if CAP_GL
|
2019-09-05 10:00:55 +00:00
|
|
|
EX color_t text_color;
|
|
|
|
EX int text_shift;
|
|
|
|
EX GLuint text_texture;
|
|
|
|
EX int texts_merged;
|
|
|
|
EX int shapes_merged;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
#if MINIMIZE_GL_CALLS
|
2023-04-14 23:14:29 +00:00
|
|
|
PPR lprio;
|
2021-02-07 19:40:49 +00:00
|
|
|
ld m_shift;
|
2023-04-14 23:14:29 +00:00
|
|
|
vector<glhr::colored_vertex> triangle_vertices;
|
|
|
|
vector<glhr::colored_vertex> line_vertices;
|
2019-05-26 16:04:02 +00:00
|
|
|
#endif
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void glflush() {
|
2020-04-17 13:03:05 +00:00
|
|
|
DEBBI(DF_GRAPH, ("glflush"));
|
2019-05-26 16:04:02 +00:00
|
|
|
#if MINIMIZE_GL_CALLS
|
|
|
|
if(isize(triangle_vertices)) {
|
2023-04-14 23:14:29 +00:00
|
|
|
// printf("%3d | %d shapes, %d/%d vertices\n", lprio, shapes_merged, isize(triangle_vertices), isize(line_vertices));
|
|
|
|
current_display->next_shader_flags = GF_VARCOLOR;
|
|
|
|
current_display->set_all(0, m_shift);
|
|
|
|
if(true) {
|
2019-05-26 16:04:02 +00:00
|
|
|
glhr::be_nontextured();
|
|
|
|
glapplymatrix(Id);
|
|
|
|
glhr::current_vertices = NULL;
|
2023-04-14 23:14:29 +00:00
|
|
|
glhr::prepare(triangle_vertices);
|
|
|
|
glhr::color2(0xFFFFFFFF);
|
2019-05-26 16:04:02 +00:00
|
|
|
glDrawArrays(GL_TRIANGLES, 0, isize(triangle_vertices));
|
|
|
|
}
|
|
|
|
triangle_vertices.clear();
|
2023-04-14 23:14:29 +00:00
|
|
|
if(isize(line_vertices)) goto jump;
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
if(isize(line_vertices)) {
|
2023-04-14 23:14:29 +00:00
|
|
|
current_display->next_shader_flags = GF_VARCOLOR;
|
|
|
|
current_display->set_all(0, m_shift);
|
|
|
|
jump:
|
|
|
|
if(true) {
|
2019-05-26 16:04:02 +00:00
|
|
|
glhr::be_nontextured();
|
|
|
|
glapplymatrix(Id);
|
|
|
|
glhr::current_vertices = NULL;
|
2023-04-14 23:14:29 +00:00
|
|
|
glhr::prepare(line_vertices);
|
|
|
|
glhr::color2(0xFFFFFFFF);
|
2019-05-26 16:04:02 +00:00
|
|
|
glDrawArrays(GL_LINES, 0, isize(line_vertices));
|
|
|
|
}
|
|
|
|
line_vertices.clear();
|
|
|
|
}
|
|
|
|
shapes_merged = 0;
|
|
|
|
#endif
|
2020-11-19 17:20:06 +00:00
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
if(isize(text_vertices)) {
|
2019-10-21 20:34:20 +00:00
|
|
|
current_display->next_shader_flags = GF_TEXTURE;
|
|
|
|
dynamicval<eModel> m(pmodel, mdPixel);
|
2020-07-27 16:49:04 +00:00
|
|
|
if(!svg::in) current_display->set_all(0,0);
|
2020-11-19 17:20:06 +00:00
|
|
|
|
|
|
|
auto drawer = [] {
|
|
|
|
glhr::color2(text_color);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, text_texture);
|
|
|
|
glhr::set_depthtest(false);
|
2019-05-26 16:04:02 +00:00
|
|
|
glhr::current_vertices = NULL;
|
|
|
|
glhr::prepare(text_vertices);
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, isize(text_vertices));
|
2020-11-19 17:20:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#if CAP_VR
|
2020-12-30 17:34:13 +00:00
|
|
|
if(vrhr::should_render() && vrhr::in_menu())
|
2020-11-19 17:20:06 +00:00
|
|
|
vrhr::in_vr_ui(drawer);
|
|
|
|
|
|
|
|
else
|
|
|
|
#endif
|
2024-01-07 08:07:54 +00:00
|
|
|
for(int ed = (current_display->separate_eyes() && text_shift)?-1:0; ed<2; ed+=2) {
|
2020-11-19 17:20:06 +00:00
|
|
|
glhr::set_modelview(glhr::translate(-ed*text_shift-current_display->xcenter,-current_display->ycenter, 0));
|
|
|
|
current_display->set_mask(ed);
|
|
|
|
drawer();
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
GLERR("print");
|
|
|
|
}
|
|
|
|
|
2024-01-07 08:07:54 +00:00
|
|
|
if(current_display->separate_eyes() && text_shift && !svg::in) current_display->set_mask(0);
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
texts_merged = 0;
|
|
|
|
text_vertices.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-07-03 12:42:33 +00:00
|
|
|
#if CAP_SDL && !ISMOBILE
|
2021-03-06 13:53:25 +00:00
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
SDL_Surface *aux;
|
2021-03-06 13:53:25 +00:00
|
|
|
#if CAP_SDL2
|
|
|
|
SDL_Renderer *auxrend;
|
|
|
|
#else
|
|
|
|
#define auxrend aux
|
|
|
|
#endif
|
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CAP_POLY
|
2019-09-05 10:00:55 +00:00
|
|
|
#if HDR
|
2019-05-26 16:04:02 +00:00
|
|
|
#define POLYMAX 60000
|
2019-09-05 10:00:55 +00:00
|
|
|
#endif
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX vector<glvertex> glcoords;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-09-05 10:00:55 +00:00
|
|
|
EX int spherespecial, spherephase;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
#if CAP_POLY
|
|
|
|
int polyi;
|
|
|
|
|
2019-09-05 10:00:55 +00:00
|
|
|
EX int polyx[POLYMAX], polyxr[POLYMAX], polyy[POLYMAX];
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
int poly_flags;
|
|
|
|
|
|
|
|
void add1(const hyperpoint& H) {
|
|
|
|
glcoords.push_back(glhr::pointtogl(H));
|
|
|
|
}
|
|
|
|
|
2020-08-20 14:02:34 +00:00
|
|
|
int axial_sign() {
|
|
|
|
return ((axial_x ^ axial_y)&1) ? -1:1;
|
|
|
|
}
|
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
bool is_behind(const hyperpoint& H) {
|
2020-08-20 14:02:34 +00:00
|
|
|
if(pmodel == mdAxial && sphere) return axial_sign() * H[2] <= BEHIND_LIMIT;
|
2020-12-29 01:51:43 +00:00
|
|
|
if(in_vr_sphere) return false;
|
2020-04-16 22:53:58 +00:00
|
|
|
return pmodel == mdDisk && (hyperbolic ? H[2] >= 0 : true) && (nonisotropic ? false : pconf.alpha + H[2] <= BEHIND_LIMIT);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hyperpoint be_just_on_view(const hyperpoint& H1, const hyperpoint &H2) {
|
2020-04-16 22:53:58 +00:00
|
|
|
// H1[2] * t + H2[2] * (1-t) == BEHIND_LIMIT - pconf.alpha
|
|
|
|
// H2[2]- BEHIND_LIMIT + pconf.alpha = t * (H2[2] - H1[2])
|
2020-08-20 14:02:34 +00:00
|
|
|
ld t = (axial_sign() * H2[2] - BEHIND_LIMIT + (pmodel == mdAxial ? 0 : pconf.alpha)) / (H2[2] - H1[2]) * axial_sign();
|
2019-05-26 16:04:02 +00:00
|
|
|
return H1 * t + H2 * (1-t);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool last_infront;
|
|
|
|
|
|
|
|
bool nif_error_in(ld x1, ld y1, ld x2, ld y2) {
|
|
|
|
return pow(x1 * x2 + y2 * y2, 2) < (x1*x1+y1*y1)*(x2*x2+y2*y2)*.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool knowgood;
|
|
|
|
hyperpoint goodpoint;
|
|
|
|
vector<pair<int, hyperpoint>> tofix;
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX bool two_sided_model() {
|
2020-12-27 16:37:39 +00:00
|
|
|
#if CAP_VR
|
2020-12-30 13:20:30 +00:00
|
|
|
bool in_vr = vrhr::rendering();
|
2020-12-27 16:37:39 +00:00
|
|
|
#else
|
|
|
|
constexpr bool in_vr = false;
|
|
|
|
#endif
|
2019-08-15 13:05:43 +00:00
|
|
|
if(GDIM == 3) return false;
|
2020-12-29 01:51:43 +00:00
|
|
|
if(in_vr_sphere) return true;
|
2023-08-15 13:20:29 +00:00
|
|
|
if(pmodel == mdHemisphere || pmodel == mdHyperboloid) return !in_vr;
|
2019-05-26 16:04:02 +00:00
|
|
|
// if(pmodel == mdHemisphere) return true;
|
2021-09-16 20:26:23 +00:00
|
|
|
if(pmodel == mdDisk) return sphere || (hyperbolic && pconf.alpha < 0 && pconf.alpha > -1);
|
2020-10-08 16:22:28 +00:00
|
|
|
if(pmodel == mdRetroLittrow) return sphere;
|
|
|
|
if(pmodel == mdRetroHammer) return sphere;
|
2019-05-26 16:04:02 +00:00
|
|
|
if(pmodel == mdRotatedHyperboles) return true;
|
2020-04-16 22:53:58 +00:00
|
|
|
if(pmodel == mdSpiral && pconf.spiral_cone < 360) return true;
|
2019-05-26 16:04:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX int get_side(const hyperpoint& H) {
|
2020-12-31 17:36:03 +00:00
|
|
|
#if CAP_VR
|
2020-12-29 01:51:43 +00:00
|
|
|
if(in_vr_sphere) {
|
|
|
|
hyperpoint Hscr;
|
|
|
|
applymodel(shiftless(H), Hscr);
|
|
|
|
Hscr[3] = 1;
|
|
|
|
E4;
|
|
|
|
hyperpoint actual = vrhr::hmd_mv * Hscr;
|
|
|
|
ld val = 0;
|
|
|
|
for(int i=0; i<3; i++) val += (vr_sphere_center[i] - actual[i]) * actual[i];
|
|
|
|
return val > 0 ? -1 : 1;
|
|
|
|
}
|
2020-12-31 17:36:03 +00:00
|
|
|
#endif
|
2019-05-26 16:04:02 +00:00
|
|
|
if(pmodel == mdDisk && sphere) {
|
|
|
|
double curnorm = H[0]*H[0]+H[1]*H[1]+H[2]*H[2];
|
2020-04-16 22:53:58 +00:00
|
|
|
double horizon = curnorm / pconf.alpha;
|
2019-05-26 16:04:02 +00:00
|
|
|
return (H[2] <= -horizon) ? -1 : 1;
|
|
|
|
}
|
2021-09-16 20:26:23 +00:00
|
|
|
if(pmodel == mdDisk && hyperbolic && pconf.alpha < 0 && pconf.alpha > -1) {
|
|
|
|
return (H[2] * (H[2] + pconf.alpha) < sqhypot_d(2, H)) ? -1 : 1;
|
|
|
|
}
|
2020-10-08 16:22:28 +00:00
|
|
|
if(pmodel == mdRetroLittrow && sphere) {
|
|
|
|
return H[2] >= 0 ? 1 : -1;
|
|
|
|
}
|
|
|
|
if(pmodel == mdRetroHammer && sphere) {
|
|
|
|
return H[2] >= 0 ? 1 : -1;
|
|
|
|
}
|
2019-05-26 16:04:02 +00:00
|
|
|
if(pmodel == mdRotatedHyperboles)
|
|
|
|
return H[1] > 0 ? -1 : 1;
|
2023-08-14 14:18:44 +00:00
|
|
|
if(pmodel == mdHyperboloid) {
|
2024-06-28 12:00:52 +00:00
|
|
|
auto H1 = H; if(sphere && pconf.small_hyperboloid) H1 = mid(H, C0);
|
|
|
|
return det2(pconf.ball() * cspin90(2, 1) * rgpushxto0(H1)) > 0 ? 1 : -1;
|
2023-08-14 14:18:44 +00:00
|
|
|
}
|
2022-04-07 18:50:16 +00:00
|
|
|
if(pmodel == mdHyperboloidFlat && sphere)
|
|
|
|
return H[2] >= 0 ? 1 : -1;
|
2023-08-15 13:20:29 +00:00
|
|
|
if(pmodel == mdHemisphere && !sphere) {
|
2019-05-26 16:04:02 +00:00
|
|
|
hyperpoint res;
|
2020-07-27 16:49:04 +00:00
|
|
|
applymodel(shiftless(H), res);
|
2024-06-27 22:00:33 +00:00
|
|
|
return res[2] < 0 ? 1 : -1;
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
2022-04-07 18:50:16 +00:00
|
|
|
if(pmodel == mdHemisphere && sphere) {
|
|
|
|
auto H1 = H;
|
2024-06-28 12:00:52 +00:00
|
|
|
if(pconf.small_hyperboloid) H1 = mid(H, C0);
|
2022-04-07 18:50:16 +00:00
|
|
|
int s = H1[2] > 0 ? 1 : -1;
|
|
|
|
if(hemi_side && s != hemi_side) return -spherespecial;
|
|
|
|
H1[0] /= H1[2]; H1[1] /= H1[2];
|
2023-08-14 14:18:44 +00:00
|
|
|
H1[2] = -s * sqrt(1 + H1[0]*H1[0] + H1[1] * H1[1]);
|
|
|
|
dynamicval<geometryinfo1> g(cginf.g, giHyperb2);
|
2023-08-15 08:55:01 +00:00
|
|
|
return det2(pconf.ball() * cspin90(2, 1) * rgpushxto0(H1)) > 0 ? 1 : -1;
|
2022-04-07 18:50:16 +00:00
|
|
|
}
|
2020-04-16 22:53:58 +00:00
|
|
|
if(pmodel == mdSpiral && pconf.spiral_cone < 360) {
|
2020-07-27 16:49:04 +00:00
|
|
|
return cone_side(shiftless(H));
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX bool correct_side(const hyperpoint& H) {
|
2019-05-26 16:04:02 +00:00
|
|
|
return get_side(H) == spherespecial;
|
|
|
|
}
|
|
|
|
|
|
|
|
hyperpoint Hlast;
|
|
|
|
|
|
|
|
void fixpoint(glvertex& hscr, hyperpoint H) {
|
|
|
|
hyperpoint bad = H, good = goodpoint;
|
|
|
|
|
|
|
|
for(int i=0; i<10; i++) {
|
|
|
|
hyperpoint mid = midz(bad, good);
|
|
|
|
if(correct_side(mid))
|
|
|
|
good = mid;
|
|
|
|
else
|
|
|
|
bad = mid;
|
|
|
|
}
|
|
|
|
hyperpoint Hscr;
|
2020-07-27 16:49:04 +00:00
|
|
|
applymodel(shiftless(good), Hscr);
|
2020-12-27 16:37:39 +00:00
|
|
|
#if CAP_VR
|
2020-12-30 13:20:30 +00:00
|
|
|
if(vrhr::rendering())
|
2020-12-27 16:14:50 +00:00
|
|
|
hscr = glhr::makevertex(Hscr[0], Hscr[1]*pconf.stretch, Hscr[2]);
|
|
|
|
else
|
2020-12-27 16:37:39 +00:00
|
|
|
#endif
|
2020-12-27 16:14:50 +00:00
|
|
|
hscr = glhr::makevertex(Hscr[0]*current_display->radius, Hscr[1]*current_display->radius*pconf.stretch, Hscr[2]*current_display->radius);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
void addpoint(const shiftpoint& H) {
|
2019-05-26 16:04:02 +00:00
|
|
|
if(true) {
|
|
|
|
ld z = current_display->radius;
|
2020-04-16 22:53:58 +00:00
|
|
|
// if(pconf.alpha + H[2] <= BEHIND_LIMIT && pmodel == mdDisk) poly_flags |= POLY_BEHIND;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2020-12-27 16:37:39 +00:00
|
|
|
#if CAP_VR
|
2020-12-30 13:20:30 +00:00
|
|
|
if(vrhr::rendering()) z = 1;
|
2020-12-27 16:37:39 +00:00
|
|
|
#endif
|
2020-12-27 16:14:50 +00:00
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
if(spherespecial) {
|
2020-07-27 16:49:04 +00:00
|
|
|
auto H0 = H.h;
|
|
|
|
if(correct_side(H0)) {
|
2019-05-26 16:04:02 +00:00
|
|
|
poly_flags |= POLY_INFRONT, last_infront = false;
|
2020-07-27 16:49:04 +00:00
|
|
|
if(!knowgood || (spherespecial > 0 ? H[2]>goodpoint[2] : H[2]<goodpoint[2])) goodpoint = H0, knowgood = true;
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
else if(sphere && (poly_flags & POLY_ISSIDE)) {
|
|
|
|
double curnorm = H[0]*H[0]+H[1]*H[1]+H[2]*H[2];
|
2020-04-16 22:53:58 +00:00
|
|
|
double horizon = curnorm / pconf.alpha;
|
2019-05-26 16:04:02 +00:00
|
|
|
poly_flags |= POLY_NOTINFRONT;
|
|
|
|
if(last_infront && nif_error_in(glcoords.back()[0], glcoords.back()[1], H[0], H[1]))
|
|
|
|
poly_flags |= POLY_NIF_ERROR;
|
|
|
|
|
|
|
|
last_infront = true;
|
|
|
|
|
|
|
|
z *=
|
2020-04-16 22:53:58 +00:00
|
|
|
(sqrt(curnorm - horizon*horizon) / (pconf.alpha - horizon)) /
|
|
|
|
(sqrt(curnorm - H[2]*H[2]) / (pconf.alpha+H[2]));
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
poly_flags |= POLY_NOTINFRONT;
|
2020-07-27 16:49:04 +00:00
|
|
|
tofix.push_back(make_pair(glcoords.size(), H0));
|
|
|
|
add1(H0);
|
2019-05-26 16:04:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hyperpoint Hscr;
|
|
|
|
applymodel(H, Hscr);
|
|
|
|
if(sphere && pmodel == mdSpiral) {
|
|
|
|
if(isize(glcoords)) {
|
|
|
|
hyperpoint Hscr1;
|
2022-11-12 21:38:45 +00:00
|
|
|
shiftpoint H1 = H; H1.shift += TAU;
|
2020-07-27 16:49:04 +00:00
|
|
|
applymodel(H1, Hscr1);
|
2019-05-26 16:04:02 +00:00
|
|
|
if(hypot_d(2, Hlast-Hscr1) < hypot_d(2, Hlast-Hscr)) { Hscr = Hscr1; }
|
2022-11-12 21:38:45 +00:00
|
|
|
H1.shift -= 2 * TAU;
|
2020-07-27 16:49:04 +00:00
|
|
|
applymodel(H1, Hscr1);
|
2019-05-26 16:04:02 +00:00
|
|
|
if(hypot_d(2, Hlast-Hscr1) < hypot_d(2, Hlast-Hscr)) { Hscr = Hscr1; }
|
|
|
|
}
|
|
|
|
Hlast = Hscr;
|
|
|
|
}
|
2020-12-27 16:37:39 +00:00
|
|
|
#if CAP_VR
|
2020-12-30 13:20:30 +00:00
|
|
|
if(vrhr::rendering()) {
|
2020-12-27 16:14:50 +00:00
|
|
|
for(int i=0; i<3; i++) Hscr[i] *= z;
|
|
|
|
}
|
2020-12-27 16:37:39 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if(GDIM == 2) {
|
2019-05-26 16:04:02 +00:00
|
|
|
for(int i=0; i<3; i++) Hscr[i] *= z;
|
2020-04-16 22:53:58 +00:00
|
|
|
Hscr[1] *= pconf.stretch;
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
Hscr[0] *= z;
|
2020-04-16 22:53:58 +00:00
|
|
|
Hscr[1] *= z * pconf.stretch;
|
|
|
|
Hscr[2] = 1 - 2 * (-Hscr[2] - pconf.clip_min) / (pconf.clip_max - pconf.clip_min);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
add1(Hscr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void coords_to_poly() {
|
|
|
|
polyi = isize(glcoords);
|
|
|
|
for(int i=0; i<polyi; i++) {
|
2024-01-07 08:07:54 +00:00
|
|
|
if(!current_display->separate_eyes()) glcoords[i][2] = 0;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
polyx[i] = current_display->xcenter + glcoords[i][0] - glcoords[i][2];
|
|
|
|
polyxr[i] = current_display->xcenter + glcoords[i][0] + glcoords[i][2];
|
|
|
|
polyy[i] = current_display->ycenter + glcoords[i][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
bool behind3(shiftpoint h) {
|
|
|
|
if(pmodel == mdGeodesic)
|
|
|
|
return lp_apply(inverse_exp(h))[2] < 0;
|
2022-05-17 07:40:33 +00:00
|
|
|
if(pmodel == mdLiePerspective)
|
2022-12-25 11:14:36 +00:00
|
|
|
return lp_apply(lie_log(h))[2] < 0;
|
2023-04-14 23:18:47 +00:00
|
|
|
#if MAXMDIM >= 4
|
2022-10-13 22:56:48 +00:00
|
|
|
if(pmodel == mdRelPerspective)
|
2022-12-25 11:14:36 +00:00
|
|
|
return lp_apply(rel_log(h, false))[2] < 0;
|
2023-04-14 23:18:47 +00:00
|
|
|
#endif
|
2020-04-06 08:43:28 +00:00
|
|
|
return h[2] < 0;
|
|
|
|
}
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
void addpoly(const shiftmatrix& V, const vector<glvertex> &tab, int ofs, int cnt) {
|
2019-10-21 20:34:20 +00:00
|
|
|
if(pmodel == mdPixel) {
|
2019-05-26 16:04:02 +00:00
|
|
|
for(int i=ofs; i<ofs+cnt; i++) {
|
|
|
|
hyperpoint h = glhr::gltopoint(tab[i]);
|
2021-03-30 09:27:48 +00:00
|
|
|
#if MAXMDIM >= 4
|
2019-05-26 16:04:02 +00:00
|
|
|
h[3] = 1;
|
2021-03-30 09:27:48 +00:00
|
|
|
#endif
|
2020-07-27 16:49:04 +00:00
|
|
|
h = V.T * h;
|
2019-05-26 16:04:02 +00:00
|
|
|
add1(h);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tofix.clear(); knowgood = false;
|
2022-05-17 07:40:33 +00:00
|
|
|
if(in_perspective()) {
|
2023-05-15 00:25:13 +00:00
|
|
|
if(get_shader_flags() & SF_SEMIDIRECT) {
|
|
|
|
dynamicval<bool> d(computing_semidirect, true);
|
|
|
|
for(int i=ofs; i<ofs+cnt; i++) {
|
|
|
|
hyperpoint Hscr;
|
|
|
|
applymodel(V * glhr::gltopoint(tab[i]), Hscr);
|
|
|
|
add1(Hscr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(poly_flags & POLY_TRIANGLES) {
|
2020-04-06 08:43:28 +00:00
|
|
|
for(int i=ofs; i<ofs+cnt; i+=3) {
|
2020-07-27 16:49:04 +00:00
|
|
|
shiftpoint h0 = V * glhr::gltopoint(tab[i]);
|
|
|
|
shiftpoint h1 = V * glhr::gltopoint(tab[i+1]);
|
|
|
|
shiftpoint h2 = V * glhr::gltopoint(tab[i+2]);
|
2020-04-06 08:43:28 +00:00
|
|
|
if(!behind3(h0) && !behind3(h1) && !behind3(h2))
|
|
|
|
addpoint(h0), addpoint(h1), addpoint(h2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for(int i=ofs; i<ofs+cnt; i++) {
|
2020-07-27 16:49:04 +00:00
|
|
|
shiftpoint h = V * glhr::gltopoint(tab[i]);
|
2020-04-06 08:43:28 +00:00
|
|
|
if(!behind3(h)) addpoint(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-07-27 16:49:04 +00:00
|
|
|
shiftpoint last = V * glhr::gltopoint(tab[ofs]);
|
|
|
|
bool last_behind = is_behind(last.h);
|
2019-05-26 16:04:02 +00:00
|
|
|
if(!last_behind) addpoint(last);
|
|
|
|
hyperpoint enter = C0;
|
|
|
|
hyperpoint firstleave;
|
|
|
|
int start_behind = last_behind ? 1 : 0;
|
|
|
|
for(int i=ofs+1; i<ofs+cnt; i++) {
|
2020-07-27 16:49:04 +00:00
|
|
|
shiftpoint curr = V*glhr::gltopoint(tab[i]);
|
|
|
|
if(is_behind(curr.h) != last_behind) {
|
|
|
|
hyperpoint h = be_just_on_view(last.h, curr.h);
|
2019-05-26 16:04:02 +00:00
|
|
|
if(start_behind == 1) start_behind = 2, firstleave = h;
|
|
|
|
if(!last_behind) enter = h;
|
|
|
|
else if(h[0] * enter[0] + h[1] * enter[1] < 0) poly_flags |= POLY_BEHIND;
|
2020-07-27 16:49:04 +00:00
|
|
|
addpoint(shiftless(h));
|
2019-05-26 16:04:02 +00:00
|
|
|
last_behind = !last_behind;
|
|
|
|
}
|
|
|
|
if(!last_behind) addpoint(curr);
|
|
|
|
last = curr;
|
|
|
|
}
|
|
|
|
if(start_behind == 2) {
|
|
|
|
if(firstleave[0] * enter[0] + firstleave[1] * enter[1] < 0) poly_flags |= POLY_BEHIND;
|
2020-07-27 16:49:04 +00:00
|
|
|
else addpoint(shiftless(firstleave));
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
if(knowgood && isize(tofix)) {
|
|
|
|
|
|
|
|
if(true) {
|
2020-07-27 16:49:04 +00:00
|
|
|
hyperpoint Hx = V.T * C0, Hy = goodpoint;
|
2019-05-26 16:04:02 +00:00
|
|
|
for(int i=0; i<20; i++) {
|
|
|
|
hyperpoint mid = midz(Hx, Hy);
|
|
|
|
if(correct_side(mid)) Hy = mid;
|
|
|
|
else Hx = mid;
|
|
|
|
}
|
|
|
|
goodpoint = midz(Hy, goodpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(auto& p: tofix)
|
|
|
|
fixpoint(glcoords[p.first], p.second);
|
2024-06-28 12:00:52 +00:00
|
|
|
|
|
|
|
if(sphere && among(pmodel, mdHemisphere, mdHyperboloid) && pconf.small_hyperboloid) {
|
|
|
|
bool left = false, right = false;
|
|
|
|
for(auto h: glcoords) { hyperpoint h1; applymodel(shiftless(glhr::gltopoint(h)), h1);
|
|
|
|
if(h1[0] < -0) left = true;
|
|
|
|
if(h1[0] > +0) right = true;
|
|
|
|
}
|
|
|
|
if(left && right) poly_flags |= POLY_NIF_ERROR;
|
|
|
|
}
|
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
/*
|
|
|
|
hyperpoint Hscr;
|
|
|
|
applymodel(goodpoint, Hscr);
|
2020-04-16 22:53:58 +00:00
|
|
|
glcoords.push_back(make_array<GLfloat>(Hscr[0]*current_display->radius+10, Hscr[1]*current_display->radius*pconf.stretch, Hscr[2]*vid.radius));
|
|
|
|
glcoords.push_back(make_array<GLfloat>(Hscr[0]*current_display->radius, Hscr[1]*current_display->radius*pconf.stretch+10, Hscr[2]*vid.radius));
|
|
|
|
glcoords.push_back(make_array<GLfloat>(Hscr[0]*current_display->radius-10, Hscr[1]*current_display->radius*pconf.stretch, Hscr[2]*vid.radius));
|
|
|
|
glcoords.push_back(make_array<GLfloat>(Hscr[0]*current_display->radius, Hscr[1]*current_display->radius*pconf.stretch-10, Hscr[2]*vid.radius));
|
|
|
|
glcoords.push_back(make_array<GLfloat>(Hscr[0]*current_display->radius+10, Hscr[1]*current_display->radius*pconf.stretch, Hscr[2]*vid.radius)); */
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CAP_SDLGFX
|
2021-03-06 13:53:25 +00:00
|
|
|
void aapolylineColor(SDL_Renderer *s, int*x, int *y, int polyi, color_t col) {
|
2019-05-26 16:04:02 +00:00
|
|
|
for(int i=1; i<polyi; i++)
|
2021-03-07 13:14:53 +00:00
|
|
|
aalineColor(s, x[i-1], y[i-1], x[i], y[i], align(col));
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-06 13:53:25 +00:00
|
|
|
void polylineColor(SDL_Renderer *s, int *x, int *y, int polyi, color_t col) {
|
2019-05-26 16:04:02 +00:00
|
|
|
for(int i=1; i<polyi; i++)
|
2021-03-07 13:14:53 +00:00
|
|
|
lineColor(s, x[i-1], y[i-1], x[i], y[i], align(col));
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-06 13:53:25 +00:00
|
|
|
EX void filledPolygonColorI(SDL_Renderer *s, int* px, int *py, int polyi, color_t col) {
|
2019-05-26 16:04:02 +00:00
|
|
|
std::vector<Sint16> spx(px, px + polyi);
|
|
|
|
std::vector<Sint16> spy(py, py + polyi);
|
2021-03-07 13:14:53 +00:00
|
|
|
filledPolygonColor(s, spx.data(), spy.data(), polyi, align(col));
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CAP_TEXTURE
|
|
|
|
void drawTexturedTriangle(SDL_Surface *s, int *px, int *py, glvertex *tv, color_t col) {
|
2019-08-07 18:03:50 +00:00
|
|
|
transmatrix source = matrix3(
|
|
|
|
px[0], px[1], px[2],
|
|
|
|
py[0], py[1], py[2],
|
|
|
|
1, 1, 1);
|
|
|
|
|
|
|
|
|
|
|
|
transmatrix target = matrix3(
|
|
|
|
tv[0][0], tv[1][0], tv[2][0],
|
|
|
|
tv[0][1], tv[1][1], tv[2][1],
|
|
|
|
1, 1, 1
|
|
|
|
);
|
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
transmatrix isource = inverse(source);
|
|
|
|
int minx = px[0], maxx = px[0];
|
|
|
|
int miny = py[0], maxy = py[0];
|
|
|
|
for(int i=1; i<3; i++)
|
|
|
|
minx = min(minx, px[i]), maxx = max(maxx, px[i]),
|
|
|
|
miny = min(miny, py[i]), maxy = max(maxy, py[i]);
|
|
|
|
for(int mx=minx; mx<maxx; mx++)
|
|
|
|
for(int my=miny; my<maxy; my++) {
|
|
|
|
hyperpoint h = isource * point3(mx, my, 1);
|
|
|
|
if(h[0] >= -1e-7 && h[1] >= -1e-7 && h[2] >= -1e-7) {
|
|
|
|
hyperpoint ht = target * h;
|
|
|
|
int tw = texture::config.data.twidth;
|
|
|
|
int x = int(ht[0] * tw) & (tw-1);
|
|
|
|
int y = int(ht[1] * tw) & (tw-1);
|
2019-11-09 10:20:30 +00:00
|
|
|
color_t c;
|
|
|
|
if(texture::config.data.texture_pixels.size() == 0)
|
|
|
|
c = 0xFFFFFFFF;
|
|
|
|
else
|
|
|
|
c = texture::config.data.texture_pixels[y * tw + x];
|
2019-05-26 16:04:02 +00:00
|
|
|
auto& pix = qpixel(s, mx, my);
|
|
|
|
for(int p=0; p<3; p++) {
|
|
|
|
int alpha = part(c, 3) * part(col, 0);
|
|
|
|
auto& v = part(pix, p);
|
|
|
|
v = ((255*255 - alpha) * 255 * v + alpha * part(col, p+1) * part(c, p) + 255 * 255 * 255/2 + 1) / (255 * 255 * 255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX int global_projection;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2021-05-21 23:24:28 +00:00
|
|
|
#if !CAP_GL
|
|
|
|
flagtype get_shader_flags() { return 0; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CAP_GL
|
|
|
|
|
2019-08-25 17:14:03 +00:00
|
|
|
int min_slr, max_slr = 0;
|
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
#if MAXMDIM >= 4
|
|
|
|
extern renderbuffer *floor_textures;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void dqi_poly::gldraw() {
|
2020-11-08 10:49:19 +00:00
|
|
|
GLWRAP;
|
2019-05-26 16:04:02 +00:00
|
|
|
auto& v = *tab;
|
|
|
|
int ioffset = offset;
|
|
|
|
|
|
|
|
#if MINIMIZE_GL_CALLS
|
2024-01-07 08:07:54 +00:00
|
|
|
if(current_display->separate_eyes() == 0 && !tinf && (color == 0 || ((flags & (POLY_VCONVEX | POLY_CCONVEX)) && !(flags & (POLY_INVERSE | POLY_FORCE_INVERTED))))) {
|
2023-04-14 23:14:29 +00:00
|
|
|
if(lprio != prio || texts_merged || m_shift != V.shift) {
|
2019-05-26 16:04:02 +00:00
|
|
|
glflush();
|
2023-04-14 23:14:29 +00:00
|
|
|
lprio = prio;
|
2021-02-07 19:40:49 +00:00
|
|
|
m_shift = V.shift;
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
shapes_merged++;
|
|
|
|
|
|
|
|
if((flags & POLY_CCONVEX) && !(flags & POLY_VCONVEX)) {
|
2023-04-14 23:14:29 +00:00
|
|
|
vector<glhr::colored_vertex> v2(cnt+1);
|
|
|
|
for(int i=0; i<cnt+1; i++) v2[i] = glhr::colored_vertex( V.T * glhr::gltopoint( v[offset+i-1] ), color);
|
2019-05-26 16:04:02 +00:00
|
|
|
if(color) for(int i=0; i<cnt; i++) triangle_vertices.push_back(v2[0]), triangle_vertices.push_back(v2[i]), triangle_vertices.push_back(v2[i+1]);
|
2023-04-14 23:14:29 +00:00
|
|
|
if(outline) {
|
|
|
|
for(auto& v: v2) v.set_color(outline);
|
|
|
|
for(int i=1; i<cnt; i++) line_vertices.push_back(v2[i]), line_vertices.push_back(v2[i+1]);
|
|
|
|
}
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
else {
|
2023-04-14 23:14:29 +00:00
|
|
|
vector<glhr::colored_vertex> v2(cnt);
|
|
|
|
for(int i=0; i<cnt; i++) v2[i] = glhr::colored_vertex( V.T * glhr::gltopoint( v[offset+i] ), color);
|
2019-05-26 16:04:02 +00:00
|
|
|
if(color) for(int i=2; i<cnt-1; i++) triangle_vertices.push_back(v2[0]), triangle_vertices.push_back(v2[i-1]), triangle_vertices.push_back(v2[i]);
|
2023-04-14 23:14:29 +00:00
|
|
|
if(outline) {
|
|
|
|
for(auto& v: v2) v.set_color(outline);
|
|
|
|
for(int i=1; i<cnt; i++) line_vertices.push_back(v2[i-1]), line_vertices.push_back(v2[i]);
|
|
|
|
}
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else glflush();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(tinf) {
|
2020-09-11 09:08:27 +00:00
|
|
|
bool col = isize(tinf->colors);
|
|
|
|
if(col)
|
|
|
|
glhr::be_color_textured();
|
|
|
|
else
|
|
|
|
glhr::be_textured();
|
2020-04-17 13:01:55 +00:00
|
|
|
if(flags & POLY_SHADE_TEXTURE) current_display->next_shader_flags |= GF_TEXTURE_SHADED;
|
2022-10-11 17:56:37 +00:00
|
|
|
if(flags & POLY_NO_FOG) current_display->next_shader_flags |= GF_NO_FOG;
|
2019-05-26 16:04:02 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, tinf->texture_id);
|
2020-09-11 09:08:27 +00:00
|
|
|
if(isize(tinf->colors))
|
|
|
|
glhr::vertices_texture_color(v, tinf->tvertices, tinf->colors, offset, offset_texture);
|
|
|
|
else
|
|
|
|
glhr::vertices_texture(v, tinf->tvertices, offset, offset_texture);
|
2019-05-26 16:04:02 +00:00
|
|
|
ioffset = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glhr::be_nontextured();
|
2022-10-11 17:56:37 +00:00
|
|
|
if(flags & POLY_NO_FOG) current_display->next_shader_flags |= GF_NO_FOG;
|
2019-05-26 16:04:02 +00:00
|
|
|
glhr::vertices(v);
|
|
|
|
}
|
2019-08-25 17:14:03 +00:00
|
|
|
|
|
|
|
next_slr:
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2024-01-07 08:07:54 +00:00
|
|
|
for(int ed = current_display->separate_eyes() ? -1 : 0; ed<2; ed+=2) {
|
2019-05-26 16:04:02 +00:00
|
|
|
if(global_projection && global_projection != ed) continue;
|
2020-07-24 00:30:50 +00:00
|
|
|
|
|
|
|
if(min_slr < max_slr) {
|
2020-07-27 16:49:04 +00:00
|
|
|
current_display->set_all(ed, sl2 ? 0 : V.shift);
|
|
|
|
glhr::set_index_sl(V.shift + M_PI * min_slr * hybrid::csteps / cgi.psl_steps);
|
2020-07-24 00:30:50 +00:00
|
|
|
}
|
2022-05-28 16:44:42 +00:00
|
|
|
else if(sl2) {
|
|
|
|
current_display->set_all(ed, 0);
|
|
|
|
glhr::set_index_sl(V.shift);
|
|
|
|
}
|
2020-07-27 16:49:04 +00:00
|
|
|
else {
|
2022-05-28 16:44:42 +00:00
|
|
|
current_display->set_all(ed, sl2 ? 0 : V.shift);
|
|
|
|
glhr::set_index_sl(V.shift + M_PI * min_slr * hybrid::csteps / cgi.psl_steps);
|
2020-07-27 16:49:04 +00:00
|
|
|
}
|
|
|
|
bool draw = color;
|
|
|
|
|
2019-10-21 20:34:20 +00:00
|
|
|
flagtype sp = get_shader_flags();
|
|
|
|
|
|
|
|
if(sp & SF_DIRECT) {
|
|
|
|
if((sp & SF_BAND) && V[2][2] > 1e8) continue;
|
2020-07-27 16:49:04 +00:00
|
|
|
glapplymatrix(V.T);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(draw) {
|
|
|
|
if(flags & POLY_TRIANGLES) {
|
|
|
|
glhr::color2(color, (flags & POLY_INTENSE) ? 2 : 1);
|
2024-08-21 17:20:23 +00:00
|
|
|
if(flags & POLY_FORCE_DEPTH) {
|
|
|
|
glhr::set_depthtest(true);
|
|
|
|
glhr::set_depthwrite(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glhr::set_depthtest(model_needs_depth() && prio < PPR::SUPERLINE);
|
|
|
|
glhr::set_depthwrite(model_needs_depth() && prio != PPR::TRANSPARENT_SHADOW && prio != PPR::EUCLIDEAN_SKY);
|
|
|
|
}
|
2023-02-18 17:32:01 +00:00
|
|
|
glhr::set_fogbase(prio == PPR::SKY ? 1.0 + ((abs(cgi.SKY - cgi.LOWSKY)) / sightranges[geometry]) : 1.0);
|
2019-05-26 16:04:02 +00:00
|
|
|
glDrawArrays(GL_TRIANGLES, ioffset, cnt);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glEnable(GL_STENCIL_TEST);
|
|
|
|
|
|
|
|
glColorMask( GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE );
|
|
|
|
glhr::set_depthtest(false);
|
|
|
|
glStencilOp( GL_INVERT, GL_INVERT, GL_INVERT);
|
|
|
|
glStencilFunc( GL_ALWAYS, 0x1, 0x1 );
|
|
|
|
glhr::color2(0xFFFFFFFF);
|
2022-12-08 18:38:39 +00:00
|
|
|
glDrawArrays(tinf ? GL_TRIANGLES : GL_TRIANGLE_FAN, ioffset, cnt);
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
current_display->set_mask(ed);
|
|
|
|
glhr::color2(color);
|
|
|
|
glhr::set_depthtest(model_needs_depth() && prio < PPR::SUPERLINE);
|
2019-06-24 12:42:30 +00:00
|
|
|
glhr::set_depthwrite(model_needs_depth() && prio != PPR::TRANSPARENT_SHADOW && prio != PPR::EUCLIDEAN_SKY);
|
|
|
|
glhr::set_fogbase(prio == PPR::SKY ? 1.0 + (euclid ? 20 : 5 / sightranges[geometry]) : 1.0);
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
if(flags & (POLY_INVERSE | POLY_FORCE_INVERTED)) {
|
|
|
|
glStencilOp( GL_ZERO, GL_ZERO, GL_ZERO);
|
|
|
|
glStencilFunc( GL_NOTEQUAL, 1, 1);
|
|
|
|
GLfloat xx = vid.xres;
|
|
|
|
GLfloat yy = vid.yres;
|
|
|
|
vector<glvertex> scr = {
|
2019-10-21 20:34:20 +00:00
|
|
|
glhr::makevertex(-xx, -yy, 0),
|
|
|
|
glhr::makevertex(+xx, -yy, 0),
|
|
|
|
glhr::makevertex(+xx, +yy, 0),
|
|
|
|
glhr::makevertex(-xx, +yy, 0)
|
2019-05-26 16:04:02 +00:00
|
|
|
};
|
|
|
|
glhr::vertices(scr);
|
|
|
|
glhr::id_modelview();
|
|
|
|
glDrawArrays(tinf ? GL_TRIANGLES : GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
glhr::vertices(v);
|
2020-07-27 16:49:04 +00:00
|
|
|
if(sp & SF_DIRECT) glapplymatrix(V.T);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
glStencilOp( GL_ZERO, GL_ZERO, GL_ZERO);
|
|
|
|
glStencilFunc( GL_EQUAL, 1, 1);
|
2022-12-08 18:38:39 +00:00
|
|
|
glDrawArrays(tinf ? GL_TRIANGLES : GL_TRIANGLE_FAN, ioffset, cnt);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 09:25:55 +00:00
|
|
|
if(outline && !tinf) {
|
2022-04-22 22:57:04 +00:00
|
|
|
if(flags & POLY_APEIROGONAL) cnt = apeiro_cnt;
|
2019-05-26 16:04:02 +00:00
|
|
|
glhr::color2(outline);
|
|
|
|
glhr::set_depthtest(model_needs_depth() && prio < PPR::SUPERLINE);
|
2019-06-24 12:42:30 +00:00
|
|
|
glhr::set_depthwrite(model_needs_depth() && prio != PPR::TRANSPARENT_SHADOW && prio != PPR::EUCLIDEAN_SKY);
|
|
|
|
glhr::set_fogbase(prio == PPR::SKY ? 1.0 + (euclid ? 20 : 5 / sightranges[geometry]) : 1.0);
|
2020-04-06 09:25:55 +00:00
|
|
|
|
|
|
|
if(flags & POLY_TRIANGLES) {
|
|
|
|
vector<glvertex> v1;
|
|
|
|
v1.reserve(cnt * 2);
|
|
|
|
for(int i=0; i<cnt; i+= 3) {
|
|
|
|
v1.push_back(v[offset+i]);
|
|
|
|
v1.push_back(v[offset+i+1]);
|
|
|
|
v1.push_back(v[offset+i+1]);
|
|
|
|
v1.push_back(v[offset+i+2]);
|
|
|
|
v1.push_back(v[offset+i+2]);
|
|
|
|
v1.push_back(v[offset+i]);
|
|
|
|
}
|
|
|
|
glhr::vertices(v1);
|
|
|
|
glDrawArrays(GL_LINES, 0, cnt*2);
|
|
|
|
// glDrawArrays(GL_LINE_STRIP, ioffset, cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
glDrawArrays(GL_LINE_STRIP, offset, cnt);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-25 17:14:03 +00:00
|
|
|
|
2020-07-24 00:30:50 +00:00
|
|
|
if(min_slr+1 < max_slr) {
|
2019-08-25 17:14:03 +00:00
|
|
|
min_slr++;
|
|
|
|
goto next_slr;
|
|
|
|
}
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
EX ld scale_at(const shiftmatrix& T) {
|
2022-10-23 13:40:37 +00:00
|
|
|
if(GDIM == 3 && pmodel == mdPerspective) {
|
|
|
|
ld z = (tC0(unshift(T)))[2];
|
|
|
|
if(z == 0) return 1;
|
|
|
|
z = 1 / abs(z);
|
|
|
|
if(z > 10) return 10;
|
|
|
|
return z;
|
|
|
|
}
|
2019-07-30 10:59:02 +00:00
|
|
|
if(sol) return 1;
|
2019-05-26 16:04:02 +00:00
|
|
|
hyperpoint h1, h2, h3;
|
|
|
|
applymodel(tC0(T), h1);
|
|
|
|
applymodel(T * xpush0(.01), h2);
|
|
|
|
applymodel(T * ypush(.01) * C0, h3);
|
2022-03-27 07:04:05 +00:00
|
|
|
if(mdBandAny()) {
|
|
|
|
ld x2 = 2;
|
|
|
|
if(pmodel == mdBandEquiarea) x2 /= 2;
|
|
|
|
ld x4 = 2 * x2;
|
|
|
|
if(h2[0] > h1[0] + x2) h2[0] -= x4;
|
|
|
|
if(h2[0] < h1[0] - x2) h2[0] += x4;
|
|
|
|
if(h3[0] > h1[0] + x2) h3[0] -= x4;
|
|
|
|
if(h3[0] < h1[0] - x2) h3[0] += x4;
|
|
|
|
}
|
2019-05-26 16:04:02 +00:00
|
|
|
return sqrt(hypot_d(2, h2-h1) * hypot_d(2, h3-h1) / .0001);
|
|
|
|
}
|
|
|
|
|
2020-07-03 13:35:22 +00:00
|
|
|
EX int perfect_linewidth = 1;
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
EX ld linewidthat(const shiftpoint& h) {
|
2021-02-06 00:39:18 +00:00
|
|
|
if(!vid.fineline) return 1;
|
2020-08-01 14:42:02 +00:00
|
|
|
else if(hyperbolic && pmodel == mdDisk && pconf.alpha == 1 && !ISWEB && !flat_on) {
|
2019-08-17 21:28:41 +00:00
|
|
|
double dz = h[LDIM];
|
2019-10-21 20:34:20 +00:00
|
|
|
if(dz < 1) return 1;
|
2019-05-26 16:04:02 +00:00
|
|
|
else {
|
|
|
|
double dx = sqrt(dz * dz - 1);
|
|
|
|
double dfc = dx/(dz+1);
|
|
|
|
dfc = 1 - dfc*dfc;
|
|
|
|
return dfc;
|
|
|
|
}
|
|
|
|
}
|
2022-10-23 13:40:37 +00:00
|
|
|
else if(hyperbolic && pmodel == mdRelPerspective) {
|
|
|
|
if(abs(h[3]) < 1e-6) return 1;
|
|
|
|
return 1 / (1 + abs(h[3]));
|
|
|
|
}
|
|
|
|
else if(sl2 && pmodel == mdRelPerspective) {
|
|
|
|
if(abs(h[2]) < 1e-6) return 1;
|
|
|
|
return 1 / (1 + abs(h[2]));
|
|
|
|
}
|
|
|
|
else if(hyperbolic && GDIM == 3 && pmodel == mdPerspective && pconf.alpha == 0 && h[3] < 0.99) {
|
|
|
|
return 1;
|
|
|
|
}
|
2020-07-03 13:35:22 +00:00
|
|
|
else if(perfect_linewidth >= (inHighQual ? 1 : 2)) {
|
2020-07-27 16:49:04 +00:00
|
|
|
hyperpoint h0 = h.h / zlevel(h.h);
|
|
|
|
shiftmatrix T = shiftless(rgpushxto0(h0), h.shift);
|
2019-05-26 16:04:02 +00:00
|
|
|
return scale_at(T);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void set_width(ld w) {
|
2019-07-12 21:15:09 +00:00
|
|
|
#if MINIMIZE_GL_CALLS
|
|
|
|
if(w != glhr::current_linewidth) glflush();
|
|
|
|
#endif
|
2020-07-03 12:42:33 +00:00
|
|
|
#if CAP_GL
|
2019-07-12 21:15:09 +00:00
|
|
|
glhr::set_linewidth(w);
|
2020-07-03 12:42:33 +00:00
|
|
|
#endif
|
2019-07-12 21:15:09 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 17:08:16 +00:00
|
|
|
// this part makes cylindrical projections on the sphere work
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2019-08-14 17:08:16 +00:00
|
|
|
namespace cyl {
|
|
|
|
|
|
|
|
int loop_min = 0, loop_max = 0;
|
2019-08-14 18:11:10 +00:00
|
|
|
vector<ld> periods;
|
2019-08-14 16:59:21 +00:00
|
|
|
|
2019-08-14 06:23:09 +00:00
|
|
|
ld period_at(ld y) {
|
|
|
|
|
|
|
|
ld m = current_display->radius;
|
2020-04-16 22:53:58 +00:00
|
|
|
y /= (m * pconf.stretch);
|
2019-08-14 06:23:09 +00:00
|
|
|
|
|
|
|
switch(pmodel) {
|
|
|
|
case mdBand:
|
2020-09-15 17:17:07 +00:00
|
|
|
case mdMiller:
|
2019-08-14 06:23:09 +00:00
|
|
|
return m * 4;
|
|
|
|
case mdSinusoidal:
|
2019-08-14 18:11:10 +00:00
|
|
|
return m * 2 * cos(y * M_PI);
|
2019-08-14 06:23:09 +00:00
|
|
|
case mdMollweide:
|
2019-08-14 18:11:10 +00:00
|
|
|
return m * 2 * sqrt(1 - y*y*4);
|
2019-08-14 16:59:21 +00:00
|
|
|
case mdCollignon: {
|
2020-04-16 22:53:58 +00:00
|
|
|
if(pconf.collignon_reflected && y > 0) y = -y;
|
|
|
|
y += signed_sqrt(pconf.collignon_parameter);
|
2019-08-14 18:11:10 +00:00
|
|
|
return abs(m*y*2/1.2);
|
2019-08-14 16:59:21 +00:00
|
|
|
}
|
2019-08-14 06:23:09 +00:00
|
|
|
default:
|
|
|
|
return m * 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 11:28:48 +00:00
|
|
|
void ori_to_scr(glvertex& g) {
|
|
|
|
auto& Ori = pconf.mori().v2;
|
2023-08-08 14:27:52 +00:00
|
|
|
tie(g[0], g[1]) = make_pair(
|
|
|
|
Ori[0][0] * g[0] + Ori[0][1] * g[1],
|
|
|
|
Ori[1][0] * g[0] + Ori[1][1] * g[1]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-08-14 11:28:48 +00:00
|
|
|
void scr_to_ori(glvertex& g) {
|
|
|
|
auto& Ori = pconf.mori().v2;
|
|
|
|
/* we invert it, so transposition is applied in the formula */
|
2023-08-08 14:27:52 +00:00
|
|
|
tie(g[0], g[1]) = make_pair(
|
|
|
|
Ori[0][0] * g[0] + Ori[1][0] * g[1],
|
|
|
|
Ori[0][1] * g[0] + Ori[1][1] * g[1]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-14 17:08:16 +00:00
|
|
|
void adjust(bool tinf) {
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2019-08-14 18:11:10 +00:00
|
|
|
periods.resize(isize(glcoords));
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
if(!models::model_straight)
|
2019-05-26 16:04:02 +00:00
|
|
|
for(auto& g: glcoords)
|
2023-08-14 11:28:48 +00:00
|
|
|
scr_to_ori(g);
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2019-08-14 18:11:10 +00:00
|
|
|
for(int i = 0; i<isize(glcoords); i++) periods[i] = period_at(glcoords[i][1]);
|
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
auto dist = [] (ld a, ld b) { return max(b, a-b); };
|
|
|
|
|
|
|
|
ld chypot = hypot(dist(vid.xres, current_display->xcenter), dist(vid.yres, current_display->ycenter));
|
|
|
|
|
|
|
|
ld cmin = -chypot/2, cmax = chypot/2, dmin = -chypot, dmax = chypot;
|
2019-08-14 18:11:10 +00:00
|
|
|
|
2020-04-16 22:53:58 +00:00
|
|
|
ld z = pconf.stretch * current_display->radius;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2019-08-14 18:11:10 +00:00
|
|
|
switch(pmodel) {
|
|
|
|
case mdSinusoidal: case mdBandEquidistant: case mdMollweide:
|
|
|
|
dmax = z/2, dmin = -dmax;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case mdBandEquiarea:
|
|
|
|
dmax = z/M_PI, dmin = -dmax;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case mdCollignon:
|
2020-04-16 22:53:58 +00:00
|
|
|
dmin = z * (signed_sqrt(pconf.collignon_parameter - 1) - signed_sqrt(pconf.collignon_parameter));
|
|
|
|
if(pconf.collignon_reflected) dmax = -dmin;
|
|
|
|
else dmax = z * (signed_sqrt(pconf.collignon_parameter + 1) - signed_sqrt(pconf.collignon_parameter));
|
2019-08-14 18:11:10 +00:00
|
|
|
break;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2019-08-14 18:11:10 +00:00
|
|
|
default: ;
|
|
|
|
}
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2019-08-14 18:11:10 +00:00
|
|
|
bool had = false;
|
|
|
|
ld first, next;
|
|
|
|
|
|
|
|
for(int i = 0; i<isize(glcoords); i++) if(periods[i] > 1) {
|
|
|
|
if(!had) {
|
|
|
|
next = first = glcoords[i][0] / periods[i];
|
|
|
|
had = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glcoords[i][0] /= periods[i];
|
|
|
|
glcoords[i][0] -= round_nearest(glcoords[i][0]-next);
|
|
|
|
next = glcoords[i][0];
|
|
|
|
glcoords[i][0] *= periods[i];
|
|
|
|
}
|
|
|
|
loop_min = min<int>(loop_min, floor((cmin - glcoords[i][0]) / periods[i]));
|
|
|
|
loop_max = max<int>(loop_max, ceil((cmax - glcoords[i][0]) / periods[i]));
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 18:11:10 +00:00
|
|
|
if(!had) return;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2019-08-14 18:11:10 +00:00
|
|
|
ld last = first - round_nearest(first-next);
|
|
|
|
|
|
|
|
if(loop_max > 100) loop_max = 100;
|
|
|
|
if(loop_min < -100) loop_min = -100;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2019-08-14 16:58:42 +00:00
|
|
|
if(abs(first - last) < 1e-6) {
|
2019-08-09 22:58:50 +00:00
|
|
|
if(!models::model_straight)
|
2019-05-26 16:04:02 +00:00
|
|
|
for(auto& g: glcoords)
|
2023-08-14 11:28:48 +00:00
|
|
|
ori_to_scr(g);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(tinf) {
|
2019-08-14 18:11:10 +00:00
|
|
|
// this cannot work after cycled
|
|
|
|
loop_min = 1; loop_max = 0; return;
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
if(last < first) {
|
|
|
|
reverse(glcoords.begin(), glcoords.end());
|
2019-08-14 18:11:10 +00:00
|
|
|
reverse(periods.begin(), periods.end());
|
2019-05-26 16:04:02 +00:00
|
|
|
swap(first, last);
|
|
|
|
}
|
2019-08-14 18:11:10 +00:00
|
|
|
|
|
|
|
for(int i=0; i<isize(glcoords); i++) glcoords[i][0] += periods[i] * loop_min;
|
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
int base = isize(glcoords);
|
2019-08-14 18:11:10 +00:00
|
|
|
|
|
|
|
for(int i=loop_min; i<loop_max; i++) {
|
|
|
|
for(int j=0; j<base; j++) {
|
2019-05-26 16:04:02 +00:00
|
|
|
glcoords.push_back(glcoords[isize(glcoords)-base]);
|
2019-08-14 18:11:10 +00:00
|
|
|
glcoords.back()[0] += periods[j];
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
glcoords.push_back(glcoords.back());
|
|
|
|
glcoords.push_back(glcoords[0]);
|
|
|
|
for(int u=1; u<=2; u++) {
|
2019-08-14 17:08:16 +00:00
|
|
|
auto& v = glcoords[isize(glcoords)-u][1];
|
2019-05-26 16:04:02 +00:00
|
|
|
v = v < 0 ? dmin : dmax;
|
|
|
|
}
|
2019-08-09 22:58:50 +00:00
|
|
|
if(!models::model_straight)
|
2019-05-26 16:04:02 +00:00
|
|
|
for(auto& g: glcoords)
|
2023-08-14 11:28:48 +00:00
|
|
|
ori_to_scr(g);
|
2019-08-14 18:11:10 +00:00
|
|
|
// we have already looped
|
|
|
|
loop_min = loop_max = 0;
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-14 17:08:16 +00:00
|
|
|
}
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
bool in_twopoint = false;
|
|
|
|
|
|
|
|
ld glhypot2(glvertex a, glvertex b) {
|
|
|
|
return (a[0]-b[0]) * (a[0]-b[0]) + (a[1]-b[1]) * (a[1]-b[1]) + (a[2]-b[2]) * (a[2]-b[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void compute_side_by_centerin(dqi_poly *p, bool& nofill) {
|
|
|
|
|
|
|
|
hyperpoint hscr;
|
2020-07-27 16:49:04 +00:00
|
|
|
shiftpoint h1 = p->V * p->intester;
|
|
|
|
if(is_behind(h1.h)) {
|
2019-05-26 16:04:02 +00:00
|
|
|
if(sphere) {
|
|
|
|
for(int i=0; i<3; i++) h1[i] = -h1[i];
|
|
|
|
poly_flags &= ~POLY_CENTERIN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nofill = true;
|
|
|
|
}
|
2020-12-29 01:51:43 +00:00
|
|
|
applymodel(h1, hscr);
|
2020-12-30 13:20:30 +00:00
|
|
|
if(!vrhr::rendering()) {
|
2020-12-29 01:51:43 +00:00
|
|
|
hscr[0] *= current_display->radius; hscr[1] *= current_display->radius * pconf.stretch;
|
|
|
|
}
|
2019-05-26 16:04:02 +00:00
|
|
|
for(int i=0; i<isize(glcoords)-1; i++) {
|
|
|
|
double x1 = glcoords[i][0] - hscr[0];
|
|
|
|
double y1 = glcoords[i][1] - hscr[1];
|
|
|
|
double x2 = glcoords[i+1][0] - hscr[0];
|
|
|
|
double y2 = glcoords[i+1][1] - hscr[1];
|
|
|
|
if(asign(y1, y2)) {
|
|
|
|
ld x = xcross(x1, y1, x2, y2);
|
|
|
|
if(x < -1e-6) poly_flags ^= POLY_CENTERIN;
|
|
|
|
else if (x < 1e-6) nofill = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
poly_flags &= ~POLY_INVERSE;
|
|
|
|
if(poly_flags & POLY_CENTERIN) {
|
|
|
|
poly_flags |= POLY_INVERSE;
|
2020-07-27 16:49:04 +00:00
|
|
|
if(abs(zlevel(tC0(p->V.T)) - 1) > 1e-6) nofill = true;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
/* nofill = true;
|
|
|
|
outline = (flags & POLY_CENTERIN) ? 0x00FF00FF : 0xFF0000FF;
|
|
|
|
addpoint(hscr); */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
if(poly_flags & POLY_BADCENTERIN) {
|
2020-04-16 22:53:58 +00:00
|
|
|
glcoords.push_back(glhr::makevertex(hscr[0]+10, hscr[1]*pconf.stretch, hscr[2]));
|
|
|
|
glcoords.push_back(glhr::makevertex(hscr[0], hscr[1]*pconf.stretch+10, hscr[2]));
|
|
|
|
glcoords.push_back(glhr::makevertex(hscr[0]-10, hscr[1]*pconf.stretch, hscr[2]));
|
|
|
|
glcoords.push_back(glhr::makevertex(hscr[0], hscr[1]*pconf.stretch-10, hscr[2]));
|
|
|
|
glcoords.push_back(glhr::makevertex(hscr[0]+10, hscr[1]*pconf.stretch, hscr[2]));
|
2019-05-26 16:04:02 +00:00
|
|
|
} */
|
|
|
|
}
|
|
|
|
|
|
|
|
void compute_side_by_area() {
|
|
|
|
|
|
|
|
double rarea = 0;
|
|
|
|
for(int i=0; i<isize(glcoords)-1; i++)
|
|
|
|
rarea += glcoords[i][0] * glcoords[i+1][1] - glcoords[i][1] * glcoords[i+1][0];
|
|
|
|
rarea += glcoords.back()[0] * glcoords[0][1] - glcoords.back()[1] * glcoords[0][0];
|
|
|
|
|
|
|
|
if(rarea>0)
|
|
|
|
poly_flags ^= POLY_INVERSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ld get_width(dqi_poly* p) {
|
2019-10-21 20:34:20 +00:00
|
|
|
if((p->flags & POLY_FORCEWIDE) || pmodel == mdPixel)
|
2019-07-13 12:38:42 +00:00
|
|
|
return p->linewidth;
|
|
|
|
else if(p->flags & POLY_PRECISE_WIDE) {
|
2019-05-26 16:04:02 +00:00
|
|
|
ld maxwidth = 0;
|
|
|
|
for(int i=0; i<p->cnt; i++) {
|
2020-07-27 16:49:04 +00:00
|
|
|
shiftpoint h1 = p->V * glhr::gltopoint((*p->tab)[p->offset+i]);
|
2019-05-26 16:04:02 +00:00
|
|
|
maxwidth = max(maxwidth, linewidthat(h1));
|
|
|
|
}
|
|
|
|
return maxwidth * p->linewidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return linewidthat(tC0(p->V)) * p->linewidth;
|
|
|
|
}
|
|
|
|
|
2019-07-13 12:38:51 +00:00
|
|
|
void debug_this() { }
|
|
|
|
|
2019-08-18 14:58:44 +00:00
|
|
|
glvertex junk = glhr::makevertex(0,0,1);
|
|
|
|
|
2019-09-08 23:35:45 +00:00
|
|
|
EX namespace s2xe {
|
|
|
|
|
|
|
|
int maxgen;
|
|
|
|
bool with_zero;
|
|
|
|
ld minz, maxy, miny;
|
|
|
|
|
|
|
|
typedef array<ld, 5> pt;
|
|
|
|
|
|
|
|
basic_textureinfo stinf;
|
|
|
|
|
|
|
|
pt lerp(const pt& h0, const pt& h1, ld x) {
|
|
|
|
pt s;
|
|
|
|
for(int i=0; i<5; i++) s[i] = h0[i] + (h1[i]-h0[i]) * x;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add2(pt h, int gen) {
|
2022-11-12 21:38:45 +00:00
|
|
|
glcoords.push_back(glhr::pointtogl(point31(sin(h[0]) * (h[1] + TAU * gen), cos(h[0]) * (h[1] + TAU * gen), h[2])));
|
2019-09-08 23:35:45 +00:00
|
|
|
stinf.tvertices.push_back(glhr::makevertex(h[3], h[4], 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void addall(pt h0, pt h1, pt h2) {
|
|
|
|
for(int gen=-maxgen; gen <= maxgen; gen++) if(gen || with_zero) {
|
|
|
|
add2(h0, gen);
|
|
|
|
add2(h1, gen);
|
|
|
|
add2(h2, gen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_s2xe0(dqi_poly *p);
|
|
|
|
|
|
|
|
bool to_right(const pt& h2, const pt& h1) {
|
|
|
|
ld x2 = h2[0];
|
|
|
|
ld x1 = h1[0];
|
2022-11-12 21:38:45 +00:00
|
|
|
if(x2 < x1) x2 += TAU;
|
2019-09-08 23:35:45 +00:00
|
|
|
return x2 >= x2 && x2 <= x1 + M_PI;
|
|
|
|
}
|
|
|
|
|
|
|
|
EX int qrings = 32;
|
|
|
|
|
2022-11-12 21:38:45 +00:00
|
|
|
ld seg() { return TAU / qrings; }
|
2019-09-08 23:35:45 +00:00
|
|
|
|
|
|
|
void add_ortho_triangle(pt bl, pt tl, pt br, pt tr) {
|
|
|
|
|
|
|
|
auto sg = seg();
|
|
|
|
|
|
|
|
int s0 = ceil(bl[0] / sg);
|
|
|
|
int s1 = floor(br[0] / sg);
|
|
|
|
|
|
|
|
pt bat[1000], tat[1000];
|
|
|
|
|
|
|
|
bat[0] = bl; tat[0] = tl;
|
|
|
|
|
|
|
|
int s = 1;
|
|
|
|
|
|
|
|
for(int i = s0; i <= s1; i++) {
|
|
|
|
ld f = (i*sg-bl[0]) / (br[0]-bl[0]);
|
|
|
|
|
|
|
|
bat[s] = lerp(bl, br, f);
|
|
|
|
tat[s] = lerp(tl, tr, f);
|
|
|
|
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bat[s] = br; tat[s] = tr;
|
|
|
|
|
|
|
|
while(s--) {
|
|
|
|
addall(bat[s], bat[s+1], tat[s+1]);
|
|
|
|
addall(bat[s], tat[s+1], tat[s]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_ordered_triangle(array<pt, 3> v) {
|
2022-11-12 21:38:45 +00:00
|
|
|
if(v[1][0] < v[0][0]) v[1][0] += TAU;
|
|
|
|
if(v[2][0] < v[1][0]) v[2][0] += TAU;
|
2019-09-10 07:22:35 +00:00
|
|
|
if(v[2][0] - v[0][0] < 1e-6) return;
|
2019-09-08 23:35:45 +00:00
|
|
|
ld x = (v[1][0] - v[0][0]) / (v[2][0] - v[0][0]);
|
|
|
|
|
2022-11-12 21:38:45 +00:00
|
|
|
if(v[2][0] < v[0][0] + 45._deg && maxy < 135._deg && sightranges[geometry] <= 5) {
|
2019-09-08 23:35:45 +00:00
|
|
|
addall(v[0], v[1], v[2]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto mv = lerp(v[0], v[2], x);
|
|
|
|
|
|
|
|
add_ortho_triangle(v[0], v[0], mv, v[1]);
|
|
|
|
add_ortho_triangle(mv, v[1], v[2], v[2]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
int zl = floor(v[1][0] / seg());
|
|
|
|
int zr = ceil(v[1][0] / seg());
|
|
|
|
if(zl < zr && zl * seg > v[0][0] && zr * seg < v[2][0]) {
|
|
|
|
|
|
|
|
ld fl = (zl*seg-v[0][0]) / (v[2][0]-v[0][0]);
|
|
|
|
ld fr = (zr*seg-v[0][0]) / (v[2][0]-v[0][0]);
|
|
|
|
|
|
|
|
addall(lerp(v[0], v[2], fl), v[1], lerp(v[0], v[2], fr));
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// add_ortho_triangle(v[0], tv[0], v[1], tv[1], v[2], tv[2], v[2], tv[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_triangle_around(array<pt, 3> v) {
|
2022-11-12 21:38:45 +00:00
|
|
|
ld baseheight = (v[0][1] > 90._deg) ? M_PI : 0;
|
2019-09-08 23:35:45 +00:00
|
|
|
ld tu = (v[0][3] + v[1][3] + v[2][3]) / 3;
|
|
|
|
ld tv = (v[0][4] + v[1][4] + v[2][4]) / 3;
|
|
|
|
array<pt, 3> vhigh;
|
|
|
|
for(int i=0; i<3; i++) { vhigh[i] = v[i]; vhigh[i][1] = baseheight; vhigh[i][3] = tu; vhigh[i][4] = tv; }
|
2022-11-12 21:38:45 +00:00
|
|
|
if(v[1][0] < v[0][0]) v[1][0] = v[1][0] + TAU, vhigh[1][0] = vhigh[1][0] + TAU;
|
2019-09-08 23:35:45 +00:00
|
|
|
add_ortho_triangle(v[0], vhigh[0], v[1], vhigh[1]);
|
2022-11-12 21:38:45 +00:00
|
|
|
if(v[2][0] < v[1][0]) v[2][0] = v[2][0] + TAU, vhigh[2][0] = vhigh[2][0] + TAU;
|
2019-09-08 23:35:45 +00:00
|
|
|
add_ortho_triangle(v[1], vhigh[1], v[2], vhigh[2]);
|
2022-11-12 21:38:45 +00:00
|
|
|
if(v[0][0] < v[2][0]) v[0][0] = v[0][0] + TAU, vhigh[0][0] = vhigh[0][0] + TAU;
|
2019-09-08 23:35:45 +00:00
|
|
|
add_ortho_triangle(v[2], vhigh[2], v[0], vhigh[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_s2xe_triangle(array<pt, 3> v) {
|
|
|
|
bool r0 = to_right(v[1], v[0]);
|
|
|
|
bool r1 = to_right(v[2], v[1]);
|
|
|
|
bool r2 = to_right(v[0], v[2]);
|
|
|
|
|
|
|
|
minz = min(abs(v[0][2]), max(abs(v[1][2]), abs(v[2][2])));
|
|
|
|
auto& s = sightranges[geometry];
|
2022-11-12 21:38:45 +00:00
|
|
|
maxgen = sqrt(s * s - minz * minz) / TAU + 1;
|
2019-09-08 23:35:45 +00:00
|
|
|
|
|
|
|
maxy = max(v[0][1], max(v[1][1], v[2][1]));
|
|
|
|
miny = min(v[0][1], min(v[1][1], v[2][1]));
|
|
|
|
with_zero = true;
|
2022-11-12 21:38:45 +00:00
|
|
|
if(maxy < 45._deg) {
|
2019-09-08 23:35:45 +00:00
|
|
|
add2(v[0], 0);
|
|
|
|
add2(v[1], 0);
|
|
|
|
add2(v[2], 0);
|
|
|
|
with_zero = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
rotated:
|
|
|
|
if(r0 && r1 && r2) {
|
|
|
|
add_triangle_around(v);
|
|
|
|
}
|
|
|
|
else if(r0 && r1) {
|
|
|
|
add_ordered_triangle(v);
|
|
|
|
}
|
|
|
|
else if(r2 && !r0 && !r1) {
|
|
|
|
add_ordered_triangle(make_array(v[2], v[1], v[0]));
|
|
|
|
}
|
|
|
|
else if(!r0 && !r1 && !r2) {
|
|
|
|
add_triangle_around(make_array(v[2], v[1], v[0]));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tie(r0, r1, r2) = make_tuple(r1, r2, r0);
|
|
|
|
tie(v[0], v[1], v[2]) = make_tuple(v[1], v[2], v[0]);
|
|
|
|
goto rotated;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 12:48:36 +00:00
|
|
|
#if CAP_GL
|
2019-09-08 23:35:45 +00:00
|
|
|
void draw_s2xe(dqi_poly *p) {
|
|
|
|
if(!p->cnt) return;
|
2019-09-10 07:22:35 +00:00
|
|
|
if(p->flags & POLY_TRIANGLES) {
|
2019-09-08 23:35:45 +00:00
|
|
|
dqi_poly npoly = *p;
|
|
|
|
npoly.offset = 0;
|
|
|
|
npoly.tab = &glcoords;
|
2019-09-10 07:22:35 +00:00
|
|
|
if(p->tinf) {
|
|
|
|
npoly.tinf = p->tinf ? &stinf : NULL;
|
|
|
|
npoly.offset_texture = 0;
|
|
|
|
stinf.texture_id = p->tinf->texture_id;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
npoly.tinf = NULL;
|
|
|
|
}
|
2020-07-27 16:49:04 +00:00
|
|
|
npoly.V = shiftless(Id);
|
|
|
|
auto& pV = p->V.T;
|
2019-09-08 23:35:45 +00:00
|
|
|
set_width(1);
|
|
|
|
glcoords.clear();
|
|
|
|
stinf.tvertices.clear();
|
|
|
|
for(int i=0; i<p->cnt; i+=3) {
|
|
|
|
array<pt, 3> v;
|
|
|
|
for(int k=0; k<3; k++) {
|
2020-07-27 16:49:04 +00:00
|
|
|
hyperpoint h = pV * glhr::gltopoint( (*p->tab)[p->offset+i+k]);
|
2019-09-08 23:35:45 +00:00
|
|
|
v[k][2] = hypot_d(3, h);
|
|
|
|
|
|
|
|
auto dp = product_decompose(h);
|
|
|
|
v[k][2] = dp.first;
|
|
|
|
v[k][0] = atan2(h[0], h[1]);
|
|
|
|
v[k][1] = acos_auto_clamp(dp.second[2]);
|
2019-09-10 07:22:35 +00:00
|
|
|
if(p->tinf) {
|
|
|
|
auto& tv = p->tinf->tvertices[p->offset_texture+i+k];
|
|
|
|
v[k][3] = tv[0];
|
|
|
|
v[k][4] = tv[1];
|
|
|
|
}
|
2019-09-08 23:35:45 +00:00
|
|
|
}
|
|
|
|
add_s2xe_triangle(v);
|
|
|
|
}
|
|
|
|
npoly.cnt = isize(glcoords);
|
|
|
|
npoly.gldraw();
|
|
|
|
}
|
|
|
|
else draw_s2xe0(p);
|
|
|
|
}
|
2020-07-03 12:48:36 +00:00
|
|
|
#endif
|
2019-09-08 23:35:45 +00:00
|
|
|
|
2019-08-18 16:43:57 +00:00
|
|
|
struct point_data {
|
|
|
|
hyperpoint direction;
|
|
|
|
ld distance;
|
|
|
|
ld z;
|
|
|
|
int bad;
|
|
|
|
};
|
|
|
|
|
2020-07-03 12:48:36 +00:00
|
|
|
#if CAP_GL
|
2019-09-08 23:35:45 +00:00
|
|
|
void draw_s2xe0(dqi_poly *p) {
|
2019-08-20 12:48:35 +00:00
|
|
|
if(!p->cnt) return;
|
|
|
|
dqi_poly npoly = *p;
|
|
|
|
npoly.offset = 0;
|
|
|
|
npoly.tab = &glcoords;
|
2020-07-27 16:49:04 +00:00
|
|
|
npoly.V = shiftless(Id);
|
2019-11-03 13:44:26 +00:00
|
|
|
npoly.flags &= ~ (POLY_INVERSE | POLY_FORCE_INVERTED);
|
2019-08-20 12:48:35 +00:00
|
|
|
set_width(1);
|
|
|
|
glcoords.clear();
|
|
|
|
|
2022-11-12 21:38:45 +00:00
|
|
|
int maxgen = sightranges[geometry] / TAU + 1;
|
2019-08-18 16:43:57 +00:00
|
|
|
|
|
|
|
auto crossdot = [&] (const hyperpoint h1, const hyperpoint h2) { return make_pair(h1[0] * h2[1] - h1[1] * h2[0], h1[0] * h2[0] + h1[1] * h2[1]); };
|
|
|
|
vector<point_data> pd;
|
|
|
|
for(int i=0; i<p->cnt; i++) {
|
2020-07-27 16:49:04 +00:00
|
|
|
hyperpoint h = p->V.T * glhr::gltopoint( (*p->tab)[p->offset+i]);
|
2019-08-19 12:58:39 +00:00
|
|
|
pd.emplace_back();
|
|
|
|
auto& next = pd.back();
|
2019-08-18 16:43:57 +00:00
|
|
|
auto dp = product_decompose(h);
|
|
|
|
next.direction = dp.second;
|
|
|
|
next.z = dp.first;
|
|
|
|
// next.tpoint = p->tinf ? p->tinf->tvertices[p->offset+i] : glvertex();
|
|
|
|
ld hyp = hypot_d(2, next.direction);
|
|
|
|
next.distance = acos_auto_clamp(next.direction[2]);
|
|
|
|
if(hyp == 0) {
|
|
|
|
next.direction = point2(1, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
next.direction[0] /= hyp;
|
|
|
|
next.direction[1] /= hyp;
|
|
|
|
}
|
|
|
|
if(next.distance < 1e-3) next.bad = 1;
|
|
|
|
else if(next.distance > M_PI - 1e-3) next.bad = 2;
|
|
|
|
else next.bad = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
glcoords.resize(p->cnt);
|
2019-11-03 13:44:40 +00:00
|
|
|
for(auto c: pd) if(c.bad == 2) return;
|
|
|
|
bool no_gens = false;
|
|
|
|
for(int i=0; i<p->cnt; i++) {
|
|
|
|
auto &c1 = pd[i];
|
|
|
|
auto &c0 = pd[i==0?p->cnt-1 : i-1];
|
2022-11-12 21:38:45 +00:00
|
|
|
if(c1.distance > 90._deg && c0.distance > 90._deg && crossdot(c0.direction, c1.direction).second < 0) return;
|
2019-11-03 13:44:40 +00:00
|
|
|
if(c1.bad == 2) return;
|
|
|
|
if(c1.bad == 1) no_gens = true;
|
2019-08-18 16:43:57 +00:00
|
|
|
}
|
2019-11-03 13:44:40 +00:00
|
|
|
|
|
|
|
if(!no_gens) {
|
|
|
|
|
|
|
|
vector<ld> angles(p->cnt);
|
2019-08-18 16:43:57 +00:00
|
|
|
for(int i=0; i<p->cnt; i++) {
|
2019-11-03 13:44:40 +00:00
|
|
|
angles[i] = atan2(pd[i].direction[1], pd[i].direction[0]);
|
2019-08-18 20:08:34 +00:00
|
|
|
}
|
2019-11-03 13:44:40 +00:00
|
|
|
sort(angles.begin(), angles.end());
|
2022-11-12 21:38:45 +00:00
|
|
|
angles.push_back(angles[0] + TAU);
|
2019-11-03 13:44:40 +00:00
|
|
|
bool ok = false;
|
|
|
|
for(int i=1; i<isize(angles); i++)
|
|
|
|
if(angles[i] >= angles[i-1] + M_PI) ok = true;
|
|
|
|
if(!ok) {
|
2022-11-12 21:38:45 +00:00
|
|
|
for(auto &c: pd) if(c.distance > 90._deg) return;
|
2019-11-03 13:44:40 +00:00
|
|
|
no_gens = true;
|
2019-08-18 16:43:57 +00:00
|
|
|
}
|
2019-11-03 13:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int g = no_gens ? 0 : maxgen;
|
|
|
|
|
|
|
|
for(int gen=-g; gen<=g; gen++) {
|
|
|
|
for(int i=0; i<p->cnt; i++) {
|
|
|
|
auto& cur = pd[i];
|
2022-11-12 21:38:45 +00:00
|
|
|
ld d = cur.distance + TAU * gen;
|
2019-11-03 13:44:40 +00:00
|
|
|
hyperpoint h;
|
|
|
|
h[0] = cur.direction[0] * d;
|
|
|
|
h[1] = cur.direction[1] * d;
|
|
|
|
h[2] = cur.z;
|
|
|
|
glcoords[i] = glhr::pointtogl(h);
|
2019-08-18 16:43:57 +00:00
|
|
|
}
|
2019-11-03 13:44:40 +00:00
|
|
|
npoly.gldraw();
|
2019-08-18 16:43:57 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-03 12:48:36 +00:00
|
|
|
#endif
|
2019-09-08 23:35:45 +00:00
|
|
|
EX }
|
2019-08-18 16:43:57 +00:00
|
|
|
|
2020-07-24 21:39:30 +00:00
|
|
|
EX int berger_limit = 2;
|
|
|
|
|
|
|
|
void draw_stretch(dqi_poly *p) {
|
|
|
|
|
|
|
|
dqi_poly npoly = *p;
|
|
|
|
|
|
|
|
npoly.offset = 0;
|
|
|
|
npoly.tab = &glcoords;
|
2020-07-27 16:49:04 +00:00
|
|
|
npoly.V = shiftless(Id);
|
2020-07-24 21:39:30 +00:00
|
|
|
npoly.flags &= ~(POLY_INVERSE | POLY_FORCE_INVERTED);
|
|
|
|
|
2020-09-16 03:57:05 +00:00
|
|
|
transmatrix T2 = stretch::translate( tC0(iso_inverse(View)) );
|
2020-07-24 21:39:30 +00:00
|
|
|
transmatrix U = View * T2;
|
|
|
|
|
2020-09-16 03:57:05 +00:00
|
|
|
transmatrix iUV = iso_inverse(U) * p->V.T;
|
2020-07-24 21:39:30 +00:00
|
|
|
|
|
|
|
vector<hyperpoint> hs;
|
|
|
|
vector<hyperpoint> ths;
|
|
|
|
hs.resize(p->cnt);
|
|
|
|
ths.resize(p->cnt);
|
|
|
|
for(int i=0; i<p->cnt; i++)
|
|
|
|
hs[i] = iUV * glhr::gltopoint( (*p->tab)[p->offset+i] );
|
|
|
|
|
|
|
|
vector<vector<hyperpoint> > results;
|
|
|
|
results.resize(p->cnt);
|
|
|
|
|
|
|
|
auto& stinf = s2xe::stinf;
|
|
|
|
|
|
|
|
if(p->tinf) {
|
|
|
|
npoly.tinf = &stinf;
|
|
|
|
npoly.offset_texture = 0;
|
|
|
|
stinf.texture_id = p->tinf->texture_id;
|
|
|
|
stinf.tvertices.clear();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
npoly.tinf = NULL;
|
|
|
|
}
|
2020-07-27 16:49:04 +00:00
|
|
|
npoly.V = shiftless(Id);
|
2020-07-24 21:39:30 +00:00
|
|
|
set_width(1);
|
|
|
|
glcoords.clear();
|
|
|
|
|
|
|
|
for(int i=0; i<p->cnt; i++) results[i] = stretch::inverse_exp_all(hs[i], berger_limit);
|
|
|
|
|
2020-07-25 01:13:30 +00:00
|
|
|
auto test = [] (hyperpoint a, hyperpoint b) -> bool {
|
|
|
|
return sqhypot_d(3, a-b) < 2;
|
|
|
|
};
|
|
|
|
|
2021-05-21 23:24:28 +00:00
|
|
|
#if CAP_GL
|
2020-07-25 01:13:30 +00:00
|
|
|
if(p->flags & POLY_TRIANGLES) {
|
|
|
|
for(int i=0; i<p->cnt; i+=3) {
|
|
|
|
auto &la = results[i];
|
|
|
|
auto &lb = results[i+1];
|
|
|
|
auto &lc = results[i+2];
|
2020-07-24 21:39:30 +00:00
|
|
|
|
2020-07-25 01:13:30 +00:00
|
|
|
for(auto& ha: la) for(auto& hb: lb) if(test(ha, hb))
|
|
|
|
for(auto& hc: lc) if(test(ha, hc) && test(hb, hc)) {
|
|
|
|
|
|
|
|
glcoords.push_back(glhr::pointtogl(U * ha));
|
|
|
|
glcoords.push_back(glhr::pointtogl(U * hb));
|
|
|
|
glcoords.push_back(glhr::pointtogl(U * hc));
|
|
|
|
if(p->tinf)
|
|
|
|
for(int j=0; j<3; j++)
|
|
|
|
stinf.tvertices.push_back(p->tinf->tvertices[p->offset_texture+i+j]);
|
|
|
|
}
|
2020-07-24 21:39:30 +00:00
|
|
|
}
|
2020-07-25 01:13:30 +00:00
|
|
|
npoly.cnt = isize(glcoords);
|
|
|
|
npoly.gldraw();
|
2020-07-24 21:39:30 +00:00
|
|
|
}
|
2020-07-25 01:13:30 +00:00
|
|
|
else if(p->cnt) {
|
|
|
|
for(auto& ha: results[0]) {
|
|
|
|
vector<hyperpoint> has;
|
|
|
|
has.push_back(ha);
|
|
|
|
glcoords.push_back(glhr::pointtogl(U * ha));
|
|
|
|
for(int i=1; i<p->cnt; i++) {
|
|
|
|
hyperpoint best = C0;
|
|
|
|
ld dist = 10;
|
|
|
|
for(auto& hb: results[i]) {
|
|
|
|
ld d = sqhypot_d(3, hb-has.back());
|
|
|
|
if(d < dist) dist = d, best = hb;
|
|
|
|
}
|
|
|
|
if(dist < 2) has.push_back(best);
|
|
|
|
}
|
|
|
|
if(isize(has) < 3) continue;
|
|
|
|
glcoords.clear();
|
|
|
|
for(auto& h: has) glcoords.push_back(glhr::pointtogl(U * h));
|
|
|
|
npoly.cnt = isize(glcoords);
|
|
|
|
npoly.gldraw();
|
|
|
|
}
|
2021-05-21 23:24:28 +00:00
|
|
|
}
|
|
|
|
#endif
|
2020-07-24 21:39:30 +00:00
|
|
|
}
|
|
|
|
|
2019-10-21 20:42:27 +00:00
|
|
|
EX namespace ods {
|
|
|
|
#if CAP_ODS
|
|
|
|
|
|
|
|
EX bool project(hyperpoint h, hyperpoint& h1, hyperpoint& h2, bool eye) {
|
|
|
|
ld tanalpha = tan_auto(vid.ipd/2);
|
|
|
|
if(eye) tanalpha = -tanalpha;
|
|
|
|
if(!sphere) tanalpha = -tanalpha;
|
|
|
|
|
|
|
|
ld& x = h[0];
|
|
|
|
ld z = -h[1];
|
|
|
|
ld y = -h[2];
|
|
|
|
ld& t = h[3];
|
|
|
|
|
|
|
|
ld y02 = (x*x + y*y - tanalpha*tanalpha*t*t);
|
|
|
|
if(y02 < 0) return false;
|
|
|
|
ld y0 = sqrt(y02);
|
|
|
|
ld theta = atan(z / y0);
|
|
|
|
|
|
|
|
for(int i=0; i<2; i++) {
|
|
|
|
hyperpoint& h = (i ? h1 : h2);
|
|
|
|
if(i == 1) theta = -theta, y0 = -y0;
|
|
|
|
|
|
|
|
ld x0 = t * tanalpha;
|
|
|
|
|
|
|
|
ld phi = atan2(y, x) - atan2(y0, x0) + M_PI;
|
|
|
|
|
2020-02-26 00:27:04 +00:00
|
|
|
ld delta;
|
|
|
|
if(euclid) delta = hypot(y0, z);
|
|
|
|
else if(sphere) delta = atan2_auto(z / sin(theta), t / cos_auto(vid.ipd/2));
|
|
|
|
else {
|
|
|
|
// ld delta = euclid ? hypot(y0,z) : atan2_auto(z / sin(theta), t / cos_auto(vid.ipd/2));
|
|
|
|
ld p = z / sin(theta) / t * cos_auto(vid.ipd / 2);
|
|
|
|
delta = (p > 1) ? 13 : (p < -1) ? -13 : atanh(p);
|
|
|
|
}
|
2019-10-21 20:42:27 +00:00
|
|
|
|
|
|
|
if(euclid || hyperbolic) phi -= M_PI;
|
|
|
|
if(hyperbolic) delta = -delta;
|
|
|
|
|
|
|
|
h[0] = phi;
|
|
|
|
h[1] = theta;
|
|
|
|
h[2] = delta;
|
|
|
|
if(euclid || hyperbolic) h[1] = -theta;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_ods(dqi_poly *p) {
|
|
|
|
auto& stinf = s2xe::stinf;
|
|
|
|
|
|
|
|
if(!p->cnt) return;
|
|
|
|
if(!(p->flags & POLY_TRIANGLES)) return;
|
|
|
|
|
|
|
|
dqi_poly npoly = *p;
|
|
|
|
npoly.offset = 0;
|
|
|
|
npoly.tab = &glcoords;
|
2023-12-02 18:34:06 +00:00
|
|
|
npoly.V = shiftless(Id);
|
2019-10-21 20:42:27 +00:00
|
|
|
npoly.tinf = p->tinf ? &stinf : NULL;
|
|
|
|
if(npoly.tinf) {
|
|
|
|
npoly.offset_texture = 0;
|
|
|
|
stinf.texture_id = p->tinf->texture_id;
|
|
|
|
stinf.tvertices.clear();
|
|
|
|
}
|
2023-12-02 18:34:06 +00:00
|
|
|
npoly.V = shiftless(Id);
|
2019-10-21 20:42:27 +00:00
|
|
|
glcoords.clear();
|
|
|
|
|
|
|
|
array<hyperpoint, 6> h;
|
|
|
|
|
|
|
|
if(0) for(int i=0; i<p->cnt; i+=3) {
|
|
|
|
for(int j=0; j<3; j++)
|
2023-12-02 18:34:06 +00:00
|
|
|
h[j] = unshift(p->V) * glhr::gltopoint((*p->tab)[p->offset+i+j]);
|
2019-10-21 20:42:27 +00:00
|
|
|
|
|
|
|
for(int j=0; j<3; j++) {
|
|
|
|
glcoords.push_back(glhr::makevertex(h[j][0], h[j][1], h[j][2]));
|
|
|
|
if(npoly.tinf) stinf.tvertices.push_back(p->tinf->tvertices[i+j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(1) for(int i=0; i<p->cnt; i+=3) {
|
|
|
|
|
|
|
|
for(int j=0; j<3; j++) {
|
2023-12-02 18:34:06 +00:00
|
|
|
shiftpoint o = p->V * glhr::gltopoint((*p->tab)[p->offset+i+j]);
|
2022-12-08 18:38:06 +00:00
|
|
|
if(nonisotropic || gproduct) {
|
2023-12-02 18:34:06 +00:00
|
|
|
auto o1 = lp_apply(inverse_exp(o, pNORMAL));
|
|
|
|
o1[3] = 1;
|
2020-02-26 00:27:04 +00:00
|
|
|
dynamicval<eGeometry> g(geometry, gEuclid);
|
2023-12-02 18:34:06 +00:00
|
|
|
if(!project(o1, h[j], h[j+3], global_projection == -1))
|
2020-02-26 00:27:04 +00:00
|
|
|
goto next_i;
|
|
|
|
}
|
2023-12-02 18:34:06 +00:00
|
|
|
else if(!project(unshift(o), h[j], h[j+3], global_projection == -1))
|
2019-10-21 20:42:27 +00:00
|
|
|
goto next_i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int j=0; j<6; j++) {
|
|
|
|
// let Delta be from 0 to 2PI
|
2022-11-12 21:38:45 +00:00
|
|
|
if(h[j][2]<0) h[j][2] += TAU;
|
2019-10-21 20:42:27 +00:00
|
|
|
// Theta is from -PI/2 to PI/2. Let it be from 0 to PI
|
2022-11-12 21:38:45 +00:00
|
|
|
h[j][1] += global_projection * 90._deg;
|
2019-10-21 20:42:27 +00:00
|
|
|
h[j][3] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* natsph here */
|
|
|
|
|
|
|
|
if(h[0][2] < 0) swap(h[0], h[3]);
|
|
|
|
if(h[1][2] < 0) swap(h[1], h[4]);
|
|
|
|
if(h[2][2] < 0) swap(h[2], h[5]);
|
|
|
|
|
|
|
|
cyclefix(h[0][0], 0);
|
|
|
|
cyclefix(h[1][0], h[0][0]);
|
|
|
|
cyclefix(h[2][0], h[0][0]);
|
|
|
|
cyclefix(h[3][0], 0);
|
|
|
|
cyclefix(h[4][0], h[3][0]);
|
|
|
|
cyclefix(h[5][0], h[3][0]);
|
|
|
|
|
2022-11-12 21:38:45 +00:00
|
|
|
if(abs(h[1][1] - h[0][1]) > 90._deg) goto next_i;
|
|
|
|
if(abs(h[2][1] - h[0][1]) > 90._deg) goto next_i;
|
2019-10-21 20:42:27 +00:00
|
|
|
|
|
|
|
if(h[0][0] < -M_PI || h[0][0] > M_PI) println(hlog, h[0][0]);
|
|
|
|
|
|
|
|
if(1) {
|
|
|
|
int fst = 0, lst = 0;
|
|
|
|
if(h[1][0] < -M_PI || h[2][0] < -M_PI) lst++;
|
|
|
|
if(h[1][0] > +M_PI || h[2][0] > +M_PI) fst--;
|
|
|
|
for(int x=fst; x<=lst; x++) for(int j=0; j<3; j++) {
|
2022-11-12 21:38:45 +00:00
|
|
|
glcoords.push_back(glhr::makevertex(h[j][0] + TAU * x, h[j][1], h[j][2]));
|
2019-10-21 20:42:27 +00:00
|
|
|
if(npoly.tinf) stinf.tvertices.push_back(p->tinf->tvertices[p->offset_texture+i+j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* natsph here */
|
|
|
|
|
|
|
|
next_i: ;
|
|
|
|
}
|
|
|
|
|
|
|
|
npoly.cnt = isize(glcoords);
|
|
|
|
// npoly.color = 0xFFFFFFFF;
|
|
|
|
npoly.gldraw();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
EX }
|
|
|
|
|
2020-09-16 11:51:21 +00:00
|
|
|
/** @brief render in a broken projection; return false if normal rendering is not applicable */
|
|
|
|
bool broken_projection(dqi_poly& p0) {
|
2020-09-15 17:17:07 +00:00
|
|
|
int broken_coord = models::get_broken_coord(pmodel);
|
|
|
|
static bool in_broken = false;
|
2023-03-19 11:21:05 +00:00
|
|
|
bool both_broken = pmodel == mdConformalSquare;
|
2023-03-23 00:35:52 +00:00
|
|
|
|
|
|
|
transmatrix T = p0.V.T, IT = Id, FT = Id;
|
|
|
|
if(both_broken) FT = cspin(0, 1, 45._deg), T = FT * T, IT = cspin(0, 1, -45._deg);
|
|
|
|
|
|
|
|
ld zlow = 0;
|
|
|
|
if(both_broken) {
|
|
|
|
ld t = pconf.model_transition;
|
|
|
|
zlow = (1-t*t) / (1+t*t);
|
|
|
|
}
|
|
|
|
// x * mt / (1-z) <= 1
|
|
|
|
// sqrt(1-z*z) * mt / (1-z) <= 1
|
|
|
|
// sqrt(1-z*z) <= (1-z) / mt
|
|
|
|
|
2020-09-15 17:17:07 +00:00
|
|
|
if(broken_coord && !in_broken) {
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2020-09-15 17:17:07 +00:00
|
|
|
int zcoord = broken_coord;
|
|
|
|
int ycoord = 3 - zcoord;
|
2023-03-19 11:21:05 +00:00
|
|
|
int xcoord = 0;
|
|
|
|
|
|
|
|
zcoord = 2;
|
2020-09-15 17:17:07 +00:00
|
|
|
|
|
|
|
vector<hyperpoint> all;
|
2020-09-16 11:51:21 +00:00
|
|
|
for(int i=0; i<p0.cnt; i++)
|
2023-03-23 00:35:52 +00:00
|
|
|
all.push_back(T * glhr::gltopoint((*p0.tab)[p0.offset+i]));
|
2020-09-15 17:17:07 +00:00
|
|
|
int fail = 0;
|
|
|
|
int last_fail;
|
2020-09-16 12:03:46 +00:00
|
|
|
|
2023-08-14 09:08:37 +00:00
|
|
|
for(auto& h: all) models::scr_to_ori(h);
|
2023-03-19 11:21:05 +00:00
|
|
|
|
|
|
|
auto break_in_xz = [&] (hyperpoint a, hyperpoint b, int xcoord, int zcoord) {
|
2023-03-23 00:35:52 +00:00
|
|
|
return a[xcoord] * b[xcoord] <= 0 && (a[xcoord] * (b[zcoord]+zlow) - b[xcoord] * (a[zcoord]+zlow)) * (a[xcoord] - b[xcoord]) < 0;
|
2023-03-19 11:21:05 +00:00
|
|
|
};
|
|
|
|
|
2020-09-16 11:51:21 +00:00
|
|
|
auto break_in = [&] (hyperpoint a, hyperpoint b) {
|
2023-03-19 11:21:05 +00:00
|
|
|
if(both_broken) {
|
|
|
|
for(int xc=0; xc<2; xc++) {if(break_in_xz(a, b, xc, zcoord)) { xcoord = xc; ycoord = 1-xc; return true; } }
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return break_in_xz(a, b, xcoord, zcoord);
|
2020-09-16 11:51:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for(int i=0; i<p0.cnt-1; i++)
|
|
|
|
if(break_in(all[i], all[i+1]))
|
2020-09-15 17:17:07 +00:00
|
|
|
last_fail = i, fail++;
|
|
|
|
vector<glvertex> v;
|
2020-09-16 11:51:21 +00:00
|
|
|
dqi_poly p = p0;
|
2020-09-15 17:17:07 +00:00
|
|
|
p.tab = &v;
|
|
|
|
p.offset = 0;
|
2023-03-23 00:35:52 +00:00
|
|
|
p.V.T = IT;
|
2020-09-16 12:03:46 +00:00
|
|
|
|
|
|
|
/* we don't rotate h's back, just change p.V */
|
|
|
|
for(int i=0; i<3; i++)
|
2023-08-14 09:08:37 +00:00
|
|
|
models::scr_to_ori(p.V.T[i]);
|
2020-09-16 12:03:46 +00:00
|
|
|
|
2020-09-15 17:17:07 +00:00
|
|
|
if(fail) {
|
2020-09-16 11:51:33 +00:00
|
|
|
if(p0.tinf) return true;
|
2020-09-15 17:17:07 +00:00
|
|
|
dynamicval<bool> ib(in_broken, true);
|
2023-03-19 11:21:05 +00:00
|
|
|
|
|
|
|
ld part = ilerp(all[last_fail][xcoord], all[last_fail+1][xcoord], 0);
|
|
|
|
if(both_broken && all[last_fail][ycoord] * all[last_fail+1][ycoord] < 0) {
|
|
|
|
ld part2 = ilerp(all[last_fail][ycoord], all[last_fail+1][ycoord], 0);
|
|
|
|
if(part2 > part) part = part2, swap(xcoord, ycoord);
|
|
|
|
}
|
2020-09-15 17:17:07 +00:00
|
|
|
hyperpoint initial = normalize(lerp(all[last_fail], all[last_fail+1], 1 - (1-part) * .99));
|
|
|
|
bool have_initial = true;
|
|
|
|
v.push_back(glhr::pointtogl(initial));
|
|
|
|
last_fail++;
|
|
|
|
int at = last_fail;
|
|
|
|
do {
|
|
|
|
v.push_back(glhr::pointtogl(all[at]));
|
2023-03-19 11:21:05 +00:00
|
|
|
if(at == p0.cnt-1 && sqhypot_d(2, all[at] - all[0]) > 1e-6) {
|
2020-09-15 17:17:07 +00:00
|
|
|
p.cnt = isize(v); p.draw(); v.clear(); at = 0;
|
|
|
|
have_initial = false;
|
|
|
|
}
|
|
|
|
int next = at+1;
|
2020-09-16 11:51:21 +00:00
|
|
|
if(next == p0.cnt) next = 0;
|
|
|
|
if(break_in(all[at], all[next])) {
|
2023-03-19 11:21:05 +00:00
|
|
|
ld part = ilerp(all[at][xcoord], all[next][xcoord], 0);
|
|
|
|
if(both_broken && all[at][ycoord] * all[next][ycoord] < 0) {
|
|
|
|
ld part2 = ilerp(all[at][ycoord], all[next][ycoord], 0);
|
|
|
|
if(part2 < part) part = part2, swap(xcoord, ycoord);
|
|
|
|
}
|
|
|
|
|
2020-09-15 17:17:07 +00:00
|
|
|
hyperpoint final = normalize(lerp(all[at], all[next], part * .99));
|
|
|
|
v.push_back(glhr::pointtogl(final));
|
|
|
|
if(have_initial) {
|
|
|
|
int max = 4 << vid.linequality;
|
2023-03-19 11:21:05 +00:00
|
|
|
if(both_broken) {
|
2023-03-23 00:35:52 +00:00
|
|
|
auto square_close_corner = [&] (hyperpoint h) {
|
2023-03-19 11:21:05 +00:00
|
|
|
hyperpoint end = -C0;
|
2023-03-23 00:35:52 +00:00
|
|
|
end[0] = 0.01 * signum(h[0]);
|
|
|
|
end[1] = 0.01 * signum(h[1]);
|
|
|
|
/* if(abs(h1[0]) > abs(h1[1]))
|
|
|
|
end[0] = 0.01 * signum(h1[0]), end[1] = 0.001 * signum(h1[1]);
|
2023-03-19 11:21:05 +00:00
|
|
|
else
|
2023-03-23 00:35:52 +00:00
|
|
|
end[1] = 0.01 * signum(h1[1]), end[0] = 0.001 * signum(h1[0]); */
|
2023-03-19 11:21:05 +00:00
|
|
|
return normalize(end);
|
|
|
|
};
|
|
|
|
hyperpoint endf = square_close_corner(final);
|
|
|
|
hyperpoint endi = square_close_corner(initial);
|
|
|
|
if(endf != endi) {
|
|
|
|
for(int i=1; i<=max; i++)
|
|
|
|
v.push_back(glhr::pointtogl(lerp(final, endf, i * 1. / max)));
|
|
|
|
for(int i=0; i<=max; i++)
|
|
|
|
v.push_back(glhr::pointtogl(lerp(endi, initial, i * 1. / max)));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for(int i=1; i<=max; i++)
|
|
|
|
v.push_back(glhr::pointtogl(lerp(final, initial, i * 1. / max)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(final[xcoord] * initial[xcoord] > 0) {
|
2020-09-15 17:17:07 +00:00
|
|
|
for(int i=1; i<=max; i++)
|
|
|
|
v.push_back(glhr::pointtogl(lerp(final, initial, i * 1. / max)));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
hyperpoint end = Hypc;
|
|
|
|
end[ycoord] = final[ycoord] > 0 ? 1 : -1;
|
|
|
|
for(int i=1; i<=max; i++)
|
|
|
|
v.push_back(glhr::pointtogl(lerp(final, end, i * 1. / max)));
|
|
|
|
for(int i=1; i<=max; i++)
|
|
|
|
v.push_back(glhr::pointtogl(lerp(end, initial, i * 1. / max)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p.cnt = isize(v); p.draw(); v.clear();
|
|
|
|
initial = normalize(lerp(all[at], all[next], 1 - (1-part) * .99));
|
|
|
|
have_initial = true;
|
|
|
|
v.push_back(glhr::pointtogl(initial));
|
|
|
|
}
|
|
|
|
at = next;
|
|
|
|
}
|
|
|
|
while(at != last_fail);
|
2020-09-16 11:51:21 +00:00
|
|
|
return true;
|
2020-09-15 17:17:07 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-16 11:51:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dqi_poly::draw() {
|
|
|
|
if(flags & POLY_DEBUG) debug_this();
|
|
|
|
|
|
|
|
if(debugflags & DF_VERTEX) {
|
2024-10-05 11:07:21 +00:00
|
|
|
println(hlog, int(prio), ": V=", V, " o=", offset, " c=", cnt, " ot=", offset_texture, " ol=", outline, " lw=", linewidth, " f=", (color_t) flags, " i=", intester, " c=", cache, " ti=", (cell*) tinf);
|
2021-06-06 08:13:57 +00:00
|
|
|
for(int i=0; i<cnt; i++) print(hlog, (*tab)[offset+i]);
|
2020-09-16 11:51:21 +00:00
|
|
|
println(hlog);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CAP_ODS
|
|
|
|
if(vid.stereo_mode == sODS) {
|
|
|
|
ods::draw_ods(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CAP_GL
|
|
|
|
if(in_s2xe() && vid.usingGL && pmodel == mdPerspective && (current_display->set_all(global_projection, 0), (get_shader_flags() & SF_DIRECT))) {
|
|
|
|
s2xe::draw_s2xe(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!hyperbolic && among(pmodel, mdPolygonal, mdPolynomial)) {
|
|
|
|
bool any = false;
|
|
|
|
for(int i=0; i<cnt; i++) {
|
|
|
|
hyperpoint h1 = V.T * glhr::gltopoint((*tab)[offset+i]);
|
|
|
|
if(h1[2] > 0) any = true;
|
|
|
|
}
|
|
|
|
if(!any) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(sphere && tinf && GDIM == 2 && cnt > 3) {
|
|
|
|
int i = cnt;
|
|
|
|
cnt = 3;
|
|
|
|
for(int j=0; j<i; j+=3) {
|
|
|
|
offset += j;
|
|
|
|
offset_texture += j;
|
|
|
|
draw();
|
|
|
|
offset -= j;
|
|
|
|
offset_texture -= j;
|
|
|
|
}
|
|
|
|
cnt = i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(broken_projection(*this)) return;
|
2020-09-15 17:17:07 +00:00
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
if(sphere && pmodel == mdTwoPoint && !in_twopoint) {
|
|
|
|
#define MAX_PHASE 4
|
|
|
|
vector<glvertex> phases[MAX_PHASE];
|
|
|
|
extern int twopoint_sphere_flips;
|
|
|
|
extern bool twopoint_do_flips;
|
|
|
|
int pha;
|
|
|
|
if(twopoint_do_flips) {
|
|
|
|
for(int i=0; i<cnt; i++) {
|
2020-07-27 16:49:04 +00:00
|
|
|
shiftpoint h1 = V * glhr::gltopoint((*tab)[offset+i]);
|
2019-05-26 16:04:02 +00:00
|
|
|
for(int j=0; j<MAX_PHASE; j++) {
|
|
|
|
twopoint_sphere_flips = j;
|
|
|
|
hyperpoint h2; applymodel(h1, h2);
|
2020-04-16 22:53:58 +00:00
|
|
|
glvertex h = glhr::pointtogl(h2 * current_display->radius); h[1] *= pconf.stretch;
|
2019-05-26 16:04:02 +00:00
|
|
|
if(i == 0)
|
|
|
|
phases[j].push_back(h);
|
|
|
|
else {
|
|
|
|
int best = -1;
|
|
|
|
ld bhypot = 1e60;
|
|
|
|
for(int j0=0; j0<MAX_PHASE; j0++)
|
|
|
|
if(isize(phases[j0]) == i) {
|
|
|
|
ld chypot = glhypot2(phases[j0].back(), h);
|
|
|
|
if(chypot < bhypot || best == -1) bhypot = chypot, best = j0;
|
|
|
|
}
|
|
|
|
phases[best].push_back(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
twopoint_sphere_flips = 0;
|
|
|
|
pha = MAX_PHASE-1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pha = 1;
|
|
|
|
if(true) {
|
|
|
|
// a
|
|
|
|
// b
|
|
|
|
// lin(a,b) is of form (x, 0, z)
|
|
|
|
int cpha = 0;
|
|
|
|
for(int i=0; i<cnt; i++) {
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
shiftpoint h1 = V * glhr::gltopoint((*tab)[offset+i]);
|
2020-04-16 22:53:58 +00:00
|
|
|
hyperpoint mh1; applymodel(h1, mh1); mh1[1] *= pconf.stretch;
|
2019-05-26 16:04:02 +00:00
|
|
|
phases[cpha].push_back(glhr::pointtogl(mh1 * current_display->radius));
|
|
|
|
|
|
|
|
// check if the i-th edge intersects the boundary of the ellipse
|
|
|
|
// (which corresponds to the segment between the antipodes of foci)
|
|
|
|
// if yes, switch cpha to the opposite
|
2020-07-27 16:49:04 +00:00
|
|
|
shiftpoint h2 = V * glhr::gltopoint((*tab)[offset+(i+1)%cnt]);
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
hyperpoint ah1 = h1.h, ah2 = h2.h;
|
2023-08-14 09:08:37 +00:00
|
|
|
models::scr_to_ori(ah1);
|
|
|
|
models::scr_to_ori(ah2);
|
2019-05-26 16:04:02 +00:00
|
|
|
if(ah1[1] * ah2[1] > 0) continue;
|
|
|
|
ld c1 = ah1[1], c2 = -ah2[1];
|
|
|
|
if(c1 < 0) c1 = -c1, c2 = -c2;
|
|
|
|
hyperpoint h = ah1 * c1 + ah2 * c2;
|
|
|
|
h /= hypot_d(3, h);
|
2020-04-16 22:53:58 +00:00
|
|
|
if(h[2] < 0 && abs(h[0]) < sin(pconf.twopoint_param)) cpha = 1-cpha, pha = 2;
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
if(cpha == 1) pha = 0;
|
|
|
|
}
|
|
|
|
}
|
2019-10-21 20:34:20 +00:00
|
|
|
dynamicval<eModel> d1(pmodel, mdPixel);
|
2020-07-27 16:49:04 +00:00
|
|
|
dynamicval<transmatrix> d2(V.T, Id);
|
2019-05-26 16:04:02 +00:00
|
|
|
dynamicval<int> d3(offset, 0);
|
|
|
|
dynamicval<decltype(tab)> d4(tab, tab);
|
|
|
|
for(int j=0; j<pha; j++) {
|
|
|
|
dynamicval<int> d5(cnt, isize(phases[j]));
|
|
|
|
tab = &phases[j];
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if(spherespecial && prio == PPR::MOBILE_ARROW) {
|
|
|
|
if(spherephase == 0) return;
|
|
|
|
dynamicval<int> ss(spherespecial, 0);
|
|
|
|
draw();
|
|
|
|
return;
|
|
|
|
} */
|
|
|
|
|
2021-05-21 23:24:28 +00:00
|
|
|
#if CAP_GL
|
2020-07-27 16:49:04 +00:00
|
|
|
if(vid.usingGL && (current_display->set_all(global_projection, V.shift), get_shader_flags() & SF_DIRECT) && sphere && (stretch::factor || ray::in_use)) {
|
2020-07-24 21:39:30 +00:00
|
|
|
draw_stretch(this);
|
|
|
|
return;
|
|
|
|
}
|
2021-05-21 23:24:28 +00:00
|
|
|
#endif
|
2020-07-24 21:39:30 +00:00
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
#if CAP_GL
|
2020-07-27 16:49:04 +00:00
|
|
|
if(vid.usingGL && (current_display->set_all(global_projection, V.shift), get_shader_flags() & SF_DIRECT)) {
|
2020-07-24 00:30:50 +00:00
|
|
|
if(sl2 && pmodel == mdGeodesic && hybrid::csteps) {
|
2020-07-27 16:49:04 +00:00
|
|
|
ld z = atan2(V.T[2][3], V.T[3][3]) + V.shift;
|
2019-08-25 17:14:03 +00:00
|
|
|
auto zr = sightranges[geometry];
|
2020-07-24 00:30:50 +00:00
|
|
|
ld ns = stretch::not_squared();
|
|
|
|
ld db = cgi.psl_steps / M_PI / ns / hybrid::csteps;
|
|
|
|
|
|
|
|
min_slr = floor((-zr - z) * db);
|
|
|
|
max_slr = ceil((zr - z) * db);
|
2019-08-25 17:14:03 +00:00
|
|
|
if(min_slr > max_slr) return;
|
2020-05-25 00:26:35 +00:00
|
|
|
if(flags & POLY_ONE_LEVEL) min_slr = max_slr = 0;
|
2020-07-24 00:30:50 +00:00
|
|
|
max_slr++;
|
2019-08-25 17:14:03 +00:00
|
|
|
}
|
2020-11-08 10:51:36 +00:00
|
|
|
else min_slr = 0, max_slr = 0;
|
2019-07-12 21:15:09 +00:00
|
|
|
set_width(get_width(this));
|
2019-05-26 16:04:02 +00:00
|
|
|
flags &= ~POLY_INVERSE;
|
|
|
|
gldraw();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
glcoords.clear();
|
|
|
|
poly_flags = flags;
|
|
|
|
|
|
|
|
double d = 0, curradius = 0;
|
|
|
|
if(sphere) {
|
2020-07-27 16:49:04 +00:00
|
|
|
d = det(V.T);
|
2019-05-26 16:04:02 +00:00
|
|
|
curradius = pow(abs(d), 1/3.);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* outline = 0x80808080;
|
|
|
|
color = 0; */
|
|
|
|
|
|
|
|
last_infront = false;
|
|
|
|
|
|
|
|
addpoly(V, *tab, offset, cnt);
|
2020-04-16 22:53:58 +00:00
|
|
|
if(!(sphere && pconf.alpha < .9)) if(pmodel != mdJoukowsky) if(!(flags & POLY_ALWAYS_IN)) for(int i=1; i<isize(glcoords); i++) {
|
2019-05-26 16:04:02 +00:00
|
|
|
ld dx = glcoords[i][0] - glcoords[i-1][0];
|
|
|
|
ld dy = glcoords[i][1] - glcoords[i-1][1];
|
|
|
|
if(dx > vid.xres * 2 || dy > vid.yres * 2) return;
|
|
|
|
}
|
|
|
|
if(poly_flags & POLY_BEHIND) return;
|
|
|
|
if(isize(glcoords) <= 1) return;
|
|
|
|
|
2019-08-14 17:08:16 +00:00
|
|
|
cyl::loop_min = cyl::loop_max = 0;
|
2024-02-22 00:16:43 +00:00
|
|
|
if((sphere && mdBandAny()) || pmodel == mdPolar)
|
2019-08-14 17:08:16 +00:00
|
|
|
cyl::adjust(tinf);
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
int poly_limit = max(vid.xres, vid.yres) * 2;
|
|
|
|
|
|
|
|
|
|
|
|
if(0) for(auto& p: glcoords) {
|
|
|
|
if(abs(p[0]) > poly_limit || abs(p[1]) > poly_limit)
|
|
|
|
return; // too large!
|
|
|
|
}
|
|
|
|
|
|
|
|
bool equi = mdAzimuthalEqui() || pmodel == mdFisheye;
|
|
|
|
|
|
|
|
bool nofill = false;
|
|
|
|
|
|
|
|
if(poly_flags & POLY_NIF_ERROR) return;
|
|
|
|
|
2020-04-16 22:53:58 +00:00
|
|
|
if(spherespecial == 1 && sphere && (poly_flags & POLY_INFRONT) && (poly_flags & POLY_NOTINFRONT) && pconf.alpha <= 1) {
|
2019-05-26 16:04:02 +00:00
|
|
|
bool around_center = false;
|
|
|
|
for(int i=0; i<isize(glcoords)-1; i++) {
|
|
|
|
double x1 = glcoords[i][0];
|
|
|
|
double y1 = glcoords[i][1];
|
|
|
|
double x2 = glcoords[i+1][0];
|
|
|
|
double y2 = glcoords[i+1][1];
|
|
|
|
if(asign(y1, y2)) {
|
|
|
|
ld x = xcross(x1, y1, x2, y2);
|
|
|
|
if(x < -1e-6) around_center = !around_center;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(around_center) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_have_inverse = false;
|
|
|
|
if(sphere && pmodel == mdDisk && (spherespecial > 0 || equi)) can_have_inverse = true;
|
2020-12-30 13:20:30 +00:00
|
|
|
if(vrhr::rendering()) can_have_inverse = false;
|
2020-09-15 17:13:24 +00:00
|
|
|
if(sphere && among(pmodel, mdEquidistant, mdEquiarea)) can_have_inverse = true;
|
2019-05-26 16:04:02 +00:00
|
|
|
if(pmodel == mdJoukowsky) can_have_inverse = true;
|
2020-04-16 22:53:58 +00:00
|
|
|
if(pmodel == mdJoukowskyInverted && pconf.skiprope) can_have_inverse = true;
|
|
|
|
if(pmodel == mdDisk && hyperbolic && pconf.alpha <= -1) can_have_inverse = true;
|
|
|
|
if(pmodel == mdSpiral && pconf.skiprope) can_have_inverse = true;
|
2019-07-03 02:53:56 +00:00
|
|
|
if(pmodel == mdCentralInversion) can_have_inverse = true;
|
2024-06-28 12:00:52 +00:00
|
|
|
|
|
|
|
if(among(pmodel, mdHemisphere, mdHyperboloid) && sphere && pconf.small_hyperboloid) can_have_inverse = true;
|
2024-07-21 19:27:36 +00:00
|
|
|
if(GDIM == 3) can_have_inverse = false;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
if(can_have_inverse && !(poly_flags & POLY_ISSIDE)) {
|
|
|
|
|
|
|
|
if(!tinf)
|
|
|
|
compute_side_by_centerin(this, nofill);
|
|
|
|
|
|
|
|
else {
|
|
|
|
if(d < 0) poly_flags ^= POLY_INVERSE;
|
2019-07-03 02:53:56 +00:00
|
|
|
if(pmodel == mdCentralInversion) poly_flags ^= POLY_INVERSE;
|
2019-05-26 16:04:02 +00:00
|
|
|
compute_side_by_area();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(poly_flags & POLY_INVERSE) {
|
2020-04-16 22:53:58 +00:00
|
|
|
if(curradius < pconf.alpha - 1e-6) return;
|
2019-05-26 16:04:02 +00:00
|
|
|
if(!sphere) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else poly_flags &=~ POLY_INVERSE;
|
2024-06-28 12:00:52 +00:00
|
|
|
|
|
|
|
if(among(pmodel, mdHemisphere, mdHyperboloid) && sphere && pconf.small_hyperboloid && (poly_flags & POLY_INVERSE)) return;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
if(spherespecial) {
|
2020-12-29 01:49:58 +00:00
|
|
|
if(!(poly_flags & POLY_INFRONT)) return;
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int lastl = 0;
|
|
|
|
|
2019-08-14 17:08:16 +00:00
|
|
|
for(int l=cyl::loop_min; l <= cyl::loop_max; l++) {
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
if(l || lastl) {
|
|
|
|
for(int i=0; i<isize(glcoords); i++) {
|
2023-08-08 14:27:52 +00:00
|
|
|
glcoords[i][0] += pconf.mori().get()[0][0] * cyl::periods[i] * (l - lastl);
|
|
|
|
glcoords[i][1] += pconf.mori().get()[1][0] * cyl::periods[i] * (l - lastl);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
lastl = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(equi && (poly_flags & POLY_INVERSE)) {
|
2020-07-27 16:49:04 +00:00
|
|
|
if(abs(zlevel(V.T * C0) - 1) < 1e-6 && !tinf) {
|
2019-05-26 16:04:02 +00:00
|
|
|
// we should fill the other side
|
|
|
|
ld h = atan2(glcoords[0][0], glcoords[0][1]);
|
|
|
|
for(int i=0; i<=360; i++) {
|
|
|
|
ld a = i * degree + h;
|
2020-04-16 22:53:58 +00:00
|
|
|
glcoords.push_back(glhr::makevertex(current_display->radius * sin(a), current_display->radius * pconf.stretch * cos(a), 0));
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
poly_flags ^= POLY_INVERSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If we are on a zlevel, the algorithm above will not work correctly.
|
|
|
|
// It is hard to tell what to do in this case. Just fill neither side
|
|
|
|
nofill = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CAP_GL
|
|
|
|
if(vid.usingGL) {
|
|
|
|
poly_flags &= ~(POLY_VCONVEX | POLY_CCONVEX);
|
|
|
|
// if(pmodel == 0) for(int i=0; i<qglcoords; i++) glcoords[i][2] = current_display->scrdist;
|
|
|
|
if(tinf && (poly_flags & POLY_INVERSE)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-07-12 21:15:09 +00:00
|
|
|
set_width(get_width(this));
|
2019-05-26 16:04:02 +00:00
|
|
|
dqi_poly npoly = (*this);
|
2020-07-27 16:49:04 +00:00
|
|
|
npoly.V = shiftless(Id, V.shift);
|
2019-05-26 16:04:02 +00:00
|
|
|
npoly.tab = &glcoords;
|
|
|
|
npoly.offset = 0;
|
|
|
|
npoly.cnt = isize(glcoords);
|
|
|
|
if(nofill) npoly.color = 0, npoly.tinf = NULL;
|
|
|
|
npoly.flags = poly_flags;
|
|
|
|
npoly.gldraw();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-03 18:56:41 +00:00
|
|
|
#if CAP_SVG
|
2019-05-26 16:04:02 +00:00
|
|
|
if(svg::in) {
|
|
|
|
coords_to_poly();
|
|
|
|
color_t col = color;
|
|
|
|
if(poly_flags & POLY_INVERSE) col = 0;
|
2020-04-06 08:43:28 +00:00
|
|
|
if(poly_flags & POLY_TRIANGLES) {
|
|
|
|
for(int i=0; i<polyi; i+=3)
|
|
|
|
svg::polygon(polyx+i, polyy+i, 3, col, outline, get_width(this));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
svg::polygon(polyx, polyy, polyi, col, outline, get_width(this));
|
2019-05-26 16:04:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
coords_to_poly();
|
|
|
|
|
2020-05-03 18:56:41 +00:00
|
|
|
#if CAP_XGD
|
2019-05-26 16:04:02 +00:00
|
|
|
gdpush(1); gdpush(color); gdpush(outline); gdpush(polyi);
|
|
|
|
for(int i=0; i<polyi; i++) gdpush(polyx[i]), gdpush(polyy[i]);
|
2020-05-03 18:56:41 +00:00
|
|
|
#elif CAP_SDLGFX
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
if(tinf) {
|
|
|
|
#if CAP_TEXTURE
|
|
|
|
if(!(poly_flags & POLY_INVERSE))
|
|
|
|
for(int i=0; i<polyi; i += 3)
|
|
|
|
drawTexturedTriangle(s, polyx+i, polyy+i, &tinf->tvertices[offset_texture + i], color);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if(poly_flags & POLY_INVERSE) {
|
|
|
|
int i = polyi;
|
|
|
|
if(true) {
|
|
|
|
polyx[i] = 0; polyy[i] = 0; i++;
|
|
|
|
polyx[i] = vid.xres; polyy[i] = 0; i++;
|
|
|
|
polyx[i] = vid.xres; polyy[i] = vid.yres; i++;
|
|
|
|
polyx[i] = 0; polyy[i] = vid.yres; i++;
|
|
|
|
polyx[i] = 0; polyy[i] = 0; i++;
|
|
|
|
}
|
2021-03-06 13:53:25 +00:00
|
|
|
filledPolygonColorI(srend, polyx, polyy, polyi+5, color);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
2020-04-06 08:43:28 +00:00
|
|
|
else if(poly_flags & POLY_TRIANGLES) {
|
|
|
|
for(int i=0; i<polyi; i+=3)
|
2021-03-06 13:53:25 +00:00
|
|
|
filledPolygonColorI(srend, polyx+i, polyy+i, 3, color);
|
2020-04-06 08:43:28 +00:00
|
|
|
}
|
|
|
|
else
|
2021-03-06 13:53:25 +00:00
|
|
|
filledPolygonColorI(srend, polyx, polyy, polyi, color);
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2024-01-07 08:07:54 +00:00
|
|
|
if(current_display->separate_eyes()) filledPolygonColorI(auxrend, polyxr, polyy, polyi, color);
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2021-03-06 13:53:25 +00:00
|
|
|
((vid.antialias & AA_NOGL) ?aapolylineColor:polylineColor)(srend, polyx, polyy, polyi, outline);
|
2024-01-07 08:07:54 +00:00
|
|
|
if(current_display->separate_eyes()) aapolylineColor(auxrend, polyxr, polyy, polyi, outline);
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
if(vid.xres >= 2000 || fatborder) {
|
|
|
|
int xmi = 3000, xma = -3000;
|
|
|
|
for(int t=0; t<polyi; t++) xmi = min(xmi, polyx[t]), xma = max(xma, polyx[t]);
|
|
|
|
|
|
|
|
if(xma > xmi + 20) for(int x=-1; x<2; x++) for(int y=-1; y<=2; y++) if(x*x+y*y == 1) {
|
|
|
|
for(int t=0; t<polyi; t++) polyx[t] += x, polyy[t] += y;
|
2021-03-06 13:53:25 +00:00
|
|
|
aapolylineColor(srend, polyx, polyy, polyi, outline);
|
2019-05-26 16:04:02 +00:00
|
|
|
for(int t=0; t<polyi; t++) polyx[t] -= x, polyy[t] -= y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<glvertex> prettylinepoints;
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void prettypoint(const hyperpoint& h) {
|
2019-05-26 16:04:02 +00:00
|
|
|
prettylinepoints.push_back(glhr::pointtogl(h));
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void prettylinesub(const hyperpoint& h1, const hyperpoint& h2, int lev) {
|
2019-10-21 20:34:20 +00:00
|
|
|
if(lev >= 0 && pmodel != mdPixel) {
|
2019-05-26 16:04:02 +00:00
|
|
|
hyperpoint h3 = midz(h1, h2);
|
|
|
|
prettylinesub(h1, h3, lev-1);
|
|
|
|
prettylinesub(h3, h2, lev-1);
|
|
|
|
}
|
|
|
|
else prettypoint(h2);
|
|
|
|
}
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
EX void prettyline(hyperpoint h1, hyperpoint h2, ld shift, color_t col, int lev, int flags, PPR prio) {
|
2019-05-26 16:04:02 +00:00
|
|
|
prettylinepoints.clear();
|
|
|
|
prettypoint(h1);
|
|
|
|
prettylinesub(h1, h2, lev);
|
|
|
|
dqi_poly ptd;
|
2020-07-27 16:49:04 +00:00
|
|
|
ptd.V = shiftless(Id, shift);
|
2019-05-26 16:04:02 +00:00
|
|
|
ptd.tab = &prettylinepoints;
|
|
|
|
ptd.offset = 0;
|
|
|
|
ptd.cnt = isize(prettylinepoints);
|
|
|
|
ptd.linewidth = vid.linewidth;
|
|
|
|
ptd.color = 0;
|
|
|
|
ptd.outline = col;
|
|
|
|
ptd.flags = POLY_ISSIDE | POLY_PRECISE_WIDE | flags;
|
|
|
|
ptd.tinf = NULL;
|
|
|
|
ptd.intester = C0;
|
|
|
|
ptd.prio = prio;
|
|
|
|
ptd.draw();
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void prettypoly(const vector<hyperpoint>& t, color_t fillcol, color_t linecol, int lev) {
|
2019-05-26 16:04:02 +00:00
|
|
|
prettylinepoints.clear();
|
|
|
|
prettypoint(t[0]);
|
|
|
|
for(int i=0; i<isize(t); i++)
|
|
|
|
prettylinesub(t[i], t[(i+1)%3], lev);
|
|
|
|
dqi_poly ptd;
|
2020-07-27 16:49:04 +00:00
|
|
|
ptd.V = shiftless(Id);
|
2019-05-26 16:04:02 +00:00
|
|
|
ptd.tab = &prettylinepoints;
|
|
|
|
ptd.offset = 0;
|
|
|
|
ptd.cnt = isize(prettylinepoints);
|
|
|
|
ptd.linewidth = vid.linewidth;
|
|
|
|
ptd.color = fillcol;
|
|
|
|
ptd.outline = linecol;
|
|
|
|
ptd.flags = POLY_ISSIDE | POLY_PRECISE_WIDE;
|
|
|
|
ptd.tinf = NULL;
|
|
|
|
ptd.intester = C0;
|
|
|
|
ptd.draw();
|
|
|
|
}
|
2021-12-11 23:30:07 +00:00
|
|
|
|
|
|
|
EX vector<glvertex> curvedata;
|
|
|
|
EX int curvestart = 0;
|
|
|
|
EX bool keep_curvedata = false;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void queuereset(eModel m, PPR prio) {
|
2019-07-12 21:15:23 +00:00
|
|
|
queueaction(prio, [m] () { glflush(); pmodel = m; });
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dqi_line::draw() {
|
|
|
|
dynamicval<ld> d(vid.linewidth, width);
|
2020-07-27 16:49:04 +00:00
|
|
|
prettyline(H1.h, unshift(H2, H1.shift), H1.shift, color, prf, 0, prio);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dqi_string::draw() {
|
2024-10-05 11:03:29 +00:00
|
|
|
dynamicval<fontdata*> df(cfont, font);
|
2019-05-26 16:04:02 +00:00
|
|
|
#if CAP_SVG
|
|
|
|
if(svg::in) {
|
|
|
|
svg::text(x, y, size, str, frame, color, align);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2020-05-03 18:56:41 +00:00
|
|
|
#if !ISMOBILE
|
2019-05-26 16:04:02 +00:00
|
|
|
int fr = frame & 255;
|
|
|
|
displayfrSP(x, y, shift, fr, size, str, color, align, frame >> 8);
|
|
|
|
#else
|
|
|
|
displayfr(x, y, frame, size, str, color, align);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void dqi_circle::draw() {
|
|
|
|
#if CAP_SVG
|
|
|
|
if(svg::in) {
|
|
|
|
svg::circle(x, y, size, color, fillcolor, linewidth);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
drawCircle(x, y, size, color, fillcolor);
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void initquickqueue() {
|
2019-05-26 16:04:02 +00:00
|
|
|
ptds.clear();
|
|
|
|
poly_outline = OUTLINE_NONE;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void sortquickqueue() {
|
2019-05-26 16:04:02 +00:00
|
|
|
for(int i=1; i<isize(ptds);)
|
|
|
|
if(i && ptds[i]->prio < ptds[i-1]->prio) {
|
|
|
|
swap(ptds[i], ptds[i-1]);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
else i++;
|
|
|
|
}
|
|
|
|
|
2024-10-05 11:03:29 +00:00
|
|
|
EX void clear_curvedata() {
|
|
|
|
if(keep_curvedata) return;
|
|
|
|
curvedata.clear();
|
|
|
|
for(auto& d: fontdatas) if(d.second.finf) d.second.finf->tvertices.clear();
|
|
|
|
curvestart = 0;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void quickqueue() {
|
2019-11-03 12:36:06 +00:00
|
|
|
current_display->next_shader_flags = 0;
|
2019-05-26 16:04:02 +00:00
|
|
|
spherespecial = 0;
|
2020-07-27 16:49:04 +00:00
|
|
|
reset_projection(); current_display->set_all(0, 0);
|
2019-05-26 16:04:02 +00:00
|
|
|
int siz = isize(ptds);
|
|
|
|
for(int i=0; i<siz; i++) ptds[i]->draw();
|
|
|
|
ptds.clear();
|
2024-10-05 11:03:29 +00:00
|
|
|
clear_curvedata();
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
/* todo */
|
|
|
|
ld xintval(const shiftpoint& h) {
|
2022-12-04 13:48:12 +00:00
|
|
|
if(sphere_flipped) return -h.h[2];
|
2020-07-27 16:49:04 +00:00
|
|
|
if(hyperbolic) return -h.h[2];
|
|
|
|
return -intval(h.h, C0);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 10:00:55 +00:00
|
|
|
EX ld backbrightness = .25;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2020-05-25 00:26:50 +00:00
|
|
|
EX purehookset hooks_drawqueue;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
constexpr int PMAX = int(PPR::MAX);
|
|
|
|
int qp[PMAX], qp0[PMAX];
|
|
|
|
|
|
|
|
color_t darken_color(color_t& color, bool outline) {
|
|
|
|
int alpha = color & 255;
|
2022-12-04 13:48:12 +00:00
|
|
|
if(sphere && pmodel == mdDisk && pconf.alpha <= 0.99)
|
2019-05-26 16:04:02 +00:00
|
|
|
return 0;
|
|
|
|
else {
|
|
|
|
if(outline && alpha < 255)
|
|
|
|
return color - alpha + int(backbrightness * alpha);
|
|
|
|
else
|
|
|
|
return (gradient(modelcolor>>8, color>>8, 0, backbrightness, 1)<<8) | 0xFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dqi_poly::draw_back() {
|
|
|
|
dynamicval<color_t> dvo(outline, darken_color(outline, true));
|
|
|
|
dynamicval<color_t> dvc(color, darken_color(color, false));
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void dqi_line::draw_back() {
|
|
|
|
dynamicval<color_t> dvc(color, darken_color(color, true));
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void sort_drawqueue() {
|
2020-04-17 13:03:05 +00:00
|
|
|
DEBBI(DF_GRAPH, ("sort_drawqueue"));
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
for(int a=0; a<PMAX; a++) qp[a] = 0;
|
|
|
|
|
|
|
|
int siz = isize(ptds);
|
|
|
|
|
|
|
|
#if MINIMIZE_GL_CALLS
|
Remove USE_UNORDERED_MAP because it has bit-rotted.
Trying to compile with `-DUSE_UNORDERED_MAP` produces lots of compiler errors
like these, because of missing `std::hash` specializations.
Also, `#define unordered_map map` is just evil!
```
./nonisotropic.cpp:875:36: note: in instantiation of template class 'std::__1::unordered_map<hr::nilv::mvec, hr::heptagon *,
std::__1::hash<hr::nilv::mvec>, std::__1::equal_to<hr::nilv::mvec>, std::__1::allocator<std::__1::pair<const hr::nilv::mvec, hr::heptagon
*> > >' requested here
unordered_map<mvec, heptagon*> at;
^
./nonisotropic.cpp:239:58: note: in instantiation of template class 'std::__1::unordered_map<std::__1::pair<hr::heptagon *, hr::heptagon *>,
hr::heptagon *, std::__1::hash<std::__1::pair<hr::heptagon *, hr::heptagon *> >, std::__1::equal_to<std::__1::pair<hr::heptagon *,
hr::heptagon *> >, std::__1::allocator<std::__1::pair<const std::__1::pair<hr::heptagon *, hr::heptagon *>, hr::heptagon *> > >'
requested here
unordered_map<pair<heptagon*, heptagon*>, heptagon*> at;
^
./nonisotropic.cpp:457:49: error: no matching member function for call to 'iadj'
while(h1->distance < h2->distance) back = iadj(h2, down) * back, h2 = h2->cmove(down);
^~~~
cell.cpp:42:15: note: candidate function not viable: no known conversion from 'hr::sn::hrmap_solnih' to 'hr::hrmap' for object argument
transmatrix iadj(heptagon *h, int d) {
^
cell.cpp:41:22: note: candidate function not viable: no known conversion from 'hr::sn::hrmap_solnih' to 'hr::hrmap' for object argument
struct transmatrix iadj(cell *c, int i) { cell *c1 = c->cmove(i); return adj(c1, c->c.spin(i)); }
^
```
2020-09-25 03:15:19 +00:00
|
|
|
map<color_t, vector<unique_ptr<drawqueueitem>>> subqueue;
|
2022-07-05 17:23:05 +00:00
|
|
|
for(auto& p: ptds) subqueue[(p->prio == PPR::CIRCLE || p->prio == PPR::OUTCIRCLE) ? 0 : p->outline_group()].push_back(std::move(p));
|
2019-05-26 16:04:02 +00:00
|
|
|
ptds.clear();
|
2022-07-05 17:23:05 +00:00
|
|
|
for(auto& p: subqueue) for(auto& r: p.second) ptds.push_back(std::move(r));
|
2019-05-26 16:04:02 +00:00
|
|
|
subqueue.clear();
|
2022-07-05 17:23:05 +00:00
|
|
|
for(auto& p: ptds) subqueue[(p->prio == PPR::CIRCLE || p->prio == PPR::OUTCIRCLE) ? 0 : p->color].push_back(std::move(p));
|
2019-05-26 16:04:02 +00:00
|
|
|
ptds.clear();
|
2022-07-05 17:23:05 +00:00
|
|
|
for(auto& p: subqueue) for(auto& r: p.second) ptds.push_back(std::move(r));
|
2019-05-26 16:04:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for(auto& p: ptds) {
|
|
|
|
int pd = p->prio - PPR::ZERO;
|
|
|
|
if(pd < 0 || pd >= PMAX) {
|
|
|
|
printf("Illegal priority %d\n", pd);
|
|
|
|
p->prio = PPR(rand() % int(PPR::MAX));
|
|
|
|
}
|
|
|
|
qp[pd]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int total = 0;
|
|
|
|
for(int a=0; a<PMAX; a++) {
|
|
|
|
int b = qp[a];
|
|
|
|
qp0[a] = qp[a] = total; total += b;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<unique_ptr<drawqueueitem>> ptds2;
|
|
|
|
ptds2.resize(siz);
|
|
|
|
|
2022-07-05 17:23:05 +00:00
|
|
|
for(int i = 0; i<siz; i++) ptds2[qp[int(ptds[i]->prio)]++] = std::move(ptds[i]);
|
2019-05-26 16:04:02 +00:00
|
|
|
swap(ptds, ptds2);
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void reverse_priority(PPR p) {
|
2019-05-26 16:04:02 +00:00
|
|
|
reverse(ptds.begin()+qp0[int(p)], ptds.begin()+qp[int(p)]);
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void reverse_side_priorities() {
|
2019-05-26 16:04:02 +00:00
|
|
|
for(PPR p: {PPR::REDWALLs, PPR::REDWALLs2, PPR::REDWALLs3, PPR::WALL3s,
|
2020-02-26 00:15:30 +00:00
|
|
|
PPR::LAKEWALL, PPR::INLAKEWALL, PPR::BELOWBOTTOM, PPR::BSHALLOW, PPR::ASHALLOW})
|
2019-05-26 16:04:02 +00:00
|
|
|
reverse_priority(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
// on the sphere, parts on the back are drawn first
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void draw_backside() {
|
2020-04-17 13:03:05 +00:00
|
|
|
DEBBI(DF_GRAPH, ("draw_backside"));
|
2020-11-01 19:10:08 +00:00
|
|
|
if(pmodel == mdHyperboloid && hyperbolic && pconf.show_hyperboloid_flat) {
|
2019-05-26 16:04:02 +00:00
|
|
|
dynamicval<eModel> dv (pmodel, mdHyperboloidFlat);
|
|
|
|
for(auto& ptd: ptds)
|
|
|
|
if(!among(ptd->prio, PPR::MOBILE_ARROW, PPR::OUTCIRCLE, PPR::CIRCLE))
|
|
|
|
ptd->draw();
|
|
|
|
}
|
|
|
|
|
2022-12-04 13:48:12 +00:00
|
|
|
spherespecial = sphere_flipped ? 1 : -1;
|
2019-05-26 16:04:02 +00:00
|
|
|
reset_projection();
|
|
|
|
|
|
|
|
if(pmodel == mdRotatedHyperboles) {
|
|
|
|
for(auto& ptd: ptds)
|
|
|
|
if(!among(ptd->prio, PPR::MOBILE_ARROW, PPR::OUTCIRCLE, PPR::CIRCLE))
|
|
|
|
ptd->draw();
|
|
|
|
glflush();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
reverse_side_priorities();
|
2020-04-06 06:39:31 +00:00
|
|
|
for(int i=isize(ptds)-1; i>=0; i--)
|
2019-05-26 16:04:02 +00:00
|
|
|
if(!among(ptds[i]->prio, PPR::MOBILE_ARROW, PPR::OUTCIRCLE, PPR::CIRCLE))
|
|
|
|
ptds[i]->draw_back();
|
|
|
|
|
|
|
|
glflush();
|
|
|
|
reverse_side_priorities();
|
|
|
|
}
|
|
|
|
|
|
|
|
spherespecial *= -1;
|
|
|
|
spherephase = 1;
|
|
|
|
reset_projection();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern bool lshiftclick, lctrlclick;
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void reverse_transparent_walls() {
|
2019-05-26 16:04:02 +00:00
|
|
|
int pt = int(PPR::TRANSPARENT_WALL);
|
|
|
|
reverse(&ptds[qp0[pt]], &ptds[qp[pt]]);
|
|
|
|
}
|
|
|
|
|
2020-12-30 18:35:15 +00:00
|
|
|
EX void set_vr_sphere() {
|
2020-12-29 01:51:43 +00:00
|
|
|
in_vr_sphere = false;
|
|
|
|
#if CAP_VR
|
2021-02-04 20:30:59 +00:00
|
|
|
in_vr_sphere = vrhr::rendering() && among(pmodel, mdDisk, mdBall, mdHyperboloid, mdHalfplane, mdHemisphere) && sphere;
|
2020-12-29 01:51:43 +00:00
|
|
|
if(in_vr_sphere) {
|
|
|
|
hyperpoint a, b;
|
|
|
|
applymodel(shiftless(point3(0, 0, 1)), a);
|
|
|
|
applymodel(shiftless(point3(0, 0, -1)), b);
|
|
|
|
vr_sphere_center = (a + b) / 2;
|
|
|
|
vr_sphere_center[3] = 1;
|
|
|
|
E4;
|
|
|
|
vr_sphere_center = vrhr::hmd_mv * vr_sphere_center;
|
|
|
|
}
|
|
|
|
#endif
|
2020-12-30 18:35:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 18:50:16 +00:00
|
|
|
EX int hemi_side = 0;
|
|
|
|
|
2020-12-30 18:35:15 +00:00
|
|
|
EX void draw_main() {
|
|
|
|
DEBBI(DF_GRAPH, ("draw_main"));
|
|
|
|
|
2021-09-17 23:39:09 +00:00
|
|
|
if(pconf.back_and_front == 1 && vid.consider_shader_projection) {
|
|
|
|
dynamicval<int> pa(pconf.back_and_front);
|
|
|
|
pconf.back_and_front = 0;
|
|
|
|
draw_main();
|
|
|
|
pconf.back_and_front = 2;
|
|
|
|
reset_projection();
|
|
|
|
draw_main();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-28 12:00:52 +00:00
|
|
|
if(pmodel == mdHemisphere && sphere && hemi_side == 0 && !vrhr::rendering() && !pconf.small_hyperboloid) {
|
2023-08-14 14:18:44 +00:00
|
|
|
hemi_side = (pconf.ball() * hyperpoint(0,1,0,1)) [2] < 0 ? 1 : -1;
|
2022-04-07 18:50:16 +00:00
|
|
|
draw_main();
|
|
|
|
|
|
|
|
if(pconf.show_hyperboloid_flat) {
|
|
|
|
dynamicval<eModel> dv (pmodel, mdHyperboloidFlat);
|
|
|
|
dynamicval<int> ds (spherespecial, 1);
|
|
|
|
for(auto& ptd: ptds)
|
2023-08-14 14:18:44 +00:00
|
|
|
if(!among(ptd->prio, PPR::MOBILE_ARROW, PPR::OUTCIRCLE, PPR::CIRCLE))
|
2022-04-07 18:50:16 +00:00
|
|
|
ptd->draw();
|
|
|
|
}
|
|
|
|
|
2023-08-15 12:21:19 +00:00
|
|
|
for(auto& ptd: ptds) if(ptd->prio == PPR::OUTCIRCLE) {
|
2024-10-05 11:11:23 +00:00
|
|
|
auto c = ptd->as_poly();
|
2023-08-15 12:21:19 +00:00
|
|
|
if(c) { c->color = 0; c->outline = 0; }
|
|
|
|
}
|
|
|
|
|
2022-04-07 18:50:16 +00:00
|
|
|
hemi_side *= -1;
|
|
|
|
draw_main();
|
|
|
|
hemi_side = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-30 18:35:15 +00:00
|
|
|
set_vr_sphere();
|
2020-12-29 01:51:43 +00:00
|
|
|
|
2020-07-24 21:39:30 +00:00
|
|
|
if(sphere && GDIM == 3 && pmodel == mdPerspective && !stretch::in() && !ray::in_use) {
|
2020-05-08 19:18:47 +00:00
|
|
|
|
|
|
|
if(ray::in_use && !ray::comparison_mode) {
|
|
|
|
ray::cast();
|
|
|
|
reset_projection();
|
|
|
|
}
|
|
|
|
|
2020-07-03 12:42:33 +00:00
|
|
|
#if CAP_GL
|
2019-05-26 16:04:02 +00:00
|
|
|
for(int p: {1, 0, 2, 3}) {
|
|
|
|
if(elliptic && p < 2) continue;
|
|
|
|
glhr::set_depthwrite(true);
|
|
|
|
if(p == 0 || p == 3) {
|
|
|
|
#ifdef GL_ES
|
|
|
|
glClearDepthf(1.0f);
|
|
|
|
#else
|
|
|
|
glClearDepth(1.0f);
|
|
|
|
#endif
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ifdef GL_ES
|
|
|
|
glClearDepthf(0.0f);
|
|
|
|
#else
|
|
|
|
glClearDepth(0.0f);
|
|
|
|
#endif
|
|
|
|
glDepthFunc(GL_GEQUAL);
|
|
|
|
}
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
glhr::be_nontextured();
|
|
|
|
spherephase = p;
|
|
|
|
reset_projection();
|
|
|
|
for(auto& ptd: ptds) ptd->draw();
|
|
|
|
if(elliptic) {
|
|
|
|
spherephase = p | 4;
|
|
|
|
reset_projection();
|
|
|
|
for(auto& ptd: ptds) ptd->draw();
|
|
|
|
}
|
|
|
|
// glflush();
|
|
|
|
}
|
2020-07-03 12:42:33 +00:00
|
|
|
#endif
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
2020-08-20 14:02:34 +00:00
|
|
|
else if(pmodel == mdAxial && sphere) {
|
|
|
|
for(auto& ptd: ptds) if(ptd->prio == PPR::OUTCIRCLE)
|
|
|
|
ptd->draw();
|
|
|
|
for(axial_x=-4; axial_x<=4; axial_x++)
|
|
|
|
for(axial_y=-4; axial_y<=4; axial_y++)
|
|
|
|
for(auto& ptd: ptds) if(ptd->prio != PPR::OUTCIRCLE) {
|
|
|
|
ptd->draw();
|
|
|
|
}
|
|
|
|
glflush();
|
|
|
|
}
|
2019-05-26 16:04:02 +00:00
|
|
|
else {
|
2020-04-21 21:37:25 +00:00
|
|
|
DEBB(DF_GRAPH, ("draw_main1"));
|
2019-11-16 02:04:01 +00:00
|
|
|
if(ray::in_use && !ray::comparison_mode) {
|
|
|
|
ray::cast();
|
|
|
|
reset_projection();
|
|
|
|
}
|
|
|
|
|
2020-04-21 21:37:25 +00:00
|
|
|
DEBB(DF_GRAPH, ("outcircle"));
|
2019-05-26 16:04:02 +00:00
|
|
|
for(auto& ptd: ptds) if(ptd->prio == PPR::OUTCIRCLE)
|
|
|
|
ptd->draw();
|
|
|
|
|
|
|
|
if(two_sided_model()) draw_backside();
|
|
|
|
|
|
|
|
for(auto& ptd: ptds) if(ptd->prio != PPR::OUTCIRCLE) {
|
2020-04-21 21:37:25 +00:00
|
|
|
DEBBI(DF_VERTEX, ("prio: ", int(ptd->prio), " color ", ptd->color));
|
2019-05-26 16:04:02 +00:00
|
|
|
dynamicval<int> ss(spherespecial, among(ptd->prio, PPR::MOBILE_ARROW, PPR::OUTCIRCLE, PPR::CIRCLE) ? 0 : spherespecial);
|
|
|
|
ptd->draw();
|
|
|
|
}
|
|
|
|
glflush();
|
2019-11-16 02:04:01 +00:00
|
|
|
|
2020-07-03 12:42:33 +00:00
|
|
|
#if CAP_RAY
|
2019-11-16 02:04:01 +00:00
|
|
|
if(ray::in_use && ray::comparison_mode) {
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
2020-04-06 06:37:22 +00:00
|
|
|
#ifdef GLES_ONLY
|
|
|
|
glClearDepthf(1.0f);
|
|
|
|
#else
|
2019-11-16 02:04:01 +00:00
|
|
|
glClearDepth(1.0f);
|
2020-04-06 06:37:22 +00:00
|
|
|
#endif
|
2019-11-16 02:04:01 +00:00
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
ray::cast();
|
|
|
|
}
|
2020-07-03 12:42:33 +00:00
|
|
|
#endif
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void drawqueue() {
|
2020-04-15 09:49:29 +00:00
|
|
|
|
2020-04-17 13:03:05 +00:00
|
|
|
DEBBI(DF_GRAPH, ("drawqueue"));
|
2020-11-19 17:20:06 +00:00
|
|
|
|
2020-04-16 19:00:28 +00:00
|
|
|
#if CAP_WRL
|
2020-04-15 09:49:29 +00:00
|
|
|
if(wrl::in) { wrl::render(); return; }
|
2020-04-16 19:00:28 +00:00
|
|
|
#endif
|
2021-03-09 12:12:53 +00:00
|
|
|
|
|
|
|
#if MAXMDIM >= 4 && CAP_GL
|
2023-02-18 17:32:01 +00:00
|
|
|
make_air();
|
2021-03-09 12:12:53 +00:00
|
|
|
#endif
|
2020-04-15 09:49:29 +00:00
|
|
|
|
2020-11-19 17:20:06 +00:00
|
|
|
#if CAP_VR
|
2020-12-30 13:20:30 +00:00
|
|
|
if(vrhr::should_render() == 1) {
|
2020-11-19 17:20:06 +00:00
|
|
|
vrhr::render();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-04-19 11:54:00 +00:00
|
|
|
callhooks(hooks_drawqueue);
|
2019-11-03 12:36:06 +00:00
|
|
|
current_display->next_shader_flags = 0;
|
2019-05-26 16:04:02 +00:00
|
|
|
reset_projection();
|
|
|
|
// reset_projection() is not sufficient here, because we need to know shaderside_projection
|
|
|
|
|
|
|
|
#if CAP_GL
|
|
|
|
if(vid.usingGL)
|
|
|
|
glClear(GL_STENCIL_BUFFER_BIT);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sort_drawqueue();
|
2020-04-17 13:03:05 +00:00
|
|
|
|
|
|
|
DEBB(DF_GRAPH, ("sort walls"));
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2020-03-07 23:33:18 +00:00
|
|
|
if(GDIM == 2)
|
2019-05-26 16:04:02 +00:00
|
|
|
for(PPR p: {PPR::REDWALLs, PPR::REDWALLs2, PPR::REDWALLs3, PPR::WALL3s,
|
2020-03-07 23:33:18 +00:00
|
|
|
PPR::LAKEWALL, PPR::INLAKEWALL, PPR::BELOWBOTTOM, PPR::ASHALLOW, PPR::BSHALLOW}) {
|
|
|
|
int pp = int(p);
|
2020-03-27 11:32:46 +00:00
|
|
|
if(qp0[pp] == qp[pp]) continue;
|
2020-03-07 23:33:18 +00:00
|
|
|
for(int i=qp0[pp]; i<qp[pp]; i++) {
|
|
|
|
auto ap = (dqi_poly&) *ptds[i];
|
|
|
|
ap.cache = xintval(ap.V * xpush0(.1));
|
|
|
|
}
|
2020-03-27 11:32:46 +00:00
|
|
|
sort(&ptds[qp0[pp]], &ptds[qp[pp]],
|
2020-03-07 23:33:18 +00:00
|
|
|
[] (const unique_ptr<drawqueueitem>& p1, const unique_ptr<drawqueueitem>& p2) {
|
|
|
|
auto ap1 = (dqi_poly&) *p1;
|
|
|
|
auto ap2 = (dqi_poly&) *p2;
|
|
|
|
return ap1.cache < ap2.cache;
|
|
|
|
});
|
|
|
|
}
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2020-03-27 11:32:46 +00:00
|
|
|
for(PPR p: {PPR::TRANSPARENT_WALL}) {
|
|
|
|
int pp = int(p);
|
|
|
|
if(qp0[pp] == qp[pp]) continue;
|
2019-05-26 16:04:02 +00:00
|
|
|
sort(&ptds[qp0[int(p)]], &ptds[qp[int(p)]],
|
|
|
|
[] (const unique_ptr<drawqueueitem>& p1, const unique_ptr<drawqueueitem>& p2) {
|
|
|
|
return p1->subprio > p2->subprio;
|
|
|
|
});
|
2020-03-27 11:32:46 +00:00
|
|
|
}
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2023-05-30 16:42:18 +00:00
|
|
|
if(draw_plain_floors && (default_flooralpha < 255 || svg::in)) for(PPR p: {PPR::FLOOR}) {
|
|
|
|
int pp = int(p);
|
|
|
|
if(qp0[pp] == qp[pp]) continue;
|
|
|
|
auto get_z = [&] (const unique_ptr<drawqueueitem>& p) -> ld {
|
2024-10-05 11:11:23 +00:00
|
|
|
auto d = p->as_poly();
|
2023-05-30 16:42:18 +00:00
|
|
|
if(!d) return 0;
|
|
|
|
hyperpoint h = Hypc;
|
|
|
|
|
|
|
|
for(int i=0; i<d->cnt; i++) h += glhr::gltopoint( (*d->tab)[d->offset + i] );
|
|
|
|
h /= d->cnt; normalize(h);
|
|
|
|
h = unshift(d->V) * h;
|
|
|
|
return h[2];
|
|
|
|
};
|
|
|
|
sort(&ptds[qp0[int(p)]], &ptds[qp[int(p)]],
|
|
|
|
[&] (const unique_ptr<drawqueueitem>& p1, const unique_ptr<drawqueueitem>& p2) {
|
|
|
|
return get_z(p1) > get_z(p2);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-26 16:04:02 +00:00
|
|
|
#if CAP_SDL
|
2024-01-07 08:07:54 +00:00
|
|
|
if(current_display->separate_eyes() && !vid.usingGL) {
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2021-03-06 13:53:25 +00:00
|
|
|
if(aux && (aux->w != s->w || aux->h != s->h)) {
|
2019-05-26 16:04:02 +00:00
|
|
|
SDL_FreeSurface(aux);
|
2021-03-06 13:53:25 +00:00
|
|
|
#if CAP_SDL2
|
|
|
|
SDL_DestroyRenderer(auxrend);
|
|
|
|
#endif
|
|
|
|
}
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
if(!aux) {
|
|
|
|
aux = SDL_CreateRGBSurface(SDL_SWSURFACE,s->w,s->h,32,0,0,0,0);
|
2021-03-06 13:53:25 +00:00
|
|
|
#if CAP_SDL2
|
|
|
|
auxrend = SDL_CreateSoftwareRenderer(aux);
|
|
|
|
#endif
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SDL_LockSurface(aux);
|
|
|
|
// memset(aux->pixels, 0, vid.xres * vid.yres * 4);
|
|
|
|
// SDL_UnlockSurface(aux);
|
|
|
|
SDL_BlitSurface(s, NULL, aux, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
spherespecial = 0;
|
|
|
|
spherephase = 0;
|
|
|
|
reset_projection();
|
|
|
|
|
2020-07-03 12:42:33 +00:00
|
|
|
#if CAP_GL
|
2024-01-07 08:07:54 +00:00
|
|
|
if(model_needs_depth() && current_display->separate_eyes()) {
|
2019-05-26 16:04:02 +00:00
|
|
|
global_projection = -1;
|
|
|
|
draw_main();
|
2020-07-03 12:42:33 +00:00
|
|
|
#if CAP_GL
|
2019-05-26 16:04:02 +00:00
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
2020-07-03 12:42:33 +00:00
|
|
|
#endif
|
2019-05-26 16:04:02 +00:00
|
|
|
global_projection = +1;
|
|
|
|
draw_main();
|
2019-07-03 02:56:03 +00:00
|
|
|
global_projection = 0;
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
2020-07-03 12:42:33 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2019-05-26 16:04:02 +00:00
|
|
|
draw_main();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CAP_SDL
|
|
|
|
if(vid.stereo_mode == sAnaglyph && !vid.usingGL) {
|
|
|
|
int qty = s->w * s->h;
|
|
|
|
int *a = (int*) s->pixels;
|
|
|
|
int *b = (int*) aux->pixels;
|
|
|
|
SDL_LockSurface(aux);
|
|
|
|
while(qty) {
|
|
|
|
*a = ((*a) & 0xFF0000) | ((*b) & 0x00FFFF);
|
|
|
|
a++; b++; qty--;
|
|
|
|
}
|
|
|
|
SDL_UnlockSurface(aux);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(vid.stereo_mode == sLR && !vid.usingGL) {
|
|
|
|
SDL_LockSurface(aux);
|
|
|
|
for(int y=0; y<vid.yres; y++)
|
|
|
|
for(int x=vid.xres/2; x<vid.xres; x++)
|
|
|
|
qpixel(s,x,y) = qpixel(aux,x,y);
|
|
|
|
SDL_UnlockSurface(aux);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-10-05 11:03:29 +00:00
|
|
|
clear_curvedata();
|
2020-08-20 14:48:55 +00:00
|
|
|
|
2021-05-21 23:24:28 +00:00
|
|
|
#if CAP_GL
|
2020-08-20 14:48:55 +00:00
|
|
|
GLERR("drawqueue");
|
2021-05-21 23:24:28 +00:00
|
|
|
#endif
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 06:17:02 +00:00
|
|
|
#if HDR
|
2019-05-26 16:04:02 +00:00
|
|
|
template<class T, class... U> T& queuea(PPR prio, U... u) {
|
|
|
|
ptds.push_back(unique_ptr<T>(new T (u...)));
|
|
|
|
ptds.back()->prio = prio;
|
|
|
|
return (T&) *ptds.back();
|
|
|
|
}
|
2019-09-06 06:17:02 +00:00
|
|
|
#endif
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2019-12-26 22:32:27 +00:00
|
|
|
#if CAP_SHAPES
|
2020-07-27 16:49:04 +00:00
|
|
|
EX dqi_poly& queuepolyat(const shiftmatrix& V, const hpcshape& h, color_t col, PPR prio) {
|
2019-05-26 16:04:02 +00:00
|
|
|
if(prio == PPR::DEFAULT) prio = h.prio;
|
|
|
|
|
|
|
|
auto& ptd = queuea<dqi_poly> (prio);
|
|
|
|
|
|
|
|
ptd.V = V;
|
|
|
|
ptd.offset = h.s;
|
|
|
|
ptd.cnt = h.e-h.s;
|
|
|
|
ptd.tab = &cgi.ourshape;
|
2021-03-25 09:56:20 +00:00
|
|
|
apply_neon_color(col, ptd.color, ptd.outline, h.flags);
|
2019-05-26 16:04:02 +00:00
|
|
|
ptd.linewidth = vid.linewidth;
|
|
|
|
ptd.flags = h.flags;
|
|
|
|
ptd.tinf = h.tinf;
|
2020-04-06 09:24:57 +00:00
|
|
|
if(neon_mode != eNeon::none && (h.flags & POLY_TRIANGLES))
|
|
|
|
ptd.tinf = nullptr;
|
2022-04-22 22:57:04 +00:00
|
|
|
ptd.apeiro_cnt = h.she - h.s;
|
2019-05-26 16:04:02 +00:00
|
|
|
ptd.offset_texture = h.texture_offset;
|
|
|
|
ptd.intester = h.intester;
|
|
|
|
return ptd;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
EX dqi_poly& queuetable(const shiftmatrix& V, const vector<glvertex>& f, int cnt, color_t linecol, color_t fillcol, PPR prio) {
|
2019-05-26 16:04:02 +00:00
|
|
|
|
|
|
|
auto& ptd = queuea<dqi_poly> (prio);
|
|
|
|
|
|
|
|
ptd.V = V;
|
|
|
|
ptd.tab = &f;
|
|
|
|
ptd.offset = 0;
|
|
|
|
ptd.cnt = cnt;
|
|
|
|
ptd.color = fillcol;
|
|
|
|
ptd.outline = linecol;
|
|
|
|
ptd.linewidth = vid.linewidth;
|
|
|
|
ptd.flags = POLY_ISSIDE | POLY_PRECISE_WIDE;
|
|
|
|
ptd.tinf = NULL;
|
|
|
|
ptd.intester = C0;
|
|
|
|
return ptd;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CAP_SHAPES
|
2020-07-27 16:49:04 +00:00
|
|
|
EX dqi_poly& queuepoly(const shiftmatrix& V, const hpcshape& h, color_t col) {
|
2019-05-26 16:04:02 +00:00
|
|
|
return queuepolyat(V,h,col,h.prio);
|
|
|
|
}
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
void queuepolyb(const shiftmatrix& V, const hpcshape& h, color_t col, int b) {
|
2019-05-26 16:04:02 +00:00
|
|
|
queuepolyat(V,h,col,h.prio+b);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void curvepoint(const hyperpoint& H1) {
|
2019-05-26 16:04:02 +00:00
|
|
|
curvedata.push_back(glhr::pointtogl(H1));
|
|
|
|
}
|
|
|
|
|
2022-10-11 17:56:56 +00:00
|
|
|
EX void curvepoint_first() {
|
|
|
|
curvedata.push_back(curvedata[curvestart]);
|
|
|
|
}
|
|
|
|
|
2023-08-15 12:28:38 +00:00
|
|
|
EX dqi_poly& queuecurve_reuse(const shiftmatrix& V, color_t linecol, color_t fillcol, PPR prio) {
|
2020-07-27 16:49:04 +00:00
|
|
|
auto &res = queuetable(V, curvedata, isize(curvedata)-curvestart, linecol, fillcol, prio);
|
2019-05-26 16:04:02 +00:00
|
|
|
res.offset = curvestart;
|
2023-08-15 12:28:38 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
EX dqi_poly& queuecurve(const shiftmatrix& V, color_t linecol, color_t fillcol, PPR prio) {
|
|
|
|
auto &res = queuecurve_reuse(V, linecol, fillcol, prio);
|
2019-05-26 16:04:02 +00:00
|
|
|
curvestart = isize(curvedata);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX dqi_action& queueaction(PPR prio, const reaction_t& action) {
|
2019-05-26 16:04:02 +00:00
|
|
|
return queuea<dqi_action> (prio, action);
|
|
|
|
}
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
EX dqi_line& queueline(const shiftpoint& H1, const shiftpoint& H2, color_t col, int prf IS(0), PPR prio IS(PPR::LINE)) {
|
2019-05-26 16:04:02 +00:00
|
|
|
auto& ptd = queuea<dqi_line> (prio);
|
|
|
|
|
|
|
|
ptd.H1 = H1;
|
|
|
|
ptd.H2 = H2;
|
|
|
|
ptd.prf = prf;
|
|
|
|
ptd.width = vid.linewidth;
|
|
|
|
ptd.color = (darkened(col >> 8) << 8) + (col & 0xFF);
|
|
|
|
|
|
|
|
return ptd;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void queuestr(int x, int y, int shift, int size, string str, color_t col, int frame IS(0), int align IS(8)) {
|
2019-05-26 16:04:02 +00:00
|
|
|
auto& ptd = queuea<dqi_string> (PPR::TEXT);
|
|
|
|
ptd.x = x;
|
|
|
|
ptd.y = y;
|
|
|
|
ptd.str = str;
|
|
|
|
ptd.align = align;
|
|
|
|
ptd.shift = shift;
|
|
|
|
ptd.size = size;
|
|
|
|
ptd.color = darkened(col);
|
|
|
|
ptd.frame = frame ? ((poly_outline & ~ 255)+frame) : 0;
|
2024-10-05 11:03:29 +00:00
|
|
|
ptd.font = cfont;
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void queuecircle(int x, int y, int size, color_t color, PPR prio IS(PPR::CIRCLE), color_t fillcolor IS(0)) {
|
2019-05-26 16:04:02 +00:00
|
|
|
auto& ptd = queuea<dqi_circle>(prio);
|
|
|
|
ptd.x = x;
|
|
|
|
ptd.y = y;
|
|
|
|
ptd.size = size;
|
|
|
|
ptd.color = color;
|
|
|
|
ptd.fillcolor = fillcolor;
|
|
|
|
ptd.linewidth = vid.linewidth;
|
|
|
|
}
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
EX void getcoord0(const shiftpoint& h, int& xc, int &yc, int &sc) {
|
2019-05-26 16:04:02 +00:00
|
|
|
hyperpoint hscr;
|
|
|
|
applymodel(h, hscr);
|
|
|
|
xc = current_display->xcenter + current_display->radius * hscr[0];
|
2020-04-16 22:53:58 +00:00
|
|
|
yc = current_display->ycenter + current_display->radius * pconf.stretch * hscr[1];
|
2019-05-26 16:04:02 +00:00
|
|
|
sc = 0;
|
|
|
|
// EYETODO sc = vid.eye * current_display->radius * hscr[2];
|
|
|
|
}
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
EX ld scale_in_pixels(const shiftmatrix& V) {
|
2019-05-26 16:04:02 +00:00
|
|
|
return scale_at(V) * cgi.scalefactor * current_display->radius / 2.5;
|
|
|
|
}
|
2019-07-31 14:14:01 +00:00
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
EX bool getcoord0_checked(const shiftpoint& h, int& xc, int &yc, int &zc) {
|
2019-07-31 14:14:01 +00:00
|
|
|
if(invalid_point(h)) return false;
|
|
|
|
if(point_behind(h)) return false;
|
|
|
|
getcoord0(h, xc, yc, zc);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
EX void queuestr(const shiftpoint& h, int size, const string& chr, color_t col, int frame IS(0)) {
|
2019-07-31 14:14:01 +00:00
|
|
|
int xc, yc, sc;
|
|
|
|
if(getcoord0_checked(h, xc, yc, sc))
|
|
|
|
queuestr(xc, yc, sc, size, chr, col, frame);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
2021-03-07 20:13:31 +00:00
|
|
|
|
2021-05-21 23:24:28 +00:00
|
|
|
#if CAP_GL
|
2021-05-27 10:58:22 +00:00
|
|
|
#if HDR
|
|
|
|
using pointfunction = function<hyperpoint(ld, ld)>;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EX hyperpoint default_pointfunction(ld x, ld y) {
|
|
|
|
return xpush(x) * ypush(y) * C0;
|
|
|
|
}
|
|
|
|
|
2021-05-29 10:16:32 +00:00
|
|
|
#if !CAP_EXTFONT
|
2021-05-27 10:58:22 +00:00
|
|
|
EX void write_in_space(const shiftmatrix& V, int fsize, double size, const string& s, color_t col, int frame IS(0), int align IS(8), PPR prio IS(PPR::TEXT), pointfunction pf IS(default_pointfunction)) {
|
2024-10-05 11:03:29 +00:00
|
|
|
if(!cfont->finf) cfont->finf = new basic_textureinfo;
|
|
|
|
auto& finf = *cfont->finf;
|
|
|
|
|
2021-03-07 20:13:31 +00:00
|
|
|
init_glfont(fsize);
|
2024-07-09 22:03:00 +00:00
|
|
|
glfont_t& f(*(cfont->glfont[fsize]));
|
2021-03-07 20:13:31 +00:00
|
|
|
finf.texture_id = f.texture;
|
|
|
|
|
|
|
|
int fstart = isize(finf.tvertices);
|
|
|
|
|
|
|
|
vector<int> chars;
|
|
|
|
int i = 0;
|
|
|
|
while(i < isize(s)) { chars.push_back(getnext(s.c_str(), i)); }
|
|
|
|
|
|
|
|
ld tw = 0;
|
|
|
|
for(int c: chars) tw += f.chars[c].w;
|
|
|
|
ld th = f.chars[32].h;
|
|
|
|
|
|
|
|
ld xpos = -tw * align / 16;
|
2019-05-26 16:04:02 +00:00
|
|
|
|
2021-03-07 20:13:31 +00:00
|
|
|
ld scale = cgi.scalefactor * size / fsize / 2;
|
|
|
|
|
|
|
|
auto pt = [&] (ld tx, ld ty, ld ix, ld iy) {
|
|
|
|
finf.tvertices.push_back(glhr::makevertex(tx, ty, 0));
|
2021-05-27 10:58:22 +00:00
|
|
|
curvedata.push_back(glhr::pointtogl(pf(ix*scale, iy*scale)));
|
2021-03-07 20:13:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for(int ch: chars) {
|
|
|
|
auto& c = f.chars[ch];
|
|
|
|
|
|
|
|
pt(c.tx0, c.ty0, xpos, -th/2);
|
|
|
|
pt(c.tx0, c.ty1, xpos, +th/2);
|
|
|
|
pt(c.tx1, c.ty1, xpos+c.w, +th/2);
|
|
|
|
pt(c.tx1, c.ty1, xpos+c.w, +th/2);
|
|
|
|
pt(c.tx1, c.ty0, xpos+c.w, -th/2);
|
|
|
|
pt(c.tx0, c.ty0, xpos, -th/2);
|
|
|
|
|
|
|
|
xpos += c.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(frame) for(int i=0; i<360; i+=45) {
|
2022-06-08 16:00:43 +00:00
|
|
|
auto &res = queuetable(V * xspinpush(i*degree, frame*scale), curvedata, isize(curvedata)-curvestart, poly_outline, poly_outline, prio);
|
2021-03-07 20:13:31 +00:00
|
|
|
res.offset = curvestart;
|
|
|
|
res.offset_texture = fstart;
|
|
|
|
res.tinf = &finf;
|
|
|
|
res.flags |= POLY_TRIANGLES;
|
|
|
|
}
|
|
|
|
|
2021-05-27 10:58:22 +00:00
|
|
|
auto &res = queuetable(V, curvedata, isize(curvedata)-curvestart, col, col, prio);
|
2021-03-07 20:13:31 +00:00
|
|
|
res.offset = curvestart;
|
|
|
|
res.offset_texture = fstart;
|
|
|
|
res.tinf = &finf;
|
|
|
|
res.flags |= POLY_TRIANGLES;
|
|
|
|
|
|
|
|
curvestart = isize(curvedata);
|
|
|
|
}
|
2021-05-21 23:24:28 +00:00
|
|
|
#endif
|
2021-05-29 10:16:32 +00:00
|
|
|
#endif
|
2021-03-07 20:13:31 +00:00
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
EX void queuestr(const shiftmatrix& V, double size, const string& chr, color_t col, int frame IS(0), int align IS(8)) {
|
2021-05-29 10:16:32 +00:00
|
|
|
#if CAP_GL && !CAP_EXTFONT
|
2021-04-25 10:03:06 +00:00
|
|
|
if(vid.usingGL) {
|
2021-03-07 20:13:31 +00:00
|
|
|
shiftmatrix V1 ;
|
|
|
|
if(GDIM == 3)
|
|
|
|
V1 = face_the_player(V);
|
2021-03-07 20:31:30 +00:00
|
|
|
else {
|
|
|
|
V1 = V;
|
2021-03-07 20:13:31 +00:00
|
|
|
V1.T = rgpushxto0(tC0(V1.T));
|
2021-03-07 20:31:30 +00:00
|
|
|
}
|
2021-03-07 20:13:31 +00:00
|
|
|
auto col1 = (col << 8) | 0xFF;
|
|
|
|
write_in_space(V1, max_glfont_size, size, chr, col1, frame, align);
|
|
|
|
return;
|
|
|
|
}
|
2021-05-21 23:24:28 +00:00
|
|
|
#endif
|
2019-07-31 14:14:01 +00:00
|
|
|
int xc, yc, sc;
|
|
|
|
if(getcoord0_checked(tC0(V), xc, yc, sc))
|
|
|
|
queuestr(xc, yc, sc, scale_in_pixels(V) * size, chr, col, frame, align);
|
2019-05-26 16:04:02 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
EX void queuestrn(const shiftmatrix& V, double size, const string& chr, color_t col, int frame IS(0), int align IS(8)) {
|
2020-01-30 16:45:05 +00:00
|
|
|
switch(neon_mode) {
|
2020-03-27 18:38:15 +00:00
|
|
|
case eNeon::none:
|
2020-01-30 16:45:05 +00:00
|
|
|
queuestr(V, size, chr, col, frame, align);
|
|
|
|
break;
|
2020-03-27 18:38:15 +00:00
|
|
|
case eNeon::neon: {
|
2020-01-30 16:45:05 +00:00
|
|
|
dynamicval<color_t> c(poly_outline, col << 8);
|
|
|
|
queuestr(V, size, chr, 0, frame, align);
|
|
|
|
break;
|
|
|
|
}
|
2020-03-27 18:38:15 +00:00
|
|
|
case eNeon::no_boundary: {
|
2020-01-30 16:45:05 +00:00
|
|
|
queuestr(V, size, chr, col, 0, align);
|
|
|
|
break;
|
|
|
|
}
|
2020-03-27 18:38:15 +00:00
|
|
|
case eNeon::neon2: {
|
2020-01-30 16:45:05 +00:00
|
|
|
dynamicval<color_t> c(poly_outline, (col << 8) | 0xFF);
|
|
|
|
queuestr(V, size, chr, (col & 0xFEFEFE) >> 1, frame, align);
|
|
|
|
break;
|
|
|
|
}
|
2020-03-27 18:38:15 +00:00
|
|
|
case eNeon::illustration: {
|
2020-01-30 16:45:05 +00:00
|
|
|
dynamicval<color_t> c(poly_outline, poly_outline);
|
2020-02-07 17:33:58 +00:00
|
|
|
if(poly_outline && (poly_outline>>8) != bordcolor) {
|
2020-01-30 16:45:05 +00:00
|
|
|
col = magentize(col << 8) >> 8;
|
|
|
|
poly_outline = 0xFF;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
col = monochromatize(col << 8) >> 8;
|
|
|
|
}
|
|
|
|
queuestr(V, size, chr, col, frame, align);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-27 16:49:04 +00:00
|
|
|
EX void queuecircle(const shiftmatrix& V, double size, color_t col) {
|
2019-07-31 14:14:01 +00:00
|
|
|
int xc, yc, sc;
|
|
|
|
if(!getcoord0_checked(tC0(V), xc, yc, sc)) return;
|
2019-05-26 16:04:02 +00:00
|
|
|
int xs, ys, ss; getcoord0(V * xpush0(.01), xs, ys, ss);
|
|
|
|
queuecircle(xc, yc, scale_in_pixels(V) * size, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|