From 4f08b20df5ae90966429074cd38cd35957823199 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 31 Dec 2014 12:53:29 +0100 Subject: [PATCH] - consider pixel stretching when rendering models. For non-voxels an aspect ratio of 1:1 must always be assumed while voxels need to be stretched so that 1 voxel unit == 1 map unit. --- src/gl/models/gl_models.cpp | 6 ++++++ src/gl/models/gl_models.h | 4 ++-- src/gl/models/gl_models_md2.cpp | 4 ---- src/gl/models/gl_models_md3.cpp | 2 +- src/gl/models/gl_voxels.cpp | 11 +++++++++++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/gl/models/gl_models.cpp b/src/gl/models/gl_models.cpp index 13a1ef9c3..bfbf21dd2 100644 --- a/src/gl/models/gl_models.cpp +++ b/src/gl/models/gl_models.cpp @@ -915,6 +915,12 @@ void gl_RenderModel(GLSprite * spr) gl_RenderState.mModelMatrix.rotate(-ANGLE_TO_FLOAT(smf->angleoffset), 0, 1, 0); gl_RenderState.mModelMatrix.rotate(smf->pitchoffset, 0, 0, 1); gl_RenderState.mModelMatrix.rotate(-smf->rolloffset, 1, 0, 0); + + // consider the pixel stretching. For non-voxels this must be factored out here + float stretch = (smf->models[0] != NULL ? smf->models[0]->getAspectFactor() : 1.f) / glset.pixelstretch; + gl_RenderState.mModelMatrix.scale(1, stretch, 1); + + gl_RenderState.EnableModelMatrix(true); gl_RenderFrameModels( smf, spr->actor->state, spr->actor->tics, RUNTIME_TYPE(spr->actor), NULL, translation ); gl_RenderState.EnableModelMatrix(false); diff --git a/src/gl/models/gl_models.h b/src/gl/models/gl_models.h index b80a11df4..0d479b68c 100644 --- a/src/gl/models/gl_models.h +++ b/src/gl/models/gl_models.h @@ -11,8 +11,6 @@ enum { VX, VZ, VY }; -static const float rModelAspectMod = 1 / 1.2f; //.833334f; - #define MD2_MAGIC 0x32504449 #define DMD_MAGIC 0x4D444D44 #define MD3_MAGIC 0x33504449 @@ -35,6 +33,7 @@ public: virtual int FindFrame(const char * name) = 0; virtual void RenderFrame(FTexture * skin, int frame, int frame2, double inter, int translation=0) = 0; virtual void BuildVertexBuffer() = 0; + virtual float getAspectFactor() { return 1.f; } FModelVertexBuffer *mVBuf; FString mFileName; @@ -298,6 +297,7 @@ public: virtual void RenderFrame(FTexture * skin, int frame, int frame2, double inter, int translation=0); FTexture *GetPaletteTexture() const { return mPalette; } void BuildVertexBuffer(); + float getAspectFactor(); }; diff --git a/src/gl/models/gl_models_md2.cpp b/src/gl/models/gl_models_md2.cpp index 21e24c768..402b20472 100644 --- a/src/gl/models/gl_models_md2.cpp +++ b/src/gl/models/gl_models_md2.cpp @@ -186,8 +186,6 @@ bool FDMDModel::Load(const char * path, int, const char * buffer, int length) frame->vertices[k].xyz[axis[c]] = (pVtx->vertex[c] * FLOAT(pfr->scale[c]) + FLOAT(pfr->translate[c])); } - // Aspect undo. - frame->vertices[k].xyz[VZ] *= rModelAspectMod; } } @@ -467,8 +465,6 @@ bool FMD2Model::Load(const char * path, int, const char * buffer, int length) frame->vertices[k].xyz[axis[c]] = (pVtx->vertex[c] * pfr->scale[c] + pfr->translate[c]); } - // Aspect ratio adjustment (1.33 -> 1.6.) - frame->vertices[k].xyz[VZ] *= rModelAspectMod; } } diff --git a/src/gl/models/gl_models_md3.cpp b/src/gl/models/gl_models_md3.cpp index cdd8d7082..9cc72307c 100644 --- a/src/gl/models/gl_models_md3.cpp +++ b/src/gl/models/gl_models_md3.cpp @@ -200,7 +200,7 @@ bool FMD3Model::Load(const char * path, int, const char * buffer, int length) { s->vertices[i].x = LittleShort(vt[i].x)/64.f; s->vertices[i].y = LittleShort(vt[i].y)/64.f; - s->vertices[i].z = LittleShort(vt[i].z)/64.f * rModelAspectMod; + s->vertices[i].z = LittleShort(vt[i].z)/64.f; UnpackVector( LittleShort(vt[i].n), s->vertices[i].nx, s->vertices[i].ny, s->vertices[i].nz); } } diff --git a/src/gl/models/gl_voxels.cpp b/src/gl/models/gl_voxels.cpp index 62377c681..c092f9dd7 100644 --- a/src/gl/models/gl_voxels.cpp +++ b/src/gl/models/gl_voxels.cpp @@ -420,6 +420,17 @@ int FVoxelModel::FindFrame(const char * name) return 0; } +//=========================================================================== +// +// Voxels need aspect ratio correction according to the current map's setting +// +//=========================================================================== + +float FVoxelModel::getAspectFactor() +{ + return glset.pixelstretch; +} + //=========================================================================== // // Voxels never interpolate between frames, they only have one.