2017-12-09 01:20:10 +00:00
|
|
|
#include <SDL/SDL_image.h>
|
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
namespace texture {
|
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
GLuint textureid = 0;
|
2017-12-09 01:20:10 +00:00
|
|
|
|
|
|
|
SDL_Surface *convertSurface(SDL_Surface* s) {
|
|
|
|
SDL_PixelFormat fmt;
|
|
|
|
// fmt.format = SDL_PIXELFORMAT_BGRA8888;
|
|
|
|
fmt.BitsPerPixel = 32;
|
|
|
|
fmt.BytesPerPixel = 4;
|
|
|
|
|
|
|
|
fmt.Ashift=24;
|
|
|
|
fmt.Rshift=16;
|
|
|
|
fmt.Gshift=8;
|
|
|
|
fmt.Bshift=0;
|
|
|
|
fmt.Amask=0xff<<24;
|
|
|
|
fmt.Rmask=0xff<<16;
|
|
|
|
fmt.Gmask=0xff<<8;
|
|
|
|
fmt.Bmask=0xff;
|
|
|
|
fmt.Aloss = fmt.Rloss = fmt.Gloss = fmt.Bloss = 0;
|
|
|
|
fmt.palette = NULL;
|
|
|
|
|
|
|
|
#ifndef SDL2
|
|
|
|
fmt.alpha = 0;
|
|
|
|
fmt.colorkey = 0x1ffffff;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return SDL_ConvertSurface(s, &fmt, SDL_SWSURFACE);
|
|
|
|
}
|
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
int twidth = 2048;
|
|
|
|
|
2017-12-09 01:20:10 +00:00
|
|
|
vector<int> expanded_data;
|
|
|
|
|
2017-12-16 14:59:31 +00:00
|
|
|
string texturename = "hyperrogue-texture.png";
|
2017-12-14 11:10:40 +00:00
|
|
|
string configname = "hyperrogue.txc";
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
eTextureState tstate;
|
2017-12-14 11:10:40 +00:00
|
|
|
eTextureState tstate_max;
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
template<class T, class U> void scale_colorarray(int origdim, const T& src, const U& dest) {
|
|
|
|
int ox = 0, tx = 0, partials[4];
|
|
|
|
int omissing = twidth, tmissing = origdim;
|
|
|
|
for(int p=0; p<4; p++) partials[p] = 0;
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
while(tx < twidth) {
|
|
|
|
int fv = min(omissing, tmissing);
|
|
|
|
int c = src(ox);
|
|
|
|
for(int p=0; p<4; p++)
|
|
|
|
partials[p] += part(c, p) * fv;
|
|
|
|
omissing -= fv; tmissing -= fv;
|
|
|
|
if(omissing == 0) {
|
|
|
|
ox++; omissing = twidth;
|
|
|
|
}
|
|
|
|
if(tmissing == 0) {
|
|
|
|
int target;
|
|
|
|
for(int p=0; p<4; p++) {
|
|
|
|
part(target, p) = partials[p] / origdim;
|
|
|
|
partials[p] = 0;
|
|
|
|
}
|
|
|
|
dest(tx++, target);
|
|
|
|
tmissing = origdim;
|
|
|
|
}
|
2017-12-09 01:20:10 +00:00
|
|
|
}
|
2017-12-14 01:53:29 +00:00
|
|
|
}
|
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
bool loadTextureGL() {
|
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
if(textureid == 0) glGenTextures(1, &textureid );
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
glBindTexture( GL_TEXTURE_2D, textureid);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
|
|
|
|
|
|
|
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, twidth, twidth, 0,
|
|
|
|
GL_BGRA, GL_UNSIGNED_BYTE,
|
|
|
|
&expanded_data[0] );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool whitetexture() {
|
|
|
|
expanded_data.resize(0);
|
|
|
|
expanded_data.resize(twidth * twidth, 0xFFFFFFFF);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool readtexture() {
|
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
SDL_Surface *txt = IMG_Load(texturename.c_str());
|
2017-12-14 11:10:40 +00:00
|
|
|
if(!txt) {
|
|
|
|
addMessage(XLAT("Failed to load %1", texturename));
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-14 01:53:29 +00:00
|
|
|
auto txt2 = convertSurface(txt);
|
|
|
|
|
|
|
|
int tx = txt->w, ty = txt->h;
|
|
|
|
|
|
|
|
SDL_FreeSurface(txt);
|
|
|
|
|
|
|
|
vector<int> half_expanded(twidth * ty);
|
|
|
|
expanded_data.resize(twidth * twidth);
|
|
|
|
|
|
|
|
int origdim = max(tx, ty);
|
|
|
|
int base_x = tx/2 - origdim/2;
|
|
|
|
int base_y = ty/2 - origdim/2;
|
2017-12-17 23:24:56 +00:00
|
|
|
|
|
|
|
ZZ = 0; // outside is black
|
2017-12-14 01:53:29 +00:00
|
|
|
|
|
|
|
/* for(int y=0; y<twidth; y++)
|
|
|
|
for(int x=0; x<twidth; x++)
|
|
|
|
expanded_data[y*twidth+x] = qpixel(txt2, y%ty, x%tx); */
|
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
for(int x=0; x<twidth; x++)
|
|
|
|
scale_colorarray(origdim,
|
|
|
|
[&] (int y) { return base_y+y < 0 || base_y+y >= ty ? 0 : half_expanded[x + (base_y + y) * twidth]; },
|
|
|
|
[&] (int y, int v) { expanded_data[twidth * y + x] = v; }
|
|
|
|
);
|
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
for(int y=0; y<ty; y++)
|
|
|
|
scale_colorarray(origdim,
|
|
|
|
[&] (int x) { return qpixel(txt2, base_x + x, y); },
|
|
|
|
[&] (int x, int v) { half_expanded[twidth * y + x] = v; }
|
|
|
|
);
|
|
|
|
|
|
|
|
SDL_FreeSurface(txt2);
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
return true;
|
2017-12-09 01:20:10 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
transmatrix itt = Id;
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
unsigned grid_color = 0;
|
|
|
|
unsigned mesh_color = 0;
|
|
|
|
unsigned master_color = 0xFFFFFF10;
|
|
|
|
unsigned slave_color = 0xFF000008;
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
int color_alpha = 0;
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
int gsplits = 1;
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
void mapTextureTriangle(textureinfo &mi, array<hyperpoint, 3> vview, array<hyperpoint, 3> vmap, int splits = gsplits) {
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
if(splits) {
|
|
|
|
array<hyperpoint, 3> vview2 = { mid(vview[1], vview[2]), mid(vview[2], vview[0]), mid(vview[0], vview[1]) };
|
|
|
|
array<hyperpoint, 3> vmap2 = { mid(vmap [1], vmap [2]), mid(vmap [2], vmap [0]), mid(vmap [0], vmap [1]) };
|
|
|
|
mapTextureTriangle(mi, {vview[0], vview2[1], vview2[2]}, {vmap[0], vmap2[1], vmap2[2]}, splits-1);
|
|
|
|
mapTextureTriangle(mi, {vview[1], vview2[2], vview2[0]}, {vmap[1], vmap2[2], vmap2[0]}, splits-1);
|
|
|
|
mapTextureTriangle(mi, {vview[2], vview2[0], vview2[1]}, {vmap[2], vmap2[0], vmap2[1]}, splits-1);
|
|
|
|
mapTextureTriangle(mi, {vview2[0], vview2[1], vview2[2]}, {vmap2[0], vmap2[1], vmap2[2]}, splits-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-09 01:20:10 +00:00
|
|
|
for(int i=0; i<3; i++) {
|
|
|
|
for(int j=0; j<3; j++)
|
2017-12-14 01:53:29 +00:00
|
|
|
mi.vertices.push_back(vview[i][j]);
|
2017-12-09 01:20:10 +00:00
|
|
|
hyperpoint inmodel;
|
2017-12-14 01:53:29 +00:00
|
|
|
applymodel(mi.M * vmap[i], inmodel);
|
|
|
|
inmodel = itt * inmodel;
|
|
|
|
inmodel[0] *= vid.radius * 1. / vid.scrsize;
|
|
|
|
inmodel[1] *= vid.radius * 1. / vid.scrsize;
|
|
|
|
mi.tvertices.push_back((inmodel[0]+1)/2);
|
|
|
|
mi.tvertices.push_back((inmodel[1]+1)/2);
|
2017-12-09 01:20:10 +00:00
|
|
|
mi.tvertices.push_back(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
map<int, textureinfo> texture_map;
|
2017-12-14 01:53:29 +00:00
|
|
|
set<cell*> models;
|
|
|
|
|
|
|
|
void mapTexture(cell *c, textureinfo& mi, patterns::patterninfo &si, const transmatrix& T) {
|
|
|
|
mi.c = c;
|
|
|
|
mi.vertices.clear();
|
|
|
|
mi.tvertices.clear();
|
|
|
|
mi.symmetries = si.symmetries;
|
|
|
|
mi.current_type = c->type;
|
|
|
|
mi.current_geometry = geometry;
|
|
|
|
mi.current_trunc = nontruncated;
|
|
|
|
|
|
|
|
mi.M = T * applyPatterndir(c, si);
|
|
|
|
|
|
|
|
if(tstate == tsAdjusting) return;
|
|
|
|
|
|
|
|
ld z = ctof(c) ? rhexf : hexvdist;
|
|
|
|
|
2017-12-16 08:03:50 +00:00
|
|
|
// int sym = si.symmetries;
|
2017-12-14 01:53:29 +00:00
|
|
|
|
|
|
|
for(int i=0; i<c->type; i++) {
|
|
|
|
hyperpoint h1 = spin(M_PI + M_PI * (2*i +1) / c->type) * xpush(z) * C0;
|
|
|
|
hyperpoint h2 = spin(M_PI + M_PI * (2*i -1) / c->type) * xpush(z) * C0;
|
2017-12-16 08:03:50 +00:00
|
|
|
hyperpoint hm1 = spin(M_PI + M_PI * (2*i +1) / c->type) * xpush(z) * C0;
|
|
|
|
hyperpoint hm2 = spin(M_PI + M_PI * (2*i -1) / c->type) * xpush(z) * C0;
|
2017-12-14 01:53:29 +00:00
|
|
|
mapTextureTriangle(mi, {C0, h1, h2}, {C0, hm1, hm2});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int recolor(int col) {
|
|
|
|
if(color_alpha == 0) return col;
|
|
|
|
if(color_alpha == 255) return col | 0xFFFFFF00;
|
|
|
|
for(int i=1; i<4; i++)
|
|
|
|
part(col, i) = color_alpha + ((255-color_alpha) * part(col,i) + 127) / 255;
|
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool apply(cell *c, const transmatrix &V, int col) {
|
|
|
|
if(tstate == tsOff) return false;
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-09 02:48:30 +00:00
|
|
|
using namespace patterns;
|
2017-12-09 07:06:41 +00:00
|
|
|
auto si = getpatterninfo0(c);
|
2017-12-14 01:53:29 +00:00
|
|
|
|
|
|
|
if(tstate == tsAdjusting) {
|
|
|
|
queuepolyat(V, shFullCross[ctof(c)], 0, PPR_LINE);
|
2017-12-17 23:24:56 +00:00
|
|
|
lastptd().u.poly.outline = models.count(c) ? master_color : slave_color;
|
2017-12-14 01:53:29 +00:00
|
|
|
queuepolyat(V, shFullFloor[ctof(c)], 0, PPR_LINE);
|
2017-12-17 23:24:56 +00:00
|
|
|
lastptd().u.poly.outline = models.count(c) ? master_color : slave_color;
|
2017-12-14 01:53:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-12-09 01:20:10 +00:00
|
|
|
try {
|
2017-12-09 07:06:41 +00:00
|
|
|
auto& mi = texture_map.at(si.id);
|
2017-12-14 01:53:29 +00:00
|
|
|
|
2017-12-09 07:06:41 +00:00
|
|
|
qfi.spin = applyPatterndir(c, si);
|
2017-12-09 01:20:10 +00:00
|
|
|
|
|
|
|
int n = mi.vertices.size() / 3;
|
2017-12-14 01:53:29 +00:00
|
|
|
|
|
|
|
if(geometry != mi.current_geometry || nontruncated != mi.current_trunc) {
|
|
|
|
// we can easily make it more symmetric
|
|
|
|
mi.symmetries = gcd(mi.symmetries, si.symmetries);
|
|
|
|
|
|
|
|
printf("Redrawing tile #%d from %d to %d\n", si.id, mi.current_type, c->type);
|
|
|
|
int nbase = n * mi.symmetries / mi.current_type;
|
|
|
|
int ntarget = nbase * c->type / mi.symmetries;
|
|
|
|
printf("n = %d nbase = %d ntarget = %d\n", n, nbase, ntarget);
|
|
|
|
vector<GLfloat> new_tvertices = move(mi.tvertices);
|
|
|
|
new_tvertices.resize(3*ntarget);
|
|
|
|
for(int i=3*nbase; i<3*ntarget; i++) {
|
|
|
|
new_tvertices[i] = new_tvertices[i - 3*nbase];
|
|
|
|
}
|
|
|
|
|
|
|
|
mapTexture(c, mi, si, Id);
|
|
|
|
mi.tvertices = move(new_tvertices);
|
|
|
|
n = mi.vertices.size() / 3;
|
|
|
|
printf("new n = %d\n", n);
|
|
|
|
}
|
2017-12-09 01:20:10 +00:00
|
|
|
|
|
|
|
qfi.special = false;
|
|
|
|
qfi.shape = &shFullFloor[ctof(c)];
|
|
|
|
qfi.tinf = &mi;
|
|
|
|
|
|
|
|
if(chasmg == 2) return false;
|
|
|
|
else if(chasmg && wmspatial) {
|
|
|
|
if(detaillevel == 0) return false;
|
2017-12-17 23:24:56 +00:00
|
|
|
queuetable(V * qfi.spin, &mi.vertices[0], n, mesh_color, recolor(c->land == laCocytus ? 0x080808FF : 0x101010FF), PPR_LAKEBOTTOM);
|
2017-12-09 01:20:10 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-12-17 23:24:56 +00:00
|
|
|
queuetable(V * qfi.spin, &mi.vertices[0], n, mesh_color, recolor(col), PPR_FLOOR);
|
2017-12-09 01:20:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lastptd().u.poly.tinf = &mi;
|
2017-12-17 23:24:56 +00:00
|
|
|
if(grid_color) {
|
2017-12-14 01:53:29 +00:00
|
|
|
queuepolyat(V, shFullFloor[ctof(c)], 0, PPR_FLOOR);
|
2017-12-17 23:24:56 +00:00
|
|
|
lastptd().u.poly.outline = grid_color;
|
2017-12-14 01:53:29 +00:00
|
|
|
}
|
2017-12-09 01:20:10 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch(out_of_range) {
|
2017-12-14 01:53:29 +00:00
|
|
|
// printf("Ignoring tile #%d : not mapped\n", si.id);
|
2017-12-09 01:20:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void perform_mapping() {
|
2017-12-14 01:53:29 +00:00
|
|
|
if(gsplits < 0) gsplits = 0;
|
|
|
|
if(gsplits > 4) gsplits = 4;
|
2017-12-09 02:48:30 +00:00
|
|
|
using namespace patterns;
|
2017-12-09 01:20:10 +00:00
|
|
|
texture_map.clear();
|
|
|
|
for(auto p: gmatrix) {
|
|
|
|
cell *c = p.first;
|
2017-12-09 07:06:41 +00:00
|
|
|
auto si = getpatterninfo0(c);
|
2017-12-09 01:20:10 +00:00
|
|
|
bool replace = false;
|
2017-12-09 19:01:50 +00:00
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
// int sgn = sphere ? -1 : 1;
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-09 07:06:41 +00:00
|
|
|
if(!texture_map.count(si.id))
|
2017-12-09 01:20:10 +00:00
|
|
|
replace = true;
|
2017-12-16 08:03:50 +00:00
|
|
|
else if(hdist0(p.second*sphereflip * C0) < hdist0(texture_map[si.id].M * sphereflip * C0))
|
2017-12-09 01:20:10 +00:00
|
|
|
replace = true;
|
|
|
|
|
|
|
|
if(replace) {
|
2017-12-09 07:06:41 +00:00
|
|
|
auto& mi = texture_map[si.id];
|
2017-12-14 01:53:29 +00:00
|
|
|
mapTexture(c, mi, si, p.second);
|
|
|
|
mi.texture_id = textureid;
|
2017-12-17 23:24:56 +00:00
|
|
|
}
|
|
|
|
texture_map[si.id].matrices.push_back(p.second);
|
2017-12-09 01:20:10 +00:00
|
|
|
}
|
2017-12-14 01:53:29 +00:00
|
|
|
models.clear();
|
|
|
|
for(auto& t: texture_map) models.insert(t.second.c);
|
2017-12-09 01:20:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int forgeArgs() {
|
|
|
|
using namespace arg;
|
|
|
|
|
|
|
|
if(0) ;
|
2017-12-14 11:10:40 +00:00
|
|
|
else if(argis("-txpic")) {
|
2017-12-09 01:20:10 +00:00
|
|
|
shift(); texturename = args();
|
|
|
|
}
|
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
else if(argis("-fsp")) {
|
|
|
|
shift(); gsplits = argf();
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
else if(argis("-txc")) {
|
|
|
|
shift(); configname = args();
|
|
|
|
}
|
|
|
|
|
2017-12-09 01:20:10 +00:00
|
|
|
else return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
bool newmove = false;
|
|
|
|
|
2017-12-09 01:20:10 +00:00
|
|
|
auto texture_hook =
|
2017-12-14 01:53:29 +00:00
|
|
|
addHook(hooks_args, 100, forgeArgs);
|
|
|
|
|
|
|
|
void drawRawTexture() {
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glcolor2(0xFFFFFF20);
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(0, 0, vid.scrdist);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, textureid);
|
|
|
|
vector<GLfloat> tver, sver;
|
|
|
|
for(int i=0; i<4; i++) {
|
|
|
|
int cx[4] = {1, -1, -1, 1};
|
|
|
|
int cy[4] = {1, 1, -1, -1};
|
|
|
|
int x = cx[i];
|
|
|
|
int y = cy[i];
|
|
|
|
hyperpoint inmodel = hpxyz(x, y, 1);
|
|
|
|
inmodel = itt * inmodel;
|
|
|
|
tver.push_back((inmodel[0]+1)/2);
|
|
|
|
tver.push_back((inmodel[1]+1)/2);
|
|
|
|
tver.push_back(0);
|
|
|
|
sver.push_back(x * vid.scrsize);
|
|
|
|
sver.push_back(y * vid.scrsize);
|
|
|
|
sver.push_back(0);
|
|
|
|
}
|
|
|
|
activateVertexArray(&sver[0], 4);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glTexCoordPointer(3, GL_FLOAT, 0, &tver[0]);
|
|
|
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glPopMatrix();
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
}
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-16 08:03:50 +00:00
|
|
|
struct magicmapper_point {
|
|
|
|
cell *c;
|
|
|
|
hyperpoint cell_relative;
|
|
|
|
hyperpoint texture_coords;
|
|
|
|
};
|
|
|
|
|
|
|
|
vector<magicmapper_point> amp;
|
|
|
|
|
|
|
|
struct magic_param {
|
|
|
|
bool do_spin;
|
|
|
|
ld spinangle, scale, proj, moveangle, shift;
|
|
|
|
|
|
|
|
void shuffle() {
|
|
|
|
do_spin = hrand(2);
|
|
|
|
spinangle = hrandf() - hrandf();
|
|
|
|
moveangle = hrandf() * 2 * M_PI;
|
|
|
|
shift = hrandf() - hrandf();
|
|
|
|
scale = hrandf() - hrandf();
|
|
|
|
proj = hrandf() - hrandf();
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply(ld delta) {
|
|
|
|
vid.alpha *= exp(delta * proj);
|
|
|
|
vid.scale *= exp(delta * scale);
|
|
|
|
|
|
|
|
if(do_spin)
|
|
|
|
View = spin(delta * spinangle) * View;
|
|
|
|
else
|
|
|
|
View = spin(moveangle) * xpush(delta*shift) * spin(-moveangle) * View;
|
|
|
|
|
|
|
|
fixmatrix(View);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ld magic_quality() {
|
|
|
|
gmatrix.clear();
|
|
|
|
calcparam();
|
|
|
|
|
|
|
|
ld q = 0;
|
|
|
|
for(auto& p: amp) {
|
|
|
|
hyperpoint inmodel;
|
|
|
|
applymodel(shmup::ggmatrix(p.c) * p.cell_relative, inmodel);
|
|
|
|
inmodel[0] *= vid.radius * 1. / vid.scrsize;
|
|
|
|
inmodel[1] *= vid.radius * 1. / vid.scrsize;
|
|
|
|
q += intvalxy(inmodel, p.texture_coords);
|
|
|
|
}
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyMagic() {
|
|
|
|
ld cq = magic_quality();
|
|
|
|
|
|
|
|
int last_success = 0;
|
|
|
|
|
|
|
|
for(int s=0; s<50000 && s<last_success + 1000; s++) {
|
|
|
|
magic_param p;
|
|
|
|
p.shuffle();
|
|
|
|
|
|
|
|
bool failed = false;
|
|
|
|
|
|
|
|
for(ld delta = 1; delta > 1e-9; delta *= (failed ? -.7 : 1.2)) {
|
|
|
|
p.apply(delta);
|
|
|
|
ld nq = magic_quality();
|
|
|
|
if(nq < cq) {
|
|
|
|
cq = nq;
|
|
|
|
last_success = s;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p.apply(-delta);
|
|
|
|
failed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum eTexturePanstate {tpsModel, tpsMove, tpsScale, tpsAffine, tpsZoom, tpsProjection, tpsMagic};
|
2017-12-14 01:53:29 +00:00
|
|
|
eTexturePanstate panstate;
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
void mousemovement() {
|
|
|
|
static hyperpoint lastmouse;
|
|
|
|
|
|
|
|
hyperpoint mouseeu = hpxyz((mousex - vid.xcenter + .0) / vid.scrsize, (mousey - vid.ycenter + .0) / vid.scrsize, 1);
|
|
|
|
bool nonzero = mouseeu[0] || mouseeu[1];
|
|
|
|
|
|
|
|
switch(panstate) {
|
|
|
|
case tpsModel:
|
|
|
|
if(!newmove && mouseh[2] < 50 && lastmouse[2] < 50) {
|
|
|
|
panning(lastmouse, mouseh);
|
|
|
|
perform_mapping();
|
|
|
|
}
|
|
|
|
lastmouse = mouseh; newmove = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case tpsMove: {
|
|
|
|
if(!newmove)
|
|
|
|
itt = itt * inverse(eupush(mouseeu)) * eupush(lastmouse);
|
|
|
|
lastmouse = mouseeu; newmove = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case tpsScale: {
|
|
|
|
if(nonzero && !newmove)
|
|
|
|
itt = itt * inverse(euscalezoom(mouseeu)) * euscalezoom(lastmouse);
|
|
|
|
if(nonzero) lastmouse = mouseeu;
|
|
|
|
newmove = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case tpsAffine: {
|
|
|
|
if(!newmove)
|
|
|
|
itt = itt * inverse(euaffine(mouseeu)) * euaffine(lastmouse);
|
|
|
|
lastmouse = mouseeu; newmove = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case tpsZoom: {
|
|
|
|
// do not zoom in portrait!
|
|
|
|
if(nonzero && !newmove) {
|
2017-12-16 08:03:50 +00:00
|
|
|
View = inverse(spintox(mouseeu)) * spintox(lastmouse) * View;
|
2017-12-14 11:10:40 +00:00
|
|
|
vid.scale = vid.scale * sqrt(intvalxy(C0, mouseeu)) / sqrt(intvalxy(C0, lastmouse));
|
|
|
|
}
|
|
|
|
if(nonzero) lastmouse = mouseeu;
|
|
|
|
newmove = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case tpsProjection: {
|
|
|
|
if(nonzero && !newmove) {
|
|
|
|
vid.alpha = vid.alpha * sqrt(intvalxy(C0, mouseeu)) / sqrt(intvalxy(C0, lastmouse));
|
|
|
|
}
|
|
|
|
if(nonzero) lastmouse = mouseeu;
|
|
|
|
newmove = false;
|
|
|
|
}
|
|
|
|
|
2017-12-16 08:03:50 +00:00
|
|
|
case tpsMagic: {
|
|
|
|
if(!mouseover) return;
|
|
|
|
if(newmove) {
|
|
|
|
magicmapper_point newpoint;
|
|
|
|
newpoint.c = mouseover;
|
|
|
|
newpoint.cell_relative = inverse(gmatrix[mouseover]) * mouseh;
|
|
|
|
amp.push_back(newpoint);
|
|
|
|
newmove = false;
|
|
|
|
}
|
|
|
|
amp.back().texture_coords = mouseeu;
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
patterns::patterninfo si_save;
|
|
|
|
|
|
|
|
saverlist texturesavers;
|
|
|
|
|
|
|
|
bool target_nontrunc;
|
|
|
|
|
|
|
|
void init_textureconfig() {
|
|
|
|
texturesavers = move(savers);
|
|
|
|
for(int i=0; i<3; i++)
|
|
|
|
for(int j=0; j<3; j++)
|
|
|
|
addsaver(itt[i][j], "texturematrix_" + its(i) + its(j), i==j ? 1 : 0);
|
|
|
|
|
|
|
|
for(int i=0; i<3; i++)
|
|
|
|
for(int j=0; j<3; j++)
|
|
|
|
addsaver(View[i][j], "viewmatrix_" + its(i) + its(j), i==j ? 1 : 0);
|
|
|
|
|
|
|
|
addsaverenum(targetgeometry, "geometry", gNormal);
|
|
|
|
addsaverenum(target_nontrunc, "chamfering", false);
|
|
|
|
// ... geometry parameters
|
|
|
|
|
|
|
|
addsaver(patterns::whichPattern, "pattern", 0);
|
|
|
|
addsaver(patterns::subpattern_flags, "pattern flags", 0);
|
|
|
|
|
|
|
|
cell *ctr = euclid ? centerover : viewctr.h->c7;
|
|
|
|
si_save = patterns::getpatterninfo0(ctr);
|
|
|
|
|
|
|
|
addsaver(si_save.id, "center type", 1);
|
|
|
|
addsaver(si_save.dir, "center direction", 0);
|
|
|
|
addsaver(si_save.reflect, "center reflection", false);
|
|
|
|
addsaver(twidth, "texture resolution", 2048);
|
|
|
|
addsaver(gsplits, "precision", 1);
|
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
addsaver(grid_color, "grid color", 0);
|
2017-12-14 11:10:40 +00:00
|
|
|
addsaver(color_alpha, "alpha color", 0);
|
2017-12-17 23:24:56 +00:00
|
|
|
addsaver(mesh_color, "mesh color", 0);
|
2017-12-14 11:10:40 +00:00
|
|
|
|
|
|
|
addsaver(vid.alpha, "projection", 1);
|
|
|
|
addsaver(vid.scale, "scale", 1);
|
|
|
|
|
|
|
|
addsaver(texturename, "texture filename", "");
|
|
|
|
|
|
|
|
swap(texturesavers, savers);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool save_textureconfig() {
|
|
|
|
init_textureconfig();
|
|
|
|
FILE *f = fopen(configname.c_str(), "wt");
|
|
|
|
if(!f) return false;
|
|
|
|
|
|
|
|
targetgeometry = geometry;
|
|
|
|
target_nontrunc = nontruncated;
|
|
|
|
|
|
|
|
for(auto s: texturesavers) if(s->dosave())
|
|
|
|
fprintf(f, "%s=%s\n", s->name.c_str(), s->save().c_str());
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool load_textureconfig() {
|
|
|
|
init_textureconfig();
|
|
|
|
|
|
|
|
FILE *f = fopen(configname.c_str(), "rt");
|
|
|
|
if(!f) return false;
|
|
|
|
swap(texturesavers, savers);
|
|
|
|
for(auto s: savers) s->reset();
|
|
|
|
loadNewConfig(f);
|
|
|
|
swap(texturesavers, savers);
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
if(1) {
|
|
|
|
dynamicval<char> d1(patterns::whichPattern, patterns::whichPattern);
|
|
|
|
dynamicval<int> d2(patterns::subpattern_flags, patterns::subpattern_flags);
|
|
|
|
|
|
|
|
if(targetgeometry != geometry) {
|
|
|
|
restartGame('g');
|
|
|
|
return load_textureconfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(nontruncated != target_nontrunc) {
|
|
|
|
restartGame('7');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!readtexture()) return false;
|
2017-12-17 23:24:56 +00:00
|
|
|
if(!loadTextureGL()) return false;
|
2017-12-16 08:03:50 +00:00
|
|
|
calcparam();
|
2017-12-14 11:10:40 +00:00
|
|
|
drawthemap();
|
|
|
|
perform_mapping();
|
|
|
|
tstate = tstate_max = tsActive;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
void showMenu() {
|
|
|
|
cmode = sm::SIDE | sm::MAYDARK | sm::DIALOG_STRICT_X;
|
2017-12-09 01:20:10 +00:00
|
|
|
gamescreen(0);
|
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
if(tstate == tsAdjusting)
|
|
|
|
drawRawTexture();
|
|
|
|
|
2017-12-09 01:20:10 +00:00
|
|
|
dialog::init(XLAT("texture mode"));
|
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
if(tstate == tsOff) {
|
|
|
|
dialog::addSelItem(XLAT("select the texture's pattern"), XLAT("..."), 'r');
|
|
|
|
if(tstate_max == tsAdjusting)
|
|
|
|
dialog::addSelItem(XLAT("readjust the texture"), texturename, 't');
|
|
|
|
if(tstate_max == tsActive)
|
|
|
|
dialog::addSelItem(XLAT("reactivate the texture"), texturename, 't');
|
|
|
|
dialog::addSelItem(XLAT("open texture file"), texturename, 'o');
|
|
|
|
dialog::addSelItem(XLAT("load texture config"), "...", 'l');
|
|
|
|
}
|
2017-12-14 01:53:29 +00:00
|
|
|
|
|
|
|
if(tstate == tsAdjusting) {
|
2017-12-14 11:10:40 +00:00
|
|
|
dialog::addSelItem(XLAT("enable the texture"), texturename, 't');
|
2017-12-14 01:53:29 +00:00
|
|
|
dialog::addBoolItem(XLAT("move the model"), panstate == tpsModel, 'm');
|
|
|
|
dialog::addBoolItem(XLAT("move the texture"), panstate == tpsMove, 'a');
|
|
|
|
dialog::addBoolItem(XLAT("zoom/scale the texture"), panstate == tpsScale, 'x');
|
|
|
|
dialog::addBoolItem(XLAT("zoom/scale the model"), panstate == tpsZoom, 'z');
|
|
|
|
dialog::addBoolItem(XLAT("projection"), panstate == tpsProjection, 'p');
|
|
|
|
dialog::addBoolItem(XLAT("affine transformations"), panstate == tpsAffine, 'y');
|
2017-12-16 08:03:50 +00:00
|
|
|
dialog::addBoolItem(XLAT("magic"), panstate == tpsMagic, 'A');
|
2017-12-17 23:24:56 +00:00
|
|
|
|
|
|
|
dialog::addBoolItem(XLAT("grid color (master)"), "...", 'M');
|
|
|
|
dialog::addBoolItem(XLAT("grid color (copy)"), "...", 'C');
|
2017-12-16 08:03:50 +00:00
|
|
|
|
|
|
|
if(panstate == tpsMagic) {
|
|
|
|
dialog::addSelItem(XLAT("delete markers"), its(size(amp)), 'D');
|
|
|
|
dialog::addSelItem(XLAT("perform auto-adjustment"), "...", 'R');
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
dialog::addSelItem(XLAT("precision"), its(gsplits), 'p');
|
2017-12-14 01:53:29 +00:00
|
|
|
}
|
2017-12-09 01:20:10 +00:00
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
if(tstate == tsActive) {
|
|
|
|
/* dialog::addSelItem(XLAT("texture scale"), fts(iscale), 's');
|
|
|
|
dialog::addSelItem(XLAT("texture angle"), fts(irotate), 'a');
|
|
|
|
dialog::addSelItem(XLAT("texture position X"), fts(ix), 'x');
|
|
|
|
dialog::addSelItem(XLAT("texture position Y"), fts(iy), 'y'); */
|
2017-12-14 11:10:40 +00:00
|
|
|
dialog::addBoolItem(XLAT("deactivate the texture"), true, 't');
|
|
|
|
dialog::addBoolItem(XLAT("readjust the texture"), true, 'r');
|
2017-12-17 23:24:56 +00:00
|
|
|
dialog::addSelItem(XLAT("grid alpha"), "...", 'g');
|
|
|
|
dialog::addSelItem(XLAT("mesh alpha"), "...", 'm');
|
2017-12-14 01:53:29 +00:00
|
|
|
dialog::addSelItem(XLAT("color alpha"), its(color_alpha), 'c');
|
2017-12-14 11:10:40 +00:00
|
|
|
dialog::addSelItem(XLAT("save the texture config"), "...", 's');
|
2017-12-09 01:20:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dialog::addItem(XLAT("help"), SDLK_F1);
|
|
|
|
dialog::addItem(XLAT("back"), '0');
|
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
getcstat = '-';
|
|
|
|
|
2017-12-09 01:20:10 +00:00
|
|
|
dialog::display();
|
|
|
|
|
2017-12-16 08:03:50 +00:00
|
|
|
if(tstate == tsAdjusting) {
|
|
|
|
initquickqueue();
|
|
|
|
char letter = 'A';
|
|
|
|
for(auto& am: amp) {
|
|
|
|
hyperpoint h = shmup::ggmatrix(am.c) * am.cell_relative;
|
|
|
|
display(h);
|
|
|
|
queuechr(h, vid.fsize, letter, 0xC00000, 1);
|
|
|
|
|
|
|
|
hyperpoint inmodel;
|
|
|
|
applymodel(h, inmodel);
|
|
|
|
inmodel[0] *= vid.radius * 1. / vid.scrsize;
|
|
|
|
inmodel[1] *= vid.radius * 1. / vid.scrsize;
|
|
|
|
queuechr(
|
|
|
|
vid.xcenter + vid.scrsize * inmodel[0],
|
|
|
|
vid.ycenter + vid.scrsize * inmodel[1],
|
|
|
|
0, vid.fsize/2, letter, 0xC0C0C0, 1);
|
|
|
|
|
|
|
|
queuechr(
|
|
|
|
vid.xcenter + vid.scrsize * am.texture_coords[0],
|
|
|
|
vid.ycenter + vid.scrsize * am.texture_coords[1],
|
|
|
|
0, vid.fsize, letter, 0x00C000, 1);
|
|
|
|
|
|
|
|
letter++;
|
|
|
|
}
|
|
|
|
quickqueue();
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
if(holdmouse) mousemovement();
|
2017-12-14 01:53:29 +00:00
|
|
|
|
2017-12-09 01:20:10 +00:00
|
|
|
keyhandler = [] (int sym, int uni) {
|
2017-12-14 01:53:29 +00:00
|
|
|
// handlePanning(sym, uni);
|
2017-12-09 01:20:10 +00:00
|
|
|
dialog::handleNavigation(sym, uni);
|
2017-12-14 01:53:29 +00:00
|
|
|
|
|
|
|
if(uni == '-' && tstate == tsAdjusting) {
|
|
|
|
if(!holdmouse) {
|
|
|
|
holdmouse = true;
|
|
|
|
newmove = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(uni == 'm' && tstate == tsAdjusting) panstate = tpsModel;
|
|
|
|
else if(uni == 'a' && tstate == tsAdjusting) panstate = tpsMove;
|
|
|
|
else if(uni == 'x' && tstate == tsAdjusting) panstate = tpsScale;
|
|
|
|
else if(uni == 'y' && tstate == tsAdjusting) panstate = tpsAffine;
|
|
|
|
else if(uni == 'z' && tstate == tsAdjusting) panstate = tpsZoom;
|
|
|
|
else if(uni == 'p' && tstate == tsAdjusting) panstate = tpsProjection;
|
2017-12-16 08:03:50 +00:00
|
|
|
else if(uni == 'A' && tstate == tsAdjusting) panstate = tpsMagic;
|
|
|
|
else if(uni == 'D' && tstate == tsAdjusting) amp.clear();
|
|
|
|
else if(uni == 'R' && tstate == tsAdjusting) applyMagic();
|
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
else if(uni == 's' && tstate == tsActive)
|
|
|
|
dialog::openFileDialog(configname, XLAT("texture config to save:"), ".txc",
|
|
|
|
[] () {
|
|
|
|
return save_textureconfig();
|
|
|
|
});
|
|
|
|
|
|
|
|
else if(uni == 'l' && tstate == tsOff)
|
|
|
|
dialog::openFileDialog(configname, XLAT("texture config to load:"), ".txc",
|
|
|
|
[] () {
|
|
|
|
return load_textureconfig();
|
|
|
|
});
|
|
|
|
|
|
|
|
else if(uni == 'r' && tstate == tsOff)
|
2017-12-09 02:48:30 +00:00
|
|
|
pushScreen(patterns::showPattern);
|
2017-12-14 11:10:40 +00:00
|
|
|
|
|
|
|
else if(uni == 'o' && tstate == tsOff)
|
|
|
|
dialog::openFileDialog(texturename, XLAT("texture to load:"), ".png",
|
|
|
|
[] () {
|
2017-12-17 23:24:56 +00:00
|
|
|
if(readtexture() && loadTextureGL()) {
|
2017-12-14 11:10:40 +00:00
|
|
|
if(tstate_max == tsOff) tstate_max = tsAdjusting;
|
|
|
|
tstate = tstate_max;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
});
|
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
else if(uni == 'n' && tstate == tsOff) {
|
|
|
|
addMessage("white");
|
|
|
|
if(whitetexture() && loadTextureGL()) {
|
|
|
|
tstate = tstate_max = tsActive;
|
|
|
|
perform_mapping();
|
|
|
|
mapeditor::colortouse = 0xFFFF00FF;
|
|
|
|
mapeditor::initdraw(cwt.c);
|
|
|
|
pushScreen(mapeditor::showDrawEditor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
else if(uni == 't' && tstate == tsOff)
|
|
|
|
tstate = tstate_max;
|
|
|
|
|
|
|
|
else if((uni == 't' || uni == 'r') && tstate == tsAdjusting) {
|
|
|
|
tstate = tstate_max = tsActive;
|
|
|
|
perform_mapping();
|
2017-12-09 01:20:10 +00:00
|
|
|
}
|
2017-12-14 11:10:40 +00:00
|
|
|
|
|
|
|
else if(uni == 't' && tstate == tsActive)
|
|
|
|
tstate = tsOff;
|
|
|
|
|
|
|
|
else if(uni == 'r' && tstate == tsActive) {
|
|
|
|
tstate = tsAdjusting;
|
|
|
|
texture_map.clear();
|
|
|
|
}
|
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
else if(uni == 'g' && tstate == tsActive)
|
|
|
|
dialog::openColorDialog(grid_color, NULL);
|
|
|
|
else if(uni == 'm' && tstate == tsActive)
|
|
|
|
dialog::openColorDialog(mesh_color, NULL);
|
|
|
|
|
|
|
|
else if(uni == 'M' && tstate == tsAdjusting)
|
|
|
|
dialog::openColorDialog(master_color, NULL);
|
|
|
|
else if(uni == 'C' && tstate == tsActive)
|
|
|
|
dialog::openColorDialog(slave_color, NULL);
|
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
else if(uni == 'c' && tstate == tsActive) {
|
2017-12-14 01:53:29 +00:00
|
|
|
dialog::editNumber(color_alpha, 0, 255, 15, 0, XLAT("color alpha"),
|
|
|
|
XLAT("The higher the value, the less important the color of underlying terrain is."));
|
2017-12-09 01:20:10 +00:00
|
|
|
}
|
2017-12-14 11:10:40 +00:00
|
|
|
else if(uni == 'p' && tstate == tsAdjusting) {
|
2017-12-14 01:53:29 +00:00
|
|
|
dialog::editNumber(gsplits, 0, 4, 1, 1, XLAT("precision"),
|
|
|
|
XLAT("precision"));
|
2017-12-09 01:20:10 +00:00
|
|
|
dialog::reaction = perform_mapping;
|
|
|
|
}
|
|
|
|
else if(doexiton(sym, uni))
|
|
|
|
popScreen();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
int lastupdate;
|
|
|
|
|
|
|
|
void update() {
|
|
|
|
if(lastupdate && ticks > lastupdate + 100) {
|
|
|
|
loadTextureGL();
|
|
|
|
lastupdate = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pair<int,int> ptc(hyperpoint h) {
|
|
|
|
hyperpoint inmodel;
|
|
|
|
applymodel(h, inmodel);
|
|
|
|
inmodel = itt * inmodel;
|
|
|
|
inmodel[0] *= vid.radius * 1. / vid.scrsize;
|
|
|
|
inmodel[1] *= vid.radius * 1. / vid.scrsize;
|
|
|
|
int x = (1 + inmodel[0]) * twidth / 2;
|
|
|
|
int y = (1 + inmodel[1]) * twidth / 2;
|
|
|
|
return make_pair(x,y);
|
|
|
|
}
|
|
|
|
|
|
|
|
int near(pair<int, int> p1, pair<int, int> p2) {
|
|
|
|
return max(abs(p1.first-p2.first), abs(p1.second - p2.second));
|
|
|
|
}
|
|
|
|
|
|
|
|
void filltriangle(array<hyperpoint, 3> v, int col, int lev) {
|
|
|
|
pair<int,int> p[3] = {ptc(v[0]), ptc(v[1]), ptc(v[2])};
|
|
|
|
|
|
|
|
if(0) for(int i=0; i<3; i++)
|
|
|
|
printf("#%d fillt #%d %s -> %d,%d\n", lev, i, display(v[i]), p[i].first, p[i].second);
|
|
|
|
int d2 = near(p[0], p[1]), d1 = near(p[0], p[2]), d0 = near(p[1], p[2]);
|
|
|
|
|
|
|
|
if((d0 <= 1 && d1 <= 1 && d2 <= 1) || lev >= 5) {
|
|
|
|
for(int i=0; i<3; i++)
|
|
|
|
expanded_data[((p[i].first) & (twidth-1)) + (p[i].second & (twidth-1)) * twidth] = col;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(d1 >= d0 && d1 >= d2)
|
|
|
|
swap(v[0], v[1]);
|
|
|
|
else if(d2 >= d0 && d2 >= d1)
|
|
|
|
swap(v[0], v[2]);
|
|
|
|
|
|
|
|
hyperpoint v3 = mid(v[1], v[2]);
|
|
|
|
filltriangle({v[0], v[1], v3}, col, lev+1);
|
|
|
|
filltriangle({v[0], v[2], v3}, col, lev+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fillcircle(hyperpoint h, int col) {
|
|
|
|
transmatrix A = rgpushxto0(h);
|
|
|
|
|
|
|
|
ld rad = .02;
|
|
|
|
|
|
|
|
filltriangle({A * xpush(rad) * C0, A * spin(M_PI * 2/3) * C0, A * spin(-M_PI * 2/3) * C0}, col, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawPixel(cell *c, hyperpoint h, int col) {
|
|
|
|
printf("s = %d\n", size(gmatrix));
|
|
|
|
|
|
|
|
try {
|
|
|
|
transmatrix M = gmatrix.at(c);
|
|
|
|
auto si = patterns::getpatterninfo0(c);
|
|
|
|
h = inverse(M * applyPatterndir(c, si)) * h;
|
|
|
|
auto& tinf = texture_map[si.id];
|
|
|
|
for(auto& M2: tinf.matrices) for(int i = 0; i<c->type; i += si.symmetries) {
|
|
|
|
hyperpoint inmodel;
|
|
|
|
|
|
|
|
fillcircle(M2 * spin(2 * M_PI * i / c->type) * h, col);
|
|
|
|
lastupdate = ticks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(out_of_range) {}
|
|
|
|
}
|
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
}
|
2017-12-14 11:10:40 +00:00
|
|
|
|
2017-12-14 01:53:29 +00:00
|
|
|
// todo texture editor
|
2017-12-14 11:10:40 +00:00
|
|
|
// todo `three octagons` with two colors
|
2017-12-17 23:24:56 +00:00
|
|
|
|