aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
blob: 10d4c09539c311d51f81dad12e8145704a20e7cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "util.h"

AxisAngle AxisAngleIdentity() {
	return (AxisAngle){Vector3Zero(), 0.0};
}

float signum(float n) {
	if (n > 0.0)
		return 1.0;
	else if (n < 0.0)
		return -1.0;
	else
		return 0.0;
}

float closestAngle(float a1, float a2) {
	float a = fmodf(a1, PI);
	float b = fmodf(a2, PI);
	float dir = b - a;

	if (fabsf(dir) > (PI/2))
		dir = -(signum(dir) * PI) + dir;

	return dir;
}