1
0

r_dotpln.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 <math.h>
  27. #include <commctrl.h>
  28. #include "resource.h"
  29. #include "r_defs.h"
  30. #include "../Agave/Language/api_language.h"
  31. #ifndef LASER
  32. #define C_THISCLASS C_DotPlaneClass
  33. #define MOD_NAME "Render / Dot Plane"
  34. #define NUM_WIDTH 64
  35. class C_THISCLASS : public C_RBASE {
  36. protected:
  37. float r;
  38. float atable[NUM_WIDTH*NUM_WIDTH];
  39. float vtable[NUM_WIDTH*NUM_WIDTH];
  40. int ctable[NUM_WIDTH*NUM_WIDTH];
  41. int color_tab[64];
  42. public:
  43. C_THISCLASS();
  44. virtual ~C_THISCLASS();
  45. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int, int);
  46. virtual char *get_desc() { static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_RENDER_DOT_PLANE,desc,128):desc); }
  47. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  48. virtual void load_config(unsigned char *data, int len);
  49. virtual int save_config(unsigned char *data);
  50. int rotvel,angle;
  51. int colors[5];
  52. void initcolortab();
  53. };
  54. #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
  55. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  56. void C_THISCLASS::load_config(unsigned char *data, int len)
  57. {
  58. int pos=0;
  59. if (len-pos >= 4) { rotvel=GET_INT(); pos+=4; }
  60. int x;
  61. for (x = 0; x < 5; x ++)
  62. {
  63. if (len-pos >= 4) { colors[x]=GET_INT(); pos+=4; }
  64. }
  65. if (len-pos >= 4) { angle=GET_INT(); pos+=4; }
  66. if (len-pos >= 4) { int rr=GET_INT(); pos+=4; r=rr/32.0f;}
  67. initcolortab();
  68. }
  69. int C_THISCLASS::save_config(unsigned char *data)
  70. {
  71. int rr;
  72. int pos=0;
  73. int x;
  74. PUT_INT(rotvel); pos+=4;
  75. for (x = 0; x < 5; x ++)
  76. {
  77. PUT_INT(colors[x]); pos+=4;
  78. }
  79. PUT_INT(angle); pos+=4;
  80. rr=(int)(r*32.0f);
  81. PUT_INT(rr); pos+=4;
  82. return pos;
  83. }
  84. void C_THISCLASS::initcolortab()
  85. {
  86. int x,r,g,b,dr,dg,db,t;
  87. for (t=0; t < 4; t ++)
  88. {
  89. r=(colors[t]&255)<<16;
  90. g=((colors[t]>>8)&255)<<16;
  91. b=((colors[t]>>16)&255)<<16;
  92. dr=(((colors[t+1]&255)-(colors[t]&255))<<16)/16;
  93. dg=((((colors[t+1]>>8)&255)-((colors[t]>>8)&255))<<16)/16;
  94. db=((((colors[t+1]>>16)&255)-((colors[t]>>16)&255))<<16)/16;
  95. for (x = 0; x < 16; x ++)
  96. {
  97. color_tab[t*16+x]=(r>>16)|((g>>16)<<8)|((b>>16)<<16);
  98. r+=dr;g+=dg;b+=db;
  99. }
  100. }
  101. }
  102. C_THISCLASS::C_THISCLASS()
  103. {
  104. colors[0]=RGB(24,107,28); // reverse BGR :)
  105. colors[1]=RGB(35,10,255);
  106. colors[2]=RGB(116,29,42);
  107. colors[3]=RGB(217,54,144);
  108. colors[4]=RGB(255,136,107);
  109. initcolortab();
  110. memset(atable,0,sizeof(atable));
  111. memset(vtable,0,sizeof(vtable));
  112. memset(ctable,0,sizeof(ctable));
  113. angle=-20;
  114. rotvel=16;
  115. }
  116. C_THISCLASS::~C_THISCLASS()
  117. {
  118. }
  119. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int width, int height)
  120. {
  121. if (isBeat&0x80000000) return 0;
  122. float btable[NUM_WIDTH];
  123. int fo, p;
  124. float matrix[16],matrix2[16];
  125. matrixRotate(matrix,2,r);
  126. matrixRotate(matrix2,1,(float)angle);
  127. matrixMultiply(matrix,matrix2);
  128. matrixTranslate(matrix2,0.0f,-20.0f,400.0f);
  129. matrixMultiply(matrix,matrix2);
  130. memcpy(btable,&atable[0],sizeof(float)*NUM_WIDTH);
  131. for (fo = 0; fo < NUM_WIDTH; fo ++)
  132. {
  133. float *i, *o, *v, *ov;
  134. int *c,*oc;
  135. int t=(NUM_WIDTH-(fo+2))*NUM_WIDTH;
  136. i = &atable[t];
  137. o = &atable[t+NUM_WIDTH];
  138. v = &vtable[t];
  139. ov = &vtable[t+NUM_WIDTH];
  140. c = &ctable[t];
  141. oc = &ctable[t+NUM_WIDTH];
  142. if (fo == NUM_WIDTH-1)
  143. {
  144. unsigned char *sd = (unsigned char *)&visdata[0][0][0];
  145. i = btable;
  146. for (p = 0; p < NUM_WIDTH; p ++)
  147. {
  148. register int t;
  149. t=max(sd[0],sd[1]);
  150. t=max(t,sd[2]);
  151. *o = (float)t;
  152. t>>=2;
  153. if (t > 63) t=63;
  154. *oc++=color_tab[t];
  155. *ov++ = (*o++ - *i++) / 90.0f;
  156. sd+=3;
  157. }
  158. }
  159. else for (p = 0; p < NUM_WIDTH; p ++)
  160. {
  161. *o = *i++ + *v;
  162. if (*o < 0.0f) *o=0.0f;
  163. *ov++ = *v++ - 0.15f*(*o++/255.0f);
  164. *oc++ = *c++;
  165. }
  166. }
  167. float adj=width*440.0f/640.0f;
  168. float adj2=height*440.0f/480.0f;
  169. if (adj2 < adj) adj=adj2;
  170. for (fo = 0; fo < NUM_WIDTH; fo ++)
  171. {
  172. int f = (r < 90.0 || r > 270.0) ? NUM_WIDTH-fo-1 : fo;
  173. float dw=350.0f/(float)NUM_WIDTH, w = -(NUM_WIDTH*0.5f)*dw;
  174. float q = (f - NUM_WIDTH*0.5f)*dw;
  175. int *ct = &ctable[f*NUM_WIDTH];
  176. float *at = &atable[f*NUM_WIDTH];
  177. int da=1;
  178. if (r < 180.0)
  179. {
  180. da=-1;
  181. dw=-dw;
  182. w=-w+dw;
  183. ct += NUM_WIDTH-1;
  184. at += NUM_WIDTH-1;
  185. }
  186. for (p = 0; p < NUM_WIDTH; p ++)
  187. {
  188. float x, y, z;
  189. matrixApply(matrix,w,64.0f-*at,q,&x,&y,&z);
  190. z = adj / z;
  191. register int ix = (int) (x * z) + (width/2);
  192. register int iy = (int) (y * z) + (height/2);
  193. if (iy >= 0 && iy < height && ix >= 0 && ix < width)
  194. {
  195. BLEND_LINE(framebuffer + iy*width + ix,*ct);
  196. }
  197. w+=dw;
  198. ct+=da;
  199. at+=da;
  200. }
  201. }
  202. r += rotvel/5.0f;
  203. if (r >= 360.0f) r -= 360.0f;
  204. if (r < 0.0f) r += 360.0f;
  205. return 0;
  206. }
  207. C_RBASE *R_DotPlane(char *desc)
  208. {
  209. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  210. return (C_RBASE *) new C_THISCLASS();
  211. }
  212. static C_THISCLASS *g_this;
  213. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  214. {
  215. int *a=NULL;
  216. switch (uMsg)
  217. {
  218. case WM_COMMAND:
  219. if (LOWORD(wParam) == IDC_BUTTON1)
  220. {
  221. g_this->rotvel=0;
  222. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETPOS,1,50);
  223. }
  224. if (LOWORD(wParam) >= IDC_C1 && LOWORD(wParam) <= IDC_C5) {
  225. GR_SelectColor(hwndDlg,&g_this->colors[IDC_C5-LOWORD(wParam)]);
  226. InvalidateRect(GetDlgItem(hwndDlg,LOWORD(wParam)),NULL,FALSE);
  227. g_this->initcolortab();
  228. }
  229. return 0;
  230. case WM_DRAWITEM:
  231. {
  232. DRAWITEMSTRUCT *di=(DRAWITEMSTRUCT *)lParam;
  233. if (di->CtlID >= IDC_C1 && di->CtlID <= IDC_C5)
  234. {
  235. GR_DrawColoredButton(di,g_this->colors[IDC_C5-di->CtlID]);
  236. }
  237. }
  238. return 0;
  239. case WM_INITDIALOG:
  240. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMIN,0,0);
  241. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMAX,0,101);
  242. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETPOS,1,g_this->rotvel+50);
  243. SendDlgItemMessage(hwndDlg,IDC_ANGLE,TBM_SETRANGEMIN,0,0);
  244. SendDlgItemMessage(hwndDlg,IDC_ANGLE,TBM_SETRANGEMAX,0,181);
  245. SendDlgItemMessage(hwndDlg,IDC_ANGLE,TBM_SETPOS,1,g_this->angle+90);
  246. return 1;
  247. case WM_HSCROLL:
  248. {
  249. HWND swnd = (HWND) lParam;
  250. int t = (int) SendMessage(swnd,TBM_GETPOS,0,0);
  251. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER1))
  252. {
  253. g_this->rotvel=t-50;
  254. }
  255. if (swnd == GetDlgItem(hwndDlg,IDC_ANGLE))
  256. {
  257. g_this->angle=t-90;
  258. }
  259. }
  260. }
  261. return 0;
  262. }
  263. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  264. {
  265. g_this = this;
  266. return WASABI_API_CREATEDIALOG(IDD_CFG_DOTPLANE,hwndParent,g_DlgProc);
  267. }
  268. #else
  269. C_RBASE *R_DotPlane(char *desc) { return NULL; }
  270. #endif