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
25 #include <math.h> /* atan() */
47 void navi_pos(int xdif
, int ydif
)
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
)
68 cam
= get_proc_by_pid(MCP
)->object
[0];
69 rv
[0] = (cam
->rotate
.x
+ ydif
);
70 rv
[1] = (cam
->rotate
.y
+ xdif
);
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
;
89 xf
= winw
/ (float)winh
;
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
;
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);
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
);