2 * Copyright (C) 2003-2010 Neverball authors
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
15 #include "game_common.h"
18 #include "solid_vary.h"
20 /*---------------------------------------------------------------------------*/
22 const char *status_to_str(int s)
26 case GAME_NONE: return _("Aborted");
27 case GAME_TIME: return _("Time-out");
28 case GAME_GOAL: return _("Success");
29 case GAME_FALL: return _("Fall-out");
30 default: return _("Unknown");
34 const char *view_to_str(int v)
38 case VIEW_CHASE: return _("Chase");
39 case VIEW_LAZY: return _("Lazy");
40 case VIEW_MANUAL: return _("Manual");
41 default: return _("Unknown");
45 /*---------------------------------------------------------------------------*/
47 const float GRAVITY_UP[] = { 0.0f, +9.8f, 0.0f };
48 const float GRAVITY_DN[] = { 0.0f, -9.8f, 0.0f };
50 void game_tilt_init(struct game_tilt *tilt)
66 * Compute appropriate tilt axes from the view basis.
68 void game_tilt_axes(struct game_tilt *tilt, float view_e[3][3])
70 v_cpy(tilt->x, view_e[0]);
71 v_cpy(tilt->z, view_e[2]);
74 void game_tilt_grav(float h[3], const float g[3], const struct game_tilt *tilt)
80 /* Compute the gravity vector from the given world rotations. */
82 m_rot (Z, tilt->z, V_RAD(tilt->rz));
83 m_rot (X, tilt->x, V_RAD(tilt->rx));
88 /*---------------------------------------------------------------------------*/
90 void game_view_init(struct game_view *view)
92 view->dp = config_get_d(CONFIG_VIEW_DP) / 100.0f;
93 view->dc = config_get_d(CONFIG_VIEW_DC) / 100.0f;
94 view->dz = config_get_d(CONFIG_VIEW_DZ) / 100.0f;
98 view->c[1] = view->dc;
102 view->p[1] = view->dp;
103 view->p[2] = view->dz;
105 view->e[0][0] = 1.0f;
106 view->e[0][1] = 0.0f;
107 view->e[0][2] = 0.0f;
108 view->e[1][0] = 0.0f;
109 view->e[1][1] = 1.0f;
110 view->e[1][2] = 0.0f;
111 view->e[2][0] = 0.0f;
112 view->e[2][1] = 0.0f;
113 view->e[2][2] = 1.0f;
116 void game_view_fly(struct game_view *view, const struct s_vary *vary, float k)
118 /* float x[3] = { 1.f, 0.f, 0.f }; */
119 float y[3] = { 0.f, 1.f, 0.f };
120 float z[3] = { 0.f, 0.f, 1.f };
121 float c0[3] = { 0.f, 0.f, 0.f };
122 float p0[3] = { 0.f, 0.f, 0.f };
123 float c1[3] = { 0.f, 0.f, 0.f };
124 float p1[3] = { 0.f, 0.f, 0.f };
127 game_view_init(view);
129 /* k = 0.0 view is at the ball. */
133 v_cpy(c0, vary->uv[0].p);
134 v_cpy(p0, vary->uv[0].p);
137 v_mad(p0, p0, y, view->dp);
138 v_mad(p0, p0, z, view->dz);
139 v_mad(c0, c0, y, view->dc);
141 /* k = +1.0 view is s_view 0 */
143 if (k >= 0 && vary->base->wc > 0)
145 v_cpy(p1, vary->base->wv[0].p);
146 v_cpy(c1, vary->base->wv[0].q);
149 /* k = -1.0 view is s_view 1 */
151 if (k <= 0 && vary->base->wc > 1)
153 v_cpy(p1, vary->base->wv[1].p);
154 v_cpy(c1, vary->base->wv[1].q);
157 /* Interpolate the views. */
160 v_mad(view->p, p0, v, k * k);
163 v_mad(view->c, c0, v, k * k);
165 /* Orthonormalize the view basis. */
167 v_sub(view->e[2], view->p, view->c);
168 v_crs(view->e[0], view->e[1], view->e[2]);
169 v_crs(view->e[2], view->e[0], view->e[1]);
170 v_nrm(view->e[0], view->e[0]);
171 v_nrm(view->e[2], view->e[2]);
174 /*---------------------------------------------------------------------------*/
176 void lockstep_clr(struct lockstep *ls)
182 void lockstep_run(struct lockstep *ls, float dt)
184 ls->at += dt * ls->ts;
186 while (ls->at >= ls->dt)
193 void lockstep_scl(struct lockstep *ls, float ts)
198 /*---------------------------------------------------------------------------*/