]> git.mxchange.org Git - flightgear.git/blob - examples/netfdm/main.cpp
Restore inclusion of GLU.h
[flightgear.git] / examples / netfdm / main.cpp
1 #include <windows.h>
2 #include <time.h>
3 #include <iostream>
4 using namespace std;
5
6 #include <net_fdm.hxx>
7
8 double htond (double x) 
9 {
10     int * p = (int*)&x;
11     int tmp = p[0];
12     p[0] = htonl(p[1]);
13     p[1] = htonl(tmp);
14
15     return x;
16 }
17
18 float htonf (float x)   
19 {
20     int * p = (int *)&x;
21     *p = htonl(*p);
22     return x;
23 }
24
25 SOCKET sendSocket = -1;
26 struct sockaddr_in sendAddr;
27
28 // IP and port where FG is listening
29 char * fg_ip = "127.0.0.1";
30 int fg_port = 5500;
31
32 // update period.  controls how often updates are
33 // sent to FG.  in seconds.
34 int update_period = 1000;
35
36 void run();
37
38 int main(int argc, char ** argv)
39 {
40     WSAData wd;
41     if (WSAStartup(MAKEWORD(2,0),&wd) == 0)
42     {
43         memset(&sendAddr,0,sizeof(sendAddr));
44         sendAddr.sin_family = AF_INET;
45         sendAddr.sin_port = htons(fg_port);
46         sendAddr.sin_addr.S_un.S_addr = inet_addr(fg_ip);
47
48         sendSocket = socket(AF_INET,SOCK_DGRAM,0);
49         if (sendSocket != INVALID_SOCKET)
50         {
51             run();
52         }
53         else
54         {
55             cout << "socket() failed" << endl;
56         }
57     }
58     else
59     {
60         cout << "WSAStartup() failed" << endl;
61     }
62
63     return 0;
64 }
65
66 #define D2R (3.14159 / 180.0)
67
68 void run()
69 {
70     double latitude = 45.59823; // degs
71     double longitude = -120.69202; // degs
72     double altitude = 150.0; // meters above sea level
73  
74     float roll = 0.0; // degs
75     float pitch = 0.0; // degs
76     float yaw = 0.0; // degs
77
78     float visibility = 5000.0; // meters
79
80     while (true)
81     {
82         Sleep(update_period);
83
84         FGNetFDM fdm;
85         memset(&fdm,0,sizeof(fdm));
86         fdm.version = htonl(FG_NET_FDM_VERSION);
87
88         fdm.latitude = htond(latitude * D2R);
89         fdm.longitude = htond(longitude * D2R);
90         fdm.altitude = htond(altitude);
91
92         fdm.phi = htonf(roll * D2R);
93         fdm.theta = htonf(pitch * D2R);
94         fdm.psi = htonf(yaw * D2R);
95
96         fdm.num_engines = htonl(1);
97
98         fdm.num_tanks = htonl(1);
99         fdm.fuel_quantity[0] = htonf(100.0);
100
101         fdm.num_wheels = htonl(3);
102
103         fdm.cur_time = htonl(time(0));
104         fdm.warp = htonl(1);
105
106         fdm.visibility = htonf(visibility);
107
108         sendto(sendSocket,(char *)&fdm,sizeof(fdm),0,(struct sockaddr *)&sendAddr,sizeof(sendAddr));
109
110         static bool flag = true;
111         if (flag)
112         {
113             roll += 5.0;
114         }
115         else
116         {            
117             roll -= 5.0;
118         }
119         flag = !flag;
120     }
121 }
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143