-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
OrientationData.c
27 lines (25 loc) · 1011 Bytes
/
OrientationData.c
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
#include <Server/Packets/ReceivePackets.h>
#include <Server/Server.h>
#include <Util/Physics.h>
#include <math.h>
void receive_orientation_data(server_t* server, player_t* player, stream_t* data)
{
(void)server;
float x, y, z;
x = stream_read_f(data);
y = stream_read_f(data);
z = stream_read_f(data);
float length = sqrt((x * x) + (y * y) + (z * z));
float norm_legnth = 1 / length;
// Normalize the vectors if their length > 1
if (length > 1.f) {
player->movement.forward_orientation.x = x * norm_legnth;
player->movement.forward_orientation.y = y * norm_legnth;
player->movement.forward_orientation.z = z * norm_legnth;
} else {
player->movement.forward_orientation.x = x;
player->movement.forward_orientation.y = y;
player->movement.forward_orientation.z = z;
}
physics_reorient_player(player, &player->movement.forward_orientation);
}