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 100 101 102 103 104 105 106
|
/*
* navigation.c
*
* Copyright (C) 2004-2011 Simon Wunderlich <sw@simonwunderlich.de>
*
* This file is part of s3d, a 3d network display server.
* See http://s3d.berlios.de/ for more updates.
*
* s3d is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* s3d is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with s3d; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "global.h"
#include <math.h> /* atan() */
void navi_right(void)
{
navi_pos(1, 0);
}
void navi_left(void)
{
navi_pos(-1, 0);
}
void navi_fwd(void)
{
navi_pos(0, 1);
}
void navi_back(void)
{
navi_pos(0, -1);
}
void navi_pos(int xdif, int ydif)
{
float tv[3];
struct t_obj *cam;
cam = get_proc_by_pid(MCP)->object[0];
tv[0] = cam->translate.x;
tv[1] = cam->translate.y;
tv[2] = cam->translate.z;
tv[0] += ydif * sin((-cam->rotate.y * M_PI) / 180);
tv[2] -= ydif * cos((-cam->rotate.y * M_PI) / 180);
tv[0] -= xdif * cos((-cam->rotate.y * M_PI) / 180);
tv[2] -= xdif * sin((-cam->rotate.y * M_PI) / 180);
obj_translate(get_proc_by_pid(MCP), 0, tv);
}
void navi_rot(int xdif, int ydif)
{
float rv[3];
struct t_obj *cam;
cam = get_proc_by_pid(MCP)->object[0];
rv[0] = (cam->rotate.x + ydif);
rv[1] = (cam->rotate.y + xdif);
rv[2] = 0.0F;
if (rv[0] > 90)
rv[0] = 90;
if (rv[0] < -90)
rv[0] = -90;
if (rv[1] > 360)
rv[1] -= 360;
if (rv[1] < 0)
rv[1] += 360;
obj_rotate(get_proc_by_pid(MCP), 0, rv);
}
void ptr_move(int x, int y)
{
float tv[3], rv[3], xf, yf;
struct t_process *p;
int ptr;
if (winw > winh) {
xf = winw / (float)winh;
yf = 1;
} else {
xf = 1;
yf = winh / (float)winw;
}
tv[0] = (2.0 * x / ((float)winw) - 1.0) * xf;
tv[1] = -(2.0 * y / ((float)winh) - 1.0) * yf;
tv[2] = -1;
rv[0] = 1.5 * 180 / M_PI * atan(tv[1] / 2); /* TODO: Hm, this is not really correct ... */
rv[1] = 1.5 * 180 / M_PI * -atan(tv[0] / 2);
rv[2] = 0;
p = get_proc_by_pid(MCP);
if (-1 != (ptr = get_pointer(p))) {
obj_translate(p, ptr, tv);
obj_rotate(p, ptr, rv);
}
}
|