void RankingScene::display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* 画面とZバッファのクリア */ glClearColor(0, 0, 0, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0, 0, 0, 0, 0, 1, 0, 1, 0); textureMap["font"]->drawString(" number of players " + total, Point2D( 0, 0.015 ), 0.75, Color( 1, 1, 1 ) ); textureMap["font"]->drawString("Rank Name Score", Point2D(0.05, 0.1), 1, Color(1, 0, 0)); Color gold(1, 0.8, 0); Color silver(0.8, 0.8, 0.8); Color bronze(0.8, 0.4, 0.1); Color blue(0.7, 0.7, 1); for (int i = 0; i < 10; i++) { if (i == 0) textureMap["font"]->drawString("1st", Point2D(0.05, 0.2 + 0.07*i), 0.8, gold); else if (i == 1) textureMap["font"]->drawString("2nd", Point2D(0.05, 0.2 + 0.07*i), 0.8, silver); else if (i == 2) textureMap["font"]->drawString("3rd", Point2D(0.05, 0.2 + 0.07*i), 0.8, bronze); else textureMap["font"]->drawString(to_string((long long)(i + 1)), Point2D(0.1, 0.2 + 0.07*i), 0.8, blue); } for (int j = 0; j < 10; j++){ if (j == 0){ textureMap["font"]->drawString(rank_name[j], Point2D(0.35, 0.2 + 0.07*j), 1, gold); textureMap["font"]->drawString(rank_score[j], Point2D(0.7, 0.2 + 0.07*j), 1, gold); } else if (j == 1){ textureMap["font"]->drawString(rank_name[j], Point2D(0.35, 0.2 + 0.07*j), 1, silver); textureMap["font"]->drawString(rank_score[j], Point2D(0.7, 0.2 + 0.07*j), 1, silver); } else if (j == 2){ textureMap["font"]->drawString(rank_name[j], Point2D(0.35, 0.2 + 0.07*j), 1, bronze); textureMap["font"]->drawString(rank_score[j], Point2D(0.7, 0.2 + 0.07*j), 1, bronze); } else{ textureMap["font"]->drawString(rank_name[j], Point2D(0.35, 0.2 + 0.07*j), 1, blue); textureMap["font"]->drawString(rank_score[j], Point2D(0.7, 0.2 + 0.07*j), 1, blue); } } if (counter % FPS < FPS/2) textureMap["spaceReturn"]->draw2D(Point2D(0.7, 0.9), 0.4, Color(1, 1, 1)); }
int main(int argc, char* argv[]) { // Build your scene and setup your camera here, by calling // functions from Raytracer. The code here sets up an example // scene and renders it from two different view points, DO NOT // change this if you're just implementing part one of the // assignment. Raytracer raytracer; int width = 320; int height = 240; int aa = 2; int sceneNum = 0; double toRadian = 2*M_PI/360.0; fprintf(stderr, "Using options:\n"); #ifdef USE_EXTENDEDLIGHTS fprintf(stderr, "\tExtended light sources\n"); #else fprintf(stderr, "\tPoint light sources\n"); #endif #ifdef USE_REFRACTIONS fprintf(stderr, "\tRefractions\n"); #else fprintf(stderr, "\tNo refractions\n"); #endif #ifdef USE_REFLECTIONS fprintf(stderr, "\tReflections\n"); #else fprintf(stderr, "\tNo reflections\n"); #endif #ifdef IGNORE_SHADOWS fprintf(stderr, "\tNo shadows\n"); #else { #ifdef USE_TRANSMISSIONSHADOWS fprintf(stderr, "\tTransmission-based shadows\n"); #else fprintf(stderr, "\tSimple shadows\n"); #endif } #endif #ifdef USE_FINERFLUX fprintf(stderr, "\tFiner numerical flux intergrations\n"); #else fprintf(stderr, "\tCoarser numerical flux intergrations\n"); #endif if (argc == 3) { width = atoi(argv[1]); height = atoi(argv[2]); } else if (argc == 4) { width = atoi(argv[1]); height = atoi(argv[2]); aa = atoi(argv[3]); } else if (argc == 5) { width = atoi(argv[1]); height = atoi(argv[2]); aa = atoi(argv[3]); sceneNum = atoi(argv[4]); } // SceneNum should not exceed total scenes if ((sceneNum > 3)|| (sceneNum <0)) { sceneNum = 0; } // Camera parameters. Point3D eye(0, 0, 1); Vector3D view(0, 0, -1); Vector3D up(0, 1, 0); double fov = 60; // Defines materials for shading. Material gold( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648), Colour(0.628281, 0.555802, 0.366065), 51.2, 0.001, 0.0, 1/2.4 ); Material jade( Colour(0.22, 0.38, 0.33), Colour(0.52, 0.73, 0.57), Colour(0.316228, 0.316228, 0.316228), 12.8, 0.2 , 0.0, 0.0 ); Material polishedGold( Colour(0.24725, 0.2245, 0.0645), Colour(0.34615, 0.3143, 0.0903), Colour(0.797357, 0.723991, 0.208006), 83.2, 0.01,0.0,0.0); Material glass( Colour(0.15, 0.15, 0.15), Colour(0.08, 0.08, 0.08), Colour(0.2, 0.2, 0.2), 50.1,0.08,0.9,0.6667 ); Material glass1( Colour(0.2, 0.2, 0.2), Colour(0.2, 0.2, 0.2), Colour(0.7, 0.7, 0.7), 10.1,0.03,0.9,0.6667 ); Material steel( Colour(0.1, 0.1, 0.1), Colour(0.1, 0.1, 0.1), Colour(0.8, 0.8, 0.8), 80, 0.03, 0.0, 1.0 ); Material blueSolid( Colour(0, 0, 1), Colour(0, 0, 1), Colour(0, 0, 0), 0, 0.0, 0.0, 1.0 ); Material redSolid( Colour(1, 0, 0), Colour(1, 0, 0), Colour(0, 0, 0), 0, 0.0, 0.0, 1.0 ); Material chrome( Colour(0.25, 0.25, 0.25), Colour(0.4,0.4,0.4), Colour(0.7746, 0.7746, 0.7746), 77, 0.42, 0.0, 1.0); Material ruby( Colour(0.1745, 0.01175, 0.01175), Colour(0.61424, 0.04136, 0.04136), Colour(0.727811, 0.626959, 0.626959) , 76.8, 0.01, 0.0, 0.565); Material pearl( Colour(0.25, 0.20725, 0.20725), Colour(1, 0.829, 0.829), Colour(0.296648, 0.296648, 0.296648), 11.264, 0.1,0.0,1.0 ); Material silver(Colour(0.23125, 0.23125, 0.23125), Colour(0.2775, 0.2775, 0.2775), Colour(0.773911, 0.773911, 0.773911), 89.6, 0.4,0.0, 1.0); Material emerald(Colour(0.0215, 0.1745, 0.0215),Colour(0.07568, 0.61424, 0.07568), Colour(0.633, 0.727811, 0.633), 76.8, 0.1, 0.25, 0.637); Material brass(Colour(0.329412, 0.223529, 0.027451),Colour(0.780392, 0.568627, 0.113725), Colour(0.992157, 0.941176, 0.807843),27.8974, 0.3, 0.0, 1.0 ); Material bronze(Colour(0.2125, 0.1275, 0.054), Colour(0.714, 0.4284, 0.18144), Colour(0.393548, 0.271906, 0.166721), 25.6, 0.1, 0.0, 1.0 ); Material bronzeShiny(Colour(0.25, 0.148, 0.06475), Colour(0.4, 0.2368, 0.1036), Colour(0.774597, 0.458561, 0.200621), 76.86, 0.15, 0.0, 1.0 ); Material turquoise(Colour(0.1, 0.18725, 0.1745), Colour(0.396, 0.74151, 0.69102), Colour(0.297254, 0.30829, 0.306678), 12.8, 0.01, 0.2, 0.9); Material obsidian(Colour(0.05375, 0.05, 0.06625), Colour(0.18275, 0.17, 0.22525), Colour(0.332741, 0.328634, 0.346435), 38.4, 0.05, 0.18, 0.413); Material copper(Colour(0.19125, 0.0735, 0.0225), Colour(0.7038, 0.27048, 0.0828), Colour(0.256777, 0.137622, 0.086014), 12.8, 0.1, 0.0, 1.0 ); Material copperPolished(Colour(0.2295, 0.08825, 0.0275), Colour(0.5508, 0.2118, 0.066), Colour(0.580594, 0.223257, 0.0695701), 51.2, 0.15, 0.0, 1.0 ); Material pewter(Colour(0.105882, 0.058824, 0.113725), Colour(0.427451, 0.470588, 0.541176), Colour(0.333333, 0.333333, 0.521569), 9.84615, 0.0, 0.0, 1.0 ); // Light Sources //===================== //raytracer.addLightSource( new PointLight(Point3D(1, 1, 2),Colour(0.5, 0.5, 0.5)) ); #ifdef USE_EXTENDEDLIGHTS // Defines a ball light source raytracer.addLightSource( new BallLight(Point3D(-1, 1, 1), 2.0, Colour(0.9, 0.9, 0.9), 4) ); #else // Defines a point light source. raytracer.addLightSource( new PointLight(Point3D(0, 0, 5), Colour(0.9, 0.9,0.9) ) ); #endif if (sceneNum==0) { // Defines a point light source. //raytracer.addLightSource( new PointLight(Point3D(0, 0, 5), // Colour(0.9, 0.9, 0.9) ) ); // Add a unit square into the scene with material mat. SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &gold); SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade ); // Apply some transformations to the unit square. double factor1[3] = { 1.0, 2.0, 1.0 }; double factor2[3] = { 6.0, 6.0, 1.0 }; double factor3[3] = { 4.0, 4.0, 4.0 }; double factor4[3] = { 3.7, 3.7, 3.7 }; raytracer.translate(sphere, Vector3D(0, 0, -5)); raytracer.rotate(sphere, 'x', -45); raytracer.rotate(sphere, 'z', 45); raytracer.scale(sphere, Point3D(0, 0, 0), factor1); raytracer.translate(plane, Vector3D(0, 0, -7)); raytracer.rotate(plane, 'z', 45); raytracer.scale(plane, Point3D(0, 0, 0), factor2); /* SceneDagNode* bigSphere = raytracer.addObject( new UnitSphere(), &glass1); raytracer.scale(bigSphere, Point3D(0, 0, 0), factor3); raytracer.translate(bigSphere, Vector3D(0, 0, -7)); SceneDagNode* bigSphere2 = raytracer.addObject( new UnitSphere(), &glass1); raytracer.scale(bigSphere2, Point3D(0, 0, 0), factor4); raytracer.translate(bigSphere2, Vector3D(0, 0, -7)); */ }// end of scene 0 if (sceneNum==1) { /* raytracer.addLightSource( new BallLight(Point3D(-1, 1, 1), 5.0, Colour(0.9, 0.9, 0.9), 0.888) ); raytracer.addLightSource( new PointLight(Point3D(0, 0, 2),Colour(0.5, 0.5, 0.5)) ); */ // Add a unit square into the scene with material mat. SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &glass); SceneDagNode* sphere1 = raytracer.addObject( new UnitSphere(), &brass); SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade); SceneDagNode* cylinder = raytracer.addObject( new UnitCylinder(), &brass); // Apply some transformations to the unit square. double factor1[3] = { 1.0, 2.0, 1.0 }; double factor2[3] = { 6.0, 6.0, 1.0 }; double factor3[3] = { 0.5, 0.5, 2.0 }; raytracer.translate(sphere, Vector3D(0, 0, -5)); raytracer.rotate(sphere, 'x', -45); raytracer.rotate(sphere, 'z', 45); raytracer.scale(sphere, Point3D(0, 0, 0), factor1); raytracer.translate(sphere1, Vector3D(-2.5, 0, -5)); raytracer.translate(plane, Vector3D(0, 0, -7)); raytracer.rotate(plane, 'z', 45); raytracer.scale(plane, Point3D(0, 0, 0), factor2); raytracer.translate(cylinder, Vector3D(3, 0, -5)); //raytracer.rotate(cylinder, 'y', -20); raytracer.rotate(cylinder, 'z', 45); raytracer.rotate(cylinder, 'x', -75); raytracer.scale(cylinder, Point3D(0, 0, 0), factor3); }// end of scene1 //=============== Scene 2 ============================== //===================================================== if(sceneNum == 2) { /* raytracer.addLightSource( new BallLight(Point3D(-1, 1, 1), 5.0, Colour(0.9, 0.9, 0.9), 0.888) );*/ //raytracer.addLightSource( new PointLight(Point3D(0, 0, 2),Colour(0.5, 0.5, 0.5)) ); //Set up walls //======================================================== SceneDagNode* planeBack = raytracer.addObject( new UnitSquare(), &brass); SceneDagNode* planeBottom = raytracer.addObject( new UnitSquare(), &chrome); SceneDagNode* planeTop = raytracer.addObject( new UnitSquare(), &copperPolished); SceneDagNode* planeLeft = raytracer.addObject( new UnitSquare(), &bronzeShiny); SceneDagNode* planeRight = raytracer.addObject( new UnitSquare(), &brass); SceneDagNode* planeRear = raytracer.addObject( new UnitSquare(), &brass); double scaleFactor[3] = {8.0,8.0,1.0}; double scaleFactor1[3] = {20.01,20.01,1.0}; raytracer.translate(planeBottom, Vector3D(0, -10, 0)); raytracer.translate(planeTop, Vector3D(0, 10, 0)); raytracer.translate(planeLeft, Vector3D(-10, 0, 0)); raytracer.translate(planeRight, Vector3D(10, 0, 0)); raytracer.translate(planeBack, Vector3D(0, 0, -19.9)); raytracer.translate(planeBottom, Vector3D(0, 0, -10)); raytracer.translate(planeTop, Vector3D(0, 0, -10)); raytracer.translate(planeLeft, Vector3D(0, 0, -10)); raytracer.translate(planeRight, Vector3D(0, 0, -10)); raytracer.translate(planeRear, Vector3D(0, 0, 20)); raytracer.rotate(planeTop, 'x', 90); raytracer.rotate(planeBottom, 'x',-90); raytracer.rotate(planeLeft, 'y', -90); raytracer.rotate(planeRight, 'y', 90); raytracer.rotate(planeRear, 'x', 180); raytracer.scale(planeBack, Point3D(0, 0, 0), scaleFactor1); raytracer.scale(planeBottom, Point3D(0, 0, 0), scaleFactor1); raytracer.scale(planeTop, Point3D(0, 0, 0), scaleFactor1); raytracer.scale(planeLeft, Point3D(0, 0, 0), scaleFactor1); raytracer.scale(planeRight, Point3D(0, 0, 0), scaleFactor1); raytracer.scale(planeRear, Point3D(0, 0, 0), scaleFactor1); //=========================================================== double scaleEgg[3] = { 1.0, 1.5, 1.0 }; double scaleBall[3] = {2,2,2}; SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &glass1); SceneDagNode* sphere1 = raytracer.addObject( new UnitSphere(), &ruby); SceneDagNode* sphere2 = raytracer.addObject( new UnitSphere(), &chrome); //SceneDagNode* cone = raytracer.addObject(sphere, new UnitCone(), &emerald); //raytracer.translate(cone, Vector3D(0,0,-2)); raytracer.translate(sphere, Vector3D(-1,-1,-11)); raytracer.scale(sphere, Point3D(0,0,0), scaleBall); raytracer.translate(sphere1, Vector3D(2.5,-1,-11)); raytracer.translate(sphere2, Vector3D(2,3,-11)); //raytracer.translate(cone, Vector3D(-1,-1,-12)); raytracer.rotate(sphere1, 'z', -45); raytracer.scale(sphere1, Point3D(0,0,0), scaleEgg); //raytracer.rotate(cone, 'x', 90); }//end of scene 2 //==================== Scene 3 ================= //=============================================== if(sceneNum == 3) { #ifdef USE_EXTENDEDLIGHTS raytracer.addLightSource( new BallLight(Point3D(-5, 5, -3), 2.0, Colour(0.4, 0.4, 0.4), 2) ); raytracer.addLightSource( new BallLight(Point3D(5, 5, -3), 2.0, Colour(0.4, 0.4, 0.4), 2) ); #else raytracer.addLightSource( new PointLight(Point3D(-5, 5, 0), Colour(0.5, 0.0, 0.0) ) ); raytracer.addLightSource( new PointLight(Point3D(5, 5, 0), Colour(0.0, 0.5, 0.0) ) ); raytracer.addLightSource( new PointLight(Point3D(0, -5, 0), Colour(0.0, 0.0, 0.5) ) ); #endif double planeScale[3] = {10.0, 10.0, 1.0}; double sphereScale[3]= {1.5,1.5,1.5}; double coneScale[3] = {1.5,1.5,5}; SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &pearl); SceneDagNode* sphere1 = raytracer.addObject( new UnitSphere(), &chrome); SceneDagNode* sphere2 = raytracer.addObject( new UnitSphere(), &brass); //SceneDagNode* cone = raytracer.addObject( new UnitCone(), &turquoise); raytracer.translate(sphere1, Vector3D(1, 1.5, -6.5)); raytracer.translate(sphere2, Vector3D(-1, -1.5, -6.5)); raytracer.scale(sphere2, Point3D(0,0,0), sphereScale); raytracer.scale(sphere1, Point3D(0,0,0), sphereScale); raytracer.rotate(plane, 'z', 45); raytracer.scale(plane, Point3D(0,0,0), planeScale); raytracer.translate(plane, Vector3D(0, 0, -8)); /* raytracer.translate(cone, Vector3D(2.0,-1.0,-3)); raytracer.rotate(cone, 'x', 180); raytracer.scale(cone, Point3D(0,0,0), coneScale); */ } // Render the scene, feel free to make the image smaller for // testing purposes. raytracer.render(width, height, eye, view, up, fov, aa, "sig1.bmp", 's'); //raytracer.render(width, height, eye, view, up, fov, aa, "diffuse1.bmp",'d'); //raytracer.render(width, height, eye, view, up, fov, aa, "view1.bmp",'p'); // Render it from a different point of view. Point3D eye2(4, 2, 1); Vector3D view2(-4, -2, -6); raytracer.render(width, height, eye2, view2, up, fov, aa, "sig2.bmp", 's'); //raytracer.render(width, height, eye2, view2, up, fov, aa, "diffuse2.bmp",'d'); //raytracer.render(width, height, eye2, view2, up, fov, aa, "view2.bmp",'p'); Point3D eye3(-4, -2, 1); Vector3D view3(4, 2, -6); raytracer.render(width, height, eye3, view3, up, fov, aa, "sig3.bmp", 's'); //raytracer.render(width, height, eye3, view3, up, fov, aa, "diffuse3.bmp",'d'); raytracer.render(width, height, eye3, view3, up, fov, aa, "view3.bmp",'p'); return 0; }
int read_msg(char *src, char *Instr, char *Arg1, char *Arg2) { //printf("Received: FROM => %s\tCMD => %s,%s,%s\n",src,Instr,Arg1,Arg2); char instr[CONTENT_MAX]; char arg1[CONTENT_MAX]; char arg2[CONTENT_MAX]; strcpy(instr,Instr); strcpy(arg1,Arg1); strcpy(arg2,Arg2); if(echo(instr)) { message_host(src,"echo,NULL,NULL"); } /* Database will immediately notify its registered clients if local data * has been updated, only when the database is configured to PUSH updates * with the command line flag -p */ else if(incr(instr)) { if(PUSH_UPDATES) { // send invalidation msg to all known clients struct cache_entry *client; int index=0; /* Iterates over all saved clients */ for(index=0;index<clients_cache->length;index++) { client = get_index(index,clients_cache); printf("Pushing updates to client [%s]\n",client->value); char msg[CONTENT_MAX]; sprintf(msg,"%s,%s,%s",inv,arg1,arg2); message_host(client->value,msg); } } /* Routine for updating local data */ if(rome(arg1)) { if(gold(arg2)) { r.gold++; } if(silver(arg2)) { r.silver++; } if(bronze(arg2)) { r.bronze++; } if(tennis(arg2)) { score_tennis.rome_score++; } if(soccer(arg2)) { score_soccer.rome_score++; } if(frisbee(arg2)) { score_frisbee.rome_score++; } } if(gaul(arg1)) { if(gold(arg2)) { g.gold++; } if(silver(arg2)) { g.silver++; } if(bronze(arg2)) { g.bronze++; } if(tennis(arg2)) { score_tennis.gaul_score++; } if(soccer(arg2)) { score_soccer.gaul_score++; } if(frisbee(arg2)) { score_frisbee.gaul_score++; } } /* Display updates on the terminal screen */ printf("Update received -------------------------\n" "Gaul >> Gold %d, Silver %d, Bronze %d\n" "Rome >> Gold %d, Silver %d, Bronze %d\n" "--------------------------------------------\n" "Tennis: Gaul %d | Rome %d\n" "Frisbee: Gaul %d | Rome %d\n" "Soccer: Gaul %d | Rome %d\n", r.gold, r.silver, r.bronze, g.gold, g.silver, g.bronze, score_tennis.gaul_score, score_tennis.rome_score, score_frisbee.gaul_score, score_frisbee.rome_score, score_soccer.gaul_score, score_soccer.rome_score); } /* Service client query */ else if(query(instr)) { // when a front-end server queries for the first time, add it to the // cache of known hosts printf("Responding to query [%s:%s] from client [%s]\n", arg1,arg2,src); while(clients_cache==NULL); // wait for client cache to come online struct cache_entry *connected_client; unsigned int client_id; inet_pton(AF_INET,src,&client_id); connected_client = new_cache_entry(client_id,src); if(!found(client_id,clients_cache)) add_cache_entry(SORTED,connected_client,clients_cache); /* Build query response */ char response[100]; if(rome(arg1)) { if(gold(arg2)) { sprintf(response,"rome,gold,%d",r.gold); } if(silver(arg2)) { sprintf(response,"rome,silver,%d",r.silver); } if(bronze(arg2)) { sprintf(response,"rome,bronze,%d",r.bronze); } if(tennis(arg2)) { sprintf(response,"rome,tennis,%d",score_tennis.rome_score); } if(soccer(arg2)) { sprintf(response,"rome,soccer,%d",score_soccer.rome_score); } if(frisbee(arg2)) { sprintf(response,"rome,frisbee,%d",score_frisbee.rome_score); } } if(gaul(arg1)) { if(gold(arg2)) { sprintf(response,"gaul,gold,%d",r.gold); } if(silver(arg2)) { sprintf(response,"gaul,silver,%d",r.silver); } if(bronze(arg2)) { sprintf(response,"gaul,bronze,%d",r.bronze); } if(tennis(arg2)) { sprintf(response,"gaul,tennis,%d",score_tennis.gaul_score); } if(soccer(arg2)) { sprintf(response,"gaul,soccer,%d",score_soccer.gaul_score); } if(frisbee(arg2)) { sprintf(response,"gaul,frisbee,%d",score_soccer.gaul_score); } } printf("Responding to %s\n",src); message_host(src,response); } return 0; }