| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/lib/vecmat_external.h $ |
| 21 | * $Revision: 3 $ |
| 22 | * $Date: 2/19/99 4:26p $ |
| 23 | * $Author: Jason $ |
| 24 | * |
| 25 | * Contains any header information that can/should be exported to DLLs |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/lib/vecmat_external.h $ |
| 28 | * |
| 29 | * 3 2/19/99 4:26p Jason |
| 30 | * more work on Katmai support |
| 31 | * |
| 32 | * 2 1/21/99 11:15p Jeff |
| 33 | * pulled out some structs and defines from header files and moved them |
| 34 | * into seperate header files so that multiplayer dlls don't require major |
| 35 | * game headers, just those new headers. Side effect is a shorter build |
| 36 | * time. Also cleaned up some header file #includes that weren't needed. |
| 37 | * This affected polymodel.h, object.h, player.h, vecmat.h, room.h, |
| 38 | * manage.h and multi.h |
| 39 | * |
| 40 | * $NoKeywords: $ |
| 41 | */ |
| 42 | |
| 43 | #ifndef VECMAT_EXTERNAL_H |
| 44 | #define VECMAT_EXTERNAL_Hcxx . . $ `lib/vecmat_external.h:44:9`! |
| 45 | |
| 46 | #include <cstdint> |
| 47 | |
| 48 | // Angles are unsigned shorts |
| 49 | typedef uint16_tcxx . . $ uint16_t# anglecxx . . $ angle#; // make sure this matches up with fix.h |
| 50 | |
| 51 | struct angveccxx . . $ angvec# { |
| 52 | anglecxx . . $ angle# pcxx . . $ angvec#p., hcxx . . $ angvec#h., bcxx . . $ angvec#b.; |
| 53 | }; |
| 54 | |
| 55 | #define IDENTITY_MATRIXcxx . . $ `lib/vecmat_external.h:55:9`! \ |
| 56 | { \ |
| 57 | {1.0, 0, 0}, {0, 1.0, 0}, { 0, 0, 1.0 } \ |
| 58 | } |
| 59 | |
| 60 | struct vectorcxx . . $ vector# { |
| 61 | float xcxx . . $ vector#x., ycxx . . $ vector#y., zcxx . . $ vector#z.; |
| 62 | }; |
| 63 | |
| 64 | struct vector4cxx . . $ vector4# { |
| 65 | float xcxx . . $ vector4#x., ycxx . . $ vector4#y., zcxx . . $ vector4#z., kat_padcxx . . $ vector4#kat_pad.; |
| 66 | }; |
| 67 | |
| 68 | struct vector_arraycxx . . $ vector_array# { |
| 69 | float xyzcxx . . $ vector_array#xyz.[3]; |
| 70 | }; |
| 71 | |
| 72 | struct matrixcxx . . $ matrix# { |
| 73 | vectorcxx . . $ vector# rveccxx . . $ matrix#rvec., uveccxx . . $ matrix#uvec., fveccxx . . $ matrix#fvec.; |
| 74 | }; |
| 75 | |
| 76 | struct matrix4cxx . . $ matrix4# { |
| 77 | vector4cxx . . $ vector4# rveccxx . . $ matrix4#rvec., uveccxx . . $ matrix4#uvec., fveccxx . . $ matrix4#fvec.; |
| 78 | }; |
| 79 | |
| 80 | // Zero's out a vector |
| 81 | static inline void vm_MakeZerocxx . . $ vm_MakeZero(ec8cf6451c36d470).(vectorcxx . . $ vector# *v) { v->xcxx . . $ vector#x. = v->ycxx . . $ vector#y. = v->zcxx . . $ vector#z. = 0; } |
| 82 | |
| 83 | // Set an angvec to {0,0,0} |
| 84 | static inline void vm_MakeZerocxx . . $ vm_MakeZero(7b076424e81684e7).(angveccxx . . $ angvec# *a) { a->pcxx . . $ angvec#p. = a->hcxx . . $ angvec#h. = a->bcxx . . $ angvec#b. = 0; } |
| 85 | |
| 86 | // Checks for equality |
| 87 | static inline bool operatorcxx . . $ `operator==`(718c890c104af0f3).==(vectorcxx . . $ vector# a, vectorcxx . . $ vector# b) { |
| 88 | bool equality = false; |
| 89 | // Adds two vectors. |
| 90 | |
| 91 | if (a.xcxx . . $ vector#x. == b.xcxx . . $ vector#x. && a.ycxx . . $ vector#y. == b.ycxx . . $ vector#y. && a.zcxx . . $ vector#z. == b.zcxx . . $ vector#z.) |
| 92 | equality = true; |
| 93 | |
| 94 | return equality; |
| 95 | } |
| 96 | |
| 97 | // Checks for inequality |
| 98 | static inline bool operatorcxx . . $ `operator!=`(718c890c104af0f3).!=(vectorcxx . . $ vector# a, vectorcxx . . $ vector# b) { |
| 99 | bool equality = true; |
| 100 | // Adds two vectors. |
| 101 | |
| 102 | if (a.xcxx . . $ vector#x. == b.xcxx . . $ vector#x. && a.ycxx . . $ vector#y. == b.ycxx . . $ vector#y. && a.zcxx . . $ vector#z. == b.zcxx . . $ vector#z.) |
| 103 | equality = false; |
| 104 | |
| 105 | return equality; |
| 106 | } |
| 107 | |
| 108 | // Adds 2 vectors |
| 109 | static inline vectorcxx . . $ vector# operatorcxx . . $ operator+(b77b703cd1e43e33).+(vectorcxx . . $ vector# a, vectorcxx . . $ vector# b) { |
| 110 | // Adds two vectors. |
| 111 | |
| 112 | a.xcxx . . $ vector#x. += b.xcxx . . $ vector#x.; |
| 113 | a.ycxx . . $ vector#y. += b.ycxx . . $ vector#y.; |
| 114 | a.zcxx . . $ vector#z. += b.zcxx . . $ vector#z.; |
| 115 | |
| 116 | return a; |
| 117 | } |
| 118 | |
| 119 | // Adds 2 vectors |
| 120 | static inline vectorcxx . . $ vector# operatorcxx . . $ `operator+=`(801a8d6f7ab7bef9).+=(vectorcxx . . $ vector# &a, vectorcxx . . $ vector# b) { return (a =cxx . . $ vector#`operator=`(c0842353a20857d). a +cxx . . $ operator+(b77b703cd1e43e33). b); } |
| 121 | |
| 122 | // Adds 2 matrices |
| 123 | static inline matrixcxx . . $ matrix# operatorcxx . . $ operator+(683f8e040c904cb).+(matrixcxx . . $ matrix# a, matrixcxx . . $ matrix# b) { |
| 124 | // Adds two 3x3 matrixs. |
| 125 | |
| 126 | a.rveccxx . . $ matrix#rvec. +=cxx . . $ `operator+=`(801a8d6f7ab7bef9). b.rveccxx . . $ matrix#rvec.; |
| 127 | a.uveccxx . . $ matrix#uvec. +=cxx . . $ `operator+=`(801a8d6f7ab7bef9). b.uveccxx . . $ matrix#uvec.; |
| 128 | a.fveccxx . . $ matrix#fvec. +=cxx . . $ `operator+=`(801a8d6f7ab7bef9). b.fveccxx . . $ matrix#fvec.; |
| 129 | |
| 130 | return a; |
| 131 | } |
| 132 | |
| 133 | // Adds 2 matrices |
| 134 | static inline matrixcxx . . $ matrix# operatorcxx . . $ `operator+=`(3149f8f1fe1d09b5).+=(matrixcxx . . $ matrix# &a, matrixcxx . . $ matrix# b) { return (a =cxx . . $ matrix#`operator=`(e859ffc26b91394f). a +cxx . . $ operator+(683f8e040c904cb). b); } |
| 135 | |
| 136 | // Subtracts 2 vectors |
| 137 | static inline vectorcxx . . $ vector# operatorcxx . . $ operator-(b77b703cd1e43e33).-(vectorcxx . . $ vector# a, vectorcxx . . $ vector# b) { |
| 138 | // subtracts two vectors |
| 139 | |
| 140 | a.xcxx . . $ vector#x. -= b.xcxx . . $ vector#x.; |
| 141 | a.ycxx . . $ vector#y. -= b.ycxx . . $ vector#y.; |
| 142 | a.zcxx . . $ vector#z. -= b.zcxx . . $ vector#z.; |
| 143 | |
| 144 | return a; |
| 145 | } |
| 146 | |
| 147 | // Subtracts 2 vectors |
| 148 | static inline vectorcxx . . $ vector# operatorcxx . . $ `operator-=`(801a8d6f7ab7bef9).-=(vectorcxx . . $ vector# &a, vectorcxx . . $ vector# b) { return (a =cxx . . $ vector#`operator=`(c0842353a20857d). a -cxx . . $ operator-(b77b703cd1e43e33). b); } |
| 149 | |
| 150 | // Subtracts 2 matrices |
| 151 | static inline matrixcxx . . $ matrix# operatorcxx . . $ operator-(683f8e040c904cb).-(matrixcxx . . $ matrix# a, matrixcxx . . $ matrix# b) { |
| 152 | // subtracts two 3x3 matrices |
| 153 | |
| 154 | a.rveccxx . . $ matrix#rvec. =cxx . . $ vector#`operator=`(c0842353a20857d). a.rveccxx . . $ matrix#rvec. -cxx . . $ operator-(b77b703cd1e43e33). b.rveccxx . . $ matrix#rvec.; |
| 155 | a.uveccxx . . $ matrix#uvec. =cxx . . $ vector#`operator=`(c0842353a20857d). a.uveccxx . . $ matrix#uvec. -cxx . . $ operator-(b77b703cd1e43e33). b.uveccxx . . $ matrix#uvec.; |
| 156 | a.fveccxx . . $ matrix#fvec. =cxx . . $ vector#`operator=`(c0842353a20857d). a.fveccxx . . $ matrix#fvec. -cxx . . $ operator-(b77b703cd1e43e33). b.fveccxx . . $ matrix#fvec.; |
| 157 | |
| 158 | return a; |
| 159 | } |
| 160 | |
| 161 | // Subtracts 2 matrices |
| 162 | static inline matrixcxx . . $ matrix# operatorcxx . . $ `operator-=`(3149f8f1fe1d09b5).-=(matrixcxx . . $ matrix# &a, matrixcxx . . $ matrix# b) { return (a =cxx . . $ matrix#`operator=`(e859ffc26b91394f). a -cxx . . $ operator-(683f8e040c904cb). b); } |
| 163 | |
| 164 | // Does a simple dot product calculation |
| 165 | static inline float operatorcxx . . $ `operator*`(4a721543d64e126a).*(vectorcxx . . $ vector# u, vectorcxx . . $ vector# v) { return (u.xcxx . . $ vector#x. * v.xcxx . . $ vector#x.) + (u.ycxx . . $ vector#y. * v.ycxx . . $ vector#y.) + (u.zcxx . . $ vector#z. * v.zcxx . . $ vector#z.); } |
| 166 | |
| 167 | // Scalar multiplication |
| 168 | static inline vectorcxx . . $ vector# operatorcxx . . $ `operator*`(252247219a31502c).*(vectorcxx . . $ vector# v, float s) { |
| 169 | v.xcxx . . $ vector#x. *= s; |
| 170 | v.ycxx . . $ vector#y. *= s; |
| 171 | v.zcxx . . $ vector#z. *= s; |
| 172 | |
| 173 | return v; |
| 174 | } |
| 175 | |
| 176 | // Scalar multiplication |
| 177 | static inline vectorcxx . . $ vector# operatorcxx . . $ `operator*=`(f132838b2cd11d6).*=(vectorcxx . . $ vector# &v, float s) { return (v =cxx . . $ vector#`operator=`(c0842353a20857d). v *cxx . . $ `operator*`(252247219a31502c). s); } |
| 178 | |
| 179 | // Scalar multiplication |
| 180 | static inline vectorcxx . . $ vector# operatorcxx . . $ `operator*`(9d6577ff3e9faa29).*(float s, vectorcxx . . $ vector# v) { return v *cxx . . $ `operator*`(252247219a31502c). s; } |
| 181 | |
| 182 | // Scalar multiplication |
| 183 | static inline matrixcxx . . $ matrix# operatorcxx . . $ `operator*`(5bf4712a21a2cf30).*(float s, matrixcxx . . $ matrix# m) { |
| 184 | m.fveccxx . . $ matrix#fvec. =cxx . . $ vector#`operator=`(c0842353a20857d). m.fveccxx . . $ matrix#fvec. *cxx . . $ `operator*`(252247219a31502c). s; |
| 185 | m.uveccxx . . $ matrix#uvec. =cxx . . $ vector#`operator=`(c0842353a20857d). m.uveccxx . . $ matrix#uvec. *cxx . . $ `operator*`(252247219a31502c). s; |
| 186 | m.rveccxx . . $ matrix#rvec. =cxx . . $ vector#`operator=`(c0842353a20857d). m.rveccxx . . $ matrix#rvec. *cxx . . $ `operator*`(252247219a31502c). s; |
| 187 | |
| 188 | return m; |
| 189 | } |
| 190 | |
| 191 | // Scalar multiplication |
| 192 | static inline matrixcxx . . $ matrix# operatorcxx . . $ `operator*`(2f7784e05c935c16).*(matrixcxx . . $ matrix# m, float s) { return s *cxx . . $ `operator*`(5bf4712a21a2cf30). m; } |
| 193 | |
| 194 | // Scalar multiplication |
| 195 | static inline matrixcxx . . $ matrix# operatorcxx . . $ `operator*=`(4cd1ba218a163e9e).*=(matrixcxx . . $ matrix# &m, float s) { return (m =cxx . . $ matrix#`operator=`(e859ffc26b91394f). m *cxx . . $ `operator*`(2f7784e05c935c16). s); } |
| 196 | |
| 197 | // Scalar division |
| 198 | static inline vectorcxx . . $ vector# operatorcxx . . $ `operator/`(252247219a31502c)./(vectorcxx . . $ vector# src, float n) { |
| 199 | src.xcxx . . $ vector#x. /= n; |
| 200 | src.ycxx . . $ vector#y. /= n; |
| 201 | src.zcxx . . $ vector#z. /= n; |
| 202 | |
| 203 | return src; |
| 204 | } |
| 205 | |
| 206 | // Scalar division |
| 207 | static inline vectorcxx . . $ vector# operatorcxx . . $ `operator/=`(f132838b2cd11d6)./=(vectorcxx . . $ vector# &src, float n) { return (src =cxx . . $ vector#`operator=`(c0842353a20857d). src /cxx . . $ `operator/`(252247219a31502c). n); } |
| 208 | |
| 209 | // Scalar division |
| 210 | static inline matrixcxx . . $ matrix# operatorcxx . . $ `operator/`(2f7784e05c935c16)./(matrixcxx . . $ matrix# src, float n) { |
| 211 | src.fveccxx . . $ matrix#fvec. =cxx . . $ vector#`operator=`(c0842353a20857d). src.fveccxx . . $ matrix#fvec. /cxx . . $ `operator/`(252247219a31502c). n; |
| 212 | src.rveccxx . . $ matrix#rvec. =cxx . . $ vector#`operator=`(c0842353a20857d). src.rveccxx . . $ matrix#rvec. /cxx . . $ `operator/`(252247219a31502c). n; |
| 213 | src.uveccxx . . $ matrix#uvec. =cxx . . $ vector#`operator=`(c0842353a20857d). src.uveccxx . . $ matrix#uvec. /cxx . . $ `operator/`(252247219a31502c). n; |
| 214 | |
| 215 | return src; |
| 216 | } |
| 217 | |
| 218 | // Scalar division |
| 219 | static inline matrixcxx . . $ matrix# operatorcxx . . $ `operator/=`(4cd1ba218a163e9e)./=(matrixcxx . . $ matrix# &src, float n) { return (src =cxx . . $ matrix#`operator=`(e859ffc26b91394f). src /cxx . . $ `operator/`(2f7784e05c935c16). n); } |
| 220 | |
| 221 | // Computes a cross product between u and v, returns the result |
| 222 | // in Normal. |
| 223 | static inline vectorcxx . . $ vector# operatorcxx . . $ `operator^`(b77b703cd1e43e33).^(vectorcxx . . $ vector# u, vectorcxx . . $ vector# v) { |
| 224 | vectorcxx . . $ vector# dest; |
| 225 | |
| 226 | dest.xcxx . . $ vector#x. = (u.ycxx . . $ vector#y. * v.zcxx . . $ vector#z.) - (u.zcxx . . $ vector#z. * v.ycxx . . $ vector#y.); |
| 227 | dest.ycxx . . $ vector#y. = (u.zcxx . . $ vector#z. * v.xcxx . . $ vector#x.) - (u.xcxx . . $ vector#x. * v.zcxx . . $ vector#z.); |
| 228 | dest.zcxx . . $ vector#z. = (u.xcxx . . $ vector#x. * v.ycxx . . $ vector#y.) - (u.ycxx . . $ vector#y. * v.xcxx . . $ vector#x.); |
| 229 | |
| 230 | return dest; |
| 231 | } |
| 232 | |
| 233 | // Matrix transpose |
| 234 | static inline matrixcxx . . $ matrix# operatorcxx . . $ `operator~`(1e820934589b6814).~(matrixcxx . . $ matrix# m) { |
| 235 | float t; |
| 236 | |
| 237 | t = m.uveccxx . . $ matrix#uvec..xcxx . . $ vector#x.; |
| 238 | m.uveccxx . . $ matrix#uvec..xcxx . . $ vector#x. = m.rveccxx . . $ matrix#rvec..ycxx . . $ vector#y.; |
| 239 | m.rveccxx . . $ matrix#rvec..ycxx . . $ vector#y. = t; |
| 240 | t = m.fveccxx . . $ matrix#fvec..xcxx . . $ vector#x.; |
| 241 | m.fveccxx . . $ matrix#fvec..xcxx . . $ vector#x. = m.rveccxx . . $ matrix#rvec..zcxx . . $ vector#z.; |
| 242 | m.rveccxx . . $ matrix#rvec..zcxx . . $ vector#z. = t; |
| 243 | t = m.fveccxx . . $ matrix#fvec..ycxx . . $ vector#y.; |
| 244 | m.fveccxx . . $ matrix#fvec..ycxx . . $ vector#y. = m.uveccxx . . $ matrix#uvec..zcxx . . $ vector#z.; |
| 245 | m.uveccxx . . $ matrix#uvec..zcxx . . $ vector#z. = t; |
| 246 | |
| 247 | return m; |
| 248 | } |
| 249 | |
| 250 | // Negate vector |
| 251 | static inline vectorcxx . . $ vector# operatorcxx . . $ operator-(9e07539e219c6f20).-(vectorcxx . . $ vector# a) { |
| 252 | a.xcxx . . $ vector#x. *= -1; |
| 253 | a.ycxx . . $ vector#y. *= -1; |
| 254 | a.zcxx . . $ vector#z. *= -1; |
| 255 | |
| 256 | return a; |
| 257 | } |
| 258 | |
| 259 | // Apply a matrix to a vector |
| 260 | static inline vectorcxx . . $ vector# operatorcxx . . $ `operator*`(14b8f9ac5c1e7b85).*(vectorcxx . . $ vector# v, matrixcxx . . $ matrix# m) { |
| 261 | vectorcxx . . $ vector# result; |
| 262 | |
| 263 | result.xcxx . . $ vector#x. = v *cxx . . $ `operator*`(4a721543d64e126a). m.rveccxx . . $ matrix#rvec.; |
| 264 | result.ycxx . . $ vector#y. = v *cxx . . $ `operator*`(4a721543d64e126a). m.uveccxx . . $ matrix#uvec.; |
| 265 | result.zcxx . . $ vector#z. = v *cxx . . $ `operator*`(4a721543d64e126a). m.fveccxx . . $ matrix#fvec.; |
| 266 | |
| 267 | return result; |
| 268 | } |
| 269 | |
| 270 | static inline float vm_Dot3Vectorcxx . . $ vm_Dot3Vector(38e0f2941be198c5).(float x, float y, float z, vectorcxx . . $ vector# *v) { return (x * v->xcxx . . $ vector#x.) + (y * v->ycxx . . $ vector#y.) + (z * v->zcxx . . $ vector#z.); } |
| 271 | |
| 272 | #define vm_GetSurfaceNormalcxx . . $ `lib/vecmat_external.h:272:9`! vm_GetNormal |
| 273 | |
| 274 | #endif |