// ■リフラクションマッピング #include "myView.h" // ラベル #define LB_1 1001 // 方位角 #define LB_2 1002 // 仰角 #define LB_3 1003 // 距離 #define LB_4 1004 // 反射率 #define LB_5 1005 // 屈折率 #define LB_6 1006 // 物体色 #define LB_7 1007 // 透明度 // エディットボックス #define ED_1 2001 // 方位角 #define ED_2 2002 // 仰角 #define ED_3 2003 // 距離 #define ED_4 2004 // 反射率 #define ED_5 2005 // 屈折率 #define ED_6 2006 // (欠番) #define ED_7 2007 // 透明度 // ボタン #define BT_1 3001 // ボタン1 #define BT_2 3002 // ボタン2 #define BT_3 3003 // ボタン3 // チェックボックス #define CH_1 4001 // チェックボックス1 // スクロールバー #define SC_1 5001 // スクロールバー1 static HWND lbColor;//色指定用ラベル static CHOOSECOLOR chooseColor; COLORREF colorRef[16]; static HWND bt1;//, bt2, bt3; // 実行指定用ボタン static HWND editA, editB, editC, editD, editE, editF;//変換用係数を指定するeditBox static HWND ch1;// チェックボックス static HWND lb7;// static SCROLLINFO scr; static HWND scroll; static myBitmap txt;static int edFlag=false; //--------------------------------------------------------------------- //■リフラクションマッピング // 以下の係数を用いる //  diffuse:拡散反射係数, specular: 鏡面反射係数, ambient: 環境光, // reflect: 反射率, refract: 屈折率, matColor: 物体色。 // Point mapping(Point V, int dir) { //(注意)言語によってasin, acosで求まる値の範囲が異なるので // 適宜 a, e の値を調整すること double a=0, e = (asin((double)dir*(double)V.Z)+PI/2)/PI; double XX=V.X, YY=V.Y; double aa=acos((double)dir*XX/sqrt(XX*XX+YY*YY))/PI/2; double wi=txt.b.bmWidth, hi=txt.b.bmHeight; a=aa; if(V.Y>0) a= aa; //C#のときは不要, VC++, VB用 else if(V.Y<0) a=-aa; //C#のときは不要, VC++, VB用 return setPoint(a*wi+ txt.b.bmWidth/2, e*hi);//VC++用 //return setPoint(a*wi, e*hi); //C#, VBのときはこちら } Point mapping(Point V){return mapping(V, 1);} double mixPixel(HDC hdc, int X1, int Y1){ return ((double)RED (GetPixel(hdc,X1,Y1))+ (double)GREEN(GetPixel(hdc,X1,Y1))+ (double)BLUE (GetPixel(hdc,X1,Y1)))/3; } int transColor(int Cm, int C, double alfa){//透明度による色 alfa=0のとき不透明 double beta=1-alfa; int R=(int)(beta*(double)RED (Cm)+alfa*(double)RED (C)); if(R>255) R=255; int G=(int)(beta*(double)GREEN(Cm)+alfa*(double)GREEN(C)); if(G>255) G=255; int B=(int)(beta*(double)BLUE (Cm)+alfa*(double)BLUE (C)); if(B>255) B=255; return RGB(R,G,B); } void drawBall(){ //球体 HCURSOR hc=LoadCursor(NULL,IDC_WAIT); SetCursor(hc); HDC hdctx =startBitmap(txt); Ball Ba=setBall(setPoint(0,0,0),100); double n=refract; init2D(500,400); origin(250,200); Point L0 = setPoint(0,400,1000); //照明光 Point V0 = mlt(200,(unit(0,5))); //視点 setview(V0); int Transmit=SendMessage(ch1, BM_GETCHECK,0,0L); for(int x=0;x0 ) scr.nPos--;break; case SB_LINERIGHT : if(scr.nPos=(int)scr.nPage )scr.nPos -=scr.nPage;break; case SB_PAGERIGHT : if((scr.nPos+(int)scr.nPage)<(scr.nMax-1))scr.nPos +=scr.nPage; else scr.nPos=scr.nMax; break; case SB_THUMBPOSITION: scr.nPos=HIWORD(wp);break; } SetScrollInfo(scroll, SB_CTL, & scr, TRUE); TCHAR str[128]; wsprintf(str,TEXT("透明度 %d \%"), scr.nPos); SetWindowText(lb7, str); } void procCommand(HWND hw, WPARAM wp, LPARAM lp){ switch(LOWORD(wp)){ case BT_1: procBall(hw) ; return; case CH_1: SendMessage(ch1, BM_SETCHECK,!SendMessage(ch1, BM_GETCHECK,0,0L),0L);break; } } void procLButtonDown(HWND hw, WPARAM wp, LPARAM lp){ int X=LOWORD(lp), Y=HIWORD(lp); if(X>=620 && Y>=240 && X<=670 && Y<=260){ chooseColor.lStructSize=sizeof(CHOOSECOLOR); chooseColor.hwndOwner=hw; chooseColor.hInstance=0; chooseColor.lpCustColors=colorRef; chooseColor.Flags=CC_ANYCOLOR; if(ChooseColor(&chooseColor)){ matColor=chooseColor.rgbResult; InvalidateRect(hw, NULL, TRUE); } } } LRESULT CALLBACK WndProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp){ switch(msg){ case WM_DESTROY : PostQuitMessage(0) ; return 0; case WM_CREATE : procCreate (hw, wp, lp); return 0; case WM_PAINT : procPaint (hw, wp, lp); return 0; case WM_COMMAND : procCommand(hw, wp, lp); case WM_LBUTTONDOWN : procLButtonDown(hw, wp, lp); case WM_HSCROLL : procHScroll(hw, wp, lp); return 0; } return DefWindowProc(hw, msg, wp, lp); }