From 07a43c572ebbcebf63a4732d82cadd2c9e819e5d Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 5 Jan 2021 23:45:50 +1100 Subject: [PATCH] - Build: Extend `spritetype` struct with interpolation variables and numerous methods to do with pos, angle and interpolation of such. --- source/build/include/buildtypes.h | 82 ++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/source/build/include/buildtypes.h b/source/build/include/buildtypes.h index da0ca8a5a..caf5eda00 100644 --- a/source/build/include/buildtypes.h +++ b/source/build/include/buildtypes.h @@ -193,6 +193,13 @@ struct spritetype }; vec3_t pos; }; + union { + struct + { + int32_t ox, oy, oz; + }; + vec3_t opos; + }; uint16_t cstat; int16_t picnum; int8_t shade; @@ -200,7 +207,7 @@ struct spritetype uint8_t xrepeat, yrepeat; int8_t xoffset, yoffset; int16_t sectnum, statnum; - int16_t ang, owner; + int16_t oang, ang, owner; union { struct { @@ -233,6 +240,79 @@ struct spritetype { memset(this, 0, sizeof(*this)); } + + void backupx() + { + opos.x = pos.x; + } + + void backupy() + { + opos.y = pos.y; + } + + void backupz() + { + opos.z = pos.z; + } + + void backupvec2() + { + opos.vec2 = pos.vec2; + } + + void backuppos() + { + opos = pos; + } + + void backupang() + { + oang = ang; + } + + void backuploc() + { + backuppos(); + backupang(); + } + + int32_t interpolatedx(double const smoothratio, int const scale = 16) + { + return ox + MulScale(x - ox, smoothratio, scale); + } + + int32_t interpolatedy(double const smoothratio, int const scale = 16) + { + return oy + MulScale(y - oy, smoothratio, scale); + } + + int32_t interpolatedz(double const smoothratio, int const scale = 16) + { + return oz + MulScale(z - oz, smoothratio, scale); + } + + vec2_t interpolatedvec2(double const smoothratio, int const scale = 16) + { + return vec2_t({ + interpolatedx(smoothratio, scale), + interpolatedy(smoothratio, scale) + }); + } + + vec3_t interpolatedvec3(double const smoothratio, int const scale = 16) + { + return vec3_t({ + interpolatedx(smoothratio, scale), + interpolatedy(smoothratio, scale), + interpolatedz(smoothratio, scale) + }); + } + + int16_t interpolatedang(double const smoothratio) + { + return oang + MulScale(((ang + 1024 - oang) & 2047) - 1024, smoothratio, 16); + } }; using tspritetype = spritetype;