3 #define _TWR_DICE_THRESHOLD 0.4f
5 const int8_t _twr_dice_vectors[][3] =
19 memset(
self, 0,
sizeof(*
self));
23 self->_threshold = _TWR_DICE_THRESHOLD;
28 self->_threshold = threshold;
33 int8_t vector_x = _twr_dice_vectors[
self->_face][0];
34 int8_t vector_y = _twr_dice_vectors[
self->_face][1];
35 int8_t vector_z = _twr_dice_vectors[
self->_face][2];
39 if ((vector_x == 0 && (x_axis < -self->_threshold || x_axis > self->_threshold)) ||
40 (vector_x == 1 && (x_axis < 1.f - self->_threshold)) ||
41 (vector_x == -1 && (x_axis > -1.f + self->_threshold)))
46 if ((vector_y == 0 && (y_axis < -self->_threshold || y_axis > self->_threshold)) ||
47 (vector_y == 1 && (y_axis < 1.f - self->_threshold)) ||
48 (vector_y == -1 && (y_axis > -1.f + self->_threshold)))
53 if ((vector_z == 0 && (z_axis < -self->_threshold || z_axis > self->_threshold)) ||
54 (vector_z == 1 && (z_axis < 1.f - self->_threshold)) ||
55 (vector_z == -1 && (z_axis > -1.f + self->_threshold)))
62 for (
size_t i = 1; i <= 6; i++)
64 float delta_x = _twr_dice_vectors[i][0] - x_axis;
65 float delta_y = _twr_dice_vectors[i][1] - y_axis;
66 float delta_z = _twr_dice_vectors[i][2] - z_axis;
68 if (delta_x < 0.f) { delta_x = -delta_x; }
69 if (delta_y < 0.f) { delta_y = -delta_y; }
70 if (delta_z < 0.f) { delta_z = -delta_z; }
72 if (delta_x < 1.f - self->_threshold &&
73 delta_y < 1.f - self->_threshold &&
74 delta_z < 1.f - self->_threshold)
void twr_dice_set_threshold(twr_dice_t *self, float threshold)
Set threshold.
twr_dice_face_t
Dice faces.
void twr_dice_init(twr_dice_t *self, twr_dice_face_t start)
Initialize dice.
void twr_dice_feed_vectors(twr_dice_t *self, float x_axis, float y_axis, float z_axis)
Feed dice with X/Y/Z axis vectors.
twr_dice_face_t twr_dice_get_face(twr_dice_t *self)
Get calculated dice face.
struct twr_dice_t twr_dice_t
Dice instance.
@ TWR_DICE_FACE_UNKNOWN
Unknown dice face.
@ TWR_DICE_FACE_6
Dice face 6.
@ TWR_DICE_FACE_1
Dice face 1.
@ TWR_DICE_FACE_5
Dice face 5.
@ TWR_DICE_FACE_4
Dice face 4.
@ TWR_DICE_FACE_3
Dice face 3.
@ TWR_DICE_FACE_2
Dice face 2.