X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fwarpzonelib%2Fmathlib.qc;h=395547036ceb8fa24e6045f3d1aec5b4cb4f8c6a;hp=b948b203eeb36ac4a06d00b6a91ab038b6dc1be3;hb=99c1b6ca80a69e112d410ee493d62f757b2c6df8;hpb=bb80a6aba067167c6ef8d5f3465f03bd34142fa2 diff --git a/qcsrc/warpzonelib/mathlib.qc b/qcsrc/warpzonelib/mathlib.qc index b948b203e..395547036 100644 --- a/qcsrc/warpzonelib/mathlib.qc +++ b/qcsrc/warpzonelib/mathlib.qc @@ -1,11 +1,10 @@ +#include "mathlib.qh" #if defined(CSQC) #include "../dpdefs/csprogsdefs.qh" - #include "mathlib.qh" #elif defined(MENUQC) #elif defined(SVQC) - #include "../dpdefs/progsdefs.qh" #include "../dpdefs/dpextensions.qh" - #include "mathlib.qh" + #include "../dpdefs/progsdefs.qh" #endif int fpclassify(float x) @@ -175,6 +174,20 @@ float tgamma(float x) return exp(v.x) * v.y; } +/** + * Pythonic mod: + * TODO: %% operator? + * + * 1 % 2 == 1 + * -1 % 2 == 1 + * 1 % -2 == -1 + * -1 % -2 == -1 + */ +float pymod(float x, float y) +{ + return x - y * floor(x / y); +} + float nearbyint(float x) { return rint(x); @@ -276,3 +289,11 @@ int isunordered(float x, float y) { return !(x < y || x == y || x > y); } + +vector cross(vector a, vector b) +{ + return + '1 0 0' * (a.y * b.z - a.z * b.y) + + '0 1 0' * (a.z * b.x - a.x * b.z) + + '0 0 1' * (a.x * b.y - a.y * b.x); +}