From a798ca74c59ad6fb41705cdec201cb18a78ef997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Fri, 17 Jul 2020 10:51:43 +0300 Subject: [PATCH] Cleanup|Client: Removed the "misc" subdirectory Relevant code moved to libdoomsday. --- doomsday/apps/client/include/misc/r_util.h | 128 --------- doomsday/apps/client/include/render/r_main.h | 82 +++++- .../apps/client/include/render/walledge.h | 2 +- .../resource/lightmaterialdecoration.h | 2 +- .../client/include/{misc => world}/ihplane.h | 0 doomsday/apps/client/src/gl/gl_main.cpp | 25 +- doomsday/apps/client/src/misc/r_util.cpp | 252 ------------------ doomsday/apps/client/src/render/billboard.cpp | 3 +- doomsday/apps/client/src/render/r_main.cpp | 174 +++++++++++- doomsday/apps/client/src/render/r_things.cpp | 16 +- doomsday/apps/client/src/render/rend_main.cpp | 2 +- .../apps/client/src/render/rend_particle.cpp | 2 +- .../apps/client/src/render/rendersystem.cpp | 2 +- .../client/src/resource/texturevariant.cpp | 3 +- doomsday/apps/server/CMakeLists.txt | 1 - .../libs/doomsday/include/doomsday/r_util.h | 40 +++ doomsday/libs/doomsday/src/r_util.cpp | 87 ++++++ 17 files changed, 394 insertions(+), 427 deletions(-) delete mode 100644 doomsday/apps/client/include/misc/r_util.h rename doomsday/apps/client/include/{misc => world}/ihplane.h (100%) delete mode 100644 doomsday/apps/client/src/misc/r_util.cpp create mode 100644 doomsday/libs/doomsday/include/doomsday/r_util.h create mode 100644 doomsday/libs/doomsday/src/r_util.cpp diff --git a/doomsday/apps/client/include/misc/r_util.h b/doomsday/apps/client/include/misc/r_util.h deleted file mode 100644 index d5a848a6e0..0000000000 --- a/doomsday/apps/client/include/misc/r_util.h +++ /dev/null @@ -1,128 +0,0 @@ -/** @file r_util.h Refresh Utility Routines. - * - * @authors Copyright © 2003-2017 Jaakko Keränen - * @authors Copyright © 2006-2015 Daniel Swanson - * - * @par License - * GPL: http://www.gnu.org/licenses/gpl.html - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. This program is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with this program; if not, see: - * http://www.gnu.org/licenses - */ - -#ifndef DE_REFRESH_UTIL_H -#define DE_REFRESH_UTIL_H - -#include -#include -#include - -#include "api_gl.h" - -#ifdef __CLIENT__ -#undef min -#undef max - -/** - * Description of an inclusive..inclusive light intensity range. - * - * @ingroup data - */ -struct LightRange -{ - float min; - float max; - - LightRange(float _min = 0, float _max = 0) : min(_min), max(_max) {} - LightRange(float const minMax[2]) : min(minMax[0]), max(minMax[1]) {} - LightRange(const de::Vec2f &minMax) : min(minMax.x), max(minMax.y) {} - LightRange(const LightRange &other) : min(other.min), max(other.max) {} - - /// Returns a textual representation of the lightlevels. - de::String asText() const { - return de::Stringf("(min: %.2f max: %.2f)", min, max); - } -}; -#endif - -float R_MovementYaw(float const mom[2]); -float R_MovementXYYaw(float momx, float momy); - -float R_MovementPitch(float const mom[3]); -float R_MovementXYZPitch(float momx, float momy, float momz); - -#ifdef __CLIENT__ - -/** - * Get a global angle from Cartesian coordinates in the map coordinate space - * relative to the viewer. - * - * @param point Map point to test. - * - * @return Angle between the test point and view x,y. - */ -angle_t R_ViewPointToAngle(de::Vec2d point); - -/// @copydoc R_ViewPointToAngle() -inline angle_t R_ViewPointToAngle(coord_t x, coord_t y) { - return R_ViewPointToAngle(de::Vec2d(x, y)); -} - -/** - * Determine distance to the specified point relative to the viewer. - * - * @param x X coordinate to test. - * @param y Y coordinate to test. - * - * @return Distance from the viewer to the test point. - */ -coord_t R_ViewPointDistance(coord_t x, coord_t y); - -#endif - -de::Vec3d R_ClosestPointOnPlane(const de::Vec3f &planeNormal, - const de::Vec3d &planePoint, const de::Vec3d &origin); - -#ifdef __CLIENT__ - -void R_ProjectViewRelativeLine2D(coord_t const center[2], dd_bool alignToViewPlane, - coord_t width, coord_t offset, coord_t start[2], coord_t end[2]); - -void R_ProjectViewRelativeLine2D(de::Vec2d const center, bool alignToViewPlane, - coord_t width, coord_t offset, de::Vec2d &start, de::Vec2d &end); - -#endif - -/** - * Scale @a color uniformly so that the highest component becomes one. - */ -void R_AmplifyColor(de::Vec3f &color); - -void R_ScaleAmbientRGB(float *out, const float *in, float mul); - -/** - * Generate texcoords on the surface centered on point. - * - * @param s Texture s coords written back here. - * @param t Texture t coords written back here. - * @param point Point on surface around which texture is centered. - * @param xScale Scale multiplier on the horizontal axis. - * @param yScale Scale multiplier on the vertical axis. - * @param v1 Top left vertex of the surface being projected on. - * @param v2 Bottom right vertex of the surface being projected on. - * @param tangentMatrix Normalized tangent space matrix for the surface being projected to. - * - * @return @c true if the generated coords are within bounds. - */ -bool R_GenerateTexCoords(de::Vec2f &s, de::Vec2f &t, const de::Vec3d &point, - float xScale, float yScale, const de::Vec3d &v1, const de::Vec3d &v2, - const de::Mat3f &tangentMatrix); - -#endif // DE_REFRESH_UTIL_H diff --git a/doomsday/apps/client/include/render/r_main.h b/doomsday/apps/client/include/render/r_main.h index d563b28f7d..7807d3e36b 100644 --- a/doomsday/apps/client/include/render/r_main.h +++ b/doomsday/apps/client/include/render/r_main.h @@ -18,10 +18,10 @@ * 02110-1301 USA */ -#ifndef DE_RENDER_R_MAIN_H -#define DE_RENDER_R_MAIN_H +#pragma once #include "dd_types.h" +#include DE_EXTERN_C int levelFullBright; @@ -41,4 +41,80 @@ void Rend_Draw2DPlayerSprites(); */ void Rend_Draw3DPlayerSprites(); -#endif // DE_RENDER_R_MAIN_H +#ifdef min +# undef min +#endif +#ifdef max +# undef max +#endif + +/** + * Description of an inclusive..inclusive light intensity range. + * + * @ingroup data + */ +struct LightRange +{ + float min; + float max; + + LightRange(float _min = 0, float _max = 0) : min(_min), max(_max) {} + LightRange(float const minMax[2]) : min(minMax[0]), max(minMax[1]) {} + LightRange(const de::Vec2f &minMax) : min(minMax.x), max(minMax.y) {} + LightRange(const LightRange &other) : min(other.min), max(other.max) {} + + /// Returns a textual representation of the lightlevels. + de::String asText() const { + return de::Stringf("(min: %.2f max: %.2f)", min, max); + } +}; + +/** + * Get a global angle from Cartesian coordinates in the map coordinate space + * relative to the viewer. + * + * @param point Map point to test. + * + * @return Angle between the test point and view x,y. + */ +angle_t R_ViewPointToAngle(de::Vec2d point); + +/// @copydoc R_ViewPointToAngle() +inline angle_t R_ViewPointToAngle(coord_t x, coord_t y) { + return R_ViewPointToAngle(de::Vec2d(x, y)); +} + +/** + * Determine distance to the specified point relative to the viewer. + * + * @param x X coordinate to test. + * @param y Y coordinate to test. + * + * @return Distance from the viewer to the test point. + */ +coord_t R_ViewPointDistance(coord_t x, coord_t y); + +void R_ProjectViewRelativeLine2D(coord_t const center[2], dd_bool alignToViewPlane, + coord_t width, coord_t offset, coord_t start[2], coord_t end[2]); + +void R_ProjectViewRelativeLine2D(de::Vec2d const center, bool alignToViewPlane, + coord_t width, coord_t offset, de::Vec2d &start, de::Vec2d &end); + + +/** + * Generate texcoords on the surface centered on point. + * + * @param s Texture s coords written back here. + * @param t Texture t coords written back here. + * @param point Point on surface around which texture is centered. + * @param xScale Scale multiplier on the horizontal axis. + * @param yScale Scale multiplier on the vertical axis. + * @param v1 Top left vertex of the surface being projected on. + * @param v2 Bottom right vertex of the surface being projected on. + * @param tangentMatrix Normalized tangent space matrix for the surface being projected to. + * + * @return @c true if the generated coords are within bounds. + */ +bool R_GenerateTexCoords(de::Vec2f &s, de::Vec2f &t, const de::Vec3d &point, + float xScale, float yScale, const de::Vec3d &v1, const de::Vec3d &v2, + const de::Mat3f &tangentMatrix); diff --git a/doomsday/apps/client/include/render/walledge.h b/doomsday/apps/client/include/render/walledge.h index 021d3e3e82..d425bae4f2 100644 --- a/doomsday/apps/client/include/render/walledge.h +++ b/doomsday/apps/client/include/render/walledge.h @@ -21,9 +21,9 @@ #define RENDER_WALLEDGE #include "world/line.h" +#include "world/ihplane.h" #include "wallspec.h" #include "trianglestripbuilder.h" -#include "misc/ihplane.h" #include #include diff --git a/doomsday/apps/client/include/resource/lightmaterialdecoration.h b/doomsday/apps/client/include/resource/lightmaterialdecoration.h index 60ecfb4901..2f05a51765 100644 --- a/doomsday/apps/client/include/resource/lightmaterialdecoration.h +++ b/doomsday/apps/client/include/resource/lightmaterialdecoration.h @@ -27,7 +27,7 @@ #include #include #include -#include "misc/r_util.h" // LightRange +#include "render/r_main.h" // LightRange #include "resource/clienttexture.h" #include "resource/clientmaterial.h" diff --git a/doomsday/apps/client/include/misc/ihplane.h b/doomsday/apps/client/include/world/ihplane.h similarity index 100% rename from doomsday/apps/client/include/misc/ihplane.h rename to doomsday/apps/client/include/world/ihplane.h diff --git a/doomsday/apps/client/src/gl/gl_main.cpp b/doomsday/apps/client/src/gl/gl_main.cpp index d5eb230ce5..13a475b5f6 100644 --- a/doomsday/apps/client/src/gl/gl_main.cpp +++ b/doomsday/apps/client/src/gl/gl_main.cpp @@ -30,17 +30,6 @@ #include "gl/gl_main.h" #include "api_gl.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "clientapp.h" #include "sys_system.h" // novideo @@ -66,10 +55,22 @@ #include "render/rend_model.h" #include "render/rend_particle.h" #include "render/vr.h" -#include "misc/r_util.h" #include "ui/ui_main.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include using namespace de; diff --git a/doomsday/apps/client/src/misc/r_util.cpp b/doomsday/apps/client/src/misc/r_util.cpp deleted file mode 100644 index cc8341f0ae..0000000000 --- a/doomsday/apps/client/src/misc/r_util.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/** @file r_util.cpp Refresh Utility Routines. - * - * @authors Copyright © 2003-2017 Jaakko Keränen - * @authors Copyright © 2006-2015 Daniel Swanson - * - * @par License - * GPL: http://www.gnu.org/licenses/gpl.html - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. This program is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with this program; if not, see: - * http://www.gnu.org/licenses - */ - -#include "de_base.h" -#include "misc/r_util.h" - -#include -#include -#include - -#ifdef __CLIENT__ -# include "world/p_players.h" - -# include "api_render.h" -# include "render/viewports.h" -#endif - -using namespace de; - -float R_MovementYaw(float const mom[]) -{ - return radianToDegree(atan2f(-mom[MY], mom[MX])); -} - -float R_MovementXYYaw(float momx, float momy) -{ - float mom[2] = { momx, momy }; - return R_MovementYaw(mom); -} - -float R_MovementPitch(float const mom[]) -{ - return radianToDegree(atan2f(1.2f * mom[MZ], V2f_Length(mom))); -} - -float R_MovementXYZPitch(float momx, float momy, float momz) -{ - float mom[3] = { momx, momy, momz }; - return R_MovementPitch(mom); -} - -#ifdef __CLIENT__ - -angle_t R_ViewPointToAngle(Vec2d point) -{ - const viewdata_t *viewData = &viewPlayer->viewport(); - point -= Vec2d(viewData->current.origin); - return M_PointXYToAngle(point.x, point.y); -} - -coord_t R_ViewPointDistance(coord_t x, coord_t y) -{ - const Vec3d &viewOrigin = viewPlayer->viewport().current.origin; - coord_t viewOriginv1[2] = { viewOrigin.x, viewOrigin.y }; - coord_t pointv1[2] = { x, y }; - return M_PointDistance(viewOriginv1, pointv1); -} - -#endif // __CLIENT__ - -Vec3d R_ClosestPointOnPlane(const Vec3f &planeNormal_, - const Vec3d &planePoint_, const Vec3d &origin_) -{ - vec3f_t planeNormal; V3f_Set(planeNormal, planeNormal_.x, planeNormal_.y, planeNormal_.z); - vec3d_t planePoint; V3d_Set(planePoint, planePoint_.x, planePoint_.y, planePoint_.z); - vec3d_t origin; V3d_Set(origin, origin_.x, origin_.y, origin_.z); - vec3d_t point; V3d_ClosestPointOnPlanef(point, planeNormal, planePoint, origin); - return Vec3d(point); -} - -#ifdef __CLIENT__ - -void R_ProjectViewRelativeLine2D(coord_t const center[2], dd_bool alignToViewPlane, - coord_t width, coord_t offset, coord_t start[2], coord_t end[2]) -{ - const viewdata_t *viewData = &viewPlayer->viewport(); - float sinrv, cosrv; - - if(alignToViewPlane) - { - // Should be fully aligned to view plane. - sinrv = -viewData->viewCos; - cosrv = viewData->viewSin; - } - else - { - // Transform the origin point. - coord_t trX = center[VX] - viewData->current.origin.x; - coord_t trY = center[VY] - viewData->current.origin.y; - float thangle = BANG2RAD(bamsAtan2(trY * 10, trX * 10)) - float(de::PI) / 2; - sinrv = sin(thangle); - cosrv = cos(thangle); - } - - start[VX] = center[VX]; - start[VY] = center[VY]; - - start[VX] -= cosrv * ((width / 2) + offset); - start[VY] -= sinrv * ((width / 2) + offset); - end[VX] = start[VX] + cosrv * width; - end[VY] = start[VY] + sinrv * width; -} - -void R_ProjectViewRelativeLine2D(Vec2d const center, bool alignToViewPlane, - coord_t width, coord_t offset, Vec2d &start, Vec2d &end) -{ - const viewdata_t *viewData = &viewPlayer->viewport(); - float sinrv, cosrv; - - if(alignToViewPlane) - { - // Should be fully aligned to view plane. - sinrv = -viewData->viewCos; - cosrv = viewData->viewSin; - } - else - { - // Transform the origin point. - coord_t trX = center[VX] - viewData->current.origin.x; - coord_t trY = center[VY] - viewData->current.origin.y; - float thangle = BANG2RAD(bamsAtan2(trY * 10, trX * 10)) - float(de::PI) / 2; - sinrv = sin(thangle); - cosrv = cos(thangle); - } - - start = center - Vec2d(cosrv * ((width / 2) + offset), - sinrv * ((width / 2) + offset)); - end = start + Vec2d(cosrv * width, sinrv * width); -} - -void R_AmplifyColor(de::Vec3f &rgb) -{ - float max = 0; - - for(int i = 0; i < 3; ++i) - { - if(rgb[i] > max) - max = rgb[i]; - } - if(!max || max == 1) return; - - for(int i = 0; i < 3; ++i) - { - rgb[i] = rgb[i] / max; - } -} - -#endif // __CLIENT__ - -void R_ScaleAmbientRGB(float *out, const float *in, float mul) -{ - mul = de::clamp(0.f, mul, 1.f); - for(int i = 0; i < 3; ++i) - { - float val = in[i] * mul; - if(out[i] < val) - out[i] = val; - } -} - -bool R_GenerateTexCoords(Vec2f &s, Vec2f &t, const Vec3d &point, - float xScale, float yScale, const Vec3d &v1, const Vec3d &v2, - const Mat3f &tangentMatrix) -{ - const Vec3d v1ToPoint = v1 - point; - s[0] = v1ToPoint.dot(tangentMatrix.column(0)/*tangent*/) * xScale + .5f; - t[0] = v1ToPoint.dot(tangentMatrix.column(1)/*bitangent*/) * yScale + .5f; - - // Is the origin point visible? - if(s[0] >= 1 || t[0] >= 1) - return false; // Right on the X axis or below on the Y axis. - - const Vec3d v2ToPoint = v2 - point; - s[1] = v2ToPoint.dot(tangentMatrix.column(0)) * xScale + .5f; - t[1] = v2ToPoint.dot(tangentMatrix.column(1)) * yScale + .5f; - - // Is the end point visible? - if(s[1] <= 0 || t[1] <= 0) - return false; // Left on the X axis or above on the Y axis. - - return true; -} - -#undef R_ChooseAlignModeAndScaleFactor -DE_EXTERN_C dd_bool R_ChooseAlignModeAndScaleFactor(float *scale, int width, int height, - int availWidth, int availHeight, scalemode_t scaleMode) -{ - if(scaleMode == SCALEMODE_STRETCH) - { - if(scale) *scale = 1; - return true; - } - else - { - float heightAspectCorrected = height * 1.2f; - - // First try scaling horizontally to fit the available width. - float factor = float(availWidth) / float(width); - if(factor * heightAspectCorrected <= availHeight) - { - // Fits, use letterbox. - if(scale) *scale = factor; - return false; - } - - // Fit vertically instead. - if(scale) *scale = float(availHeight) / heightAspectCorrected; - return true; // Pillarbox. - } -} - -#undef R_ChooseScaleMode2 -DE_EXTERN_C scalemode_t R_ChooseScaleMode2(int width, int height, int availWidth, int availHeight, - scalemode_t overrideMode, float stretchEpsilon) -{ - const float availRatio = float(availWidth) / availHeight; - const float origRatio = float(width) / (height * 1.2f); - - // Considered identical? - if(INRANGE_OF(availRatio, origRatio, .001f)) - return SCALEMODE_STRETCH; - - if(SCALEMODE_STRETCH == overrideMode || SCALEMODE_NO_STRETCH == overrideMode) - return overrideMode; - - // Within tolerable stretch range? - return INRANGE_OF(availRatio, origRatio, stretchEpsilon)? SCALEMODE_STRETCH : SCALEMODE_NO_STRETCH; -} - -#undef R_ChooseScaleMode -DE_EXTERN_C scalemode_t R_ChooseScaleMode(int width, int height, int availWidth, int availHeight, - scalemode_t overrideMode) -{ - return R_ChooseScaleMode2(availWidth, availHeight, width, height, overrideMode, - DEFAULT_SCALEMODE_STRETCH_EPSILON); -} diff --git a/doomsday/apps/client/src/render/billboard.cpp b/doomsday/apps/client/src/render/billboard.cpp index 7a99f74107..8940235aea 100644 --- a/doomsday/apps/client/src/render/billboard.cpp +++ b/doomsday/apps/client/src/render/billboard.cpp @@ -25,8 +25,8 @@ #include "resource/clienttexture.h" #include "gl/gl_main.h" #include "resource/materialvariantspec.h" -#include "misc/r_util.h" #include "render/rend_main.h" +#include "render/r_main.h" #include "render/rendersystem.h" #include "render/vissprite.h" #include "world/p_players.h" // viewPlayer, ddPlayers @@ -36,6 +36,7 @@ #include #include #include +#include #include using namespace de; diff --git a/doomsday/apps/client/src/render/r_main.cpp b/doomsday/apps/client/src/render/r_main.cpp index e482fff08c..5981ae34dc 100644 --- a/doomsday/apps/client/src/render/r_main.cpp +++ b/doomsday/apps/client/src/render/r_main.cpp @@ -47,18 +47,18 @@ using namespace de; -dint levelFullBright; -dint weaponOffsetScaleY = 1000; -dint psp3d; +int levelFullBright; +int weaponOffsetScaleY = 1000; +int psp3d; -dfloat pspLightLevelMultiplier = 1; -dfloat pspOffset[2]; +float pspLightLevelMultiplier = 1; +float pspOffset[2]; /* * Console variables: */ -dfloat weaponFOVShift = 45; -dfloat weaponOffsetScale = 0.3183f; // 1/Pi +float weaponFOVShift = 45; +float weaponOffsetScale = 0.3183f; // 1/Pi dbyte weaponScaleMode = SCALEMODE_SMART_STRETCH; static const MaterialVariantSpec &pspriteMaterialSpec() @@ -69,9 +69,9 @@ static const MaterialVariantSpec &pspriteMaterialSpec() static void setupPSpriteParams(rendpspriteparams_t &parm, const vispsprite_t &vs) { - static const dint WEAPONTOP = 32; /// @todo Currently hardcoded here and in the plugins. + static const int WEAPONTOP = 32; /// @todo Currently hardcoded here and in the plugins. - const dfloat offScaleY = ::weaponOffsetScaleY / 1000.0f; + const float offScaleY = ::weaponOffsetScaleY / 1000.0f; DE_ASSERT(vs.psp); const ddpsprite_t &psp = *vs.psp; @@ -121,7 +121,7 @@ static void setupPSpriteParams(rendpspriteparams_t &parm, const vispsprite_t &vs Vec4f color = map.lightGrid().evaluate(vs.origin); // Apply light range compression. - for (dint i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) { color[i] += Rend_LightAdaptationDelta(color[i]); } @@ -135,7 +135,7 @@ static void setupPSpriteParams(rendpspriteparams_t &parm, const vispsprite_t &vs const Vec4f color = subsec.lightSourceColorfIntensity(); // No need for distance attentuation. - dfloat lightLevel = color.w; + float lightLevel = color.w; // Add extra light plus bonus. lightLevel += Rend_ExtraLightDelta(); @@ -146,7 +146,7 @@ static void setupPSpriteParams(rendpspriteparams_t &parm, const vispsprite_t &vs Rend_ApplyLightAdaptation(lightLevel); // Determine the final ambientColor. - for (dint i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) { parm.ambientColor[i] = lightLevel * color[i]; } @@ -288,3 +288,153 @@ void Rend_Draw3DPlayerSprites() // Restore normal projection matrix. GL_ProjectionMatrix(false); } + +angle_t R_ViewPointToAngle(Vec2d point) +{ + const viewdata_t *viewData = &viewPlayer->viewport(); + point -= Vec2d(viewData->current.origin); + return M_PointXYToAngle(point.x, point.y); +} + +coord_t R_ViewPointDistance(coord_t x, coord_t y) +{ + const Vec3d &viewOrigin = viewPlayer->viewport().current.origin; + coord_t viewOriginv1[2] = { viewOrigin.x, viewOrigin.y }; + coord_t pointv1[2] = { x, y }; + return M_PointDistance(viewOriginv1, pointv1); +} + +void R_ProjectViewRelativeLine2D(coord_t const center[2], dd_bool alignToViewPlane, + coord_t width, coord_t offset, coord_t start[2], coord_t end[2]) +{ + const viewdata_t *viewData = &viewPlayer->viewport(); + float sinrv, cosrv; + + if(alignToViewPlane) + { + // Should be fully aligned to view plane. + sinrv = -viewData->viewCos; + cosrv = viewData->viewSin; + } + else + { + // Transform the origin point. + coord_t trX = center[VX] - viewData->current.origin.x; + coord_t trY = center[VY] - viewData->current.origin.y; + float thangle = BANG2RAD(bamsAtan2(trY * 10, trX * 10)) - float(de::PI) / 2; + sinrv = sin(thangle); + cosrv = cos(thangle); + } + + start[VX] = center[VX]; + start[VY] = center[VY]; + + start[VX] -= cosrv * ((width / 2) + offset); + start[VY] -= sinrv * ((width / 2) + offset); + end[VX] = start[VX] + cosrv * width; + end[VY] = start[VY] + sinrv * width; +} + +void R_ProjectViewRelativeLine2D(Vec2d const center, bool alignToViewPlane, + coord_t width, coord_t offset, Vec2d &start, Vec2d &end) +{ + const viewdata_t *viewData = &viewPlayer->viewport(); + float sinrv, cosrv; + + if(alignToViewPlane) + { + // Should be fully aligned to view plane. + sinrv = -viewData->viewCos; + cosrv = viewData->viewSin; + } + else + { + // Transform the origin point. + coord_t trX = center[VX] - viewData->current.origin.x; + coord_t trY = center[VY] - viewData->current.origin.y; + float thangle = BANG2RAD(bamsAtan2(trY * 10, trX * 10)) - float(de::PI) / 2; + sinrv = sin(thangle); + cosrv = cos(thangle); + } + + start = center - Vec2d(cosrv * ((width / 2) + offset), + sinrv * ((width / 2) + offset)); + end = start + Vec2d(cosrv * width, sinrv * width); +} + +bool R_GenerateTexCoords(Vec2f &s, Vec2f &t, const Vec3d &point, + float xScale, float yScale, const Vec3d &v1, const Vec3d &v2, + const Mat3f &tangentMatrix) +{ + const Vec3d v1ToPoint = v1 - point; + s[0] = v1ToPoint.dot(tangentMatrix.column(0)/*tangent*/) * xScale + .5f; + t[0] = v1ToPoint.dot(tangentMatrix.column(1)/*bitangent*/) * yScale + .5f; + + // Is the origin point visible? + if(s[0] >= 1 || t[0] >= 1) + return false; // Right on the X axis or below on the Y axis. + + const Vec3d v2ToPoint = v2 - point; + s[1] = v2ToPoint.dot(tangentMatrix.column(0)) * xScale + .5f; + t[1] = v2ToPoint.dot(tangentMatrix.column(1)) * yScale + .5f; + + // Is the end point visible? + if(s[1] <= 0 || t[1] <= 0) + return false; // Left on the X axis or above on the Y axis. + + return true; +} + +#undef R_ChooseAlignModeAndScaleFactor +DE_EXTERN_C dd_bool R_ChooseAlignModeAndScaleFactor(float *scale, int width, int height, + int availWidth, int availHeight, scalemode_t scaleMode) +{ + if(scaleMode == SCALEMODE_STRETCH) + { + if(scale) *scale = 1; + return true; + } + else + { + float heightAspectCorrected = height * 1.2f; + + // First try scaling horizontally to fit the available width. + float factor = float(availWidth) / float(width); + if(factor * heightAspectCorrected <= availHeight) + { + // Fits, use letterbox. + if(scale) *scale = factor; + return false; + } + + // Fit vertically instead. + if(scale) *scale = float(availHeight) / heightAspectCorrected; + return true; // Pillarbox. + } +} + +#undef R_ChooseScaleMode2 +DE_EXTERN_C scalemode_t R_ChooseScaleMode2(int width, int height, int availWidth, int availHeight, + scalemode_t overrideMode, float stretchEpsilon) +{ + const float availRatio = float(availWidth) / availHeight; + const float origRatio = float(width) / (height * 1.2f); + + // Considered identical? + if(INRANGE_OF(availRatio, origRatio, .001f)) + return SCALEMODE_STRETCH; + + if(SCALEMODE_STRETCH == overrideMode || SCALEMODE_NO_STRETCH == overrideMode) + return overrideMode; + + // Within tolerable stretch range? + return INRANGE_OF(availRatio, origRatio, stretchEpsilon)? SCALEMODE_STRETCH : SCALEMODE_NO_STRETCH; +} + +#undef R_ChooseScaleMode +DE_EXTERN_C scalemode_t R_ChooseScaleMode(int width, int height, int availWidth, int availHeight, + scalemode_t overrideMode) +{ + return R_ChooseScaleMode2(availWidth, availHeight, width, height, overrideMode, + DEFAULT_SCALEMODE_STRETCH_EPSILON); +} diff --git a/doomsday/apps/client/src/render/r_things.cpp b/doomsday/apps/client/src/render/r_things.cpp index 57e0d5fbed..4280bb5fa1 100644 --- a/doomsday/apps/client/src/render/r_things.cpp +++ b/doomsday/apps/client/src/render/r_things.cpp @@ -22,31 +22,20 @@ #include "de_platform.h" #include "render/r_things.h" - -#include -#include -#include -#include - #include "clientapp.h" #include "dd_main.h" // App_World() #include "dd_loop.h" // frameTimePos #include "def_main.h" // states -#include "misc/r_util.h" - #include "gl/gl_main.h" #include "gl/gl_tex.h" #include "gl/gl_texmanager.h" // GL_PrepareFlaremap - #include "network/net_main.h" // clients[] - #include "render/rendersystem.h" #include "render/r_main.h" #include "render/angleclipper.h" #include "render/stateanimator.h" #include "render/rend_halo.h" #include "render/vissprite.h" - #include "world/map.h" #include "world/p_object.h" #include "world/p_players.h" @@ -54,7 +43,12 @@ #include "world/convexsubspace.h" #include "world/subsector.h" +#include +#include #include +#include +#include +#include using namespace de; using world::World; diff --git a/doomsday/apps/client/src/render/rend_main.cpp b/doomsday/apps/client/src/render/rend_main.cpp index a8e89682f7..ad542f7742 100644 --- a/doomsday/apps/client/src/render/rend_main.cpp +++ b/doomsday/apps/client/src/render/rend_main.cpp @@ -47,7 +47,6 @@ #include "gl/sys_opengl.h" #include "api_fontrender.h" -#include "misc/r_util.h" #include "render/fx/bloom.h" #include "render/fx/vignette.h" #include "render/fx/lensflares.h" @@ -84,6 +83,7 @@ #include #include #include +#include #include #include #include diff --git a/doomsday/apps/client/src/render/rend_particle.cpp b/doomsday/apps/client/src/render/rend_particle.cpp index a277728013..56361f0285 100644 --- a/doomsday/apps/client/src/render/rend_particle.cpp +++ b/doomsday/apps/client/src/render/rend_particle.cpp @@ -41,11 +41,11 @@ #include "render/vissprite.h" #include "clientapp.h" -#include "misc/r_util.h" #include "sys_system.h" // novideo #include #include +#include #include #include #include diff --git a/doomsday/apps/client/src/render/rendersystem.cpp b/doomsday/apps/client/src/render/rendersystem.cpp index 55005a090e..cd50cdff01 100644 --- a/doomsday/apps/client/src/render/rendersystem.cpp +++ b/doomsday/apps/client/src/render/rendersystem.cpp @@ -44,7 +44,7 @@ #include "world/surface.h" #include "world/contact.h" -#include "misc/r_util.h" +#include using namespace de; diff --git a/doomsday/apps/client/src/resource/texturevariant.cpp b/doomsday/apps/client/src/resource/texturevariant.cpp index bc9b097d1a..87f2979718 100644 --- a/doomsday/apps/client/src/resource/texturevariant.cpp +++ b/doomsday/apps/client/src/resource/texturevariant.cpp @@ -20,8 +20,6 @@ #include "de_base.h" -#include "misc/r_util.h" - #include "gl/gl_defer.h" #include "gl/gl_main.h" #include "gl/gl_tex.h" @@ -33,6 +31,7 @@ #include #include +#include #include #include // M_CeilPow diff --git a/doomsday/apps/server/CMakeLists.txt b/doomsday/apps/server/CMakeLists.txt index 4e0bcae0db..ca0440c144 100644 --- a/doomsday/apps/server/CMakeLists.txt +++ b/doomsday/apps/server/CMakeLists.txt @@ -33,7 +33,6 @@ set (SHARED_WITH_CLIENT ${src}/include/de_base.h ${src}/include/de_platform.h ${src}/include/edit_map.h - ${src}/include/misc/r_util.h ${src}/include/m_profiler.h ${src}/include/network/net_buf.h ${src}/include/network/net_event.h diff --git a/doomsday/libs/doomsday/include/doomsday/r_util.h b/doomsday/libs/doomsday/include/doomsday/r_util.h new file mode 100644 index 0000000000..947cfa8235 --- /dev/null +++ b/doomsday/libs/doomsday/include/doomsday/r_util.h @@ -0,0 +1,40 @@ +/** @file r_util.h Refresh Utility Routines. + * + * @authors Copyright © 2003-2017 Jaakko Keränen + * @authors Copyright © 2006-2015 Daniel Swanson + * + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. This program is distributed in the hope that it + * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. You should have received a copy of the GNU + * General Public License along with this program; if not, see: + * http://www.gnu.org/licenses + */ + +#pragma once + +#include "libdoomsday.h" +#include + +LIBDOOMSDAY_PUBLIC float R_MovementYaw(float const mom[2]); +LIBDOOMSDAY_PUBLIC float R_MovementXYYaw(float momx, float momy); + +LIBDOOMSDAY_PUBLIC float R_MovementPitch(float const mom[3]); +LIBDOOMSDAY_PUBLIC float R_MovementXYZPitch(float momx, float momy, float momz); + +LIBDOOMSDAY_PUBLIC de::Vec3d R_ClosestPointOnPlane(const de::Vec3f &planeNormal, + const de::Vec3d &planePoint, + const de::Vec3d &origin); + +/** + * Scale @a color uniformly so that the highest component becomes one. + */ +LIBDOOMSDAY_PUBLIC void R_AmplifyColor(de::Vec3f &color); + +LIBDOOMSDAY_PUBLIC void R_ScaleAmbientRGB(float *out, const float *in, float mul); diff --git a/doomsday/libs/doomsday/src/r_util.cpp b/doomsday/libs/doomsday/src/r_util.cpp new file mode 100644 index 0000000000..d985deda6e --- /dev/null +++ b/doomsday/libs/doomsday/src/r_util.cpp @@ -0,0 +1,87 @@ +/** @file r_util.cpp Refresh Utility Routines. + * + * @authors Copyright © 2003-2017 Jaakko Keränen + * @authors Copyright © 2006-2015 Daniel Swanson + * + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. This program is distributed in the hope that it + * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. You should have received a copy of the GNU + * General Public License along with this program; if not, see: + * http://www.gnu.org/licenses + */ + +#include "doomsday/r_util.h" +#include "dd_share.h" + +#include +#include +#include + +using namespace de; + +float R_MovementYaw(float const mom[]) +{ + return radianToDegree(atan2f(-mom[MY], mom[MX])); +} + +float R_MovementXYYaw(float momx, float momy) +{ + float mom[2] = { momx, momy }; + return R_MovementYaw(mom); +} + +float R_MovementPitch(float const mom[]) +{ + return radianToDegree(atan2f(1.2f * mom[MZ], V2f_Length(mom))); +} + +float R_MovementXYZPitch(float momx, float momy, float momz) +{ + float mom[3] = { momx, momy, momz }; + return R_MovementPitch(mom); +} + +Vec3d R_ClosestPointOnPlane(const Vec3f &planeNormal_, + const Vec3d &planePoint_, const Vec3d &origin_) +{ + vec3f_t planeNormal; V3f_Set(planeNormal, planeNormal_.x, planeNormal_.y, planeNormal_.z); + vec3d_t planePoint; V3d_Set(planePoint, planePoint_.x, planePoint_.y, planePoint_.z); + vec3d_t origin; V3d_Set(origin, origin_.x, origin_.y, origin_.z); + vec3d_t point; V3d_ClosestPointOnPlanef(point, planeNormal, planePoint, origin); + return Vec3d(point); +} + +void R_AmplifyColor(de::Vec3f &rgb) +{ + float max = 0; + + for(int i = 0; i < 3; ++i) + { + if(rgb[i] > max) + max = rgb[i]; + } + if(!max || max == 1) return; + + for(int i = 0; i < 3; ++i) + { + rgb[i] = rgb[i] / max; + } +} + +void R_ScaleAmbientRGB(float *out, const float *in, float mul) +{ + mul = de::clamp(0.f, mul, 1.f); + for(int i = 0; i < 3; ++i) + { + float val = in[i] * mul; + if(out[i] < val) + out[i] = val; + } +}