mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-11-27 14:37:16 +00:00
rug exports more to hyper.h; alt makes rotation slower
This commit is contained in:
parent
bc523b6e65
commit
39e77cee9f
67
hyper.h
67
hyper.h
@ -795,6 +795,7 @@ namespace mapeditor {
|
|||||||
|
|
||||||
namespace rug {
|
namespace rug {
|
||||||
extern bool rugged;
|
extern bool rugged;
|
||||||
|
extern bool computed;
|
||||||
extern bool renderonce;
|
extern bool renderonce;
|
||||||
extern bool rendernogl;
|
extern bool rendernogl;
|
||||||
extern int texturesize;
|
extern int texturesize;
|
||||||
@ -802,8 +803,14 @@ namespace rug {
|
|||||||
extern transmatrix currentrot;
|
extern transmatrix currentrot;
|
||||||
#if CAP_RUG
|
#if CAP_RUG
|
||||||
void show();
|
void show();
|
||||||
|
// initialize both the texture and the model
|
||||||
void init();
|
void init();
|
||||||
|
// initialize only the texture (assume model already initialized)
|
||||||
|
void reopen();
|
||||||
|
// close the rug mode, remove the texture
|
||||||
void close();
|
void close();
|
||||||
|
// clear the model
|
||||||
|
void clear_model();
|
||||||
void actDraw();
|
void actDraw();
|
||||||
void select();
|
void select();
|
||||||
void buildVertexInfo(cell *c, transmatrix V);
|
void buildVertexInfo(cell *c, transmatrix V);
|
||||||
@ -813,6 +820,66 @@ namespace rug {
|
|||||||
void push_all_points(int coord, ld val);
|
void push_all_points(int coord, ld val);
|
||||||
void apply_rotation(const transmatrix& t);
|
void apply_rotation(const transmatrix& t);
|
||||||
string makehelp();
|
string makehelp();
|
||||||
|
|
||||||
|
struct edge {
|
||||||
|
struct rugpoint *target;
|
||||||
|
double len;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct dexp_data {
|
||||||
|
hyperpoint params;
|
||||||
|
hyperpoint cont;
|
||||||
|
ld remaining_distance;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct rugpoint {
|
||||||
|
double x1, y1;
|
||||||
|
bool valid;
|
||||||
|
bool inqueue;
|
||||||
|
double dist;
|
||||||
|
hyperpoint h; // point in the represented space
|
||||||
|
hyperpoint flat; // point in the native space, in azeq
|
||||||
|
hyperpoint precompute;
|
||||||
|
vector<edge> edges;
|
||||||
|
vector<edge> anticusp_edges;
|
||||||
|
// Find-Union algorithm
|
||||||
|
rugpoint *glue;
|
||||||
|
rugpoint *getglue() {
|
||||||
|
return glue ? (glue = glue->getglue()) : this;
|
||||||
|
}
|
||||||
|
hyperpoint& glueflat() {
|
||||||
|
return glue->flat;
|
||||||
|
}
|
||||||
|
rugpoint() { glue = NULL; }
|
||||||
|
void glueto(rugpoint *x) {
|
||||||
|
x = x->getglue();
|
||||||
|
auto y = getglue();
|
||||||
|
if(x != y) y->glue = x;
|
||||||
|
}
|
||||||
|
int dexp_id;
|
||||||
|
dexp_data surface_point;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct triangle {
|
||||||
|
rugpoint *m[3];
|
||||||
|
triangle(rugpoint *m1, rugpoint *m2, rugpoint *m3) {
|
||||||
|
m[0] = m1; m[1] = m2; m[2] = m3;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern vector<rugpoint*> points;
|
||||||
|
extern vector<triangle> triangles;
|
||||||
|
|
||||||
|
extern int qvalid;
|
||||||
|
extern bool subdivide_further();
|
||||||
|
extern void subdivide();
|
||||||
|
extern bool good_shape;
|
||||||
|
extern int vertex_limit;
|
||||||
|
extern void enqueue(rugpoint *p);
|
||||||
|
void sort_rug_points();
|
||||||
|
extern bool rug_perspective;
|
||||||
|
|
||||||
|
bool handlekeys(int sym, int uni);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
89
rug.cpp
89
rug.cpp
@ -19,6 +19,11 @@ bool rug_failure = false;
|
|||||||
|
|
||||||
namespace rug {
|
namespace rug {
|
||||||
|
|
||||||
|
bool computed = false;
|
||||||
|
|
||||||
|
vector<rugpoint*> points;
|
||||||
|
vector<triangle> triangles;
|
||||||
|
|
||||||
int when_enabled;
|
int when_enabled;
|
||||||
|
|
||||||
struct rug_exception { };
|
struct rug_exception { };
|
||||||
@ -59,51 +64,10 @@ ld err_zero = 1e-3, err_zero_current, current_total_error;
|
|||||||
|
|
||||||
int queueiter, qvalid, dt;
|
int queueiter, qvalid, dt;
|
||||||
|
|
||||||
struct edge {
|
|
||||||
struct rugpoint *target;
|
|
||||||
double len;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct rugpoint {
|
|
||||||
double x1, y1;
|
|
||||||
bool valid;
|
|
||||||
bool inqueue;
|
|
||||||
double dist;
|
|
||||||
hyperpoint h; // point in the represented space
|
|
||||||
hyperpoint flat; // point in the native space, in azeq
|
|
||||||
hyperpoint precompute;
|
|
||||||
vector<edge> edges;
|
|
||||||
vector<edge> anticusp_edges;
|
|
||||||
// Find-Union algorithm
|
|
||||||
rugpoint *glue;
|
|
||||||
rugpoint *getglue() {
|
|
||||||
return glue ? (glue = glue->getglue()) : this;
|
|
||||||
}
|
|
||||||
hyperpoint& glueflat() {
|
|
||||||
return glue->flat;
|
|
||||||
}
|
|
||||||
rugpoint() { glue = NULL; }
|
|
||||||
void glueto(rugpoint *x) {
|
|
||||||
x = x->getglue();
|
|
||||||
auto y = getglue();
|
|
||||||
if(x != y) y->glue = x;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
rugpoint *finger_center;
|
rugpoint *finger_center;
|
||||||
ld finger_range = .1;
|
ld finger_range = .1;
|
||||||
ld finger_force = 1;
|
ld finger_force = 1;
|
||||||
|
|
||||||
struct triangle {
|
|
||||||
rugpoint *m[3];
|
|
||||||
triangle(rugpoint *m1, rugpoint *m2, rugpoint *m3) {
|
|
||||||
m[0] = m1; m[1] = m2; m[2] = m3;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
vector<rugpoint*> points;
|
|
||||||
vector<triangle> triangles;
|
|
||||||
|
|
||||||
bool rug_perspective = ISANDROID;
|
bool rug_perspective = ISANDROID;
|
||||||
|
|
||||||
// extra geometry functions
|
// extra geometry functions
|
||||||
@ -368,6 +332,10 @@ bool psort(rugpoint *a, rugpoint *b) {
|
|||||||
return hdist0(a->h) < hdist0(b->h);
|
return hdist0(a->h) < hdist0(b->h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sort_rug_points() {
|
||||||
|
sort(points.begin(), points.end(), psort);
|
||||||
|
}
|
||||||
|
|
||||||
void calcLengths() {
|
void calcLengths() {
|
||||||
for(auto p: points)
|
for(auto p: points)
|
||||||
for(auto& edge: p->edges)
|
for(auto& edge: p->edges)
|
||||||
@ -577,6 +545,8 @@ void comp(cell*& minimum, cell *next) {
|
|||||||
|
|
||||||
void buildRug() {
|
void buildRug() {
|
||||||
|
|
||||||
|
need_mouseh = true;
|
||||||
|
good_shape = false;
|
||||||
if(torus) {
|
if(torus) {
|
||||||
good_shape = true;
|
good_shape = true;
|
||||||
buildTorusRug();
|
buildTorusRug();
|
||||||
@ -619,7 +589,7 @@ void buildRug() {
|
|||||||
for(int i=0; i<20 && subdivide_further(); i++)
|
for(int i=0; i<20 && subdivide_further(); i++)
|
||||||
subdivide();
|
subdivide();
|
||||||
|
|
||||||
sort(points.begin(), points.end(), psort);
|
sort_rug_points();
|
||||||
|
|
||||||
calcLengths();
|
calcLengths();
|
||||||
|
|
||||||
@ -827,6 +797,7 @@ void subdivide() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Xprintf("subdivide (%d,%d)\n", N, size(triangles));
|
Xprintf("subdivide (%d,%d)\n", N, size(triangles));
|
||||||
|
need_mouseh = true;
|
||||||
divides++;
|
divides++;
|
||||||
vector<triangle> otriangles = triangles;
|
vector<triangle> otriangles = triangles;
|
||||||
triangles.clear();
|
triangles.clear();
|
||||||
@ -1001,6 +972,7 @@ void addNewPoints() {
|
|||||||
m.valid = wasvalid || sphere || hdist0(m.h) <= dist;
|
m.valid = wasvalid || sphere || hdist0(m.h) <= dist;
|
||||||
if(m.valid && !wasvalid) {
|
if(m.valid && !wasvalid) {
|
||||||
qvalid++;
|
qvalid++;
|
||||||
|
need_mouseh = true;
|
||||||
|
|
||||||
if(!good_shape) optimize(&m, i > 7);
|
if(!good_shape) optimize(&m, i > 7);
|
||||||
|
|
||||||
@ -1048,7 +1020,7 @@ void physics() {
|
|||||||
for(auto& e: m->anticusp_edges)
|
for(auto& e: m->anticusp_edges)
|
||||||
moved = force(*m, *e.target, anticusp_dist, true) || moved;
|
moved = force(*m, *e.target, anticusp_dist, true) || moved;
|
||||||
|
|
||||||
if(moved) enqueue(m);
|
if(moved) enqueue(m), need_mouseh = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1329,16 +1301,14 @@ void drawRugScene() {
|
|||||||
stereo::set_mask(0);
|
stereo::set_mask(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
|
||||||
stereo::set_mask(0), stereo::set_viewport(0);
|
stereo::set_mask(0), stereo::set_viewport(0);
|
||||||
stereo::set_projection(0);
|
stereo::set_projection(0);
|
||||||
|
|
||||||
need_mouseh = true;
|
|
||||||
|
|
||||||
if(rug_failure) {
|
if(rug_failure) {
|
||||||
rug::close();
|
rug::close();
|
||||||
|
rug::clear_model();
|
||||||
rug::init();
|
rug::init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1348,7 +1318,7 @@ void drawRugScene() {
|
|||||||
|
|
||||||
transmatrix currentrot;
|
transmatrix currentrot;
|
||||||
|
|
||||||
void init() {
|
void reopen() {
|
||||||
if(rugged) return;
|
if(rugged) return;
|
||||||
when_enabled = ticks;
|
when_enabled = ticks;
|
||||||
GLERR("before init");
|
GLERR("before init");
|
||||||
@ -1361,7 +1331,10 @@ void init() {
|
|||||||
rugged = true;
|
rugged = true;
|
||||||
if(renderonce) prepareTexture();
|
if(renderonce) prepareTexture();
|
||||||
if(!rugged) return;
|
if(!rugged) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_model() {
|
||||||
|
clear_model();
|
||||||
genrug = true;
|
genrug = true;
|
||||||
drawthemap();
|
drawthemap();
|
||||||
genrug = false;
|
genrug = false;
|
||||||
@ -1393,17 +1366,26 @@ void init() {
|
|||||||
}
|
}
|
||||||
catch(rug_exception) {
|
catch(rug_exception) {
|
||||||
close();
|
close();
|
||||||
|
clear_model();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
reopen();
|
||||||
|
if(rugged) init_model();
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_model() {
|
||||||
|
triangles.clear();
|
||||||
|
for(int i=0; i<size(points); i++) delete points[i];
|
||||||
|
points.clear();
|
||||||
|
pqueue = queue<rugpoint*> ();
|
||||||
|
}
|
||||||
|
|
||||||
void close() {
|
void close() {
|
||||||
if(!rugged) return;
|
if(!rugged) return;
|
||||||
rugged = false;
|
rugged = false;
|
||||||
delete glbuf;
|
delete glbuf;
|
||||||
triangles.clear();
|
|
||||||
for(int i=0; i<size(points); i++) delete points[i];
|
|
||||||
points.clear();
|
|
||||||
pqueue = queue<rugpoint*> ();
|
|
||||||
finger_center = NULL;
|
finger_center = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1505,6 +1487,7 @@ void actDraw() {
|
|||||||
|
|
||||||
#if CAP_HOLDKEYS
|
#if CAP_HOLDKEYS
|
||||||
Uint8 *keystate = SDL_GetKeyState(NULL);
|
Uint8 *keystate = SDL_GetKeyState(NULL);
|
||||||
|
if(keystate[SDLK_LALT]) alpha /= 10;
|
||||||
|
|
||||||
transmatrix t = Id;
|
transmatrix t = Id;
|
||||||
|
|
||||||
@ -1574,7 +1557,9 @@ void actDraw() {
|
|||||||
if(keystate[SDLK_PAGEDOWN]) model_distance *= exp(alpha);
|
if(keystate[SDLK_PAGEDOWN]) model_distance *= exp(alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(qm) apply_rotation(t);
|
if(qm) {
|
||||||
|
apply_rotation(t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user