gsd_fringe.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. /*!
  2. \file gsd_fonts.c
  3. \brief OGSF library - manipulating surfaces/fridge (lower level function)
  4. GRASS OpenGL gsurf OGSF Library
  5. \todo This file needs to be re-written in OpenGL
  6. (C) 1999-2008 by the GRASS Development Team
  7. This program is free software under the
  8. GNU General Public License (>=v2).
  9. Read the file COPYING that comes with GRASS
  10. for details.
  11. \author Bill Brown USACERL, GMSL/University of Illinois
  12. \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
  13. */
  14. #include <grass/gstypes.h>
  15. #include "gsget.h"
  16. #include "rowcol.h"
  17. #define FRINGE_FORE 0x000000
  18. #define FRINGE_WIDTH 2
  19. /*!
  20. \brief Normals
  21. */
  22. float Nnorth[] = { 0.0, 0.8, 0.6 };
  23. float Nsouth[] = { 0.0, -0.8, 0.6 };
  24. float Neast[] = { 0.8, 0.0, 0.6 };
  25. float Nwest[] = { -0.8, 0.0, 0.6 };
  26. float Ntop[] = { 0.0, 0.0, 1.0 };
  27. float Nbottom[] = { 0.0, 0.0, -1.0 };
  28. /*!
  29. \brief Display fridge
  30. \todo add elevation for bottom
  31. add color option
  32. add ruler grid lines
  33. \param surf surface (geosurf)
  34. \param clr
  35. \param elev
  36. \param where
  37. */
  38. void gsd_display_fringe(geosurf * surf, unsigned long clr, float elev,
  39. int where[4])
  40. {
  41. float bot, xres, yres; /* world size of view cell */
  42. int ycnt, xcnt; /* number of view cells across */
  43. float xmax, ymax;
  44. xres = surf->x_mod * surf->xres;
  45. yres = surf->y_mod * surf->yres;
  46. xcnt = VCOLS(surf);
  47. ycnt = VROWS(surf);
  48. xmax = surf->xmax;
  49. ymax = surf->ymax;
  50. /*
  51. bot = surf->zmin - ((surf->zrange/4.) * surf->z_exag);
  52. */
  53. bot = elev - ((surf->zrange / 4.) * surf->z_exag);
  54. gsd_linewidth(FRINGE_WIDTH);
  55. gsd_colormode(CM_COLOR);
  56. /* North fringe */
  57. if (where[0] || where[1]) {
  58. glNormal3fv(Nnorth);
  59. gsd_color_func(clr);
  60. gsd_zwritemask(0x0);
  61. gsd_fringe_horiz_poly(bot, surf, 0, 0);
  62. gsd_color_func(FRINGE_FORE); /* WHITE */
  63. gsd_fringe_horiz_line(bot, surf, 0, 0);
  64. gsd_zwritemask(0xffffffff);
  65. /* wmpack (0); ??? glColorMask */
  66. gsd_color_func(clr);
  67. gsd_fringe_horiz_poly(bot, surf, 0, 0);
  68. }
  69. /* South fringe */
  70. if (where[2] || where[3]) {
  71. glNormal3fv(Nsouth);
  72. gsd_color_func(clr);
  73. gsd_zwritemask(0x0);
  74. gsd_fringe_horiz_poly(bot, surf, ycnt - 2, 1);
  75. gsd_color_func(FRINGE_FORE); /* WHITE */
  76. gsd_fringe_horiz_line(bot, surf, ycnt - 2, 1);
  77. gsd_zwritemask(0xffffffff);
  78. /* wmpack (0); ??? glColorMask */
  79. gsd_color_func(clr);
  80. gsd_fringe_horiz_poly(bot, surf, ycnt - 2, 1);
  81. }
  82. /* West fringe */
  83. if (where[0] || where[2]) {
  84. glNormal3fv(Nwest);
  85. gsd_color_func(clr);
  86. gsd_zwritemask(0x0);
  87. gsd_fringe_vert_poly(bot, surf, 0, 0);
  88. gsd_color_func(FRINGE_FORE);
  89. gsd_fringe_vert_line(bot, surf, 0, 0);
  90. gsd_zwritemask(0xffffffff);
  91. gsd_color_func(clr);
  92. gsd_fringe_vert_poly(bot, surf, 0, 0);
  93. }
  94. /* East fringe */
  95. if (where[1] || where[3]) {
  96. glNormal3fv(Neast);
  97. gsd_color_func(clr);
  98. gsd_zwritemask(0x0);
  99. gsd_fringe_vert_poly(bot, surf, xcnt - 2, 1);
  100. gsd_color_func(FRINGE_FORE);
  101. gsd_fringe_vert_line(bot, surf, xcnt - 2, 1);
  102. gsd_zwritemask(0xffffffff);
  103. gsd_color_func(clr);
  104. gsd_fringe_vert_poly(bot, surf, xcnt - 2, 1);
  105. }
  106. return;
  107. }
  108. /*!
  109. \brief ADD
  110. \param bot
  111. \param surf surface (geosurf)
  112. \param row
  113. \param side
  114. */
  115. void gsd_fringe_horiz_poly(float bot, geosurf * surf, int row, int side)
  116. {
  117. int col;
  118. int cnt;
  119. float pt[4];
  120. typbuff *buff;
  121. long offset;
  122. int xcnt;
  123. GS_set_draw(GSD_FRONT);
  124. gsd_pushmatrix();
  125. gsd_do_scale(1);
  126. gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
  127. buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
  128. xcnt = VCOLS(surf);
  129. gsd_bgnpolygon();
  130. col = 0;
  131. /* floor left */
  132. pt[X] = col * (surf->x_mod * surf->xres);
  133. pt[Y] =
  134. ((surf->rows - 1) * surf->yres) -
  135. ((row + side) * (surf->y_mod * surf->yres));
  136. pt[Z] = bot;
  137. gsd_vert_func(pt);
  138. offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
  139. GET_MAPATT(buff, offset, pt[Z]);
  140. pt[Z] = pt[Z] * surf->z_exag;
  141. gsd_vert_func(pt);
  142. cnt = 1;
  143. for (col = 0; col < xcnt - 1; col++) {
  144. /* bottom right */
  145. pt[X] = col * (surf->x_mod * surf->xres);
  146. pt[Y] =
  147. ((surf->rows - 1) * surf->yres) -
  148. ((row + side) * (surf->y_mod * surf->yres));
  149. offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
  150. GET_MAPATT(buff, offset, pt[Z]);
  151. pt[Z] = pt[Z] * surf->z_exag;
  152. gsd_vert_func(pt);
  153. cnt++;
  154. }
  155. col--;
  156. pt[X] = col * (surf->x_mod * surf->xres);
  157. pt[Y] =
  158. ((surf->rows - 1) * surf->yres) -
  159. ((row + side) * (surf->y_mod * surf->yres));
  160. pt[Z] = bot;
  161. gsd_vert_func(pt);
  162. gsd_endpolygon();
  163. GS_done_draw();
  164. gsd_popmatrix();
  165. gsd_flush();
  166. return;
  167. }
  168. /*!
  169. \brief ADD
  170. \param bot
  171. \param surf surface (geosurf)
  172. \param row
  173. \param side
  174. */
  175. void gsd_fringe_horiz_line(float bot, geosurf * surf, int row, int side)
  176. {
  177. int col;
  178. int cnt;
  179. float pt[4];
  180. typbuff *buff;
  181. long offset;
  182. int xcnt;
  183. GS_set_draw(GSD_FRONT);
  184. gsd_pushmatrix();
  185. gsd_do_scale(1);
  186. gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
  187. buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
  188. xcnt = VCOLS(surf);
  189. gsd_bgnline();
  190. col = 0;
  191. /* floor left */
  192. pt[X] = col * (surf->x_mod * surf->xres);
  193. pt[Y] =
  194. ((surf->rows - 1) * surf->yres) -
  195. ((row + side) * (surf->y_mod * surf->yres));
  196. pt[Z] = bot;
  197. gsd_vert_func(pt);
  198. offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
  199. GET_MAPATT(buff, offset, pt[Z]);
  200. pt[Z] = pt[Z] * surf->z_exag;
  201. gsd_vert_func(pt);
  202. cnt = 1;
  203. for (col = 0; col < xcnt - 1; col++) {
  204. /* bottom right */
  205. pt[X] = col * (surf->x_mod * surf->xres);
  206. pt[Y] =
  207. ((surf->rows - 1) * surf->yres) -
  208. ((row + side) * (surf->y_mod * surf->yres));
  209. offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
  210. GET_MAPATT(buff, offset, pt[Z]);
  211. pt[Z] = pt[Z] * surf->z_exag;
  212. gsd_vert_func(pt);
  213. cnt++;
  214. }
  215. col--;
  216. pt[X] = col * (surf->x_mod * surf->xres);
  217. pt[Y] =
  218. ((surf->rows - 1) * surf->yres) -
  219. ((row + side) * (surf->y_mod * surf->yres));
  220. pt[Z] = bot;
  221. gsd_vert_func(pt);
  222. col = 0;
  223. pt[X] = col * (surf->x_mod * surf->xres);
  224. pt[Y] =
  225. ((surf->rows - 1) * surf->yres) -
  226. ((row + side) * (surf->y_mod * surf->yres));
  227. pt[Z] = bot;
  228. gsd_vert_func(pt);
  229. gsd_endline();
  230. GS_done_draw();
  231. gsd_popmatrix();
  232. gsd_flush();
  233. return;
  234. }
  235. /*!
  236. \brief ADD
  237. \param bot
  238. \param surf surface (geosurf)
  239. \param col
  240. \param side [unused]
  241. */
  242. void gsd_fringe_vert_poly(float bot, geosurf * surf, int col, int side)
  243. {
  244. int row;
  245. int cnt;
  246. float pt[4];
  247. typbuff *buff;
  248. long offset;
  249. int ycnt;
  250. GS_set_draw(GSD_FRONT);
  251. gsd_pushmatrix();
  252. gsd_do_scale(1);
  253. gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
  254. gsd_bgnpolygon();
  255. buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
  256. ycnt = VROWS(surf);
  257. row = 0;
  258. /* floor left */
  259. pt[X] = col * (surf->x_mod * surf->xres);
  260. pt[Y] =
  261. ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
  262. pt[Z] = bot;
  263. gsd_vert_func(pt);
  264. offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
  265. GET_MAPATT(buff, offset, pt[Z]);
  266. pt[Z] = pt[Z] * surf->z_exag;
  267. gsd_vert_func(pt);
  268. cnt = 1;
  269. for (row = 0; row < ycnt - 1; row++) {
  270. /* bottom right */
  271. pt[X] = col * (surf->x_mod * surf->xres);
  272. pt[Y] =
  273. ((surf->rows - 1) * surf->yres) -
  274. (row * (surf->y_mod * surf->yres));
  275. offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
  276. GET_MAPATT(buff, offset, pt[Z]);
  277. pt[Z] = pt[Z] * surf->z_exag;
  278. gsd_vert_func(pt);
  279. cnt++;
  280. }
  281. row--;
  282. pt[X] = col * (surf->x_mod * surf->xres);
  283. pt[Y] =
  284. ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
  285. pt[Z] = bot;
  286. gsd_vert_func(pt);
  287. gsd_endpolygon();
  288. GS_done_draw();
  289. gsd_popmatrix();
  290. gsd_flush();
  291. return;
  292. }
  293. /*!
  294. \brief ADD
  295. \param bot
  296. \param surf surface (geosurf)
  297. \param col
  298. \param side [unused]
  299. */
  300. void gsd_fringe_vert_line(float bot, geosurf * surf, int col, int side)
  301. {
  302. int row;
  303. int cnt;
  304. float pt[4];
  305. typbuff *buff;
  306. long offset;
  307. int ycnt;
  308. GS_set_draw(GSD_FRONT);
  309. gsd_pushmatrix();
  310. gsd_do_scale(1);
  311. gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
  312. buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
  313. ycnt = VROWS(surf);
  314. gsd_bgnline();
  315. row = 0;
  316. /* floor left */
  317. pt[X] = col * (surf->x_mod * surf->xres);
  318. pt[Y] =
  319. ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
  320. pt[Z] = bot;
  321. gsd_vert_func(pt);
  322. offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
  323. GET_MAPATT(buff, offset, pt[Z]);
  324. pt[Z] = pt[Z] * surf->z_exag;
  325. gsd_vert_func(pt);
  326. cnt = 1;
  327. for (row = 0; row < ycnt - 1; row++) {
  328. /* bottom right */
  329. pt[X] = col * (surf->x_mod * surf->xres);
  330. pt[Y] =
  331. ((surf->rows - 1) * surf->yres) -
  332. (row * (surf->y_mod * surf->yres));
  333. offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
  334. GET_MAPATT(buff, offset, pt[Z]);
  335. pt[Z] = pt[Z] * surf->z_exag;
  336. gsd_vert_func(pt);
  337. cnt++;
  338. }
  339. row--;
  340. pt[X] = col * (surf->x_mod * surf->xres);
  341. pt[Y] =
  342. ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
  343. pt[Z] = bot;
  344. gsd_vert_func(pt);
  345. row = 0;
  346. pt[X] = col * (surf->x_mod * surf->xres);
  347. pt[Y] =
  348. ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
  349. pt[Z] = bot;
  350. gsd_vert_func(pt);
  351. gsd_endline();
  352. GS_done_draw();
  353. gsd_popmatrix();
  354. gsd_flush();
  355. return;
  356. }
  357. /*!
  358. \brief ADD
  359. \param bot
  360. \param surf surface (geosurf)
  361. \param row
  362. \param side
  363. */
  364. void gsd_fringe_horiz_line2(float bot, geosurf * surf, int row, int side)
  365. {
  366. int col;
  367. int cnt;
  368. float pt[4];
  369. typbuff *buff;
  370. long offset;
  371. int xcnt;
  372. GS_set_draw(GSD_FRONT);
  373. gsd_pushmatrix();
  374. gsd_do_scale(1);
  375. gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
  376. buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
  377. xcnt = VCOLS(surf);
  378. gsd_bgnline();
  379. col = 0;
  380. /* floor left */
  381. pt[X] = surf->xmin + (col * (surf->x_mod * surf->xres));
  382. pt[Y] = surf->ymax - ((row + side) * (surf->y_mod * surf->yres));
  383. pt[Z] = bot;
  384. gsd_vert_func(pt);
  385. offset = 0;
  386. GET_MAPATT(buff, offset, pt[Z]);
  387. pt[Z] = pt[Z] * surf->z_exag;
  388. gsd_vert_func(pt);
  389. cnt = 1;
  390. for (col = 0; col < xcnt - 1; col++) {
  391. /* bottom right */
  392. pt[X] = surf->xmin + (col * (surf->x_mod * surf->xres));
  393. pt[Y] = surf->ymax - ((row + side) * (surf->y_mod * surf->yres));
  394. offset = col * surf->x_mod;
  395. GET_MAPATT(buff, offset, pt[Z]);
  396. pt[Z] = pt[Z] * surf->z_exag;
  397. gsd_vert_func(pt);
  398. cnt++;
  399. }
  400. col--;
  401. pt[X] = surf->xmin + (col * (surf->x_mod * surf->xres));
  402. pt[Y] = surf->ymax - ((row + side) * (surf->y_mod * surf->yres));
  403. pt[Z] = bot;
  404. gsd_vert_func(pt);
  405. gsd_endline();
  406. GS_done_draw();
  407. gsd_popmatrix();
  408. gsd_flush();
  409. return;
  410. }