aboutsummaryrefslogtreecommitdiff
path: root/src/poser_imu.c
blob: 7615170be2d5b12ae124b9f6dc91d6b5ac227e85 (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
26
27
28
29
30
31
32
33
#include <survive.h>
#include <survive_imu.h>

#include <stdio.h>
#include <stdlib.h>

int PoserIMU(SurviveObject *so, PoserData *pd) {
	PoserType pt = pd->pt;
	SurviveContext *ctx = so->ctx;
	SurviveIMUTracker *dd = so->PoserData;

	if (!dd) {
		so->PoserData = dd = malloc(sizeof(SurviveIMUTracker));
		*dd = (SurviveIMUTracker){};
	}

	switch (pt) {
	case POSERDATA_IMU: {
		PoserDataIMU *imu = (PoserDataIMU *)pd;

		survive_imu_tracker_integrate(so, dd, imu);

		PoserData_poser_pose_func(pd, so, &dd->pose);

		// if(magnitude3d(dd->pose.Pos) > 1)
		// SV_ERROR("IMU drift");
		return 0;
	}
	}
	return -1;
}

REGISTER_LINKTIME(PoserIMU);