Release s3d 0.2.2
[s3d.git] / server / navigation.c
blob96da1d2e8ea48c40509bd7e2438606cae0ab337c
1 /*
2 * navigation.c
4 * Copyright (C) 2004-2011 Simon Wunderlich <dotslash@packetmixer.de>
6 * This file is part of s3d, a 3d network display server.
7 * See http://s3d.berlios.de/ for more updates.
9 * s3d is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * s3d is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with s3d; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "global.h"
25 #include <math.h> /* atan() */
27 void navi_right(void)
29 navi_pos(1, 0);
32 void navi_left(void)
34 navi_pos(-1, 0);
37 void navi_fwd(void)
39 navi_pos(0, 1);
42 void navi_back(void)
44 navi_pos(0, -1);
47 void navi_pos(int xdif, int ydif)
49 float tv[3];
50 struct t_obj *cam;
51 cam = get_proc_by_pid(MCP)->object[0];
52 tv[0] = cam->translate.x;
53 tv[1] = cam->translate.y;
54 tv[2] = cam->translate.z;
56 tv[0] += ydif * sin((-cam->rotate.y * M_PI) / 180);
57 tv[2] -= ydif * cos((-cam->rotate.y * M_PI) / 180);
59 tv[0] -= xdif * cos((-cam->rotate.y * M_PI) / 180);
60 tv[2] -= xdif * sin((-cam->rotate.y * M_PI) / 180);
61 obj_translate(get_proc_by_pid(MCP), 0, tv);
64 void navi_rot(int xdif, int ydif)
66 float rv[3];
67 struct t_obj *cam;
68 cam = get_proc_by_pid(MCP)->object[0];
69 rv[0] = (cam->rotate.x + ydif);
70 rv[1] = (cam->rotate.y + xdif);
71 rv[2] = 0.0F;
72 if (rv[0] > 90)
73 rv[0] = 90;
74 if (rv[0] < -90)
75 rv[0] = -90;
76 if (rv[1] > 360)
77 rv[1] -= 360;
78 if (rv[1] < 0)
79 rv[1] += 360;
80 obj_rotate(get_proc_by_pid(MCP), 0, rv);
83 void ptr_move(int x, int y)
85 float tv[3], rv[3], xf, yf;
86 struct t_process *p;
87 int ptr;
88 if (winw > winh) {
89 xf = winw / (float)winh;
90 yf = 1;
91 } else {
92 xf = 1;
93 yf = winh / (float)winw;
95 tv[0] = (2.0 * x / ((float)winw) - 1.0) * xf;
96 tv[1] = -(2.0 * y / ((float)winh) - 1.0) * yf;
97 tv[2] = -1;
98 rv[0] = 1.5 * 180 / M_PI * atan(tv[1] / 2); /* TODO: Hm, this is not really correct ... */
99 rv[1] = 1.5 * 180 / M_PI * -atan(tv[0] / 2);
100 rv[2] = 0;
101 p = get_proc_by_pid(MCP);
102 if (-1 != (ptr = get_pointer(p))) {
103 obj_translate(p, ptr, tv);
104 obj_rotate(p, ptr, rv);