Berusky3d.cpp 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. /*
  2. Berusky
  3. - udelat konzoli (alt+tab) - prepinani na konzoli
  4. (konzole misto hry a zpet)
  5. */
  6. #include <stdarg.h>
  7. #include <stdio.h>
  8. #include <math.h>
  9. #include <assert.h>
  10. #include <time.h>
  11. #include "3d_all.h"
  12. #include "Object.h"
  13. #include "Setup.h"
  14. #include "Berusky_universal.h"
  15. #include "Berusky3d_castice.h"
  16. #include "Berusky3d.h"
  17. #include "Berusky3d_ini.h"
  18. #include "Berusky3d_load.h"
  19. #include "Berusky3d_render.h"
  20. #include "Berusky3d_animace.h"
  21. #include "Berusky3d_kofola_interface.h"
  22. #include "Berusky3d_light.h"
  23. #include "Berusky3d_kamery.h"
  24. #include "Berusky3d_kofola2d.h"
  25. #define KAM_MIN_VZDAL 1.0f
  26. G_KONFIG ber, *p_ber = &ber;
  27. void ber_ini_mod(G_KONFIG * p_ber)
  28. {
  29. init_matrix(&p_ber->kamera.word);
  30. init_matrix(&p_ber->kamera.camera);
  31. p_ber->kamera.vzdal = MIN_VZDAL_KAMERY;
  32. p_ber->kamera.fi = (float) MIN_UHEL_KAMERY;
  33. p_ber->kamera.r = 0.0f;
  34. p_ber->kamera.roll = 0.0f;
  35. p_ber->kamera.fov = p_ber->kam.fov;
  36. p_ber->kamera.p.x = p_ber->x_start;
  37. p_ber->kamera.p.y = p_ber->y_start;
  38. p_ber->kamera.p.z = p_ber->z_start;
  39. calc_camera_bod(&p_ber->kamera.camera, &p_ber->kamera.invcam,
  40. &p_ber->kamera.p, p_ber->kamera.vzdal,
  41. p_ber->kamera.fi, p_ber->kamera.r);
  42. kam_set_normal_screen(p_ber);
  43. }
  44. void ber_nahod_mod(G_KONFIG * p_ber)
  45. {
  46. p_ber->p_word = &p_ber->kamera.word;
  47. p_ber->p_project = &p_ber->kamera.project;
  48. p_ber->p_camera = &p_ber->kamera.camera;
  49. p_ber->p_invcam = &p_ber->kamera.invcam;
  50. p_ber->p_vzdal = &p_ber->kamera.vzdal;
  51. p_ber->p_vzdal_kor = &p_ber->kamera.vzdal_kor;
  52. p_ber->p_fi = &p_ber->kamera.fi;
  53. p_ber->p_rfi = &p_ber->kamera.r;
  54. p_ber->p_target = &p_ber->kamera.t;
  55. p_ber->p_pos = &p_ber->kamera.p;
  56. p_ber->p_roll = &p_ber->kamera.roll;
  57. p_ber->p_mod = &p_ber->kamera.aktivni;
  58. p_ber->kamera.aktivni |= GAME_KAMERA_POLAR;
  59. p_ber->kamera.zmena = TRUE;
  60. set_matrix_world(p_ber->p_word);
  61. set_matrix_camera(p_ber->p_camera);
  62. set_matrix_project(p_ber->p_project);
  63. set_matrix_camera_project(p_ber->p_project);
  64. kam_set_normal_screen(p_ber);
  65. kprintf(TRUE, "kam.fov = %.2fs", RAD2DEG(p_ber->kam.fov));
  66. kprintf(TRUE, "kam.near_plane = %.2fm", p_ber->kam.near_plane);
  67. kprintf(TRUE, "kam.far_plane = %.2fm", p_ber->kam.far_plane);
  68. kprintf(TRUE, "kam.min_degree = %.2fs", RAD2DEG(p_ber->kam.min_uhel));
  69. kprintf(TRUE, "kam.max_degree = %.2fs", RAD2DEG(p_ber->kam.max_uhel));
  70. kprintf(TRUE, "kam.min_dist = %.2fm", p_ber->kam.min_vzdal);
  71. kprintf(TRUE, "kam.max_dist = %.2fm", p_ber->kam.max_vzdal);
  72. }
  73. void ber_uloz_lookup(G_KONFIG * p_ber)
  74. {
  75. bitmapa *p_bmp1 = bmp_vyrob(256, 256);
  76. bitmapa *p_bmp2 = bmp_vyrob(256, 256);
  77. dword barva;
  78. float i1, i2;
  79. int x, y, i;
  80. for (y = 0; y < 256; y++) {
  81. for (x = 0; x < 256; x++) {
  82. i = y * MAX_LOOK_TABLE + x;
  83. i1 = (float) p_ber->p_looksqrt_linear[i] / (0xffffff);
  84. i2 = (float) p_ber->p_looksqrt_quadratic[i] / (0xffffff);
  85. barva = 0;
  86. add_mult_color(&barva, 0xffffffff, i1);
  87. bmp_putpixel(p_bmp1, x, y, barva);
  88. barva = 0;
  89. add_mult_color(&barva, 0xffffffff, i2);
  90. bmp_putpixel(p_bmp2, x, y, barva);
  91. }
  92. }
  93. bmp_uloz("e:\\linear.png", p_bmp1);
  94. bmp_uloz("e:\\kvad.png", p_bmp2);
  95. }
  96. void ber_rekonfiguruj_hra(G_KONFIG * p_ber)
  97. {
  98. char pom[200];
  99. p_ber->conf_ovladani_rohy =
  100. GetPrivateProfileInt("game", "ovladani_rohy", 1, ini_file);
  101. p_ber->conf_ovladani_rohy_default =
  102. GetPrivateProfileInt("game", "ovladani_rohy_default", 0, ini_file);
  103. p_ber->conf_ovladani_rohy_smer =
  104. GetPrivateProfileInt("game", "ovladani_rohy_smer", 0, ini_file);
  105. GetPrivateProfileString("game", "ovladani_rohy_rychlost", "0.5", pom, 200,
  106. ini_file);
  107. p_ber->conf_ovladani_rohy_rychlost = (float) atof(pom);
  108. GetPrivateProfileString("game", "p_kamera_radius", "4.0", pom, 200,
  109. ini_file);
  110. p_ber->conf_pruhledna_kamera_radius = (float) atof(pom);
  111. }
  112. void ber_rekonfiguruj_3D(G_KONFIG * p_ber)
  113. {
  114. char pom[200];
  115. hwconf.ditering = GetPrivateProfileInt("game", "ditering", 0, ini_file);
  116. p_ber->conf_animace_okoli = GetPrivateProfileInt("game", "animace_okoli", 1, ini_file);
  117. p_ber->conf_caustic = GetPrivateProfileInt("game", "scene_materialy", 1, ini_file);
  118. GetPrivateProfileString("textures", "text_ostrost", "0.0", pom, 200, ini_file);
  119. txconf.text_ostrost = (float) atof(pom);
  120. // 0/1 - on/off
  121. // 1,2,3 - hi/mid/low
  122. p_ber->conf_dyn_light = GetPrivateProfileInt("game", "light_dyn", 1, ini_file);
  123. if (p_ber->conf_dyn_light)
  124. p_ber->conf_dyn_rychlost = GetPrivateProfileInt("game", "light_dyn_speed", 1, ini_file);
  125. else
  126. p_ber->conf_dyn_rychlost = LIGHT_NIC;
  127. }
  128. void ber_rekonfiguruj_3D_aplikuj(G_KONFIG * p_ber)
  129. {
  130. if (hwconf.ditering) {
  131. glEnable(GL_DITHER);
  132. }
  133. else {
  134. glDisable(GL_DITHER);
  135. }
  136. dl_nastav(p_ber);
  137. }
  138. #define DEF_PROJECT_FOV DEG2RAD(20.0f)
  139. // taky float lok-up tabulka !!!
  140. void ber_konfiguruj_berusky(G_KONFIG * p_ber)
  141. {
  142. char pom[MAX_FILENAME];
  143. int i;
  144. p_ber->conf_barva_pozadi = 0xff000000;
  145. p_ber->kam_omezeni = !GetPrivateProfileInt("debug", "debug_kamery", 0, ini_file);
  146. p_ber->kam.fov = DEF_PROJECT_FOV;
  147. p_ber->kam.far_plane = MAX_VZDAL_Z;
  148. p_ber->kam.near_plane = MIN_VZDAL_Z;
  149. p_ber->kam.max_uhel = MAX_UHEL_KAMERY;
  150. p_ber->kam.min_uhel = MIN_UHEL_KAMERY;
  151. p_ber->kam.max_vzdal = MAX_VZDAL_KAMERY;
  152. p_ber->kam.min_vzdal = MIN_VZDAL_KAMERY;
  153. p_ber->conf_zpruhlednovac = FALSE;
  154. set_matrix_init();
  155. konfiguruj_look_up(p_ber->p_looksqrt_linear,
  156. p_ber->p_looksqrt_quadratic,
  157. p_ber->p_looksqrt_linear_float, p_ber->p_looksqrt_quadratic_float);
  158. for (i = 0; i < SIN_TABLE_SIZE; i++)
  159. p_ber->sinus_table[i] = sinf(DEG2RAD(i));
  160. GetPrivateProfileString("install","save_dir","/", p_ber->dir.save_dir, MAX_FILENAME, ini_file);
  161. working_file_translate(p_ber->dir.save_dir, MAX_FILENAME);
  162. GetPrivateProfileString("install","profile_dir","/", p_ber->dir.profile_dir, MAX_FILENAME, ini_file);
  163. working_file_translate(p_ber->dir.profile_dir, MAX_FILENAME);
  164. // Load root of the data files
  165. GetPrivateProfileString("install","game_root","/", p_ber->dir.game_root_dir, MAX_FILENAME, ini_file);
  166. working_file_translate(p_ber->dir.game_root_dir, MAX_FILENAME);
  167. GetPrivateProfileString("files","bitmap_dir","/", p_ber->dir.bitmap_dir, MAX_FILENAME, ini_file);
  168. working_file_translate(p_ber->dir.bitmap_dir, MAX_FILENAME);
  169. root_dir_attach(p_ber->dir.bitmap_dir, p_ber->dir.game_root_dir);
  170. GetPrivateProfileString("files", "prvky_dir", ".", p_ber->dir.prvky_dir, MAX_FILENAME, ini_file);
  171. working_file_translate(p_ber->dir.prvky_dir, MAX_FILENAME);
  172. root_dir_attach(p_ber->dir.prvky_dir, p_ber->dir.game_root_dir);
  173. GetPrivateProfileString("files", "level_dir", ".", p_ber->dir.level_dir, MAX_FILENAME, ini_file);
  174. working_file_translate(p_ber->dir.level_dir, MAX_FILENAME);
  175. root_dir_attach(p_ber->dir.level_dir, p_ber->dir.game_root_dir);
  176. GetPrivateProfileString("files", "out_dir", ".", p_ber->dir.out_dir, MAX_FILENAME, ini_file);
  177. working_file_translate(p_ber->dir.out_dir, MAX_FILENAME);
  178. root_dir_attach(p_ber->dir.out_dir, p_ber->dir.game_root_dir);
  179. GetPrivateProfileString("files", "material_dir", ".", p_ber->dir.material_dir, MAX_FILENAME, ini_file);
  180. working_file_translate(p_ber->dir.material_dir, MAX_FILENAME);
  181. root_dir_attach(p_ber->dir.material_dir, p_ber->dir.game_root_dir);
  182. GetPrivateProfileString("files", "data_dir", ".", p_ber->dir.data_dir, MAX_FILENAME, ini_file);
  183. working_file_translate(p_ber->dir.data_dir, MAX_FILENAME);
  184. root_dir_attach(p_ber->dir.data_dir, p_ber->dir.game_root_dir);
  185. GetPrivateProfileString("files", "game_level_dir", ".", p_ber->dir.game_level_dir, MAX_FILENAME, ini_file);
  186. working_file_translate(p_ber->dir.game_level_dir, MAX_FILENAME);
  187. root_dir_attach(p_ber->dir.game_level_dir, p_ber->dir.game_root_dir);
  188. GetPrivateProfileString("files", "game_data_dir", ".", p_ber->dir.game_data_dir, MAX_FILENAME, ini_file);
  189. working_file_translate(p_ber->dir.game_data_dir, MAX_FILENAME);
  190. root_dir_attach(p_ber->dir.game_data_dir, p_ber->dir.game_root_dir);
  191. GetPrivateProfileString("files", "texture_dir", ".", p_ber->tdir.texture_dir[0], MAX_FILENAME, ini_file);
  192. working_file_translate(p_ber->tdir.texture_dir[0], MAX_FILENAME);
  193. root_dir_attach(p_ber->tdir.texture_dir[0], p_ber->dir.game_root_dir);
  194. for (i = 0; i < TEXT_DIRS; i++) {
  195. char old[200];
  196. int old_class;
  197. const struct {
  198. const char *const dir;
  199. const int dir_class;
  200. } defaults[TEXT_DIRS] = {
  201. { "textures/general", 1 },
  202. { "textures/stul", 3 },
  203. { "textures/balkon", 3 },
  204. { "textures/kanal", 3 },
  205. { "textures/voda", 3 },
  206. { "textures/silnice", 3 },
  207. { "textures/zahrada", 3 },
  208. { "textures/bazina", 3 },
  209. { "textures/les", 3 },
  210. { "textures/tutorial", 3 },
  211. { "textures/strom", 3 },
  212. { "textures/detska", 3 },
  213. { "textures/items", 2 }
  214. };
  215. const char *default_dir = defaults[i].dir;
  216. const int default_class = defaults[i].dir_class;
  217. if (!default_dir)
  218. default_dir = "";
  219. snprintf(pom, sizeof(pom), "texture_dir%d", i);
  220. snprintf(old, sizeof(old), "texture_file%d", i);
  221. get_dir_setting("files", pom, old, default_dir,
  222. p_ber->tdir.texture_dir[i],
  223. MAX_FILENAME, ini_file);
  224. working_file_translate(p_ber->tdir.texture_dir[i], MAX_FILENAME);
  225. root_dir_attach(p_ber->tdir.texture_dir[i], p_ber->dir.game_root_dir);
  226. if (p_ber->tdir.texture_dir[i][0] == '.' && !p_ber->tdir.texture_dir[i][1])
  227. p_ber->tdir.texture_dir[i][0] = 0;
  228. snprintf(pom, sizeof(pom), "texture_dir%d_class", i);
  229. p_ber->tdir.texture_dir_class[i] =
  230. GetPrivateProfileInt("files", pom, default_class, ini_file);
  231. // Remove the old setting if it's the default.
  232. snprintf(old, sizeof(old), "texture_file%d_class", i);
  233. old_class = GetPrivateProfileInt("files", old, 0, ini_file);
  234. if (old_class == default_class) {
  235. kprintf(TRUE, "Removing obsolete setting with default value: %s=%d",
  236. old, old_class);
  237. WritePrivateProfileString("files", old, NULL, ini_file);
  238. }
  239. }
  240. // 'data_pak' is no longer used, and there is no corresponding
  241. // 'data_dir'. (Well, there is a 'data_dir', but that's for
  242. // something else). So just remove 'data_pak' from the INI file if
  243. // it exists. However, only remove it if it's equal to "data.pak",
  244. // because otherwise the user has changed it and might want to
  245. // remember that setting.
  246. GetPrivateProfileString("files", "data_pak", "", pom, sizeof(pom), ini_file);
  247. if (!strcmp(pom, "data.pak"))
  248. WritePrivateProfileString("files", "data_pak", NULL, ini_file);
  249. GetPrivateProfileString("soundengine","sound_dir","/",p_ber->dir.sound_dir,MAX_FILENAME,ini_file);
  250. working_file_translate(p_ber->dir.sound_dir,MAX_FILENAME);
  251. root_dir_attach(p_ber->dir.sound_dir, p_ber->dir.game_root_dir);
  252. adas_set_sound_dir(p_ber->dir.sound_dir);
  253. GetPrivateProfileString("soundengine","music_dir","/",p_ber->dir.music_dir,MAX_FILENAME,ini_file);
  254. working_file_translate(p_ber->dir.music_dir,MAX_FILENAME);
  255. root_dir_attach(p_ber->dir.music_dir, p_ber->dir.game_root_dir);
  256. p_ber->conf_barva_pozadi_pouzit_default =
  257. p_ber->conf_barva_pozadi_pouzit =
  258. GetPrivateProfileInt("game", "barva_pozadi", 0, ini_file);
  259. p_ber->conf_extra_light_vertex =
  260. GetPrivateProfileInt("game", "extra_light_vertex", 1, ini_file);
  261. ber_rekonfiguruj_hra(p_ber);
  262. ber_rekonfiguruj_3D(p_ber);
  263. #ifdef DEBUG_MOD
  264. p_ber->debug_fps = GetPrivateProfileInt("debug", "debug_fps", 0, ini_file);
  265. p_ber->debug_vypisy =
  266. GetPrivateProfileInt("debug", "debug_vypisy", 0, ini_file);
  267. p_ber->debug_light =
  268. GetPrivateProfileInt("debug", "debug_light", 0, ini_file);
  269. p_ber->debug_draty =
  270. GetPrivateProfileInt("debug", "debug_draty", 0, ini_file);
  271. #endif
  272. nahod_state_bloky();
  273. /* Nastaveni debugu
  274. */
  275. #ifdef DEBUG_MOD
  276. p_ber->debug_frame = TRUE;
  277. #endif
  278. kprintf(TRUE, "Configuration done");
  279. }
  280. void kprintf(char log, const char *p_text, ...)
  281. {
  282. char text[2000];
  283. va_list argumenty;
  284. va_start(argumenty, p_text);
  285. vsprintf(text, p_text, argumenty);
  286. va_end(argumenty);
  287. fprintf(stderr, "%s\n", text);
  288. if (log && p_ber->debug_file) {
  289. fputs(text, p_ber->debug_file);
  290. fputc('\n', p_ber->debug_file);
  291. fflush(p_ber->debug_file);
  292. }
  293. }
  294. void kprintfe(char log, const char *p_text, ...)
  295. {
  296. char text[2000];
  297. va_list argumenty;
  298. va_start(argumenty, p_text);
  299. vsprintf(text, p_text, argumenty);
  300. va_end(argumenty);
  301. if (log && p_ber->debug_file) {
  302. fputs(text, p_ber->debug_file);
  303. fputc('\n', p_ber->debug_file);
  304. fflush(p_ber->debug_file);
  305. }
  306. exit(-1);
  307. }
  308. void kprintfl(char log, const char *p_text, ...)
  309. {
  310. char text[2000];
  311. va_list argumenty;
  312. va_start(argumenty, p_text);
  313. vsprintf(text, p_text, argumenty);
  314. va_end(argumenty);
  315. fprintf(stderr,"%s\n", text);
  316. if (log && p_ber->debug_file) {
  317. fputs(text, p_ber->debug_file);
  318. fputc('\n', p_ber->debug_file);
  319. fflush(p_ber->debug_file);
  320. }
  321. }
  322. void kerror(char log, const char *p_text, ...)
  323. {
  324. char text[2000];
  325. va_list argumenty;
  326. va_start(argumenty, p_text);
  327. vsprintf(text, p_text, argumenty);
  328. va_end(argumenty);
  329. fprintf(stderr, "FATAL ERROR: %s\n", text);
  330. if (log && p_ber->debug_file) {
  331. fputs(text, p_ber->debug_file);
  332. fputc('\n', p_ber->debug_file);
  333. fflush(p_ber->debug_file);
  334. }
  335. assert(0);
  336. exit(-1);
  337. }
  338. void kwarning(char log, const char *p_text, ...)
  339. {
  340. char text[2000];
  341. va_list argumenty;
  342. va_start(argumenty, p_text);
  343. vsprintf(text, p_text, argumenty);
  344. va_end(argumenty);
  345. fprintf(stderr, "WARNING: %s\n", text);
  346. if (log && p_ber->debug_file) {
  347. fputs(text, p_ber->debug_file);
  348. fputc('\n', p_ber->debug_file);
  349. fflush(p_ber->debug_file);
  350. }
  351. }
  352. void ddw(const char *p_text, ...)
  353. {
  354. char text[2000];
  355. va_list argumenty;
  356. va_start(argumenty, p_text);
  357. vsprintf(text, p_text, argumenty);
  358. va_end(argumenty);
  359. if (p_ber->debug_file) {
  360. fputs(text, p_ber->debug_file);
  361. fputc('\n', p_ber->debug_file);
  362. fflush(p_ber->debug_file);
  363. }
  364. }
  365. // Nahraje vlastnosti levelu a nestavy tyto vlastnosti
  366. void ber_init_level(G_KONFIG * p_ber)
  367. {
  368. float b[4];
  369. glstav_reset();
  370. if (p_ber->conf_barva_pozadi_pouzit) {
  371. rgb_float(p_ber->conf_barva_pozadi, b);
  372. glClearColor(b[0], b[1], b[2], 1.0f);
  373. }
  374. p_ber->dl_recalc = TRUE;
  375. p_ber->dl_new = TRUE;
  376. p_ber->dl_on = TRUE;
  377. p_ber->edl_recalc = TRUE;
  378. p_ber->edl_new = TRUE;
  379. /* Inicializace casu
  380. */
  381. p_ber->TimeEndLastFrame = p_ber->TimeBase = timeGetTime() / DELICKA_CASU;
  382. p_ber->TimeLastFrame = 30;
  383. /* Prvotni init anim materialu
  384. */
  385. ani_init(p_ber);
  386. /* Nahozeni animaci
  387. */
  388. tani_init_scena(p_ber);
  389. /* Inicializace kamery
  390. */
  391. ber_ini_mod(p_ber);
  392. ber_nahod_mod(p_ber);
  393. /* Nahozeni zemni mlhy
  394. */
  395. if (p_ber->zm.aktivni) {
  396. p_ber->zm.handle =
  397. edl_svetlo_vyrob_zemni_mlha(p_ber->zm.barva, p_ber->zm.v_start,
  398. p_ber->zm.v_stop, p_ber->zm.h_start, p_ber->zm.h_stop);
  399. }
  400. /* Nactu scan-code pro P,R
  401. */
  402. gl_Get_PR_ScanCode(&p_ber->conf_p_key, &p_ber->conf_r_key);
  403. /* Zpruhlednovani prvku pred kamerou
  404. */
  405. if (setup.bugs_highlight)
  406. kom_zpruhlednovat_prvky(TRUE);
  407. /* Nahodi zvyraznovani prvku
  408. */
  409. p_ber->conf_full_light = !setup.items_highlight;
  410. ber_prikaz_zvyraznovac(p_ber);
  411. /* Vypne kurzor
  412. */
  413. vypni_kurzor();
  414. /* Hodim kurzor do poloviny obrazovky
  415. */
  416. //ber_nastav_kurzor(OXRES/2,OYRES/2);
  417. /* Nastavi svetla v levelu
  418. */
  419. dl_nastav(p_ber);
  420. /* Reset mlhy
  421. */
  422. mlha_reset();
  423. /* Reload ini
  424. */
  425. kom_reload_ini();
  426. /* Nastavi flagose
  427. */
  428. p_ber->ref_pos = TRUE;
  429. p_ber->ref_rot = TRUE;
  430. p_ber->ref_zmena = FALSE;
  431. p_ber->sflag1 = FALSE;
  432. }
  433. #ifdef DEBUG_MOD
  434. void ber_tiskni_statistiku(G_KONFIG * p_ber)
  435. {
  436. PARMETAC *p_par;
  437. GAME_MESH_OLD *p_mesh;
  438. GK_ANIM *p_gk;
  439. float dir[6];
  440. BOD pos;
  441. int start = 2;
  442. int i;
  443. //int posun = 12;
  444. int posun = 20;
  445. int ppart, psystemu;
  446. int dlnum = 0;
  447. int edlnum = 0;
  448. float time;
  449. if (p_ber->debug_fps) {
  450. printfs(start, posun++, "f %.2f m %d o %d f %d", p_ber->fps,
  451. p_ber->debug.meshu, p_ber->debug.objektu, p_ber->debug.facu / 3);
  452. }
  453. kam_get_float_ext(dir, (float *) &pos);
  454. if (p_ber->debug_vypisy) {
  455. printfs(start, posun++, "bodu %d", p_ber->debug.bodu);
  456. printfs(start, posun++, "facu %d", p_ber->debug.facu / 3);
  457. printfs(start, posun++, "objektu %d", p_ber->debug.objektu);
  458. printfs(start, posun++, "poly rendered %d / total %d", p_ber->debug.poly,
  459. p_ber->polynum);
  460. printfs(start, posun++, "meshu rendered %d / total %d",
  461. p_ber->debug.meshu, p_ber->meshnum);
  462. printfs(start, posun++,
  463. "render list poly num %d / akt = %d, mesh num = %d / akt = %d",
  464. p_ber->poly_rendernum, p_ber->poly_renderakt, p_ber->mesh_rendernum,
  465. p_ber->mesh_renderakt);
  466. printfs(start, posun++, "ac %d tc %d", p_ber->debug.alfa_stage_change,
  467. p_ber->debug.text_stage_change);
  468. printfs(start, posun++, "pruhlednych %d", p_ber->prhlnum);
  469. printfs(start, posun++, "mouse [mi.t1 = %d mi.t2 = %d]", mi.t1, mi.t2);
  470. printfs(start, posun++, "r[%.2f] fi[%.2f] vzdal[%.2f] vzdal_kor[%.2f]",
  471. RAD2DEG(*p_ber->p_rfi), RAD2DEG(*p_ber->p_fi), *p_ber->p_vzdal,
  472. *p_ber->p_vzdal_kor);
  473. printfs(start, posun++, "t[%.2f,%.2f,%.2f]", p_ber->p_target->x,
  474. p_ber->p_target->y, p_ber->p_target->z);
  475. printfs(start, posun++, "p[%.2f,%.2f,%.2f]", p_ber->p_pos->x,
  476. p_ber->p_pos->y, p_ber->p_pos->z);
  477. printfs(start, posun++, "AK = %d PRCameraFlag = %d",
  478. p_ber->kamera.a_handle, PRCameraFlag);
  479. for (i = 0; i < p_ber->dl_lightnum; i++) {
  480. if (p_ber->p_dlight[i].akt)
  481. dlnum++;
  482. }
  483. for (i = 0; i < p_ber->edl_lightnum; i++) {
  484. if (p_ber->p_edlight[i].akt)
  485. edlnum++;
  486. }
  487. printfs(start, posun++, "LVertexu = %d sl = %d dl = %d edl = %d",
  488. p_ber->debug.light_vertexu, p_ber->slightnum, dlnum, edlnum);
  489. printfs(start, posun++, "LMeshu = %d", p_ber->debug.light_meshu);
  490. ppart = 0;
  491. psystemu = 0;
  492. p_par = p_ber->p_par;
  493. while (p_par) {
  494. ppart += p_par->pnum;
  495. psystemu++;
  496. p_par = p_par->p_next;
  497. }
  498. printfs(start, posun++, "systemu %d castic %d", psystemu, ppart);
  499. printfs(start, posun++, "hnizd %d viditelnych %d", p_ber->debug.hnizd,
  500. p_ber->debug.hnizd_vid);
  501. printfs(start, posun++, "Lani_vid %d", p_ber->debug.lani_vid);
  502. printfs(start, posun++, "Vertex Obj %d", p_ber->debug.vertex_obj);
  503. // p_light = &p_ber->p_edlight[0].tp;
  504. // printfs(start,posun++, "svetlo [%.3f %.3f %.3f] dosah %f",p_light->x,p_light->y,p_light->z,p_ber->p_edlight[0].dosah);
  505. for (i = 0; i < p_ber->gknum; i++) {
  506. p_gk = p_ber->p_gkzas + i;
  507. if (p_gk->flag & GK_AKTIVNI) {
  508. time = p_gk->time / (float) p_gk->time_delka;
  509. printfs(start, posun++, "G slot %d time %f", i, time);
  510. }
  511. }
  512. for (i = 0; i < p_ber->lokalnum; i++) {
  513. if (p_ber->p_lokal[i]) {
  514. p_mesh = p_ber->p_lokal[i];
  515. time =
  516. p_mesh->sim_aktivni_time / (float) (p_mesh->p_sim_aktivni->keynum *
  517. SIM_KONSTI);
  518. printfs(start, posun++, "L slot %d time %f", i, time);
  519. }
  520. }
  521. printfs(start, posun++, "time = %d", timeGetTime());
  522. }
  523. }
  524. #endif
  525. void cekej(int kolik)
  526. {
  527. int i, j, k, l;
  528. for (i = 0; i < kolik; i++) {
  529. for (j = 0; j < kolik; j++) {
  530. for (k = 0; k < kolik; k++) {
  531. for (l = 0; l < kolik; l++) {
  532. spracuj_spravy(1);
  533. }
  534. }
  535. }
  536. }
  537. }
  538. /*
  539. 1 - ok, dohral to
  540. 0 - abort
  541. */
  542. /*
  543. p - posun sceny
  544. r - rotace sceny
  545. +,- - zoom kamery
  546. */
  547. float ber_stredni_vzdalenost_ve_scene(G_KONFIG * p_ber)
  548. {
  549. BOD a, b, p;
  550. ROVINA r(0.0f, 1.0f, 0.0f, 0.0f);
  551. transf_2d_3d((float) SCREEN_XRES / 2, (float) SCREEN_YRES / 2, 0,
  552. &a.x, &a.y, &a.z,
  553. p_ber->p_camera, p_ber->p_project, SCREEN_XRES, SCREEN_YRES, SCREEN_XSTART, SCREEN_YSTART);
  554. transf_2d_3d((float) SCREEN_XRES / 2, (float) SCREEN_YRES / 2, 0.5f,
  555. &b.x, &b.y, &b.z,
  556. p_ber->p_camera, p_ber->p_project, SCREEN_XRES, SCREEN_YRES, SCREEN_XSTART, SCREEN_YSTART);
  557. if (!calc_prusek_bod(&r, &a, &b, &p))
  558. return (10.0f);
  559. else
  560. return (vzdal_bodu_bod(&a, &p));
  561. }
  562. /*
  563. inline ROVINA * calc_rovinu_bod_vektor(BOD *p, BOD *v, ROVINA *r)
  564. */
  565. void ber_prikaz_posun_sceny(G_KONFIG * p_ber, int ref)
  566. {
  567. static BOD o1, v1;
  568. static int rx, ry;
  569. BOD v2;
  570. if (!PRCameraFlag)
  571. return;
  572. PRCameraFlagChange = TRUE;
  573. nuluj_mys();
  574. nuluj_dif();
  575. kam_stop();
  576. kam_set_mod_polar();
  577. if (ref) {
  578. rx = mi.x;
  579. ry = mi.y;
  580. }
  581. else {
  582. transf_2d_3d_z((float) rx, (float) ry, *p_ber->p_vzdal_kor,
  583. &v1.x, &v1.y, &v1.z,
  584. p_ber->p_camera, p_ber->p_project,
  585. SCREEN_XRES, SCREEN_YRES, SCREEN_XSTART, SCREEN_YSTART,
  586. p_ber->kam.near_plane, p_ber->kam.far_plane);
  587. transf_2d_3d_z((float) mi.x, (float) mi.y, *p_ber->p_vzdal_kor,
  588. &v2.x, &v2.y, &v2.z,
  589. p_ber->p_camera, p_ber->p_project,
  590. SCREEN_XRES, SCREEN_YRES, SCREEN_XSTART, SCREEN_YSTART,
  591. p_ber->kam.near_plane, p_ber->kam.far_plane);
  592. p_ber->p_target->x += v1.x - v2.x;
  593. p_ber->p_target->z += v1.z - v2.z;
  594. if (!p_ber->kam_omezeni) {
  595. p_ber->p_target->y += v1.y - v2.y;
  596. }
  597. if (p_ber->kam_omezeni) {
  598. kd_je_bod_v_kostce_orez(p_ber->p_target, &p_ber->level_min,
  599. &p_ber->level_max);
  600. }
  601. ber_kamera_korekce_vzdalenosti(p_ber, p_ber->kam_omezeni, FALSE);
  602. nuluj_dif();
  603. rx = mi.x;
  604. ry = mi.y;
  605. }
  606. mi.dx = 1; // kvuli kofolovy - aby se ten kurzor nestracel
  607. p_ber->kamera.zmena = TRUE;
  608. }
  609. void ber_prikaz_rotace_sceny(G_KONFIG * p_ber, int ref)
  610. {
  611. static int rx, ry;
  612. if (!PRCameraFlag)
  613. return;
  614. PRCameraFlagChange = TRUE;
  615. nuluj_mys();
  616. nuluj_dif();
  617. kam_stop();
  618. kam_set_mod_polar();
  619. if (ref) {
  620. rx = mi.x;
  621. ry = mi.y;
  622. }
  623. else {
  624. *p_ber->p_fi += ((float) PI / 180) * (float) (mi.y - ry) * 0.5f;
  625. *p_ber->p_rfi -= ((float) PI / 180) * (float) (mi.x - rx) * 0.5f;
  626. if (p_ber->kam_omezeni) {
  627. if (*p_ber->p_fi < p_ber->kam.min_uhel)
  628. *p_ber->p_fi = p_ber->kam.min_uhel;
  629. else {
  630. if (*p_ber->p_fi > p_ber->kam.max_uhel)
  631. *p_ber->p_fi = p_ber->kam.max_uhel;
  632. }
  633. }
  634. ber_kamera_korekce_vzdalenosti(p_ber, p_ber->kam_omezeni, FALSE);
  635. rx = mi.x;
  636. ry = mi.y;
  637. }
  638. p_ber->kamera.zmena = TRUE;
  639. mi.dx = 1; // kvuli kofolovy - aby se ten kurzor nestracel
  640. }
  641. void ber_prikaz_scena_zoom(int koeficient)
  642. {
  643. kam_stop();
  644. kam_set_mod_polar();
  645. *p_ber->p_vzdal += koeficient * (*p_ber->p_vzdal) * 0.1f;
  646. if (*p_ber->p_vzdal < KAM_MIN_VZDAL)
  647. *p_ber->p_vzdal = KAM_MIN_VZDAL;
  648. if (p_ber->kam_omezeni && *p_ber->p_vzdal < p_ber->kam.min_vzdal)
  649. *p_ber->p_vzdal = p_ber->kam.min_vzdal;
  650. if (p_ber->kam_omezeni && *p_ber->p_vzdal > MAX_VZDAL_KAMERY)
  651. *p_ber->p_vzdal = MAX_VZDAL_KAMERY;
  652. ber_kamera_korekce_vzdalenosti(p_ber, p_ber->kam_omezeni, TRUE);
  653. p_ber->kamera.zmena = TRUE;
  654. PRCameraFlagChange = FALSE;
  655. }
  656. void ber_prikaz_zvyraznovac(G_KONFIG * p_ber)
  657. {
  658. p_ber->conf_full_light_last = p_ber->conf_full_light;
  659. p_ber->conf_full_light = !p_ber->conf_full_light;
  660. p_ber->dl_new = p_ber->dl_recalc = TRUE;
  661. dl_nastav(p_ber);
  662. }
  663. void ber_test_animaci(G_KONFIG * p_ber)
  664. {
  665. ExMeshHandle mh, next;
  666. ChapadloHandle *p_handle = NULL;
  667. int chapadel;
  668. static int flag;
  669. int i, j, objektu;
  670. /* -----------------------------------------------------------
  671. Tuto cast musis delat nekde na zacatku - trva to dlouho
  672. (nacteni animaci objektu)
  673. */
  674. /* Smycka - hleda a vraci postupne vsechny meshe ve scene ktere
  675. maji joint-animace
  676. */
  677. next = 0;
  678. while ((mh = kom_najdi_mesh_joint(&next)) != K_CHYBA) {
  679. /* U nalezeneho meshe nacte pocet objektu ktere maji joint-animace
  680. */
  681. objektu = chani_mesh_cti_objekty(mh);
  682. /* Projede objekty meshe (pocet objektu s animacema = objektu)
  683. a spusti jejich prvni animaci
  684. */
  685. for (i = 0; i < objektu; i++) {
  686. /* Nacni animace i-teho objektu v poradi
  687. */
  688. chani_mesh_cti_chapadelniky(mh, i, &p_handle, &chapadel);
  689. /* chapadel = pocet animaci objektu
  690. p_handle = pole handlu na tyto animace
  691. */
  692. /* Vrati jmena animaci objektu
  693. */
  694. for (j = 0; j < chapadel; j++) {
  695. char *p_jmeno = chani_cti_jmeno(p_handle[j]);
  696. (void)p_jmeno; //let's make gcc happy :)
  697. }
  698. /* -----------------------------------------------------------
  699. Tuto cast muzes delat behem hry - je to rychle
  700. */
  701. /* Vyberu si 1. animaci v objektu a tu zaradim do seznamu animaci
  702. (!!! pozor !!! pri zarazovani animace nekontroluju jestli ta animace
  703. tam uz je nebo ne, tak to musis volat jen 1x! nejlepe pred spustenim
  704. animace)
  705. */
  706. j = 0;
  707. /* Zarazenou animaci spustim
  708. */
  709. chani_go(p_handle[j], &flag, GK_LOOP, 0, 0);
  710. /* Uvolnim pole handlu (je to pole integeru, alokuje se
  711. pri volani chani_mesh_cti_chapadelniky pomoci malloc
  712. a ty to musis uvolnit kdyz to pole nepotrebujes
  713. To pole si klidne muzes ulozit do nejake sve struktury,
  714. ja ho k nicemu nepozuivam a je urceny jen pro tebe
  715. */
  716. free(p_handle);
  717. }
  718. }
  719. /* Postup pri ruseni bezici animace:
  720. 1) Zastavim animaci
  721. chani_stop(p_handle[j]);
  722. 2) Vymazu ji z fronty animaci
  723. chani_zrus(p_handle[j]);
  724. */
  725. }
  726. void ber_test_animaci2(G_KONFIG * p_ber)
  727. {
  728. }
  729. void ber_test_animaci3(G_KONFIG * p_ber)
  730. {
  731. }
  732. /*
  733. dword barva = 0xffffff;
  734. ExtraLightHandle elh = edl_svetlo_vyrob_zemni_mlha(barva, 0.0f, 3.0f, 0.0f, 60.0f);
  735. */
  736. /*
  737. z_buffer_value = ( a + b / z )
  738. N = number of bits of Z precision
  739. a = zFar / ( zFar - zNear )
  740. b = zFar * zNear / ( zNear - zFar )
  741. z = distance from the eye to the object
  742. ...and z_buffer_value is an integer.
  743. */
  744. #define PEVNA_RYCH_POSUN 100.0f
  745. #define PEVNA_RYCH_ROTACE 100.0f
  746. #define PEVNA_RYCH_ZOOM 0.5f
  747. #define POHYBLIVA_RYCH_POSUN 600.0f
  748. #define POHYBLIVA_RYCH_ROTACE 400.0f
  749. #define POHYBLIVA_RYCH_ZOOM 1.0f
  750. // Aktivovat posun v 2D osach x,y
  751. void ber_ovladani_mysi_posun(G_KONFIG * p_ber, int x, int y)
  752. {
  753. float rych_posun =
  754. PEVNA_RYCH_POSUN +
  755. p_ber->conf_ovladani_rohy_rychlost * POHYBLIVA_RYCH_POSUN;
  756. float koef = p_ber->TimeLastFrame / 1000.0f;
  757. float mx1, my1, mx2, my2;
  758. GLMATRIX proj;
  759. BOD v1, v2;
  760. if (!PRCameraFlag)
  761. return;
  762. PRCameraFlagChange = TRUE;
  763. kam_stop();
  764. kam_set_mod_polar();
  765. if (x) {
  766. mx1 = (float) SCREEN_XSTART;
  767. mx2 = mx1 - x * rych_posun * koef;
  768. }
  769. else {
  770. mx1 = mx2 = 0;
  771. }
  772. if (y) {
  773. my1 = (float) (SCREEN_YSTART);
  774. my2 = my1 - y * rych_posun * koef;
  775. }
  776. else {
  777. my1 = my2 = 0;
  778. }
  779. calc_transf_3d_2d_matrix_smpl(p_ber->p_camera, p_ber->p_project, &proj);
  780. transf_2d_3d_z_matrix(mx1, my1, *p_ber->p_vzdal_kor,
  781. &v1.x, &v1.y, &v1.z, &proj, SCREEN_XRES, SCREEN_YRES, SCREEN_XSTART, SCREEN_YSTART,
  782. p_ber->kam.near_plane, p_ber->kam.far_plane);
  783. transf_2d_3d_z_matrix(mx2, my2, *p_ber->p_vzdal_kor,
  784. &v2.x, &v2.y, &v2.z, &proj, SCREEN_XRES, SCREEN_YRES, SCREEN_XSTART, SCREEN_YSTART,
  785. p_ber->kam.near_plane, p_ber->kam.far_plane);
  786. p_ber->p_target->x += v1.x - v2.x;
  787. p_ber->p_target->z += v1.z - v2.z;
  788. if (!p_ber->kam_omezeni) {
  789. p_ber->p_target->y += v1.y - v2.y;
  790. }
  791. if (p_ber->kam_omezeni) {
  792. kd_je_bod_v_kostce_orez(p_ber->p_target, &p_ber->level_min,
  793. &p_ber->level_max);
  794. }
  795. ber_kamera_korekce_vzdalenosti(p_ber, p_ber->kam_omezeni, FALSE);
  796. p_ber->kamera.zmena = TRUE;
  797. mi.dx = 1;
  798. }
  799. // Rotace x,y - 2D osy
  800. void ber_ovladani_mysi_rotace(G_KONFIG * p_ber, int x, int y)
  801. {
  802. float rych_rotace =
  803. PEVNA_RYCH_ROTACE +
  804. p_ber->conf_ovladani_rohy_rychlost * POHYBLIVA_RYCH_ROTACE;
  805. float koef = p_ber->TimeLastFrame / 1000.0f;
  806. static int flag = K_CHYBA;
  807. if (!PRCameraFlag || flag != K_CHYBA)
  808. return;
  809. PRCameraFlagChange = TRUE;
  810. kam_stop();
  811. kam_set_mod_polar();
  812. if (x) {
  813. //camera_Fast_Turn(0,(char)(x < 0), &flag, 0.0f);
  814. *p_ber->p_rfi -=
  815. ((float) PI / 180) * (float) (-x * rych_rotace * koef) * 0.5f;
  816. }
  817. if (y) {
  818. *p_ber->p_fi +=
  819. ((float) PI / 180.0f) * (float) (-y * rych_rotace * koef) * 0.5f * 0.5f;
  820. if (*p_ber->p_fi >= DEG2RAD(88))
  821. *p_ber->p_fi = DEG2RAD(88);
  822. }
  823. if (p_ber->kam_omezeni) {
  824. if (*p_ber->p_fi < p_ber->kam.min_uhel)
  825. *p_ber->p_fi = p_ber->kam.min_uhel;
  826. else {
  827. if (*p_ber->p_fi > p_ber->kam.max_uhel)
  828. *p_ber->p_fi = p_ber->kam.max_uhel;
  829. }
  830. }
  831. ber_kamera_korekce_vzdalenosti(p_ber, p_ber->kam_omezeni, FALSE);
  832. p_ber->kamera.zmena = TRUE;
  833. mi.dx = 1; // kvuli kofolovy - aby se ten kurzor nestracel
  834. }
  835. // Zoom y - +,-
  836. void ber_ovladani_mysi_zoom(G_KONFIG * p_ber, int y)
  837. {
  838. float rych_zoom =
  839. PEVNA_RYCH_ZOOM +
  840. p_ber->conf_ovladani_rohy_rychlost * POHYBLIVA_RYCH_ZOOM;
  841. float koef = p_ber->TimeLastFrame / 1000.0f;
  842. if (y > 0) {
  843. *p_ber->p_vzdal += rych_zoom * koef;
  844. if (p_ber->kam_omezeni && *p_ber->p_vzdal > MAX_VZDAL_KAMERY)
  845. *p_ber->p_vzdal = MAX_VZDAL_KAMERY;
  846. }
  847. else {
  848. *p_ber->p_vzdal -= rych_zoom * koef;
  849. if (p_ber->kam_omezeni && *p_ber->p_vzdal < p_ber->kam.min_vzdal)
  850. *p_ber->p_vzdal = p_ber->kam.min_vzdal;
  851. else if (*p_ber->p_vzdal < KAM_MIN_VZDAL)
  852. *p_ber->p_vzdal = KAM_MIN_VZDAL;
  853. }
  854. }
  855. // ovladani kdyz je kurzor na hranich obrazovky
  856. #define X_HRANICE 4
  857. #define Y_HRANICE 4
  858. int ber_ovladani_mysi(G_KONFIG * p_ber, int *p_zmena)
  859. {
  860. int posun, rotace, smer_pos, smer_rot;
  861. *p_zmena = FALSE;
  862. if (key[p_ber->conf_p_key] || key[p_ber->conf_r_key]
  863. || !(p_ber->conf_ovladani_rohy))
  864. return (TRUE);
  865. if (p_ber->conf_ovladani_rohy_default) { // implicidne rotace
  866. posun = mi.ot2;
  867. rotace = !mi.ot2;
  868. }
  869. else { // implicidne posun
  870. posun = !mi.ot2;
  871. rotace = mi.ot2;
  872. }
  873. if (p_ber->conf_ovladani_rohy_smer) { // prehozeny smer ovladani
  874. smer_pos = -1;
  875. smer_rot = -1;
  876. }
  877. else {
  878. smer_pos = 1;
  879. smer_rot = 1;
  880. }
  881. if (mi.x <= SCREEN_XSTART + X_HRANICE) { // rotace/posun
  882. if (posun) {
  883. ber_ovladani_mysi_posun(p_ber, -smer_pos, FALSE);
  884. *p_zmena = TRUE;
  885. }
  886. else if (rotace) {
  887. ber_ovladani_mysi_rotace(p_ber, -smer_rot, FALSE);
  888. *p_zmena = TRUE;
  889. }
  890. }
  891. else if (mi.x >= SCREEN_XSTART + SCREEN_XRES - X_HRANICE) { // rotace/posun/zoom
  892. if (posun) {
  893. ber_ovladani_mysi_posun(p_ber, smer_pos, FALSE);
  894. *p_zmena = TRUE;
  895. }
  896. else if (rotace) {
  897. ber_ovladani_mysi_rotace(p_ber, smer_rot, FALSE);
  898. *p_zmena = TRUE;
  899. }
  900. }
  901. if (mi.y <= SCREEN_YSTART + Y_HRANICE) { // rotace/posun
  902. if (posun) {
  903. ber_ovladani_mysi_posun(p_ber, 0, -smer_pos);
  904. *p_zmena = TRUE;
  905. }
  906. else if (rotace) {
  907. ber_ovladani_mysi_rotace(p_ber, 0, -smer_rot);
  908. *p_zmena = TRUE;
  909. }
  910. }
  911. else if (mi.y >= SCREEN_YSTART + SCREEN_YRES - Y_HRANICE) { // rotace/posun/zoom
  912. if (posun) {
  913. ber_ovladani_mysi_posun(p_ber, 0, smer_pos);
  914. *p_zmena = TRUE;
  915. }
  916. else if (rotace) {
  917. ber_ovladani_mysi_rotace(p_ber, 0, smer_rot);
  918. *p_zmena = TRUE;
  919. }
  920. }
  921. return (TRUE);
  922. }
  923. void ber_klavesy_hra(G_KONFIG * p_ber)
  924. {
  925. if (!karmin_aktivni)
  926. return;
  927. if (PRCameraFlag) {
  928. p_ber->ref_zmena = FALSE;
  929. if (ber_ovladani_mysi(p_ber, &p_ber->ref_zmena)) {
  930. if (p_ber->ref_zmena)
  931. p_ber->sflag1 |= SFL_POSUN;
  932. }
  933. if (key[p_ber->conf_p_key]) {
  934. p_ber->sflag1 |= SFL_POSUN;
  935. ber_prikaz_posun_sceny(p_ber, p_ber->ref_pos);
  936. p_ber->ref_pos = FALSE;
  937. p_ber->ref_zmena = TRUE;
  938. }
  939. else {
  940. p_ber->ref_pos = TRUE;
  941. }
  942. if (key[p_ber->conf_r_key]) {
  943. p_ber->sflag1 |= SFL_ROTACE;
  944. ber_prikaz_rotace_sceny(p_ber, p_ber->ref_rot);
  945. p_ber->ref_rot = FALSE;
  946. p_ber->ref_zmena = TRUE;
  947. }
  948. else {
  949. p_ber->ref_rot = TRUE;
  950. }
  951. if (key[K_PLUS] || key[K_MINUS]) {
  952. ber_prikaz_scena_zoom(key[K_PLUS] ? -1 : 1);
  953. p_ber->ref_zmena = TRUE;
  954. p_ber->sflag1 |= SFL_ZOOM;
  955. key[K_PLUS] = key[K_MINUS] = FALSE;
  956. }
  957. if (p_ber->sflag1 & (SFL_POSUN | SFL_ROTACE | SFL_ZOOM)
  958. && !p_ber->ref_zmena) {
  959. p_ber->sflag1 = FALSE;
  960. PRCameraFlagChange = 2;
  961. }
  962. }
  963. #ifdef _DEBUG
  964. if (key[K_L]) {
  965. key[K_L] = FALSE;
  966. ber_test_animaci(p_ber);
  967. }
  968. if (key[K_K]) {
  969. key[K_K] = FALSE;
  970. ber_test_animaci2(p_ber);
  971. }
  972. if (key[K_J]) {
  973. key[K_J] = FALSE;
  974. ber_test_animaci3(p_ber);
  975. }
  976. #endif
  977. }