Skip to content

Commit

Permalink
Add option to configure fov on widescreens
Browse files Browse the repository at this point in the history
  • Loading branch information
cyxx committed Oct 18, 2020
1 parent 2085822 commit 10874df
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
3 changes: 2 additions & 1 deletion raycast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,8 @@ void Game::rayCastWall(int x, int z) {
cellMap->rayCastCounter = _rayCastCounter;
}
}
for (int x = 0; x < kScreenWidth; ++x) {
const int margin = kScreenWidth / 2;
for (int x = -margin; x < kScreenWidth + margin; ++x) {
rayCast(0, x, 0, kRayCastWall);
}
}
22 changes: 14 additions & 8 deletions render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct timeval _frameTimeStamp;
Render::Render(const RenderParams *params) {
memset(_clut, 0, sizeof(_clut));
_aspectRatio = 1.;
_correction = 1.;
_fov = 0;
_screenshotBuf = 0;
memset(&_overlay, 0, sizeof(_overlay));
_overlay.r = _overlay.g = _overlay.b = 255;
Expand Down Expand Up @@ -202,11 +202,11 @@ void Render::flushCachedTextures() {
_overlay.tex = 0;
}

void Render::resizeScreen(int w, int h, float *p, float correction) {
void Render::resizeScreen(int w, int h, float *p, int fov) {
_w = w;
_h = h;
_aspectRatio = p[2] / p[3];
_correction = correction / (4 / 3.);
_fov = fov / 360.;
_viewport.x = 0;
_viewport.y = 0;
_viewport.w = w;
Expand Down Expand Up @@ -559,7 +559,7 @@ void Render::clearScreen() {
}

void Render::setupProjection(int mode) {
const GLfloat aspect = 1.5 * _aspectRatio / _correction;
const GLfloat aspect = 1.5 * _aspectRatio;

switch (mode) {
case kProj2D:
Expand All @@ -581,7 +581,7 @@ void Render::setupProjection(int mode) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-.5, .5, -aspect / 2, 0., 1., 512.);
glTranslatef(0., 0., -20. * _correction);
glTranslatef(0., 0., -20.);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Expand All @@ -602,7 +602,7 @@ void Render::setupProjection(int mode) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-.5, .5, -aspect / 2, 0., 1., 4096.);
glTranslatef(0., 0., -64. * _correction);
glTranslatef(0., 0., -64.);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Expand All @@ -622,8 +622,14 @@ void Render::setupProjection(int mode) {
case kProjGame:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-.5, .5, -aspect / 2, 0., 1., 1024);
glTranslatef(0., 0., -16. * _correction);
if (_fov != 0.) {
const float h = -tan(_fov * .5) * 7.5;
const float w = aspect * h / 2;
glFrustum(w, -w, h, 0, 1., 1024);
} else {
glFrustum(-.5, .5, -aspect / 2, 0., 1., 1024);
}
glTranslatef(0., 0., -16.);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Expand Down
4 changes: 2 additions & 2 deletions render.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct Render {
uint8_t _clut[256 * 3];
int _w, _h;
float _aspectRatio;
float _correction;
float _fov;
uint8_t *_screenshotBuf;
struct {
bool rgbTex;
Expand Down Expand Up @@ -95,7 +95,7 @@ struct Render {
void clearScreen();
void setupProjection(int mode);
void drawOverlay();
void resizeScreen(int w, int h, float *p, float correction);
void resizeScreen(int w, int h, float *p, int fov);

const uint8_t *captureScreen(int *w, int *h);
};
Expand Down
22 changes: 7 additions & 15 deletions stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static const char *USAGE =
" --subtitles Display cutscene subtitles\n"
" --savepath=PATH Path to save files (default '.')\n"
" --fullscreen Fullscreen display\n"
" --widescreen=X:Y Widescreen ratio (4:3 or 16:9)\n"
" --fov=DEG Field of vision in degrees (75-130)\n"
" --soundfont=FILE SoundFont (.sf2) file for music\n"
" --texturefilter=FILTER Texture filter (default 'linear')\n"
" --texturescaler=NAME Texture scaler (default 'scale2x')\n"
Expand Down Expand Up @@ -97,7 +97,7 @@ struct GameStub_F2B : GameStub {
GameParams _params;
FileLanguage _fileLanguage, _fileVoice;
int _displayMode;
float _aspectRatio;
int _fov;
int _state, _nextState;
int _slotState;
bool _loadState, _saveState;
Expand All @@ -119,7 +119,7 @@ struct GameStub_F2B : GameStub {
_renderParams.gouraud = true;
_textureFilter = 0;
_textureScaler = 0;
_aspectRatio = 0;
_fov = 0;
}

void setState(int state) {
Expand Down Expand Up @@ -185,7 +185,7 @@ struct GameStub_F2B : GameStub {
{ "savepath", required_argument, 0, 7 },
{ "debug", required_argument, 0, 8 },
{ "fullscreen", no_argument, 0, 9 },
{ "widescreen", required_argument, 0, 10 },
{ "fov", required_argument, 0, 10 },
{ "alt-level", required_argument, 0, 11 },
{ "soundfont", required_argument, 0, 12 },
{ "texturefilter", required_argument, 0, 13 },
Expand Down Expand Up @@ -234,12 +234,7 @@ struct GameStub_F2B : GameStub {
_displayMode = kDisplayModeFullscreen;
break;
case 10:
{
int x, y;
if (sscanf(optarg, "%d:%d", &x, &y) == 2) {
_aspectRatio = x / (float)y;
}
}
_fov = atoi(optarg);
break;
case 11: {
static const char *levels[] = {
Expand Down Expand Up @@ -318,10 +313,7 @@ struct GameStub_F2B : GameStub {
return _displayMode;
}
virtual float getAspectRatio(bool widescreen) {
if (_aspectRatio <= 0) {
_aspectRatio = widescreen ? (16 / 9.) : (4 / 3.);
}
return _aspectRatio;
return 4 / 3.;
}
virtual bool hasCursor() {
return _params.mouseMode || _params.touchMode;
Expand Down Expand Up @@ -545,7 +537,7 @@ struct GameStub_F2B : GameStub {
}
}
virtual void initGL(int w, int h, float *ar) {
_render->resizeScreen(w, h, ar, _aspectRatio);
_render->resizeScreen(w, h, ar, _fov);
}
virtual void drawGL() {
_render->drawOverlay();
Expand Down

0 comments on commit 10874df

Please sign in to comment.