mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-12-25 01:20:37 +00:00
utilities to create geometry raytracers which use only HyperRogue's control scheme
This commit is contained in:
parent
409f171ca7
commit
76e6dc2002
@ -797,6 +797,8 @@ static const flagtype qSINGLE = Flag(20);
|
|||||||
static const flagtype qDEPRECATED = Flag(21);
|
static const flagtype qDEPRECATED = Flag(21);
|
||||||
static const flagtype qINFMIXED = Flag(22);
|
static const flagtype qINFMIXED = Flag(22);
|
||||||
|
|
||||||
|
static const flagtype qRAYONLY = Flag(23);
|
||||||
|
|
||||||
// note: dnext assumes that x&7 equals 7
|
// note: dnext assumes that x&7 equals 7
|
||||||
static const int SEE_ALL = 50;
|
static const int SEE_ALL = 50;
|
||||||
static const int OINF = 100;
|
static const int OINF = 100;
|
||||||
|
@ -2060,8 +2060,12 @@ EX transmatrix& get_view_orientation() {
|
|||||||
return prod ? NLP : View;
|
return prod ? NLP : View;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EX hookset<bool(const transmatrix&)> *hooks_rotate_view;
|
||||||
|
EX hookset<bool(const hyperpoint&)> *hooks_shift_view;
|
||||||
|
|
||||||
/** rotate the view using the given rotation matrix */
|
/** rotate the view using the given rotation matrix */
|
||||||
EX void rotate_view(transmatrix T) {
|
EX void rotate_view(transmatrix T) {
|
||||||
|
if(callhandlers(false, hooks_rotate_view, T)) return;
|
||||||
transmatrix& which = get_view_orientation();
|
transmatrix& which = get_view_orientation();
|
||||||
which = T * which;
|
which = T * which;
|
||||||
if(!prod && !nonisotropic) current_display->which_copy = T * current_display->which_copy;
|
if(!prod && !nonisotropic) current_display->which_copy = T * current_display->which_copy;
|
||||||
@ -2085,6 +2089,7 @@ EX transmatrix get_shift_view_of(const hyperpoint H, const transmatrix V) {
|
|||||||
|
|
||||||
/** shift the view according to the given tangent vector */
|
/** shift the view according to the given tangent vector */
|
||||||
EX void shift_view(hyperpoint H) {
|
EX void shift_view(hyperpoint H) {
|
||||||
|
if(callhandlers(false, hooks_shift_view, H)) return;
|
||||||
auto oView = View;
|
auto oView = View;
|
||||||
View = get_shift_view_of(H, View);
|
View = get_shift_view_of(H, View);
|
||||||
auto& wc = current_display->which_copy;
|
auto& wc = current_display->which_copy;
|
||||||
|
@ -1185,6 +1185,7 @@ void geometry_information::configure_floorshapes() {
|
|||||||
|
|
||||||
void geometry_information::prepare_shapes() {
|
void geometry_information::prepare_shapes() {
|
||||||
require_basics();
|
require_basics();
|
||||||
|
if(cgflags & qRAYONLY) return;
|
||||||
#if MAXMDIM >= 4
|
#if MAXMDIM >= 4
|
||||||
if(GDIM == 3 && !floor_textures) make_floor_textures();
|
if(GDIM == 3 && !floor_textures) make_floor_textures();
|
||||||
#endif
|
#endif
|
||||||
|
@ -78,6 +78,7 @@ EX bool available() {
|
|||||||
|
|
||||||
/** do we want to use the raycaster? */
|
/** do we want to use the raycaster? */
|
||||||
EX bool requested() {
|
EX bool requested() {
|
||||||
|
if(cgflags & qRAYONLY) return true;
|
||||||
if(!want_use) return false;
|
if(!want_use) return false;
|
||||||
#if CAP_TEXTURE
|
#if CAP_TEXTURE
|
||||||
if(texture::config.tstate == texture::tsActive) return false;
|
if(texture::config.tstate == texture::tsActive) return false;
|
||||||
@ -87,6 +88,7 @@ EX bool requested() {
|
|||||||
return racing::on || quotient;
|
return racing::on || quotient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if HDR
|
||||||
struct raycaster : glhr::GLprogram {
|
struct raycaster : glhr::GLprogram {
|
||||||
GLint uStart, uStartid, uM, uLength, uFovX, uFovY, uIPD, uShift;
|
GLint uStart, uStartid, uM, uLength, uFovX, uFovY, uIPD, uShift;
|
||||||
GLint uWallstart, uWallX, uWallY;
|
GLint uWallstart, uWallX, uWallY;
|
||||||
@ -96,7 +98,11 @@ struct raycaster : glhr::GLprogram {
|
|||||||
GLint uBLevel;
|
GLint uBLevel;
|
||||||
GLint uPosX, uPosY;
|
GLint uPosX, uPosY;
|
||||||
|
|
||||||
raycaster(string vsh, string fsh) : GLprogram(vsh, fsh) {
|
raycaster(string vsh, string fsh);
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
raycaster::raycaster(string vsh, string fsh) : GLprogram(vsh, fsh) {
|
||||||
println(hlog, "assigning");
|
println(hlog, "assigning");
|
||||||
uStart = glGetUniformLocation(_program, "uStart");
|
uStart = glGetUniformLocation(_program, "uStart");
|
||||||
uStartid = glGetUniformLocation(_program, "uStartid");
|
uStartid = glGetUniformLocation(_program, "uStartid");
|
||||||
@ -122,8 +128,6 @@ struct raycaster : glhr::GLprogram {
|
|||||||
uExpDecay = glGetUniformLocation(_program, "uExpDecay");
|
uExpDecay = glGetUniformLocation(_program, "uExpDecay");
|
||||||
uExpStart = glGetUniformLocation(_program, "uExpStart");
|
uExpStart = glGetUniformLocation(_program, "uExpStart");
|
||||||
|
|
||||||
uShift = glGetUniformLocation(_program, "uShift");
|
|
||||||
|
|
||||||
uBLevel = glGetUniformLocation(_program, "uBLevel");
|
uBLevel = glGetUniformLocation(_program, "uBLevel");
|
||||||
|
|
||||||
tConnections = glGetUniformLocation(_program, "tConnections");
|
tConnections = glGetUniformLocation(_program, "tConnections");
|
||||||
@ -133,7 +137,6 @@ struct raycaster : glhr::GLprogram {
|
|||||||
uPosX = glGetUniformLocation(_program, "uPosX");
|
uPosX = glGetUniformLocation(_program, "uPosX");
|
||||||
uPosY = glGetUniformLocation(_program, "uPosY");
|
uPosY = glGetUniformLocation(_program, "uPosY");
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
shared_ptr<raycaster> our_raycaster;
|
shared_ptr<raycaster> our_raycaster;
|
||||||
|
|
||||||
@ -166,6 +169,9 @@ string build_getter(string type, string name, int index) {
|
|||||||
#define GET(array, index) array "[" index "]"
|
#define GET(array, index) array "[" index "]"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
EX hookset<void(string&, string&)> *hooks_rayshader;
|
||||||
|
EX hookset<bool(shared_ptr<raycaster>)> *hooks_rayset;
|
||||||
|
|
||||||
void enable_raycaster() {
|
void enable_raycaster() {
|
||||||
if(geometry != last_geometry) reset_raycaster();
|
if(geometry != last_geometry) reset_raycaster();
|
||||||
last_geometry = geometry;
|
last_geometry = geometry;
|
||||||
@ -815,6 +821,8 @@ void enable_raycaster() {
|
|||||||
|
|
||||||
fsh += fmain;
|
fsh += fmain;
|
||||||
|
|
||||||
|
callhooks(hooks_rayshader, vsh, fsh);
|
||||||
|
|
||||||
our_raycaster = make_shared<raycaster> (vsh, fsh);
|
our_raycaster = make_shared<raycaster> (vsh, fsh);
|
||||||
}
|
}
|
||||||
full_enable(our_raycaster);
|
full_enable(our_raycaster);
|
||||||
@ -880,6 +888,10 @@ EX void cast() {
|
|||||||
glUniform1f(o->uFovX, cd->tanfov / (vid.stereo_mode == sLR ? 2 : 1));
|
glUniform1f(o->uFovX, cd->tanfov / (vid.stereo_mode == sLR ? 2 : 1));
|
||||||
glUniform1f(o->uFovY, cd->tanfov * cd->ysize / cd->xsize);
|
glUniform1f(o->uFovY, cd->tanfov * cd->ysize / cd->xsize);
|
||||||
|
|
||||||
|
glUniform1f(o->uPosX, -((cd->xcenter-cd->xtop)*2./cd->xsize - 1));
|
||||||
|
glUniform1f(o->uPosY, -((cd->ycenter-cd->ytop)*2./cd->ysize - 1));
|
||||||
|
|
||||||
|
if(!callhandlers(false, hooks_rayset, o)) {
|
||||||
deg = S7;
|
deg = S7;
|
||||||
if(prod) deg += 2;
|
if(prod) deg += 2;
|
||||||
|
|
||||||
@ -934,9 +946,6 @@ EX void cast() {
|
|||||||
glUniform1f(o->uIPD, vid.ipd);
|
glUniform1f(o->uIPD, vid.ipd);
|
||||||
GLERR("uniform mediump IPD");
|
GLERR("uniform mediump IPD");
|
||||||
|
|
||||||
glUniform1f(o->uPosX, -((cd->xcenter-cd->xtop)*2./cd->xsize - 1));
|
|
||||||
glUniform1f(o->uPosY, -((cd->ycenter-cd->ytop)*2./cd->ysize - 1));
|
|
||||||
|
|
||||||
vector<transmatrix> ms;
|
vector<transmatrix> ms;
|
||||||
for(int j=0; j<S7; j++) ms.push_back(currentmap->iadj(cwt.at, j));
|
for(int j=0; j<S7; j++) ms.push_back(currentmap->iadj(cwt.at, j));
|
||||||
if(prod) ms.push_back(mscale(Id, +cgi.plevel));
|
if(prod) ms.push_back(mscale(Id, +cgi.plevel));
|
||||||
@ -1057,6 +1066,8 @@ EX void cast() {
|
|||||||
auto cols = glhr::acolor(darkena(backcolor, 0, 0xFF));
|
auto cols = glhr::acolor(darkena(backcolor, 0, 0xFF));
|
||||||
glUniform4f(o->uFogColor, cols[0], cols[1], cols[2], cols[3]);
|
glUniform4f(o->uFogColor, cols[0], cols[1], cols[2], cols[3]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
glVertexAttribPointer(hr::aPosition, 4, GL_FLOAT, GL_FALSE, sizeof(glvertex), &screen[0]);
|
glVertexAttribPointer(hr::aPosition, 4, GL_FLOAT, GL_FALSE, sizeof(glvertex), &screen[0]);
|
||||||
if(ray::comparison_mode)
|
if(ray::comparison_mode)
|
||||||
glhr::set_depthtest(false);
|
glhr::set_depthtest(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user