/xbmc/visualizations/Goom/goom2k4-0/src/surf3d.c

http://github.com/xbmc/xbmc · C · 107 lines · 91 code · 16 blank · 0 comment · 17 complexity · 89f39ff10a180462243ce09be2eaf3d4 MD5 · raw file

  1. #include "surf3d.h"
  2. #include "goom_plugin_info.h"
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. grid3d *grid3d_new (int sizex, int defx, int sizez, int defz, v3d center) {
  7. int x = defx;
  8. int y = defz;
  9. grid3d *g = malloc (sizeof(grid3d));
  10. surf3d *s = &(g->surf);
  11. s->nbvertex = x*y;
  12. s->vertex = malloc (x*y*sizeof(v3d));
  13. s->svertex = malloc (x*y*sizeof(v3d));
  14. s->center = center;
  15. g->defx=defx;
  16. g->sizex=sizex;
  17. g->defz=defz;
  18. g->sizez=sizez;
  19. g->mode=0;
  20. while (y) {
  21. --y;
  22. x = defx;
  23. while (x) {
  24. --x;
  25. s->vertex[x+defx*y].x = (float)(x-defx/2)*sizex/defx;
  26. s->vertex[x+defx*y].y = 0;
  27. s->vertex[x+defx*y].z = (float)(y-defz/2)*sizez/defz;
  28. }
  29. }
  30. return g;
  31. }
  32. void grid3d_draw (PluginInfo *plug, grid3d *g, int color, int colorlow,
  33. int dist, Pixel *buf, Pixel *back, int W,int H) {
  34. int x;
  35. v2d v2,v2x;
  36. v2d *v2_array = malloc(g->surf.nbvertex * sizeof(v2d));
  37. v3d_to_v2d(g->surf.svertex, g->surf.nbvertex, W, H, dist, v2_array);
  38. for (x=0;x<g->defx;x++) {
  39. int z;
  40. v2x = v2_array[x];
  41. for (z=1;z<g->defz;z++) {
  42. v2 = v2_array[z*g->defx + x];
  43. if (((v2.x != -666) || (v2.y!=-666))
  44. && ((v2x.x != -666) || (v2x.y!=-666))) {
  45. plug->methods.draw_line (buf,v2x.x,v2x.y,v2.x,v2.y, colorlow, W, H);
  46. plug->methods.draw_line (back,v2x.x,v2x.y,v2.x,v2.y, color, W, H);
  47. }
  48. v2x = v2;
  49. }
  50. }
  51. free(v2_array);
  52. }
  53. void surf3d_rotate (surf3d *s, float angle) {
  54. int i;
  55. float cosa;
  56. float sina;
  57. SINCOS(angle,sina,cosa);
  58. for (i=0;i<s->nbvertex;i++) {
  59. Y_ROTATE_V3D(s->vertex[i],s->svertex[i],cosa,sina);
  60. }
  61. }
  62. void surf3d_translate (surf3d *s) {
  63. int i;
  64. for (i=0;i<s->nbvertex;i++) {
  65. TRANSLATE_V3D(s->center,s->svertex[i]);
  66. }
  67. }
  68. void grid3d_update (grid3d *g, float angle, float *vals, float dist) {
  69. int i;
  70. float cosa;
  71. float sina;
  72. surf3d *s = &(g->surf);
  73. v3d cam = s->center;
  74. cam.z += dist;
  75. SINCOS((angle/4.3f),sina,cosa);
  76. cam.y += sina*2.0f;
  77. SINCOS(angle,sina,cosa);
  78. if (g->mode==0) {
  79. if (vals)
  80. for (i=0;i<g->defx;i++)
  81. s->vertex[i].y = s->vertex[i].y*0.2 + vals[i]*0.8;
  82. for (i=g->defx;i<s->nbvertex;i++) {
  83. s->vertex[i].y *= 0.255f;
  84. s->vertex[i].y += (s->vertex[i-g->defx].y * 0.777f);
  85. }
  86. }
  87. for (i=0;i<s->nbvertex;i++) {
  88. Y_ROTATE_V3D(s->vertex[i],s->svertex[i],cosa,sina);
  89. TRANSLATE_V3D(cam,s->svertex[i]);
  90. }
  91. }