rl_cones.cpp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. #ifdef LASER
  25. #include <windows.h>
  26. #include <commctrl.h>
  27. #include "../r_defs.h"
  28. #include "../resource.h"
  29. #include <math.h>
  30. #define C_THISCLASS CLASER_MovingConeClass
  31. #define MOD_NAME "Render / Moving Cone"
  32. class C_THISCLASS : public C_RBASE {
  33. protected:
  34. public:
  35. C_THISCLASS();
  36. virtual ~C_THISCLASS();
  37. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h); // returns 1 if fbout has dest
  38. virtual char *get_desc() { return MOD_NAME; }
  39. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  40. virtual void load_config(unsigned char *data, int len);
  41. virtual int save_config(unsigned char *data);
  42. int maxdist[2],size,size2,num_seg;
  43. int s_pos;
  44. int beatcnt;
  45. double c[2];
  46. double v[2];
  47. double p[2];
  48. int mode;
  49. int colors[16],num_colors;
  50. int color_pos;
  51. };
  52. #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
  53. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  54. void C_THISCLASS::load_config(unsigned char *data, int len)
  55. {
  56. int pos=0;
  57. int x=0;
  58. if (len-pos >= 4) { num_colors=GET_INT(); pos+=4; }
  59. if (num_colors <= 16) while (len-pos >= 4 && x < num_colors) { colors[x++]=GET_INT(); pos+=4; }
  60. else num_colors=0;
  61. if (len-pos >= 4) { maxdist[0]=maxdist[1]=GET_INT(); pos+=4; }
  62. if (len-pos >= 4) { size=GET_INT(); pos+=4; }
  63. if (len-pos >= 4) { size2=GET_INT(); pos+=4; }
  64. if (len-pos >= 4) { num_seg=GET_INT(); pos+=4; }
  65. if (len-pos >= 4) { mode=GET_INT(); pos+=4; }
  66. if (len-pos >= 4) { maxdist[1]=GET_INT(); pos+=4; }
  67. s_pos=size;
  68. }
  69. int C_THISCLASS::save_config(unsigned char *data)
  70. {
  71. int pos=0,x=0;
  72. PUT_INT(num_colors); pos+=4;
  73. while (x < num_colors) { PUT_INT(colors[x]); x++; pos+=4; }
  74. PUT_INT(maxdist[0]); pos+=4;
  75. PUT_INT(size); pos+=4;
  76. PUT_INT(size2); pos+=4;
  77. PUT_INT(num_seg); pos+=4;
  78. PUT_INT(mode); pos+=4;
  79. PUT_INT(maxdist[1]); pos+=4;
  80. return pos;
  81. }
  82. C_THISCLASS::C_THISCLASS()
  83. {
  84. num_seg=8;
  85. size=size2=s_pos=8;
  86. maxdist[0]=maxdist[1]=16;
  87. c[0]=c[1]=0.0f;
  88. v[0]=-0.01551;
  89. v[1]=0.0;
  90. p[0]=-0.6;
  91. p[1]=0.3;
  92. num_colors=1;
  93. memset(colors,0,sizeof(colors));
  94. colors[0]=RGB(255,255,255);
  95. color_pos=0;
  96. beatcnt=0;
  97. mode=0;
  98. }
  99. C_THISCLASS::~C_THISCLASS()
  100. {
  101. }
  102. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h) // returns 1 if fbout has dest
  103. {
  104. if (isBeat&0x80000000) return 0;
  105. LineType l;
  106. int x;
  107. int current_color;
  108. if (!num_colors) return 0;
  109. color_pos++;
  110. if (color_pos >= num_colors * 64) color_pos=0;
  111. {
  112. int p=color_pos/64;
  113. int r=color_pos&63;
  114. int c1,c2;
  115. int r1,r2,r3;
  116. c1=colors[p];
  117. if (p+1 < num_colors)
  118. c2=colors[p+1];
  119. else c2=colors[0];
  120. r1=(((c1&255)*(63-r))+((c2&255)*r))/64;
  121. r2=((((c1>>8)&255)*(63-r))+(((c2>>8)&255)*r))/64;
  122. r3=((((c1>>16)&255)*(63-r))+(((c2>>16)&255)*r))/64;
  123. current_color=r1|(r2<<8)|(r3<<16);
  124. }
  125. float xp,yp;
  126. if (isBeat)
  127. {
  128. c[0]=((rand()%33)-16)/48.0f;
  129. c[1]=((rand()%33)-16)/48.0f;
  130. }
  131. {
  132. if (p[0] >= 0.0000001 || p[0] <= -0.0000001) v[0] -= 0.004*(p[0]-c[0]);
  133. if (p[1] >= 0.0000001 || p[1] <= -0.0000001) v[1] -= 0.004*(p[1]-c[1]);
  134. }
  135. p[0]+=v[0];
  136. p[1]+=v[1];
  137. v[0]*=0.991;
  138. v[1]*=0.991;
  139. xp=(float) (p[0]*(maxdist[0]/32.0));
  140. yp=(float) (p[1]*(maxdist[1]/32.0));
  141. if (isBeat)
  142. s_pos=size2;
  143. int sz=s_pos;
  144. s_pos=(s_pos+size)/2;
  145. {
  146. float dx,dy;
  147. float lx,ly;
  148. lx=(float) (cos(0.0)*s_pos/75.0);
  149. ly=(float) (sin(0.0)*s_pos/75.0);
  150. for (x = 0; x < num_seg; x ++)
  151. {
  152. l.mode=mode;
  153. l.color=current_color;
  154. dx=(float) (cos(0.0+(x+1)*3.14159*2.0/num_seg)*s_pos/75.0);
  155. dy=(float) (sin(0.0+(x+1)*3.14159*2.0/num_seg)*s_pos/75.0);
  156. if (!mode)
  157. {
  158. l.x2=xp+lx;
  159. l.y2=yp+ly;
  160. }
  161. else l.x2=l.y2=0;
  162. l.x1=xp+dx;
  163. l.y1=yp+dy;
  164. lx=dx;
  165. ly=dy;
  166. int x=(int) (l.x1*(w/2)+(w/2));
  167. int y=(int) (l.y1*(h/2)+(h/2));
  168. g_laser_linelist->AddLine(&l);
  169. }
  170. }
  171. return 0;
  172. }
  173. C_RBASE *RLASER_Cone(char *desc)
  174. {
  175. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  176. return (C_RBASE *) new C_THISCLASS();
  177. }
  178. static C_THISCLASS *g_this;
  179. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  180. {
  181. int *a=NULL;
  182. switch (uMsg)
  183. {
  184. case WM_DRAWITEM:
  185. {
  186. DRAWITEMSTRUCT *di=(DRAWITEMSTRUCT *)lParam;
  187. if (di->CtlID == IDC_DEFCOL && g_this->num_colors>0)
  188. {
  189. int x;
  190. int w=di->rcItem.right-di->rcItem.left;
  191. int l=0,nl;
  192. for (x = 0; x < g_this->num_colors; x ++)
  193. {
  194. int color=g_this->colors[x];
  195. nl = (w*(x+1))/g_this->num_colors;
  196. color = ((color>>16)&0xff)|(color&0xff00)|((color<<16)&0xff0000);
  197. HPEN hPen,hOldPen;
  198. HBRUSH hBrush,hOldBrush;
  199. LOGBRUSH lb={BS_SOLID,color,0};
  200. hPen = (HPEN)CreatePen(PS_SOLID,0,color);
  201. hBrush = CreateBrushIndirect(&lb);
  202. hOldPen=(HPEN)SelectObject(di->hDC,hPen);
  203. hOldBrush=(HBRUSH)SelectObject(di->hDC,hBrush);
  204. Rectangle(di->hDC,di->rcItem.left+l,di->rcItem.top,di->rcItem.left+nl,di->rcItem.bottom);
  205. SelectObject(di->hDC,hOldPen);
  206. SelectObject(di->hDC,hOldBrush);
  207. DeleteObject(hBrush);
  208. DeleteObject(hPen);
  209. l=nl;
  210. }
  211. }
  212. }
  213. return 0;
  214. case WM_INITDIALOG:
  215. SetDlgItemInt(hwndDlg,IDC_NUMCOL,g_this->num_colors,FALSE);
  216. SetDlgItemInt(hwndDlg,IDC_EDIT1,g_this->num_seg,FALSE);
  217. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMIN,0,1);
  218. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMAX,0,32);
  219. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETPOS,1,g_this->maxdist[0]);
  220. SendDlgItemMessage(hwndDlg,IDC_SLIDER7,TBM_SETRANGEMIN,0,1);
  221. SendDlgItemMessage(hwndDlg,IDC_SLIDER7,TBM_SETRANGEMAX,0,32);
  222. SendDlgItemMessage(hwndDlg,IDC_SLIDER7,TBM_SETPOS,1,g_this->maxdist[1]);
  223. SendDlgItemMessage(hwndDlg,IDC_SLIDER3,TBM_SETRANGEMIN,0,1);
  224. SendDlgItemMessage(hwndDlg,IDC_SLIDER3,TBM_SETRANGEMAX,0,128);
  225. SendDlgItemMessage(hwndDlg,IDC_SLIDER3,TBM_SETPOS,1,g_this->size);
  226. SendDlgItemMessage(hwndDlg,IDC_SLIDER4,TBM_SETRANGEMIN,0,1);
  227. SendDlgItemMessage(hwndDlg,IDC_SLIDER4,TBM_SETRANGEMAX,0,128);
  228. SendDlgItemMessage(hwndDlg,IDC_SLIDER4,TBM_SETPOS,1,g_this->size2);
  229. if (g_this->mode) CheckDlgButton(hwndDlg,IDC_RADIO1,BST_CHECKED);
  230. else CheckDlgButton(hwndDlg,IDC_RADIO2,BST_CHECKED);
  231. return 1;
  232. case WM_COMMAND:
  233. switch (LOWORD(wParam))
  234. {
  235. case IDC_RADIO1:
  236. case IDC_RADIO2:
  237. if (IsDlgButtonChecked(hwndDlg,IDC_RADIO1))
  238. g_this->mode=1;
  239. else g_this->mode=0;
  240. break;
  241. case IDC_EDIT1:
  242. {
  243. int p;
  244. BOOL tr=FALSE;
  245. p=GetDlgItemInt(hwndDlg,IDC_EDIT1,&tr,FALSE);
  246. if (tr)
  247. {
  248. g_this->num_seg=p;
  249. }
  250. }
  251. break;
  252. case IDC_NUMCOL:
  253. {
  254. int p;
  255. BOOL tr=FALSE;
  256. p=GetDlgItemInt(hwndDlg,IDC_NUMCOL,&tr,FALSE);
  257. if (tr)
  258. {
  259. if (p > 16) p = 16;
  260. g_this->num_colors=p;
  261. InvalidateRect(GetDlgItem(hwndDlg,IDC_DEFCOL),NULL,TRUE);
  262. }
  263. }
  264. break;
  265. case IDC_DEFCOL:
  266. {
  267. int wc=-1,w,h;
  268. POINT p;
  269. RECT r;
  270. GetCursorPos(&p);
  271. GetWindowRect(GetDlgItem(hwndDlg,IDC_DEFCOL),&r);
  272. p.x -= r.left;
  273. p.y -= r.top;
  274. w=r.right-r.left;
  275. h=r.bottom-r.top;
  276. if (p.x >= 0 && p.x < w && p.y >= 0 && p.y < h)
  277. {
  278. wc = (p.x*g_this->num_colors)/w;
  279. }
  280. if (wc>=0)
  281. {
  282. GR_SelectColor(hwndDlg,g_this->colors+wc);
  283. InvalidateRect(GetDlgItem(hwndDlg,IDC_DEFCOL),NULL,TRUE);
  284. }
  285. } }
  286. return 0;
  287. case WM_HSCROLL:
  288. {
  289. HWND swnd = (HWND) lParam;
  290. int t = (int) SendMessage(swnd,TBM_GETPOS,0,0);
  291. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER1))
  292. {
  293. g_this->maxdist[0]=t;
  294. }
  295. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER7))
  296. {
  297. g_this->maxdist[1]=t;
  298. }
  299. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER3))
  300. {
  301. g_this->s_pos=g_this->size=t;
  302. }
  303. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER4))
  304. {
  305. g_this->s_pos=g_this->size2=t;
  306. }
  307. }
  308. return 0;
  309. }
  310. return 0;
  311. }
  312. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  313. {
  314. g_this = this;
  315. return WASABI_API_CREATEDIALOG(IDD_CFG_LASER_CONE,hwndParent,g_DlgProc);
  316. }
  317. #endif