void Map::ShowShrinkMap() { YsRawPngDecoder png1; if(YSOK==png1.Decode("suisuipng-with light.png")) { png1.Flip(); int winWid,winHei; FsGetWindowSize(winWid,winHei); glRasterPos2d(0.0,(double)(winHei-1)); glDrawPixels(png1.wid,png1.hei,GL_RGBA,GL_UNSIGNED_BYTE,png1.rgba); // changes by Chun Fan //printf("%d %d",png1.wid,png1.hei); } glColor3ub(255,0,0); glBegin(GL_POLYGON); int i; int cx,cy,rad=8; cx=midpointx*939/2656+3; cy=600-midpointy*600/1694; for(i=0; i<64; i++) { double angle=(double)i*YS_PI/32.0; double x=(double)cx+cos(angle)*(double)rad; double y=(double)cy+sin(angle)*(double)rad; glVertex2d(x,y); } glEnd(); }
void Map::DramMap() { int winWid,winHei; FsGetWindowSize(winWid,winHei); glRasterPos2d(0.0,(double)(winHei-1)); unsigned char *p=png.rgba; int i,j; beginx=midpointx-m/2; beginy=midpointy-n/2; char *pp = new char[800*600*4]; for (i=0; i<n; i++) { for (j=0; j<m; j++) { pp[(i*m+j)*4]=p[((i+beginy)*png.wid+j+beginx)*4]; pp[(i*m+j)*4+1]=p[((i+beginy)*png.wid+j+beginx)*4+1]; pp[(i*m+j)*4+2]=p[((i+beginy)*png.wid+j+beginx)*4+2]; pp[(i*m+j)*4+3]=p[((i+beginy)*png.wid+j+beginx)*4+3]; } } glDrawPixels(m,n,GL_RGBA,GL_UNSIGNED_BYTE,pp); MoveMap(); delete [] pp; }
/* virtual */ void FsLazyWindowApplication::BeforeTerminate(void) { auto wposFn=canvasPtr->fileAndDirName->GetLastWindowPositionFileName(); int x0,y0,wid,hei; FsGetWindowPosition(x0,y0); FsGetWindowSize(wid,hei); PolyCreFileName::MakeDirectoryForFile(wposFn); FILE *fp=YsFileIO::Fopen(wposFn,"w"); if(NULL!=fp) { fprintf(fp,"POS %d %d %d %d\n",x0,y0,wid,hei); fclose(fp); } YsGLSLDeleteSharedRenderer(); delete canvasPtr; #ifdef FSGUI3D_USE_SYSTEM_FONT delete sysFont; #endif FsSleep(50); // Windows apparently has a problem terminating within certain time after last rendering. Wait 50 ms. exit(0); // This typically is quicker, otherwise destructors occasinally takes long time to finish. }
void makegif::initial(YsRawPngDecoder &image2, TextString &str ,int num,int hLTx, int hLTy, int hRBx, int hRBy) { str.Set("GIF1/1.png"); if(YSOK==image2.Decode(str.GetPointer())) { picWidth=image2.wid; picHeight=image2.hei; } else { printf("Read Error!\n"); } timeCounter=0; pictureNum=num; FsGetWindowSize(winWidth,winHeight); startX=winWidth/2; startY=winHeight/2; picLTx=startX; picLTy=startY-picHeight; picRBx=startX+picWidth; picRBy=startY; headLTx=hLTx; headLTy=hLTy; headRBx=hRBx; headRBy=hRBy; }
int main(void) { int key; struct YsGLSLBitmapRenderer *bitmapRenderer; YsBitmap bmp; FsChangeToProgramDir(); bmp.LoadPng("flash01.png"); printf("Bitmap dimension %dx%d\n",bmp.GetWidth(),bmp.GetHeight()); FsOpenWindow(32,32,640,480,1); bitmapRenderer=YsGLSLCreateBitmapRenderer(); key=FSKEY_NULL; while(FSKEY_ESC!=key) { FsPollDevice(); key=FsInkey(); int mx,my,lb,mb,rb; FsGetMouseState(lb,mb,rb,mx,my); int wid,hei; FsGetWindowSize(wid,hei); glViewport(0,0,wid,hei); glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColor3ub(255,255,255); glBegin(GL_LINES); glVertex2i(270,240); glVertex2i(370,240); glVertex2i(320,190); glVertex2i(320,290); glEnd(); YsGLSLUseBitmapRenderer(bitmapRenderer); YsGLSLRenderRGBABitmap2D(bitmapRenderer,320,240,YSGLSL_HALIGN_RIGHT,YSGLSL_VALIGN_BOTTOM,bmp.GetWidth(),bmp.GetHeight(),bmp.GetRGBABitmapPointer()); YsGLSLEndUseBitmapRenderer(bitmapRenderer); FsSwapBuffers(); FsSleep(10); } YsGLSLDeleteBitmapRenderer(bitmapRenderer); return 0; }
void CameraObject::SetUpCameraProjection(void) { int wid,hei; double aspect; FsGetWindowSize(wid,hei); aspect=(double)wid/(double)hei; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fov*180.0/YsPi,aspect,nearZ,farZ); }
void Button::Initialize(void) { SU=0,SD=0,SL=0,SR=0,SF=0,SB=0; SU1=0,SD1=0,SL1=0,SR1=0,SF1=0,SB1=0; SU2=0,SD2=0,SL2=0,SR2=0,SF2=0,SB2=0; GP = FSKEY_P; GC = FSKEY_C; GR = FSKEY_SPACE; G1 = FSKEY_0; G2 = FSKEY_1; pause=0, reset=0, cont=0, one=0, two=0; FsGetWindowSize (windowWid, windowHei); }
/* virtual */ void FsLazyWindowApplication::Interval(void) { int wid,hei; FsGetWindowSize(wid,hei); int lb,mb,rb,mx,my; auto evt=FsGetMouseEvent(lb,mb,rb,mx,my); if(0!=lb && (mx!=prevMx || my!=prevMy)) { double denom=(double)YsGreater(wid,hei); double dx=2.0*(double)(prevMx-mx)/denom; double dy=2.0*(double)(prevMy-my)/denom; drawEnv.RotateView(dx,dy); } if(evt==FSMOUSEEVENT_LBUTTONDOWN) { drawEnv.SetWindowSize(wid,hei); drawEnv.SetViewportByTwoCorner(0,0,wid,hei); drawEnv.TransformScreenCoordTo3DLine(lastClick[0],lastClick[1],mx,my); lastClick[1]*=80.0; lastClick[1]+=lastClick[0]; cellVtx.clear(); auto itscIdx=ltc.GetIntersectingBlock(lastClick[0],lastClick[1]-lastClick[0]); for(auto i : itscIdx) { YsVec3 min,max; ltc.GetBlockRange(min,max,i); auto cen=(min+max)/2.0; cellVtx.push_back(cen.xf()); cellVtx.push_back(cen.yf()); cellVtx.push_back(cen.zf()); } if(true!=ltc.ClipLine(lastClick[0],lastClick[1],lastClick[0],lastClick[1]-lastClick[0])) { printf("No intersection.\n"); } } prevMx=mx; prevMy=my; auto key=FsInkey(); if(FSKEY_ESC==key) { SetMustTerminate(true); } needRedraw=true; }
/* virtual */ void FsLazyWindowApplication::Draw(void) { int wid,hei; FsGetWindowSize(wid,hei); glViewport(0,0,wid,hei); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,(float)wid-1,(float)hei-1,0,-1,1); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); Draw(btree.GetRoot(),0,wid,40,40); FsSwapBuffers(); needRedraw=false; }
int Game(void) { DWORD passedTime = 0; FsPassedTime(true); //////////// initial setting up the scene //////////////////////////////////////// int timeSpan = 33; // milliseconds double timeInc = (double)timeSpan * 0.001; // time increment in seconds FsGetWindowSize(width, height); int lb,mb,rb,mx,my; glViewport(0, 0, width, height); ////////////////////// main simulation loop ////////////////////////// while (1) { FsPollDevice(); FsGetMouseState(lb,mb,rb,mx,my); int key=FsInkey(); if(key == FSKEY_ESC) break; timeInc = (double)(passedTime) * 0.001; clocktime += timeInc; /////////// update physics ///////////////// updateNumPhysics(simBall1, timeInc); updatePrecisePhysics(realBall, timeInc); ///////////////////////////////////////// renderScene(); ////// update time lapse ///////////////// passedTime = FsPassedTime(); // Making it up to 50fps int timediff = timeSpan-passedTime; // printf("\ntimeInc=%f, passedTime=%d, timediff=%d", timeInc, passedTime, timediff); while(timediff >= timeSpan/3) { FsSleep(5); passedTime=FsPassedTime(); // Making it up to 50fps timediff = timeSpan-passedTime; // printf("--passedTime=%d, timediff=%d", passedTime, timediff); } passedTime=FsPassedTime(true); // Making it up to 50fps } return 0; }
void FsLazyWindowApplication::MouseCoordinateTo3DLine(YsVec3 ln[2],int mx,int my) const { int wid,hei; FsGetWindowSize(wid,hei); double x=(double)mx/(double)wid; double y=(double)(hei-my)/(double)hei; x=x*2.0-1.0; y=y*2.0-1.0; ln[0].Set(x,y,-1.0); ln[1].Set(x,y, 1.0); for(int i=0; i<2; ++i) { auto &p=ln[i]; drawEnv.GetProjectionMatrix().MulInverse(p,p,1.0); drawEnv.GetViewMatrix().MulInverse(p,p,1.0); } }
/* virtual */ void FsLazyWindowApplication::Interval(void) { int wid,hei; FsGetWindowSize(wid,hei); int lb,mb,rb,mx,my; auto evt=FsGetMouseEvent(lb,mb,rb,mx,my); if(0!=lb && (mx!=prevMx || my!=prevMy)) { double denom=(double)YsGreater(wid,hei); double dx=2.0*(double)(prevMx-mx)/denom; double dy=2.0*(double)(prevMy-my)/denom; drawEnv.RotateView(dx,dy); } if(evt==FSMOUSEEVENT_LBUTTONDOWN) { double x=(double)mx/(double)wid; double y=(double)(hei-my)/(double)hei; x=x*2.0-1.0; y=y*2.0-1.0; lastClick[0].Set(x,y,-1.0); lastClick[1].Set(x,y, 1.0); for(auto &p : lastClick) { drawEnv.GetProjectionMatrix().MulInverse(p,p,1.0); drawEnv.GetViewMatrix().MulInverse(p,p,1.0); } } prevMx=mx; prevMy=my; auto key=FsInkey(); if(FSKEY_ESC==key) { SetMustTerminate(true); } needRedraw=true; }
void GameOver(int score) { int r=0; FsPollDevice(); while(FsInkey()!=0) { FsPollDevice(); } while(FsInkey()==0) { FsPollDevice(); int wid,hei; FsGetWindowSize(wid,hei); glViewport(0,0,wid,hei); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,(float)wid-1,(float)hei-1,0,-1,1); glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT); const char *msg1="Game Over"; char msg2[256]; glColor3ub(255,255,255); glRasterPos2i(32,32); glCallLists(strlen(msg1),GL_UNSIGNED_BYTE,msg1); sprintf(msg2,"Your score is %d",score); glRasterPos2i(32,48); glCallLists(strlen(msg2),GL_UNSIGNED_BYTE,msg2); FsSwapBuffers(); FsSleep(10); } }
void Score::DrawScoreCard(void) { char *gameName[] = { "Pool", "CAD", "Gear", "Keep Awake"}; FsGetWindowSize(winWid, winHei); glRasterPos2d(0.0,(double)(winHei-1)); glDrawPixels(scoreCard.wid,scoreCard.hei,GL_RGBA,GL_UNSIGNED_BYTE,scoreCard.rgba); char msg[256]; glColor3ub(0, 0, 0); for (int i=0; i<4; i++) { sprintf(msg, "Game %d: %s", i+1, gameName[i]); glRasterPos2d(175, 175+i*100); YsGlDrawFontBitmap16x24(msg); sprintf(msg, "%d trials, %s", gameCount[i], gamePassed[i]?"Passed":"Failed"); glRasterPos2d(225, 215+i*100); YsGlDrawFontBitmap16x24(msg); } }
int Menu(void) { int r=0,key; const double angleInc = PI/180.; while(r!=eStart && r!= eStop) { FsPollDevice(); key=FsInkey(); switch(key) { case FSKEY_S: r=eStart; break; case FSKEY_ESC: r=eStop; break; case FSKEY_UP: iSpeed++; break; case FSKEY_DOWN: iSpeed = max(2., iSpeed-1); break; case FSKEY_LEFT: iAngle = max(0., iAngle-angleInc); break; case FSKEY_RIGHT: iAngle = min(90.0, iAngle+angleInc); break; } initPhysics(radius, iSpeed, iAngle); if (r == eStop) return r; int wid,hei; FsGetWindowSize(wid,hei); glViewport(0,0,wid,hei); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-0.5,(GLdouble)wid-0.5,(GLdouble)hei-0.5,-0.5,-1,1); glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3ub(127,127,127); char sSpeed[128]; sprintf(sSpeed, "Initial ball speed is %f m/s. Use Up/Down keys to change it!\n", iSpeed); char sAngle[128]; sprintf(sAngle, "Initial horizon Angle is %f degrees. Use Left/Right keys to change it!\n", iAngle*180./PI); glColor3ub(255,255,255); glRasterPos2i(32,32); glCallLists(strlen(sSpeed),GL_UNSIGNED_BYTE,sSpeed); glRasterPos2i(32,64); glCallLists(strlen(sAngle),GL_UNSIGNED_BYTE,sAngle); const char *msg1="S.....Start Game"; const char *msg2="ESC...Exit"; glRasterPos2i(32,96); glCallLists(strlen(msg1),GL_UNSIGNED_BYTE,msg1); glRasterPos2i(32,128); glCallLists(strlen(msg2),GL_UNSIGNED_BYTE,msg2); FsSwapBuffers(); FsSleep(10); } return r; }
const BinaryTree <int,int>::Node *FsLazyWindowApplication::PickedNode(int mx,int my) const { int wid,hei; FsGetWindowSize(wid,hei); return PickedNode(btree.GetRoot(),mx,my,0,wid,40,40); }
int main(void) { Frame fra; int lb, mb, rb, rx, ry;//mouse variables int mode=0; int isWarp=1; // in the warp or compete mode int winner=0; int mouseDown=0; int winWid,winHei; Button Left[4]; Button Right[4]; Button Menu[6]; YsRawPngDecoder image1; YsRawPngDecoder image2; makegif gif; TextString FaceLocation[4]; TextString TemplateLocation[4]; int pos1[4]; int pos2[4]; int image2Pos[2][4]; //the first index is the image, the second index is the position int faceChosen; int templateChosen; //////////////////////////////////////////////////////////////////// // initialize the positions //////////////////////////////////////////////////////////////////// image2Pos[0][0]=95; image2Pos[0][1]=12; image2Pos[0][2]=153; image2Pos[0][3]=85; image2Pos[1][0]=290; image2Pos[1][1]=25; image2Pos[1][2]=410; image2Pos[1][3]=155; //////////////////////////////////////////////////////////////////// // initialize the face & template locations //////////////////////////////////////////////////////////////////// FaceLocation[0].Set("face0.png"); FaceLocation[1].Set("face1.png"); FaceLocation[2].Set("face2.png"); FaceLocation[3].Set("face3.png"); TemplateLocation[0].Set("template0.png"); TemplateLocation[1].Set("template1.png"); TemplateLocation[2].Set("GIF1/01.png"); TemplateLocation[3].Set("GIF2/01.png"); /////////////////////////////////////////////////////////////////////// // initialize the buttons /////////////////////////////////////////////////////////////////////// for (int i=0; i<4; i++) { Left[i].wid=160; Left[i].hei=120; Right[i].wid=160; Right[i].hei=120; } Left[0].init(20, 50, "Picture 1"); Left[1].init(20, 200, "Picture 2"); Left[2].init(20, 350, "Picture 3"); Left[3].init(20, 500, "Picture 4"); Right[0].init(1120, 50, "Template 1"); Right[1].init(1120, 200, "Template 2"); Right[2].init(1120, 350, "Gif 1"); Right[3].init(1120, 500, "Gif 2"); for (int i=0; i<6; i++) { Menu[i].wid=80; Menu[i].hei=20; } Menu[0].init(20, 5, "Start"); Menu[1].init(120, 5, "Compete"); Menu[2].init(220, 5, "Rotate"); Menu[3].init(320, 5, "Clear"); Menu[4].init(420, 5, "Exit"); Menu[5].init(520, 5, "Help"); FsOpenWindow(64,16,1300,700,1); fra.display(); FsGetWindowSize(winWid,winHei); while(1) { mouseDown=0; FsPollDevice(); glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); fra.DrawToolbox(); fra.DrawColum(); fra.DrawShowWindow(); fra.DrawExit(); for (int i=0; i<4; i++) { Left[i].draw(); Right[i].draw(); } for (int i=0; i<6; i++) { Menu[i].draw(); } //////////////////////////////////////////////////////////////////////// // get button states //////////////////////////////////////////////////////////////////////// if(FsGetMouseEvent(lb,mb,rb,rx,ry)==FSMOUSEEVENT_LBUTTONDOWN) { mouseDown=1; for (int i=0; i<4; i++) { Left[i].checkPressed(rx, ry); Right[i].checkPressed(rx, ry); } for (int i=0; i<6; i++) { Menu[i].checkPressed(rx, ry); } } if (Menu[3].state==1) { mode=WAIT_LEFTBUT; Menu[3].state=0; isWarp=1; Menu[1].state=0; winner=0; } if (Menu[1].state==1) { isWarp=0; } if (Menu[4].state==1) { break; } /////////////////////////////////////////////////////////////// // switch among different state of the game //////////////////////////////////////////////////////////////// if (isWarp==1) //in the warp mode { switch(mode) { case WAIT_LEFTBUT: { for (int i=0; i<4; i++) { if (Left[i].state==1) // if pressed { if(YSOK==image1.Decode(FaceLocation[i].GetPointer())) { printf(FaceLocation[i].GetPointer()); mode=WAIT_POS1; Left[i].state=0; faceChosen=i; break; } } } break; } case WAIT_POS1: { if (mouseDown==1) { if (rx-300<=image1.wid && 550-ry<=image1.hei && rx-300>0 && 550-ry>0) { pos1[0]=rx-300; pos1[1]=image1.hei-(550-ry); mouseDown=0; mode=WAIT_POS2; printf("first pos %d %d\n",pos1[0],pos1[1]); } } break; } case WAIT_POS2: { if (mouseDown==1) { if (rx-300<=image1.wid && 550-ry<=image1.hei && rx-300>0 && 550-ry>0) { pos1[2]=rx-300; pos1[3]=image1.hei-(550-ry); mouseDown=0; mode=WAIT_TEMPLATE; printf("second pos %d %d\n",pos1[2],pos1[3]); } } break; } case WAIT_TEMPLATE: { for (int i=0; i<2; i++) { if (Right[i].state==1) // if pressed { if(YSOK==image2.Decode(TemplateLocation[i].GetPointer())) { mode=WAIT_WARP; Right[i].state=0; templateChosen=i; pos2[0]=image2Pos[i][0]; pos2[1]=image2Pos[i][1]; pos2[2]=image2Pos[i][2]; pos2[3]=image2Pos[i][3]; break; } } } if (Right[2].state==1) { if(YSOK==image2.Decode(TemplateLocation[2].GetPointer())) { mode=WAIT_WARP; Right[2].state=0; templateChosen=2; //printf("GIF1\n"); //char *image1String=FaceLocation[faceChosen].GetPointer(); char gifString[]={"GIF1/01.png"}; //char gifString[]={"GIF2/01.png"}; gif.initial(gifString,image2,12,15,0,45,40); //initial the gif class //gif.initial(gifString,image2,4,160,50,260,165); //initial the gif class gif.setImage1(image1,FaceLocation[faceChosen].GetPointer()); // select the head picture gif.setImage1HeadLT(pos1[0],pos1[1]); // select the left top point of the head picture gif.setImage2HeadRB(pos1[2],pos1[3]); // select the right bottom point of the head picture gif.copyRGBA(image1,image2); break; } break; } if (Right[3].state==1) { if(YSOK==image2.Decode(TemplateLocation[3].GetPointer())) { mode=WAIT_WARP; Right[3].state=0; templateChosen=3; //printf("GIF1\n"); //char *image1String=FaceLocation[faceChosen].GetPointer(); //char gifString[]={"GIF1/01.png"}; char gifString[]={"GIF2/01.png"}; printf(FaceLocation[faceChosen].GetPointer()); //gif.initial(gifString,image2,12,15,0,45,40); //initial the gif class gif.initial(gifString,image2,4,160,50,260,165); //initial the gif class gif.setImage1(image1,FaceLocation[faceChosen].GetPointer()); // select the head picture gif.setImage1HeadLT(pos1[0],pos1[1]); // select the left top point of the head picture gif.setImage2HeadRB(pos1[2],pos1[3]); // select the right bottom point of the head picture gif.copyRGBA(image1,image2); break; } break; } break; } case WAIT_WARP: { if (Menu[0].state==1) { warpImage(image1, image2, pos1, pos2, 0.0); mode=FINISHED; Menu[0].state=0; } if (Menu[2].state==1) { warpImage(image1, image2, pos1, pos2,-20.0); mode=FINISHED; Menu[2].state=0; } break; } case FINISHED: { if (Menu[3].state==1) { mode=WAIT_LEFTBUT; Menu[3].state=0; } break; } } } else { switch(mode) { case WAIT_LEFTBUT: { for (int i=0; i<4; i++) { if (Left[i].state==1) // if pressed { if(YSOK==image1.Decode(FaceLocation[i].GetPointer())) { printf(FaceLocation[i].GetPointer()); mode=WAIT_TEMPLATE; Left[i].state=0; //faceChosen=i; break; } } } break; } case WAIT_TEMPLATE: { for (int i=0; i<4; i++) { if (Left[i].state==1) // if pressed { if(YSOK==image2.Decode(FaceLocation[i].GetPointer())) { printf(FaceLocation[i].GetPointer()); mode=WAIT_WARP; Left[i].state=0; //faceChosen=i; break; } } } break; } case WAIT_WARP: { if (Menu[0].state==1) { winner=BeautyCompetition(image1,image2); glRasterPos2d(300.0,(double)(winHei-50)); if (winner==1) { YsGlDrawFontBitmap20x32("PICTURE 1 WINS!"); } else if (winner==2) { YsGlDrawFontBitmap20x32("PICTURE 2 WINS!"); } printf("\nWINNER:%d!!!\n",winner); mode=FINISHED; Menu[0].state=0; } break; } case FINISHED: { if (Menu[3].state==1) { mode=WAIT_LEFTBUT; Menu[3].state=0; winner=0; } break; } } } /////////////////////////////////////////////////////////////// // actually draw ////////////////////////////////////////////////////////////// if (mode==WAIT_LEFTBUT) { //do nothing } else if (mode>WAIT_LEFTBUT && mode<=WAIT_TEMPLATE) { image1.Flip(); FsGetWindowSize(winWid,winHei); glRasterPos2d(300.0,(double)(winHei-150)); glDrawPixels(image1.wid,image1.hei,GL_RGBA,GL_UNSIGNED_BYTE,image1.rgba); image1.Flip(); } else if (mode>WAIT_TEMPLATE && mode<=FINISHED) { if (templateChosen<2) { image2.Flip(); FsGetWindowSize(winWid,winHei); glRasterPos2d(300.0,(double)(winHei-150)); glDrawPixels(image2.wid,image2.hei,GL_RGBA,GL_UNSIGNED_BYTE,image2.rgba); image2.Flip(); } else if(templateChosen==2 || templateChosen==3) { if (mode==FINISHED) { gif.draw(); } else { image2.Flip(); FsGetWindowSize(winWid,winHei); glRasterPos2d(300.0,(double)(winHei-150)); glDrawPixels(image2.wid,image2.hei,GL_RGBA,GL_UNSIGNED_BYTE,image2.rgba); image2.Flip(); } } if (winner==1) { glRasterPos2d(300.0,(double)(winHei-50)); YsGlDrawFontBitmap20x32("PICTURE 1 WINS!"); } else if (winner==2) { glRasterPos2d(300.0,(double)(winHei-50)); YsGlDrawFontBitmap20x32("PICTURE 2 WINS!"); } } FsSwapBuffers(); FsSleep(25); } return 0; }
void Button::Remap2() { FsClearEventQueue(); FsGetWindowSize (windowWid, windowHei); while(FSKEY_NULL!=FsInkey() || 0!=FsInkeyChar()) { FsPollDevice(); } //Initialize(); while(SF2==0 || checkGameControl(SF2) ) { FsPollDevice(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); DrawBackground(); DrawModeTitle2(); DrawKeyboardSetting(); double y=180.0; double dy=40.0; glColor3ub(255, 255, 255); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Up : (press key to remap)"); DrawLogo(25, 575); SF2=FsInkey(); FsSwapBuffers(); FsSleep(20); } while(SB2==0 || checkGameControl(SB2)) { FsPollDevice(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); DrawBackground(); DrawModeTitle2(); DrawKeyboardSetting(); double y=180.0; double dy=40.0; glColor3ub(155, 155, 155); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Up : (OK)"); y+=dy; glColor3ub(255, 255, 255); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Down : (press key to remap)"); DrawLogo(25, 575); SB2=FsInkey(); FsSwapBuffers(); FsSleep(20); } while(SL2==0 || checkGameControl(SL2)) { FsPollDevice(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); DrawBackground(); DrawModeTitle2(); DrawKeyboardSetting(); double y=180.0; double dy=40.0; glColor3ub(155, 155, 155); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Up : (OK)"); y+=dy; glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Down : (OK)"); y+=dy; glColor3ub(255, 255, 255); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Left : (press key to remap)"); DrawLogo(25, 575); SL2=FsInkey(); FsSwapBuffers(); FsSleep(20); } while(SR2==0 || checkGameControl(SR2)) { FsPollDevice(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); DrawBackground(); DrawModeTitle2(); DrawKeyboardSetting(); double y=180.0; double dy=40.0; glColor3ub(155, 155, 155); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Up : (OK)"); y+=dy; glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Down : (OK)"); y+=dy; glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Left : (OK)"); y+=dy; glColor3ub(255, 255, 255); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Right : (press key to remap)"); DrawLogo(25, 575); SR2=FsInkey(); FsSwapBuffers(); FsSleep(20); } }
void GameMenu::Initialize (void) { FsGetWindowSize (windowWid, windowHei); }
int main(void) { GLfloat vtx[3*3*2*8*16],texCoord[3*3*2*8*16],nom[3*3*2*8*16],col[3*4*2*8*16]; int nVtx=MakeSphere(vtx,texCoord,nom,col,16,8); YsBitmap bmp[6]; bmp[0].LoadPng("explosion01.png"); bmp[1].LoadPng("explosion02.png"); bmp[2].LoadPng("explosion03.png"); bmp[3].LoadPng("explosion04.png"); bmp[4].LoadPng("explosion05.png"); bmp[5].LoadPng("flash01.png"); FsOpenWindow(16,16,800,600,1); YsGLSL3DRenderer *variColorPerVtxShadingRenderer=YsGLSLCreateVariColorPerVtxShading3DRenderer(); YsGLSL3DRenderer *monoColorPerVtxShadingRenderer=YsGLSLCreateMonoColorPerVtxShading3DRenderer(); YsGLSL3DRenderer *monoColorPerPixShadingRenderer=YsGLSLCreateMonoColorPerPixShading3DRenderer(); YsGLSL3DRenderer *variColorPerPixShadingRenderer=YsGLSLCreateVariColorPerPixShading3DRenderer(); YsGLSL3DRenderer *monoColorPerVtxShadingWithTexRenderer=YsGLSLCreateMonoColorPerVtxShadingWithTexCoord3DRenderer(); YsGLSL3DRenderer *variColorPerVtxShadingWithTexRenderer=YsGLSLCreateVariColorPerVtxShadingWithTexCoord3DRenderer(); YsGLSL3DRenderer *monoColorPerPixShadingWithTexRenderer=YsGLSLCreateMonoColorPerPixShadingWithTexCoord3DRenderer(); YsGLSL3DRenderer *variColorPerPixShadingWithTexRenderer=YsGLSLCreateVariColorPerPixShadingWithTexCoord3DRenderer(); YsGLSL3DRenderer *renderer3d=monoColorPerVtxShadingRenderer; printf("SPACE Switch between Per Vertex and Per Pixel renderers.\n"); GLuint texId; glGenTextures(1,&texId); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,texId); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,bmp[0].GetWidth(),bmp[0].GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,bmp[0].GetRGBABitmapPointer()); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); double rot=0.0; int bmpId=0; for(int key=FSKEY_NULL; FSKEY_ESC!=key; FsSleep(10)) { FsPollDevice(); key=FsInkey(); switch(key) { case FSKEY_ENTER: bmpId=(bmpId+1)%6; glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,bmp[bmpId].GetWidth(),bmp[bmpId].GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,bmp[bmpId].GetRGBABitmapPointer()); break; case FSKEY_SPACE: if(renderer3d==monoColorPerVtxShadingRenderer) { renderer3d=monoColorPerPixShadingRenderer; } else if(renderer3d==monoColorPerPixShadingRenderer) { renderer3d=variColorPerVtxShadingRenderer; } else if(renderer3d==variColorPerVtxShadingRenderer) { renderer3d=variColorPerPixShadingRenderer; } else if(renderer3d==variColorPerPixShadingRenderer) { renderer3d=monoColorPerVtxShadingWithTexRenderer; } else if(renderer3d==monoColorPerVtxShadingWithTexRenderer) { renderer3d=variColorPerVtxShadingWithTexRenderer; } else if(renderer3d==variColorPerVtxShadingWithTexRenderer) { renderer3d=monoColorPerPixShadingWithTexRenderer; } else if(renderer3d==monoColorPerPixShadingWithTexRenderer) { renderer3d=variColorPerPixShadingWithTexRenderer; } else { renderer3d=monoColorPerVtxShadingRenderer; } break; } glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); int wid,hei; FsGetWindowSize(wid,hei); const double aspect=(double)wid/(double)hei; GLfloat modelview[16],projection[16],tfm[16]; YsGLMakePerspectivefv(projection,YSGLPI/6.0,aspect,1.0,50.0); YsGLMakeIdentityfv(modelview); YsGLMakeTranslationfv(tfm,0.0,0.0,-15.0); YsGLMultMatrixfv(modelview,modelview,tfm); YsGLMakeXZRotationfv(tfm,rot); YsGLMultMatrixfv(modelview,modelview,tfm); YsGLMakeScalingfv(tfm,3.0,3.0,3.0); YsGLMultMatrixfv(modelview,modelview,tfm); YsGLSLUse3DRenderer(monoColorPerVtxShadingRenderer); YsGLSLSet3DRendererProjectionfv(monoColorPerVtxShadingRenderer,projection); YsGLSLSet3DRendererModelViewfv(monoColorPerVtxShadingRenderer,modelview); YsGLSLEndUse3DRenderer(monoColorPerVtxShadingRenderer); YsGLSLUse3DRenderer(variColorPerVtxShadingRenderer); YsGLSLSet3DRendererProjectionfv(variColorPerVtxShadingRenderer,projection); YsGLSLSet3DRendererModelViewfv(variColorPerVtxShadingRenderer,modelview); YsGLSLEndUse3DRenderer(variColorPerVtxShadingRenderer); YsGLSLUse3DRenderer(monoColorPerPixShadingRenderer); YsGLSLSet3DRendererProjectionfv(monoColorPerPixShadingRenderer,projection); YsGLSLSet3DRendererModelViewfv(monoColorPerPixShadingRenderer,modelview); YsGLSLEndUse3DRenderer(monoColorPerPixShadingRenderer); YsGLSLUse3DRenderer(variColorPerPixShadingRenderer); YsGLSLSet3DRendererProjectionfv(variColorPerPixShadingRenderer,projection); YsGLSLSet3DRendererModelViewfv(variColorPerPixShadingRenderer,modelview); YsGLSLEndUse3DRenderer(variColorPerPixShadingRenderer); YsGLSLUse3DRenderer(monoColorPerVtxShadingWithTexRenderer); YsGLSLSet3DRendererProjectionfv(monoColorPerVtxShadingWithTexRenderer,projection); YsGLSLSet3DRendererModelViewfv(monoColorPerVtxShadingWithTexRenderer,modelview); YsGLSLEndUse3DRenderer(monoColorPerVtxShadingWithTexRenderer); YsGLSLUse3DRenderer(variColorPerVtxShadingWithTexRenderer); YsGLSLSet3DRendererProjectionfv(variColorPerVtxShadingWithTexRenderer,projection); YsGLSLSet3DRendererModelViewfv(variColorPerVtxShadingWithTexRenderer,modelview); YsGLSLEndUse3DRenderer(variColorPerVtxShadingWithTexRenderer); YsGLSLUse3DRenderer(monoColorPerPixShadingWithTexRenderer); YsGLSLSet3DRendererProjectionfv(monoColorPerPixShadingWithTexRenderer,projection); YsGLSLSet3DRendererModelViewfv(monoColorPerPixShadingWithTexRenderer,modelview); YsGLSLEndUse3DRenderer(monoColorPerPixShadingWithTexRenderer); YsGLSLUse3DRenderer(variColorPerPixShadingWithTexRenderer); YsGLSLSet3DRendererProjectionfv(variColorPerPixShadingWithTexRenderer,projection); YsGLSLSet3DRendererModelViewfv(variColorPerPixShadingWithTexRenderer,modelview); YsGLSLEndUse3DRenderer(variColorPerPixShadingWithTexRenderer); glEnable(GL_CULL_FACE); glFrontFace(GL_CW); YsGLSLUse3DRenderer(renderer3d); YsGLSLSet3DRendererTextureType(renderer3d,YSGLSL_TEX_TYPE_BILLBOARD); const GLfloat billBoardCenter[3]={0,0,0}; const GLfloat billBoardDimension[2]={3.0f,3.0f}; YsGLSLSet3DRendererBillBoardfv(renderer3d,billBoardCenter,billBoardDimension); GLfloat color[4]={0,0,1,1}; YsGLSLSet3DRendererUniformColorfv(renderer3d,color); if(renderer3d!=monoColorPerPixShadingWithTexRenderer && renderer3d!=variColorPerPixShadingWithTexRenderer && renderer3d!=monoColorPerVtxShadingWithTexRenderer && renderer3d!=variColorPerVtxShadingWithTexRenderer) { YsGLSLDrawPrimitiveVtxNomColfv(renderer3d,GL_TRIANGLES,nVtx,vtx,nom,col); } else if(renderer3d==monoColorPerPixShadingWithTexRenderer || renderer3d==monoColorPerVtxShadingWithTexRenderer) { YsGLSLDrawPrimitiveVtxTexCoordNomfv(renderer3d,GL_TRIANGLES,nVtx,vtx,texCoord,nom); } else if(renderer3d==variColorPerPixShadingWithTexRenderer || renderer3d==variColorPerVtxShadingWithTexRenderer) { YsGLSLDrawPrimitiveVtxTexCoordNomColfv(renderer3d,GL_TRIANGLES,nVtx,vtx,texCoord,nom,col); } YsGLSLEndUse3DRenderer(renderer3d); FsSwapBuffers(); rot+=YSGLPI/30.0; } YsGLSLDelete3DRenderer(monoColorPerVtxShadingRenderer); YsGLSLDelete3DRenderer(variColorPerVtxShadingRenderer); YsGLSLDelete3DRenderer(monoColorPerPixShadingRenderer); return 0; }
int main(int argc,char **argv) { Options opt; if(!parse_args(&opt,argc,argv)){ return 1; } char strk[256],strmu[256],strsigma[256],striso[256]; int terminate=0; CameraObject camera; OrbitingViewer orbit; orbit.focusY=4.0; camera.z=10.0; FsOpenWindow(16,16,800,600,1); Cylinder cylinder; cylinder.setRadius(9.0); YsVec3 min(-10.0,0.0,-10.0); YsVec3 max(10.0,20.0,10.0); Box box; box.setMinMax(min,max); std::vector <YsVec3> iniPos; const double interval=0.9; CreateUniformInitialParticleLocation(iniPos,10,40,10,YsVec3(10.0,20.0,0.0),interval); std::vector <YsVec3> drip; CreateUniformInitialParticleLocation(drip,5,5,5,YsVec3(0.0,20.0,0.0),interval); ParticleSimulation sim; if(opt.infile){ sim.read(opt.infile); } else{ //sim.init(iniPos); } sim.setObstacle(box); //sim.calculate_force(); //sim.calculate_force(); sim.mode=sim.MODE_NORMAL; glClearColor(0,0,0,0); YSBOOL pause=YSFALSE; YSBOOL cube=YSFALSE; YSBOOL savestl=YSFALSE; while(0==terminate) { FsPollDevice(); int wid,hei; FsGetWindowSize(wid,hei); int key=FsInkey(); switch(key) { case FSKEY_K: { printf("Enter k:\n"); fscanf(stdin,"%lf",strk); double k=atof(strk); sim.setK(k); break; } case FSKEY_M: { printf("Enter mu:\n"); fscanf(stdin,"%lf",strmu); double mu=atof(strmu); sim.setMu(mu); break; } case FSKEY_S: { printf("Enter Sigma:\n"); fscanf(stdin,"%lf",strmu); double sigma=atof(strsigma); sim.setSigma(sigma); break; } case FSKEY_Q: if(cube){ cube=YSFALSE; } else{ cube=YSTRUE; } break; case FSKEY_I: { printf("Enter isolevel:\n"); fscanf(stdin,"%lf",striso); double iso=atof(striso); sim.setIso(iso); break; } case FSKEY_L: if(savestl){ savestl=YSFALSE; } else{ savestl=YSTRUE; } break; case FSKEY_D: sim.placeParticles(drip); break; case FSKEY_P: YsFlip(pause); break; case FSKEY_ESC: terminate=1; break; } if(FSKEY_SPACE==key || YSTRUE!=pause) { sim.update(); } if(0!=FsGetKeyState(FSKEY_LEFT)) { orbit.h+=YsPi/180.0; } if(0!=FsGetKeyState(FSKEY_RIGHT)) { orbit.h-=YsPi/180.0; } if(0!=FsGetKeyState(FSKEY_UP)) { orbit.p+=YsPi/180.0; } if(0!=FsGetKeyState(FSKEY_DOWN)) { orbit.p-=YsPi/180.0; } if(0!=FsGetKeyState(FSKEY_F) && orbit.dist>1.0) { orbit.dist/=1.05; } if(0!=FsGetKeyState(FSKEY_B) && orbit.dist<200.0) { orbit.dist*=1.05; } orbit.SetUpCamera(camera); glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glViewport(0,0,wid,hei); // Set up 3D drawing camera.SetUpCameraProjection(); camera.SetUpCameraTransformation(); glEnable(GL_DEPTH_TEST); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1,1); // 3D drawing from here glPushMatrix(); glPointSize(3); if(cube){ sim.drawMesh(); if(savestl){ sim.shl.SaveBinStl("test.stl"); printf("stl saved\n"); savestl=YSFALSE; } } else{ sim.drawParticles(); } //sim.drawColorFieldGrid(); glPopMatrix(); // Set up 2D drawing glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,(float)wid-1,(float)hei-1,0,-1,1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_DEPTH_TEST); FsSwapBuffers(); FsSleep(25); } //sim.write(opt.outfile); return 0; }
int main(void) { double cubeMatrix[16]= { 1.0,0.0,0.0,0.0, 0.0,1.0,0.0,0.0, 0.0,0.0,1.0,0.0, 0.0,0.0,0.0,1.0 }; FsOpenWindow(32,32,800,600,1); // 800x600 pixels, useDoubleBuffer=1 glEnable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDepthFunc(GL_LESS); FsPassedTime(); // Reset the timer while(FsInkey()==0) { int mx,my,lb,mb,rb,passed; double spinX,spinY; passed=FsPassedTime(); FsPollDevice(); FsGetMouseState(lb,mb,rb,mx,my); int wid,hei,cx,cy; FsGetWindowSize(wid,hei); cx=wid/2; cy=hei/2; spinX=(double)((mx-cx)/10)*(double)passed/1000.0; // 1 pixel = degrees/sec spinY=(double)((my-cy)/10)*(double)passed/1000.0; // 1 pixel = degrees/sec glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glViewport(0,0,wid,hei); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,(double)wid/(double)hei,1.0,20.0); glTranslated(0.0,0.0,-10.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotated(spinX,0.0,1.0,0.0); glRotated(spinY,1.0,0.0,0.0); glMultMatrixd(cubeMatrix); glGetDoublev(GL_MODELVIEW_MATRIX,cubeMatrix); glBegin(GL_QUADS); glColor3ub(0,0,255); glVertex3d(-2.5,-2.5,-2.5); glVertex3d(-2.5, 2.5,-2.5); glVertex3d( 2.5, 2.5,-2.5); glVertex3d( 2.5,-2.5,-2.5); glColor3ub(255,0,0); glVertex3d(-2.5,-2.5, 2.5); glVertex3d(-2.5, 2.5, 2.5); glVertex3d( 2.5, 2.5, 2.5); glVertex3d( 2.5,-2.5, 2.5); glColor3ub(255,0,255); glVertex3d(-2.5,-2.5,-2.5); glVertex3d(-2.5,-2.5, 2.5); glVertex3d(-2.5, 2.5, 2.5); glVertex3d(-2.5, 2.5,-2.5); glColor3ub(0,255,0); glVertex3d( 2.5,-2.5,-2.5); glVertex3d( 2.5,-2.5, 2.5); glVertex3d( 2.5, 2.5, 2.5); glVertex3d( 2.5, 2.5,-2.5); glColor3ub(0,255,255); glVertex3d(-2.5,-2.5,-2.5); glVertex3d(-2.5,-2.5, 2.5); glVertex3d( 2.5,-2.5, 2.5); glVertex3d( 2.5,-2.5,-2.5); glColor3ub(255,255,0); glVertex3d(-2.5, 2.5,-2.5); glVertex3d(-2.5, 2.5, 2.5); glVertex3d( 2.5, 2.5, 2.5); glVertex3d( 2.5, 2.5,-2.5); glEnd(); FsSwapBuffers(); FsSleep(20-passed); } return 0; }
/* void MAP::SaveMap(char* nameOfNewMap) { char fn[256]; char ioBuffer[256]; FILE *fpp; //char nameOfNewMap[256]; //printf("Name the map you want to save: \n"); // create a new map name //scanf("%s", nameOfNewMap); strcpy(fn,nameOfNewMap); fpp=fopen(fn,"w"); if (fpp!=NULL) { for (int i=0;i<mapWidth;i++) { for(int j=0;j<mapHeight;j++) { _itoa(mapGrid[i][j],ioBuffer,10); fwrite(ioBuffer,1,strlen(ioBuffer),fpp); fwrite("\n",1,1,fpp); } } printf("%s is saved successfully.\n",fn); } if(fpp!=NULL) { fclose(fpp); } } bool MAP::ChangeMap(int x, int y, MONSTER monster[])//monster[2] { int findPath = 0; if ( !(x>=0 && x<mapWidth && y>=0 && y<mapHeight) ) { //printf("Mouse is not on the map.\n"); return false; } else if (mapGrid[x][y]==UNWALKABLE) // walkable=1; unwalkable=0 { //printf("Tower exsited at this position.\n"); return false; } int mapGridDuplicate[mapWidth][mapHeight]; // deep copy the current map for (int i=0; i<mapWidth; i++) { for (int j=0; j<mapHeight; j++) { mapGridDuplicate[i][j] = mapGrid[i][j]; } } mapGridDuplicate[x][y] = UNWALKABLE; // check if all monsters can walk out after building the new tower for (int m=0; m<2; m++) { if (monster[m].state==1) { findPath = finder.FindPath(monster[m].GetX(), monster[m].GetY(),75,59,mapGrid); if (findPath!=1) { //printf("Tentative tower location (%d, %d) is invalid.\n", x, y); return false; } } } mapGrid[x][y]=UNWALKABLE; //printf("Paths are found and map is changed.\n"); return true; } */ void MAP::DrawMap(int pngProjX,int pngProjY,int ExitX,int ExitY) { int ProjectionX=pngProjX,ProjectionY=600-pngProjY; FsPollDevice(); //printf("ProjectionX:%d ProjectionY:%d\n",pngProjX,pngProjY); int winWid,winHei; FsGetWindowSize(winWid,winHei); glViewport(0,0,winWid,winHei); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,(float)winWid-1,(float)winHei-1,0,-1,1); glRasterPos2d(0,(double)winHei-1); //glDrawPixels(800,600,GL_RGBA,GL_UNSIGNED_BYTE,grassfield.rgba); unsigned char *VisibleGrass; VisibleGrass=new unsigned char [800*600*4]; for(int j=0;j<600;j++) for(int i=0;i<800;i++) { VisibleGrass[(j*800+i)*4] =grassfield.rgba[((j+pngProjY)*grassfield.wid+i+pngProjX)*4]; VisibleGrass[(j*800+i)*4+1] =grassfield.rgba[((j+pngProjY)*grassfield.wid+i+pngProjX)*4+1]; VisibleGrass[(j*800+i)*4+2] =grassfield.rgba[((j+pngProjY)*grassfield.wid+i+pngProjX)*4+2]; VisibleGrass[(j*800+i)*4+3] =grassfield.rgba[((j+pngProjY)*grassfield.wid+i+pngProjX)*4+3]; } glDrawPixels(800,600,GL_RGBA,GL_UNSIGNED_BYTE,VisibleGrass); delete [] VisibleGrass; int TileSize=1600/mapWidth; for(int i=0;i<mapWidth;i++) { for(int j=0;j<mapHeight;j++) { if(mapGrid[i][j]==UNWALKABLE //&& i*TileSize>=ProjectionX-TileSize && i*TileSize<ProjectionX+800 //&& j*TileSize>=ProjectionY-TileSize && j*TileSize<ProjectionY+600 ) { int winWid,winHei; FsGetWindowSize(winWid,winHei); glViewport(0,0,winWid,winHei); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,(float)winWid-1,(float)winHei-1,0,-1,1); glRasterPos2d(-ProjectionX+TileSize*i,-ProjectionY+TileSize*j+TileSize-1);//+(double)stonewall.hei);//winHei); glDrawPixels(stonewall.wid,stonewall.hei,GL_RGBA,GL_UNSIGNED_BYTE,stonewall.rgba); /* glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glColor4ub(255,0,0,50); glBegin(GL_QUADS); glVertex2i(-ProjectionX+TileSize*i,-ProjectionY+TileSize*j); glVertex2i(-ProjectionX+TileSize*i+TileSize,-ProjectionY+TileSize*j); glVertex2i(-ProjectionX+TileSize*i+TileSize,-ProjectionY+TileSize*j+TileSize); glVertex2i(-ProjectionX+TileSize*i,-ProjectionY+TileSize*j+TileSize); glEnd(); glDisable(GL_BLEND); */ } /*else if(mapGrid[i][j]==WALKABLE) { glColor3ub(255,100,0); glBegin(GL_QUADS); glVertex2i(TileSize*i,TileSize*j); glVertex2i(TileSize*i+TileSize,TileSize*j); glVertex2i(TileSize*i+TileSize,TileSize*j+TileSize); glVertex2i(TileSize*i,TileSize*j+TileSize); glEnd(); }*/ } } //int winWid,winHei; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); FsGetWindowSize(winWid,winHei); glViewport(0,0,winWid,winHei); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,(float)winWid-1,(float)winHei-1,0,-1,1); //printf("ExitX/tile:%d,Y:%d",ExitX*2/TileSize,ExitY*2/TileSize); glRasterPos2d(-ProjectionX+(ExitX*2/TileSize)*TileSize,-ProjectionY+(ExitY*2/TileSize)*TileSize+(double)exit.hei);//winHei); glDrawPixels(exit.wid,exit.hei,GL_RGBA,GL_UNSIGNED_BYTE,exit.rgba); glDisable(GL_BLEND); /*glColor3ub(0,0,0); glRasterPos2d(720,585); YsGlDrawFontBitmap16x24("Back");*/ }
/* virtual */ void FsLazyWindowApplication::Draw(void) { int wid,hei; FsGetWindowSize(wid,hei); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); drawEnv.SetProjectionMode(YsProjectionTransformation::PERSPECTIVE); drawEnv.SetAspectRatio((double)wid/(double)hei); drawEnv.SetFOVY(YsPi/4.0); drawEnv.SetNearFar(0.1,100.0); drawEnv.SetViewTarget((min+max)/2.0); drawEnv.SetViewDistance((max-min).GetLength()); GLfloat projMat[16]; drawEnv.GetProjectionMatrix().GetOpenGlCompatibleMatrix(projMat); auto &view=drawEnv.GetViewMatrix(); YsMatrix4x4 modeling; YsMatrix4x4 fullMatrix=view*modeling; GLfloat viewMat[16]; fullMatrix.GetOpenGlCompatibleMatrix(viewMat); { YsGLSLPlain3DRenderer renderer; // Again, do not nest the renderer! renderer.SetProjection(projMat); renderer.SetModelView(viewMat); GLfloat color[8]={0,0,1,1, 1,0,0,1}; const GLfloat vtx[6]= { lastClick[0].xf(),lastClick[0].yf(),lastClick[0].zf(), lastClick[1].xf(),lastClick[1].yf(),lastClick[1].zf() }; renderer.DrawVtxCol(GL_LINES,2,vtx,color); glEnable(GL_PROGRAM_POINT_SIZE); renderer.SetUniformPointSize(3.0); renderer.DrawVtx(GL_POINTS,cellVtx.size()/3,cellVtx.data()); } { GLfloat lightDir[]={0,0,1}; YsGLSLShaded3DRenderer renderer; // Again, do not nest the renderer! renderer.SetProjection(projMat); renderer.SetModelView(viewMat); renderer.SetLightDirectionInCameraCoordinate(0,lightDir); renderer.DrawVtxNomCol(GL_TRIANGLES,vtx.size()/3,vtx.data(),nom.data(),col.data()); } YsMatrix4x4 shadowMat; shadowMat.Translate(0.0,-12.0,0.0); shadowMat.Scale(1.0,0.0,1.0); fullMatrix=view*shadowMat*modeling; fullMatrix.GetOpenGlCompatibleMatrix(viewMat); { GLfloat color[]={0,0,0,1}; YsGLSLPlain3DRenderer renderer; // Again, do not nest the renderer! renderer.SetProjection(projMat); renderer.SetModelView(viewMat); renderer.SetUniformColor(color); renderer.DrawVtx(GL_TRIANGLES,vtx.size()/3,vtx.data()); } FsSwapBuffers(); needRedraw=false; }
void Map::RunMap() { key = 0; int offset=0; char *story[] = { "Welcome to CMU Adventure!", "Whether you have made up your mind to come to CMU or", "you are still mulling over it, you are welcome to use", "this game to have a glimpse of life at CMU.", " ", "To familiarize yourself with the CMU environment,", "navigate through the satellite view map of CMU campus ", // changes by Chun Fan "to explore all the buildings.", // changes by Chun Fan " ", "Studying constitutes a large part of CMU student life.", "CMU tries to make learning fun.See how MechE students", "learn CAD & gear theory by playing the CAD & Gear games", "at Hammerschlag Hall and Hunts library.", " ", "Sometimes massive number of assignments could means ", "many sleepless nights. Play the StayAwake game to see", // changes by Chun Fan "how CMU lecturers and students fight off sleeping bugs", "during lectures in Margaret-Morrison Hall.", " ", "Student life is not just about studying, recreation is", "essential too. Have some fun by playing the Pool game", "at University Center.", " ", "At CMU, safety is utmost important.CMU provides shuttle", "buses to ferry students and staffs back home safely.", "Play the Shuttle game at Porter Hall to have a feel on", "how it is like to catch a shuttle bus at CMU.", " ", "Press Enter to start game!" }; Building building[5]; building[0].set("Uiversity Center", 1374, 1239, 110, 136); building[1].set("Hunts Hall", 1042, 662, 70, 35); building[2].set("Hammerschlag Hall", 454, 984, 111, 90); building[3].set("Porter Hall", 626, 805, 115, 75); building[4].set("Margaret-Morisson", 1489, 938, 50, 90); if(YSOK==png.Decode("instructions_background.png")) { // changes by Chun Fan //printf("Read Width=%d Height=%d\n",png.wid,png.hei); png.Flip(); } else { printf("Read Error!\n"); return ; } // Story Cover Page glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); int winWid,winHei; FsGetWindowSize(winWid, winHei); glRasterPos2d(0.0, (double)(winHei-1)); glDrawPixels(png.wid, png.hei, GL_RGBA, GL_UNSIGNED_BYTE, png.rgba); if(YSOK==png.Decode("map-with light.png")) { // changes by Chun Fan //printf("Read Width=%d Height=%d\n",png.wid,png.hei); png.Flip(); } else { printf("Read Error!\n"); return ; } glColor3ub(0,0,255); int n_line=1; glRasterPos2d(75,75); YsGlDrawFontBitmap20x32(story[0]); glColor3ub(0,0,0); for (int i=1; i<28; i++) { n_line++; glRasterPos2d(75,75+16*n_line); YsGlDrawFontBitmap12x16(story[i]); } n_line++; glColor3ub(255,0,0); glRasterPos2d(75,75+16*n_line); YsGlDrawFontBitmap12x16(story[28]); FsSwapBuffers(); while (key!=FSKEY_ENTER) { FsPollDevice(); key = FsInkey(); FsSleep(20); } key=FSKEY_NULL; int Mnumber=0; while(FSKEY_ESC!=key) { FsPollDevice(); key=FsInkey(); glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); if (key==FSKEY_M) { Mnumber++; } if (Mnumber%2==0) { DramMap();//Include check player's position(whether player can step on that part or not) and move //the map. CheckPlayersState(); player.DrawPlayerInMap(); player.DrawMovingPlayerInCorner(player.PlayersState); } if (Mnumber%2==1) { ShowShrinkMap(); } // check position int x=GetPlayersPositionX(); int y=GetPlayersPositionY(); //printf("x = %d,\t y = %d\n", x, y); srand((unsigned int)time(NULL) + rand()); for (int i=0; i<5; i++) { int x_min = building[i].getX() - building[i].getW() ; int x_max = building[i].getX() + building[i].getW() ; int y_min = building[i].getY() - building[i].getH() ; int y_max = building[i].getY() + building[i].getH() ; if (x>x_min && x<x_max && y>y_min && y<y_max) { //char name[256]; YsRawPngDecoder png4; int state0=0,state1=0,state2=0,state3=0,state4=0; FsPollDevice(); int MouseEvent; int lb,mb,rb,mx,my; //building[i].getName(name); //printf("I am in %s!\n", name); switch (i) { case 0: // pool if(YSOK==png4.Decode("ClickButton.png")) { png4.Flip(); int winWid,winHei; FsGetWindowSize(winWid,winHei); glRasterPos2d(400,300); glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba); // changes by Chun Fan //printf("%d %d",png4.wid,png4.hei); } MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my); switch(MouseEvent) { case FSMOUSEEVENT_LBUTTONDOWN: if(mx>=400 && mx<=600 && my>=200 && my<=300) { state0=1; } } if(state0==1) { score.setResult(0, poolgame.rungame()); // changes by Chun Fan //printf("Game 1: %d trials, %s\n", score.getCount(0), score.getResult(0)?"Passed":"Failed"); FsClearEventQueue(); } state0=0; //FsClearEventQueue(); break; case 1: // CAD if(YSOK==png4.Decode("ClickButton.png")) { png4.Flip(); int winWid,winHei; FsGetWindowSize(winWid,winHei); glRasterPos2d(400,300); glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba); // changes by Chun Fan //printf("%d %d",png4.wid,png4.hei); } MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my); switch(MouseEvent) { case FSMOUSEEVENT_LBUTTONDOWN: if(mx>=400 && mx<=600 && my>=200 && my<=300) { state1=1; } } if(state1==1) { score.setResult(1, cadclass.CADMain()); // changes by Chun Fan //printf("Game 2: %d trials, %s\n", score.getCount(1), score.getResult(1)?"Passed":"Failed"); FsClearEventQueue(); } state1=0; //FsClearEventQueue(); break; case 2: // gear game if(YSOK==png4.Decode("ClickButton.png")) { png4.Flip(); int winWid,winHei; FsGetWindowSize(winWid,winHei); glRasterPos2d(400,300); glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba); // changes by Chun Fan //printf("%d %d",png4.wid,png4.hei); } MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my); switch(MouseEvent) { case FSMOUSEEVENT_LBUTTONDOWN: if(mx>=400 && mx<=600 && my>=200 && my<=300) { state2=1; } } if(state2==1) { score.setResult(2, geargame.run()); // changes by Chun Fan //printf("Game 3: %d trials, %s\n", score.getCount(2), score.getResult(2)?"Passed":"Failed"); // changes by Chun Fan glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); FsClearEventQueue(); } state2=0; //FsClearEventQueue(); break; case 3: if( score.getGraduate()) { if(YSOK==png4.Decode("ClickButton.png")) { png4.Flip(); int winWid,winHei; FsGetWindowSize(winWid,winHei); glRasterPos2d(400,300); glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba); // changes by Chun Fan //printf("%d %d",png4.wid,png4.hei); } MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my); switch(MouseEvent) { case FSMOUSEEVENT_LBUTTONDOWN: if(mx>=400 && mx<=600 && my>=200 && my<=300) { state3=1; } } } if(state3==1 ) { shuttle.action(); glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); score.DrawScoreCard(); FsSwapBuffers(); FsPollDevice(); int key1 = FsInkey(); while(key1!=FSKEY_ENTER) { FsPollDevice(); key1 = FsInkey(); FsSleep(20); } glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); awardStage.SetDept("Mechanical Engineering"); awardStage.DrawStage(); awardStage.PrintCert(); FsSwapBuffers(); FsPollDevice(); key1 = FsInkey(); while(key1!=FSKEY_ENTER) { FsPollDevice(); key1 = FsInkey(); FsSleep(20); } key=FSKEY_ESC; } state3=0; //if (checkscore()==1) FsClearEventQueue(); break; case 4: // stayawake if(YSOK==png4.Decode("ClickButton.png")) { png4.Flip(); int winWid,winHei; FsGetWindowSize(winWid,winHei); glRasterPos2d(400,300); glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba); // changes by Chun Fan //printf("%d %d",png4.wid,png4.hei); } MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my); switch(MouseEvent) { case FSMOUSEEVENT_LBUTTONDOWN: if(mx>=400 && mx<=600 && my>=200 && my<=300) { state4=1; } } if(state4==1) { stayawake.StartGame(); score.setResult(3, stayawake.GetScore()); // changes by Chun Fan //printf("Game 4: %d trials, %s\n", score.getCount(3), score.getResult(3)?"Passed":"Failed"); FsClearEventQueue(); } state4=0; //FsClearEventQueue(); break; } } } FsSwapBuffers(); FsSleep(50); } }
void FsSimpleWindowIntervalCallBack(void) { int winWid,winHei; FsGetWindowSize(winWid,winHei); int lb,mb,rb,mx,my; FsGetMouseEvent(lb,mb,rb,mx,my); float r=1.0,g=0.0,b=0.0,a=1.0; glClearColor(0.1f, 0.1f, 0.1f, 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); GLfloat spriteVtx[]= { 1,1,1, -1,1,1, 1,-1,1, -1,-1,1, 1,1,-1, -1,1,-1, 1,-1,-1, -1,-1,-1, }; GLfloat spriteColor[]= { 0,0,1, 1, 0,1,0, 1, 1,0,0, 1, 1,0,1, 1, 1,1,0, 1, 1,1,1, 1, 0,0,1, 1, 0,1,0, 1, }; GLfloat monoColorVtx[]= { 1, 0, 0, -1, 0, 0, 0, 1, 0, 0,-1, 0, 0, 0, 1, 0, 0,-1, }; const int nVtx=(sizeof(spriteVtx)/(3*sizeof(GLfloat))); glDisable(GL_DEPTH_TEST); glEnable(GL_PROGRAM_POINT_SIZE); // Needed for enabling gl_PointSize in the vertex shader. glEnable(GL_POINT_SPRITE); // Needed for enabling gl_PointCoord in the fragment shader. YsGLSLUsePlain2DRenderer(YsGLSLSharedPlain2DRenderer()); YsGLSLUseWindowCoordinateInPlain2DDrawing(YsGLSLSharedPlain2DRenderer(),1); YsGLSLDrawPlain2DLinef(YsGLSLSharedPlain2DRenderer(),mx-10,my-10,mx+10,my+10,r,g,b,a); YsGLSLDrawPlain2DLinef(YsGLSLSharedPlain2DRenderer(),mx+10,my-10,mx-10,my+10,r,g,b,a); YsGLSLEndUsePlain2DRenderer(YsGLSLSharedPlain2DRenderer()); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_DEPTH_TEST); static double hdg=0.0; GLfloat modelview[16],projection[16],tfm[16]; YsGLMakeIdentityfv(modelview); YsGLMakeTranslationfv(tfm,0.0f,0.0f,-5.0f); YsGLMultMatrixfv(modelview,modelview,tfm); YsGLMakeXZRotationfv(tfm,(float)hdg); YsGLMultMatrixfv(modelview,modelview,tfm); YsGLMakePerspectivefv(projection,YSGLPI/6.0,(float)winWid/(float)winHei,1.0,50.0); YsGLSLUse3DRenderer(variColorRenderer); YsGLSLSet3DRendererModelViewfv(variColorRenderer,modelview); YsGLSLSet3DRendererProjectionfv(variColorRenderer,projection); YsGLSLDrawPrimitiveVtxColfv(variColorRenderer,GL_POINTS,nVtx,spriteVtx,spriteColor); YsGLSLEndUse3DRenderer(variColorRenderer); YsGLSLUse3DRenderer(monoColorRenderer); YsGLSLSet3DRendererModelViewfv(monoColorRenderer,modelview); YsGLSLSet3DRendererProjectionfv(monoColorRenderer,projection); YsGLSLDrawPrimitiveVtxfv(monoColorRenderer,GL_POINTS,6,monoColorVtx); YsGLSLEndUse3DRenderer(monoColorRenderer); hdg+=0.01; FsSwapBuffers(); }