1
0

r_dotfnt.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. // alphachannel safe 11/21/99
  25. #include <windows.h>
  26. #include <stdio.h>
  27. #include <math.h>
  28. #include <commctrl.h>
  29. #include "resource.h"
  30. #include "r_defs.h"
  31. #include "../Agave/Language/api_language.h"
  32. #ifndef LASER
  33. #define C_THISCLASS C_DotFountainClass
  34. #define MOD_NAME "Render / Dot Fountain"
  35. #define NUM_ROT_DIV 30
  36. #define NUM_ROT_HEIGHT 256
  37. typedef struct {
  38. float r, dr;
  39. float h, dh;
  40. float ax,ay;
  41. int c;
  42. } FountainPoint;
  43. class C_THISCLASS : public C_RBASE {
  44. protected:
  45. float r;
  46. FountainPoint points[NUM_ROT_HEIGHT][NUM_ROT_DIV];
  47. int color_tab[64];
  48. public:
  49. C_THISCLASS();
  50. virtual ~C_THISCLASS();
  51. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int, int);
  52. virtual char *get_desc() { static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_RENDER_DOT_FOUNTAIN,desc,128):desc); }
  53. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  54. virtual void load_config(unsigned char *data, int len);
  55. virtual int save_config(unsigned char *data);
  56. int rotvel,angle;
  57. int colors[5];
  58. void initcolortab();
  59. };
  60. #define PUT_INT(y) data[pos]=(y)&255; data[pos+1]=(y>>8)&255; data[pos+2]=(y>>16)&255; data[pos+3]=(y>>24)&255
  61. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  62. void C_THISCLASS::load_config(unsigned char *data, int len)
  63. {
  64. int pos=0;
  65. if (len-pos >= 4) { rotvel=GET_INT(); pos+=4; }
  66. int x;
  67. for (x = 0; x < 5; x ++)
  68. {
  69. if (len-pos >= 4) { colors[x]=GET_INT(); pos+=4; }
  70. }
  71. if (len-pos >= 4) { angle=GET_INT(); pos+=4; }
  72. if (len-pos >= 4) { int rr=GET_INT(); pos+=4; r=rr/32.0f;}
  73. initcolortab();
  74. }
  75. int C_THISCLASS::save_config(unsigned char *data)
  76. {
  77. int rr;
  78. int pos=0;
  79. int x;
  80. PUT_INT(rotvel); pos+=4;
  81. for (x = 0; x < 5; x ++)
  82. {
  83. PUT_INT(colors[x]); pos+=4;
  84. }
  85. PUT_INT(angle); pos+=4;
  86. rr=(int)(r*32.0f);
  87. PUT_INT(rr); pos+=4;
  88. return pos;
  89. }
  90. void C_THISCLASS::initcolortab()
  91. {
  92. int x,r,g,b,dr,dg,db,t;
  93. for (t=0; t < 4; t ++)
  94. {
  95. r=(colors[t]&255)<<16;
  96. g=((colors[t]>>8)&255)<<16;
  97. b=((colors[t]>>16)&255)<<16;
  98. dr=(((colors[t+1]&255)-(colors[t]&255))<<16)/16;
  99. dg=((((colors[t+1]>>8)&255)-((colors[t]>>8)&255))<<16)/16;
  100. db=((((colors[t+1]>>16)&255)-((colors[t]>>16)&255))<<16)/16;
  101. for (x = 0; x < 16; x ++)
  102. {
  103. color_tab[t*16+x]=(r>>16)|((g>>16)<<8)|((b>>16)<<16);
  104. r+=dr;g+=dg;b+=db;
  105. }
  106. }
  107. }
  108. C_THISCLASS::C_THISCLASS()
  109. {
  110. colors[0]=RGB(24,107,28); // reverse BGR :)
  111. colors[1]=RGB(35,10,255);
  112. colors[2]=RGB(116,29,42);
  113. colors[3]=RGB(217,54,144);
  114. colors[4]=RGB(255,136,107);
  115. initcolortab();
  116. memset(points,0,sizeof(points));
  117. angle=-20;
  118. rotvel=16;
  119. }
  120. C_THISCLASS::~C_THISCLASS()
  121. {
  122. }
  123. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int width, int height)
  124. {
  125. if (isBeat&0x80000000) return 0;
  126. int fo, p;
  127. float matrix[16],matrix2[16];
  128. matrixRotate(matrix,2,r);
  129. matrixRotate(matrix2,1,(float)angle);
  130. matrixMultiply(matrix,matrix2);
  131. matrixTranslate(matrix2,0.0f,-20.0f,400.0f);
  132. matrixMultiply(matrix,matrix2);
  133. FountainPoint pb[NUM_ROT_DIV];
  134. FountainPoint *in, *out;
  135. memcpy(pb,&points[0],sizeof(pb));
  136. fo = NUM_ROT_HEIGHT-2;
  137. do // transform points and remove old ones
  138. {
  139. float booga = 1.3f / (fo+100);
  140. in = &points[fo][0];
  141. out = &points[fo+1][0];
  142. for (p = 0; p < NUM_ROT_DIV; p ++)
  143. {
  144. *out = *in;
  145. out->r += out->dr;
  146. out->dh += 0.05f;
  147. out->dr += booga;
  148. out->h += out->dh;
  149. out++;
  150. in++;
  151. }
  152. } while (fo--);
  153. out = &points[0][0];
  154. in = pb;
  155. { // create new points
  156. float a;
  157. unsigned char *sd = (unsigned char *) visdata[1][0];
  158. for (p = 0; p < NUM_ROT_DIV; p ++)
  159. {
  160. int t;
  161. if (p >= NUM_ROT_DIV) t= (sd[576] ^ 128);
  162. else t= (*sd ^ 128);
  163. sd++;
  164. t*=5;
  165. t/=4;
  166. t-=64;
  167. if (isBeat) t+=128;
  168. if (t > 255) t=255;
  169. // t+=sd[576]^128;
  170. // t/=2;
  171. out->r = 1.0f;
  172. float dr = t/200.0f;
  173. if (dr < 0) dr = -dr;
  174. out->h = 250;
  175. dr += 1.0;
  176. out->dh = -dr * (100.0f + (out->dh - in->dh)) / 100.0f * 2.8f;
  177. t = t/4;
  178. if (t > 63) t = 63;
  179. out->c = color_tab[t];
  180. a = p* 3.14159f * 2.0f / NUM_ROT_DIV;
  181. out->ax=(float)sin(a);
  182. out->ay=(float)cos(a);
  183. out->dr =0.0;
  184. out++;
  185. in++;
  186. }
  187. }
  188. float adj=width*440.0f/640.0f;
  189. float adj2=height*440.0f/480.0f;
  190. if (adj2 < adj) adj=adj2;
  191. in = &points[0][0];
  192. for (fo = 0; fo < NUM_ROT_HEIGHT; fo ++)
  193. {
  194. for (p = 0; p < NUM_ROT_DIV; p ++)
  195. {
  196. register float x, y, z;
  197. matrixApply(matrix,in->ax*in->r,in->h,in->ay*in->r,&x,&y,&z);
  198. z = adj / z;
  199. if (z > 0.0000001)
  200. {
  201. register int ix = (int) (x * z) + width/2;
  202. register int iy = (int) (y * z) + height/2;
  203. if (iy >= 0 && iy < height && ix >= 0 && ix < width)
  204. {
  205. BLEND_LINE(framebuffer + iy*width + ix,in->c);
  206. }
  207. }
  208. in++;
  209. }
  210. }
  211. r += rotvel/5.0f;
  212. if (r >= 360.0f) r -= 360.0f;
  213. if (r < 0.0f) r += 360.0f;
  214. return 0;
  215. }
  216. C_RBASE *R_DotFountain(char *desc)
  217. {
  218. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  219. return (C_RBASE *) new C_THISCLASS();
  220. }
  221. static C_THISCLASS *g_this;
  222. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  223. {
  224. int *a=NULL;
  225. switch (uMsg)
  226. {
  227. case WM_COMMAND:
  228. if (LOWORD(wParam) == IDC_BUTTON1)
  229. {
  230. g_this->rotvel=0;
  231. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETPOS,1,50);
  232. }
  233. if (LOWORD(wParam) >= IDC_C1 && LOWORD(wParam) <= IDC_C5) {
  234. GR_SelectColor(hwndDlg,&g_this->colors[IDC_C5-LOWORD(wParam)]);
  235. InvalidateRect(GetDlgItem(hwndDlg,LOWORD(wParam)),NULL,FALSE);
  236. g_this->initcolortab();
  237. }
  238. return 0;
  239. case WM_DRAWITEM:
  240. {
  241. DRAWITEMSTRUCT *di=(DRAWITEMSTRUCT *)lParam;
  242. if (di->CtlID >= IDC_C1 && di->CtlID <= IDC_C5)
  243. {
  244. GR_DrawColoredButton(di,g_this->colors[IDC_C5-di->CtlID]);
  245. }
  246. }
  247. return 0;
  248. case WM_INITDIALOG:
  249. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMIN,0,0);
  250. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMAX,0,101);
  251. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETPOS,1,g_this->rotvel+50);
  252. SendDlgItemMessage(hwndDlg,IDC_ANGLE,TBM_SETRANGEMIN,0,0);
  253. SendDlgItemMessage(hwndDlg,IDC_ANGLE,TBM_SETRANGEMAX,0,181);
  254. SendDlgItemMessage(hwndDlg,IDC_ANGLE,TBM_SETPOS,1,g_this->angle+90);
  255. return 1;
  256. case WM_HSCROLL:
  257. {
  258. HWND swnd = (HWND) lParam;
  259. int t = (int) SendMessage(swnd,TBM_GETPOS,0,0);
  260. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER1))
  261. {
  262. g_this->rotvel=t-50;
  263. }
  264. if (swnd == GetDlgItem(hwndDlg,IDC_ANGLE))
  265. {
  266. g_this->angle=t-90;
  267. }
  268. }
  269. }
  270. return 0;
  271. }
  272. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  273. {
  274. g_this = this;
  275. return WASABI_API_CREATEDIALOG(IDD_CFG_DOTPLANE,hwndParent,g_DlgProc);
  276. }
  277. #else
  278. C_RBASE *R_DotFountain(char *desc) {return NULL; }
  279. #endif