-
Notifications
You must be signed in to change notification settings - Fork 25
/
FC_maya.c
101 lines (92 loc) · 2.6 KB
/
FC_maya.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// mostly ripped from Maya SDK
#include "FC_maya.h"
//init or smtg :)
void fc_InitMayaServer(char *nazwa) {
char *cptr;
cptr = strrchr(nazwa, '/');
if (cptr) strcpy(program, (cptr + 1));
else strcpy(program, nazwa);
serverStatus=FCM_STOP;
}
void fc_StartMayaServer(void) {
client_fd = CapServe(server_name);
if(client_fd>0) serverStatus=FCM_ACTIVE;
base_timeout.tv_sec = 0;
base_timeout.tv_usec = 0;
}
void fc_StopMayaServer(void) {
closesocket(client_fd);
client_fd = -1;
}
int fc_Klient(void) {
CapCommand cmd;
char ruser[64], rhost[64], realhost[64];
fd_set rd_fds;
int status;
FD_ZERO(&rd_fds);
FD_SET((unsigned int)client_fd, &rd_fds);
timeout.tv_sec = base_timeout.tv_sec;
timeout.tv_usec = base_timeout.tv_usec;
status = select(FD_SETSIZE, &rd_fds, NULL, NULL, &timeout);
if(status==0) return 1; //timeout
else if(status>0){
cmd = CapGetCommand(client_fd);
switch (cmd)
{
case CAP_CMD_QUIT:
return -1;
case CAP_CMD_AUTHORIZE:
status = CapGetAuthInfo(client_fd, ruser, rhost, realhost);
if (status < 0) return -1;
status = CapAuthorize(client_fd, 1);
break;
case CAP_CMD_INIT:
status = CapInitialize(client_fd, program);
break;
case CAP_CMD_VERSION:
status = CapVersion(client_fd, program, "1.3.4","Xantus FaceCap server");
break;
//ask for channels
case CAP_CMD_INFO:
if (!channels_created) {
status = create_channels();
if (status < 0) break;
channels_created = 1;
}
status = CapInfo(client_fd, 0.0, 0.0, 0.0, 512 * 1024, 1);
break;
case CAP_CMD_DATA:
get_data();
status = CapData(client_fd);
break;
default:
break;
}
}
return status;
}
//send data
static void get_data(void) {
int i;
for (i=0;i<MAX_MARKERS;i++) {
if(fc_entity[i].curPos[0]!=0 && fc_entity[i].curPos[1]!=0) {
CapSetData(px[i],&fc_entity[i].fixedPos[0]);
CapSetData(py[i],&fc_entity[i].fixedPos[1]);
}
}
return;
}
//create channels after markers beeing initialized
static int create_channels(void) {
int i;
char opis[50];
for (i=0;i<MAX_MARKERS;i++) {
if(fc_entity[i].curPos[0]!=0 && fc_entity[i].curPos[1]!=0) {
sprintf(opis,"%s_x",fc_entity[i].name);
px[i] = CapCreateChannel(opis, CAP_USAGE_XPOS, 1);
sprintf(opis,"%s_y",fc_entity[i].name);
py[i] = CapCreateChannel(opis, CAP_USAGE_YPOS, 1);
}
}
return 0;
}