2018-07-12 20:18:23 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) Sebastian Krzyszkowiak <dos@dosowisko.net>
|
|
|
|
*
|
|
|
|
* 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 3 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 "internal.h"
|
|
|
|
|
2018-07-18 01:57:31 +02:00
|
|
|
SYMBOL_EXPORT double DotProduct(const double v[], const double u[], int n) {
|
|
|
|
float result = 0.0;
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
result += v[i] * u[i];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-07-12 20:18:23 +02:00
|
|
|
SYMBOL_EXPORT double VectorLength(double x, double y, double z) {
|
|
|
|
return sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
SYMBOL_EXPORT double Wrap(double left, double right, double val) {
|
|
|
|
return left + fmod(val - left, right - left);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYMBOL_EXPORT double Clamp(double left, double right, double val) {
|
|
|
|
if (val > right) {
|
|
|
|
return right;
|
|
|
|
}
|
|
|
|
if (val < left) {
|
|
|
|
return left;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYMBOL_EXPORT double Lerp(double left, double right, double pos) {
|
|
|
|
return left + (right - left) * pos;
|
|
|
|
}
|
|
|
|
|
2018-07-26 17:41:31 +02:00
|
|
|
SYMBOL_EXPORT int Sign(double val) {
|
2018-10-10 21:37:54 +02:00
|
|
|
return (int)(val / fabs(val));
|
2018-07-12 20:18:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SYMBOL_EXPORT double Fract(double val) {
|
|
|
|
return val - floor(val);
|
|
|
|
}
|