示例#1
0
void PlayerInst::purchase_from_store(GameState* gs, const GameAction& action) {
	StoreInst* store = (StoreInst*)gs->get_instance(action.use_id);
	if (!store) {
		return;
	}
	LANARTS_ASSERT(dynamic_cast<StoreInst*>(gs->get_instance(action.use_id)));
	StoreInventory& inv = store->inventory();
	StoreItemSlot& slot = inv.get(action.use_id2);
	if (gold() >= slot.cost) {
		inventory().add(slot.item);
		gold() -= slot.cost;
		slot.item.clear();
	}
}
示例#2
0
void PlayerInst::pickup_item(GameState* gs, const GameAction& action) {
	const int PICKUP_RATE = 10;
	GameInst* inst = gs->get_instance(action.use_id);
	if (!inst) {
		return;
	}
	ItemInst* iteminst = dynamic_cast<ItemInst*>(inst);
	LANARTS_ASSERT(iteminst);

	const Item& type = iteminst->item_type();
	int amnt = iteminst->item_quantity();

	bool inventory_full = false;
	if (type.id == get_item_by_name("Gold")) {
		gold() += amnt;
	} else {
		itemslot_t slot = inventory().add(type);
		if (slot == -1) {
			inventory_full = true;
		} else if (projectile_should_autowield(equipment(), type,
				this->last_chosen_weaponclass)) {
			projectile_smart_equip(inventory(), slot);
		}
	}

	if (!inventory_full) {
		cooldowns().reset_pickup_cooldown(PICKUP_RATE);
		gs->remove_instance(iteminst);
	}
}
示例#3
0
	void build_team_stage_one()
	{
		//initialize the context variables and flags, find relevant tags, set up everything
		init();

		//find out the correct qty of gold and handle gold carryover.
		gold();

		//create a new instance of team and push it to back of resources::teams vector
		new_team();

		assert(t_!=NULL);

		//set team objectives if necessary
		objectives();

		// If the game state specifies additional units that can be recruited by the player, add them.
		previous_recruits();

		//place leader
		leader();

		//prepare units, populate obvious recall lists elements
		prepare_units();

	}
示例#4
0
文件: metal.cpp 项目: aroraujjwal/qt3
/*!
  Reimplementation from QStyle
 */
void MetalStyle::polish( QApplication *app)
{
    oldPalette = app->palette();

    // we simply create a nice QColorGroup with a couple of fancy
    // pixmaps here and apply to it all widgets

    QFont f("times", app->font().pointSize() );
    f.setBold( TRUE );
    f.setItalic( TRUE );
    app->setFont( f, TRUE, "QMenuBar");
    app->setFont( f, TRUE, "QPopupMenu");



    //    QPixmap button( stonedark_xpm );

    QColor gold("#B9B9A5A54040"); //same as topgrad below
    QPixmap button( 1, 1 ); button.fill( gold );

    QPixmap background(marble_xpm);
    QPixmap dark( 1, 1 ); dark.fill( red.dark() );
    QPixmap mid( stone1_xpm );
    QPixmap light( stone1_xpm );//1, 1 ); light.fill( green );

    QPalette op = app->palette();

    QColor backCol( 227,227,227 );

    // QPalette op(white);
    QColorGroup active (op.active().foreground(),
		     QBrush(op.active().button(),button),
		     QBrush(op.active().light(), light),
		     QBrush(op.active().dark(), dark),
		     QBrush(op.active().mid(), mid),
		     op.active().text(),
		     Qt::white,
		     op.active().base(),//		     QColor(236,182,120),
		     QBrush(backCol, background)
		     );
    active.setColor( QColorGroup::ButtonText,  Qt::white  );
    active.setColor( QColorGroup::Shadow,  Qt::black  );
    QColorGroup disabled (op.disabled().foreground(),
		     QBrush(op.disabled().button(),button),
		     QBrush(op.disabled().light(), light),
		     op.disabled().dark(),
		     QBrush(op.disabled().mid(), mid),
		     op.disabled().text(),
		     Qt::white,
		     op.disabled().base(),//		     QColor(236,182,120),
		     QBrush(backCol, background)
		     );

    QPalette newPalette( active, disabled, active );
    app->setPalette( newPalette, TRUE );
}
示例#5
0
int main(int argc, char*argv[])
{
    int max = MAX;
    int min = MIN;
    int size = (max-min)/2;
    int * array = (int*) malloc(sizeof(int)*size);
    int i;
    struct timespec start, end,elapsed;
    int c = 0;
    int num_threads = 1;
    int modifier = 0;
    omp_sched_t schedule = 1;
    while((c = getopt(argc,argv,"n:s:m:h")) != -1)
    {
        switch(c)
        {
            case 'n':
                num_threads = atoi(optarg);
                break;
	    case 's':
		schedule = atoi(optarg);
		break;
	    case 'm':
		modifier = atoi(optarg);
		break;
	    case 'h':
		usage();
		exit(0);
            default:
                break;
        }
    }
    omp_set_num_threads(num_threads);
    omp_set_schedule(schedule,modifier);
    clock_gettime(CLOCK_REALTIME, &start);
    for(i = 1; i < size; i++)
	array[i] = 0;
#pragma omp parallel for
    for(i = 1; i < size; i++)
	array[i] = gold(2*i);
#pragma omp parallel for
    for(i = 1; i < size; i++)
	if(array[i] == 0)
	    fprintf(stdout,"Violated at %d\n",2*i);
    clock_gettime(CLOCK_REALTIME, &end);
    elapsed.tv_sec = end.tv_sec - start.tv_sec;
    elapsed.tv_nsec = end.tv_nsec - start.tv_nsec;
    if(elapsed.tv_nsec < 0)
    {
	elapsed.tv_sec -= 1;
	elapsed.tv_nsec += 1000000000;
    }
    printf("%ld.%ld\n",elapsed.tv_sec,elapsed.tv_nsec);
    return 0;
}
TEST(ButtonProtocolTest, CheckRuns) {
  
  ButtonLed blue(1,  LOW);
  ButtonLed gold(2,  LOW);
  
  ButtonLed pin1(10, LOW);
  ButtonLed pin2(11, LOW);
  ButtonLed pin3(12, LOW);
  
  ButtonLed* buttons[] = {&pin1,&pin1,&pin2,&pin2,&pin3,&pin3};
  
  ButtonProtocol bp(buttons, (uint8_t)6, &blue, &gold);
  
  bp.check();
}
示例#7
0
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));
}
TEST(ButtonProtocolTest, HandleOtherFrame) {
  
  OpenLcbCanBuffer b;
  
  ButtonLed blue(1,  LOW);
  ButtonLed gold(2,  LOW);
  
  ButtonLed pin1(10, LOW);
  ButtonLed pin2(11, LOW);
  ButtonLed pin3(12, LOW);
  
  ButtonLed* buttons[] = {&pin1,&pin1,&pin2,&pin2,&pin3,&pin3};
  
  ButtonProtocol bp(buttons, (uint8_t)6, &blue, &gold);
  
  EXPECT_FALSE(bp.receivedFrame(&b));
}
TEST(ButtonProtocolTest, Ctor) {
  // This test is named "Ctor", and belongs to the "ButtonProtocolTest"
  // test case.
  
  //OpenLcbCanBuffer b;
  
  ButtonLed blue(1,  LOW);
  ButtonLed gold(2,  LOW);
  
  ButtonLed pin1(10, LOW);
  ButtonLed pin2(11, LOW);
  ButtonLed pin3(12, LOW);
  
  ButtonLed* buttons[] = {&pin1,&pin1,&pin2,&pin2,&pin3,&pin3};
  
  ButtonProtocol bp(buttons, (uint8_t)6, &blue, &gold);
  
}
TEST(ButtonProtocolTest, HandleButtonProtocolRequestFrame) {
  
  OpenLcbCanBuffer b;
  b.setOpenLcbMTI(0x948);
  
  ButtonLed blue(1,  LOW);
  ButtonLed gold(2,  LOW);
  
  ButtonLed pin1(10, LOW);
  ButtonLed pin2(11, LOW);
  ButtonLed pin3(12, LOW);
  
  ButtonLed* buttons[] = {&pin1,&pin1,&pin2,&pin2,&pin3,&pin3};
  
  ButtonProtocol bp(buttons, (uint8_t)6, &blue, &gold);
  
  EXPECT_TRUE(bp.receivedFrame(&b));
}
示例#11
0
	bool GatherState::canGather()
	{
		int canMine = 0;

		if (_amount > 0)
		{
			Item gold("gold", true);

			if (_target->getInventory().contains(gold))
			{
				canMine++;
			}

			Item iron("iron", true);

			if (_target->getInventory().contains(iron))
			{
				canMine++;
			}

			Item coal("coal", true);

			if (_target->getInventory().contains(coal))
			{
				canMine++;
			}

			Item wood("wood", true);

			if (_target->getInventory().contains(wood))
			{
				canMine++;
			}

			Item fish("fish", true);

			if (_target->getInventory().contains(fish))
			{
				canMine++;
			}
		}

		return !!canMine;
	}
示例#12
0
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;
}
示例#13
0
void turn_state::scoring_state(){
	DBG_AI_TESTING_SF_WITH_RCA << "\t\t------turn_state::scoring_state() begin------" << std::endl;
	// A very simple scoring function.

	state_score_ = 0.0;

	const gamemap &map = resources::gameboard->map();

	const int total_team = teams_.size();
	std::vector<double> state(total_team, 0.0);
	std::vector<int> total_level(total_team, 0);

	// Sum up the units' score, with simple HP, EXP and terrain weight.
	for(unit_map::const_unit_iterator ui = units_.begin(); ui != units_.end(); ++ui) {
		int current_side = ui->side() - 1;

		double c = static_cast<double>(ui->cost());
		double h = static_cast<double>(ui->hitpoints());
		double mh = static_cast<double>(ui->max_hitpoints());
		double e = static_cast<double>(ui->experience());
		double me = static_cast<double>(ui->max_experience());
		double def = static_cast<double>(ui->defense_modifier(map.get_terrain(ui->get_location()))/100.0);
		double unit_score = c * (h*h)/(mh*mh) * (1+(e*e)/(me*me)) * def;
		LOG_AI_TESTING_SF_WITH_RCA << "\t\t\tside " << current_side+1 << " unit " << ui->type_name() << "'s score is " << unit_score << std::endl;
		state[current_side] += unit_score;
		total_level[current_side] += ui->level();
	}


	const int total_turns = 3; // Calculate 3 turns ahead.
	std::vector<int> upkeep_per_turn(total_team, 0);
	std::vector<int> income_per_turn(total_team, 0);
	std::vector<double> gold(total_team, 0.0);

	// Add the gold that current have and that intend to
	// get as income in future totally(subtract the upkeep),
	// for each team.
	for(std::vector<team>::const_iterator ti = teams_.begin(); ti != teams_.end(); ++ti) {
		int current_side = ti->side() - 1;
		upkeep_per_turn[current_side] = total_level[current_side]>ti->support() ? total_level[current_side]-ti->support() : 0;
		income_per_turn[current_side] = ti->total_income() - upkeep_per_turn[current_side];

		// The further, the rougher. So drop 0.3 weight for each turn.
		double cg = static_cast<double>(ti->gold());
		double i = static_cast<double>(income_per_turn[current_side]);
		double weight = (1.0+(1.0-0.3*(total_turns-1.0)))*total_turns/2.0;
		gold[current_side] = cg + i * weight;
		state[current_side] += gold[current_side];

		LOG_AI_TESTING_SF_WITH_RCA << "\t\t\tside " << current_side+1 << " will totally get " << gold[current_side] << " gold." << std::endl;
	}


	for(std::vector<team>::const_iterator ti = teams_.begin(); ti != teams_.end(); ++ti) {
		int current_side = ti->side() - 1;
		LOG_AI_TESTING_SF_WITH_RCA << "\t\t\tside " << current_side+1 << "'s state: " << state[current_side] << std::endl;
		if(ti->is_enemy(own_side_)){ // 'is_enemy()' based on 1.
			state_score_ -= state[current_side];
		} else {
			state_score_ += state[current_side];
		}
	}

	LOG_AI_TESTING_SF_WITH_RCA << "\t\tState constructed with score " << state_score_ << std::endl;
	DBG_AI_TESTING_SF_WITH_RCA << "\t\t------turn_state::scoring_state() end------" << std::endl;
}
示例#14
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;
}
示例#15
0
/**
 * Wooden Monkey Scene 1
 */
void refraction_scene_1()
{
    printf("REFRACTION SCENE : 1 ----------------------------------\n\n");
    Raytracer rt;
    int width = 16 * 20 * 2;
    int height = 12 * 20 * 2;

    // Camera parameters.
    Point3D eye1(0, 0, 1), eye2(4, 2, 1);
    Vector3D view1(0, 0, -1), view2(-4, -2, -6);
    Vector3D up(0, 1, 0);
    double fov = 60;

    // Defines a material 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, LARGE_SPH_REFLECT, LARGE_SPH_REFRAC_INDX, LARGE_SPH_REFRACT);
    Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63),
                   Colour(0.316228, 0.316228, 0.316228),
                   12.8);
    // Defines a material for shading.
    Material gold_nonRefract( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648),
                              Colour(0.628281, 0.555802, 0.366065),
                              51.2, 0.8 );

    // Defines a point light source.
    double l0c = 0.5;
    PointLight * light0 = new PointLight(
        Point3D(-2, 2, 5),
        Colour(l0c, l0c, l0c),
        0.2);
    rt.addLightSource(light0);

    // Add a unit square into the scene with material mat.
    SceneDagNode* sphere = rt.addObject( new UnitSphere(), &gold );
    SceneDagNode* sphere2 = rt.addObject( new UnitSphere(), &gold_nonRefract );
    SceneDagNode* plane = rt.addObject( new UnitSquare(), &jade );
    SceneDagNode* sphere3 = rt.addObject( new UnitSphere(), &RED);
    SceneDagNode* sphere4 = rt.addObject( new UnitSphere(), &GREEN_TRANSP);
    SceneDagNode* plane2 = rt.addObject( new UnitSquare(), &jade );
//    SceneDagNode* plane3 = rt.addObject( new UnitSquare(), &jade );
//    SceneDagNode* plane4 = rt.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, 6.0 };
    rt.translate(sphere, Vector3D(0, 0, -5));
    rt.rotate(sphere, 'x', -45);
    rt.rotate(sphere, 'z', 45);
    rt.scale(sphere, Point3D(0, 0, 0), factor1);

    rt.translate(plane, Vector3D(0, 0, -7));
    rt.rotate(plane, 'z', 45);
    rt.scale(plane, Point3D(0, 0, 0), factor2);

    double f[3] = { 0.5, 0.5, 0.5 };
    rt.translate(sphere2, Vector3D(3, 0, -5));
    rt.scale(sphere2, Point3D(0, 0, 0), f);

    rt.translate(sphere3, Vector3D(0, 2, -5));
    rt.scale(sphere3, Point3D(0, 0, 0), f);

    double f2[3] = { 0.6, 0.6, 0.6 };
    rt.translate(sphere4, Vector3D(-2, 1, -3));
    rt.scale(sphere4, Point3D(0, 0, 0), f2);

    double fp2[3] = { 3.0, 3.0, 3.0 };
    rt.translate(plane2,Vector3D(-4,1,-5));
    rt.rotate(plane2, 'z', 45);
    rt.rotate(plane2, 'y', 45);
    rt.scale(plane2, Point3D(0, 0, 0), fp2);

//    rt.translate(plane3,Vector3D(-2,0,-5));
//    rt.rotate(plane2, 'z', 45);
//    rt.rotate(plane3, 'x', 90);
//	rt.scale(plane3, Point3D(0, 0, 0), fp2);
//
//    rt.translate(plane4,Vector3D(-2,1,-5));
//    rt.rotate(plane2, 'z', 45);
//    rt.rotate(plane4, 'y', 90);
//	rt.scale(plane4, Point3D(0, 0, 0), fp2);

    rt.setAAMode(Raytracer::AA_SUPER_SAMPLING);
    rt.setShadingMode(Raytracer::SCENE_MODE_PHONG);
    rt.setShadows(Raytracer::SHADOW_CAST);
    rt.setEnvMapMode(Raytracer::ENV_MAP_CUBE_SKYBOX);
    rt.setColorSpaceMode(Raytracer::COLOR_ENC_SRGB_GAMMA_CORRECT);
    rt.setReflDepth(4);

    //set the texture map for the objects of interest in the scene if texture map flag is ON
    if (TEXTURE_MAP_FLAG) {
        // load texture image
        TextureMap txtmp;
        txtmp = TextureMap(TEXTURE_IMG);
        TextureMap txtmp2 = TextureMap(TEXTURE_IMG2);
        TextureMap txtmp3 = TextureMap(TEXTURE_IMG3);

        //for now, we are only using texture map for sphere
        sphere->useTextureMapping = true;
        sphere->obj->setTextureMap(txtmp);

        sphere2->useTextureMapping = false;

        sphere4->useTextureMapping = true;
        sphere4->setTextMapOfObject(txtmp2);

        plane2->useTextureMapping = true;
        plane2->setTextMapOfObject(txtmp3);

//        plane3->useTextureMapping = true;
//        plane3->setTextMapOfObject(txtmp3);
//
//        plane4->useTextureMapping = true;
//        plane4->setTextMapOfObject(txtmp3);
    }
    // refraction if it's turned on
    if (REFRACTION_FLAG) {
        rt.setRefractionMode(REFRACTION_FLAG);
    }

    if ( rt.getEnvMapMode() != Raytracer::NONE ) {
        // load images
        EnvMap env;
        if ( _DEBUG ) {
            env = EnvMap(
                      "EnvMaps/DebugMaps/posx.bmp",
                      "EnvMaps/DebugMaps/posy.bmp",
                      "EnvMaps/DebugMaps/posz.bmp",
                      "EnvMaps/DebugMaps/negx.bmp",
                      "EnvMaps/DebugMaps/negy.bmp",
                      "EnvMaps/DebugMaps/negz.bmp"
                  );
        } else {
            env = EnvMap(
                      "EnvMaps/SaintLazarusChurch/posx.bmp",
                      "EnvMaps/SaintLazarusChurch/posy.bmp",
                      "EnvMaps/SaintLazarusChurch/posz.bmp",
                      "EnvMaps/SaintLazarusChurch/negx.bmp",
                      "EnvMaps/SaintLazarusChurch/negy.bmp",
                      "EnvMaps/SaintLazarusChurch/negz.bmp"
                  );
        }

        rt.setEnvMap(env);
    }

    printf("REFRACTION SCENE : 1 :: Rendering...\n");
    rt.render(width, height, eye2, view2, up, fov, "refraction_2.bmp");
    Point3D eye3(0, 0, 1);
    Vector3D view3(0, 0, -1);
    printf("REFRACTION SCENE : 2 :: Rendering...\n");
    rt.render(width, height, eye3, view3, up, fov, "refraction_1.bmp");

    printf("REFRACTION SCENE : 1 :: Done!\n");
}
示例#16
0
/**
 * Wooden Monkey Scene 1
 */
void wmonkey_scene_1()
{
    printf("WOODEN MONKEY SCENE : 1 ----------------------------------\n\n");
    Raytracer rt;
    int width = 16 * 20 * 2;
    int height = 12 * 20 * 2;

    // Camera parameters.
    Point3D eye1(0, 0, 1), eye2(4, 2, 1);
    Vector3D view1(0, 0, -1), view2(-4, -2, -6);
    Vector3D up(0, 1, 0);
    double fov = 60;

    // Defines a material 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.8 );
    Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63),
                   Colour(0.316228, 0.316228, 0.316228),
                   12.8);

    // Defines a point light source.
    double l0c = 0.5;
    PointLight * light0 = new PointLight(
        Point3D(-2, 2, 5),
        Colour(l0c, l0c, l0c),
        0.2);
    rt.addLightSource(light0);

    // Add a unit square into the scene with material mat.
    SceneDagNode* sphere = rt.addObject( new UnitSphere(), &gold );
    SceneDagNode* sphere2 = rt.addObject( new UnitSphere(), &gold );
    SceneDagNode* plane = rt.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, 6.0 };
    rt.translate(sphere, Vector3D(0, 0, -5));
    rt.rotate(sphere, 'x', -45);
    rt.rotate(sphere, 'z', 45);
    rt.scale(sphere, Point3D(0, 0, 0), factor1);

    rt.translate(plane, Vector3D(0, 0, -7));
    rt.rotate(plane, 'z', 45);
    rt.scale(plane, Point3D(0, 0, 0), factor2);

    double f[3] = { 0.5, 0.5, 0.5 };
    rt.translate(sphere2, Vector3D(3, 0, -5));
    rt.scale(sphere2, Point3D(0, 0, 0), f);

    rt.setAAMode(Raytracer::AA_SUPER_SAMPLING);
    rt.setShadingMode(Raytracer::SCENE_MODE_PHONG);
    rt.setShadows(Raytracer::SHADOW_CAST);
    rt.setEnvMapMode(Raytracer::ENV_MAP_CUBE_SKYBOX);
    rt.setColorSpaceMode(Raytracer::COLOR_ENC_SRGB_GAMMA_CORRECT);
    rt.setReflDepth(4);

    if ( rt.getEnvMapMode() != Raytracer::NONE ) {
        // load images
        EnvMap env;
        if ( _DEBUG ) {
            env = EnvMap(
                      "EnvMaps/DebugMaps/posx.bmp",
                      "EnvMaps/DebugMaps/posy.bmp",
                      "EnvMaps/DebugMaps/posz.bmp",
                      "EnvMaps/DebugMaps/negx.bmp",
                      "EnvMaps/DebugMaps/negy.bmp",
                      "EnvMaps/DebugMaps/negz.bmp"
                  );
        } else {
            env = EnvMap(
                      "EnvMaps/SaintLazarusChurch/posx.bmp",
                      "EnvMaps/SaintLazarusChurch/posy.bmp",
                      "EnvMaps/SaintLazarusChurch/posz.bmp",
                      "EnvMaps/SaintLazarusChurch/negx.bmp",
                      "EnvMaps/SaintLazarusChurch/negy.bmp",
                      "EnvMaps/SaintLazarusChurch/negz.bmp"
                  );
        }

        rt.setEnvMap(env);
    }

    printf("WOODEN MONKEY SCENE : 1 :: Rendering...\n");
    rt.render(width, height, eye2, view2, up, fov, "wmonkey_1.bmp");
    printf("WOODEN MONKEY SCENE : 1 :: Done!\n");
}
示例#17
0
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;

	//_render_mode = MODE_SIGNATURE;
	//_render_mode = MODE_SPECULAR;
	_render_mode = MODE_FULL_PHONG;
	//_render_mode = (mode)(MODE_AMBIENT | MODE_DIFFUSE);
	int width = 320; 
	int height = 240; 

	if (argc == 3) {
		width = atoi(argv[1]);
		height = atoi(argv[2]);
	}

	// Camera parameters.
	Point3D eye(0, 0, 1);
	Vector3D view(0, 0, -1);
	Vector3D up(0, 1, 0);
	double fov = 60;

	// Defines a material 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 );
	Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63), 
			Colour(0.316228, 0.316228, 0.316228), 
			12.8 );

	// 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, 6.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(plane, Vector3D(0, 0, -7));	
	raytracer.rotate(plane, 'z', 45); 
	raytracer.scale(plane, Point3D(0, 0, 0), factor2);

	// Render the scene, feel free to make the image smaller for
	// testing purposes.	
	raytracer.render(width, height, eye, view, up, fov, "phong1.bmp");
	
	// 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, "phong2.bmp");
	
	return 0;
}
示例#18
0
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 = 16 * 20 * 2;
    int height = 12 * 20 * 2;

    if (argc == 3) {
        width = atoi(argv[1]);
        height = atoi(argv[2]);
    }

    // Camera parameters.
    Point3D eye1(0, 0, 1), eye2(4, 2, 1);
    Vector3D view1(0, 0, -1), view2(-4, -2, -6);
//	Point3D eye1(0, 0, 1), eye2(4, 2, -6);
//	Vector3D view1(0, 0, -1), view2(-4, -2, 1);
    Vector3D up(0, 1, 0);
    double fov = 60;

    // Defines a material 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, LARGE_SPH_REFLECT, LARGE_SPH_REFRAC_INDX, LARGE_SPH_REFRACT);
    Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63),
                   Colour(0.316228, 0.316228, 0.316228),
                   12.8);

    Material red( Colour(0, 0, 0), Colour(0.9, 0.05, 0.05),
                  Colour(0.4, 0.2, 0.2),
                  12.8);

    // Defines a point light source.
    Point3D light_pos;
    if (LIGHT_DEFAULT) {
        light_pos = Point3D(0, 0, 5);
    } else {
        light_pos = LIGHT_POS_TEST;
    }

    PointLight * light0 = new PointLight(
        light_pos,
        Colour(0.9, 0.9, 0.9),
        0.1);
    raytracer.addLightSource(light0);

    // Add a unit square into the scene with material mat.
    SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &gold );
    SceneDagNode* sphere2 = raytracer.addObject( new UnitSphere(), &gold );
    SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade );

    //set the texture map for the objects of interest in the scene if texture map flag is ON
    if (TEXTURE_MAP_FLAG) {
        // load texture image
        TextureMap txtmp;
        txtmp = TextureMap(TEXTURE_IMG);
        raytracer.setTextureMap(txtmp);

        //for now, we are only using texture map for sphere
        sphere->useTextureMapping = true;
        sphere->obj->setTextureMap(txtmp);
    }


    // Apply some transformations to the unit square.
    double factor1[3] = { 1.0, 2.0, 1.0 };
    double factor2[3] = { 6.0, 6.0, 6.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(plane, Vector3D(0, 0, -7));
    raytracer.rotate(plane, 'z', 45);
    raytracer.scale(plane, Point3D(0, 0, 0), factor2);

    double f[3] = { 0.5, 0.5, 0.5 };
    raytracer.translate(sphere2, Vector3D(0, 0, -8));
    raytracer.scale(sphere2, Point3D(0, 0, 0), f);


    bool DO_SIGNATURE 				= false;
    bool DO_SIGNATURE_SS 			= false;
    bool DO_DIFFUSE 				= false;
    bool DO_PHONG 					= false;
    bool DO_PHONG_SS 				= false;
    bool DO_FULL_FEATURED 			= false;
    bool DO_WOODEN_MONKEY_SCENES 	= true;
    bool DO_REFRACTION_SCENE 		= false;

    bool RENDER_FIRST_VIEW = true;
    bool RENDER_SECOND_VIEW = true;


    raytracer.setReflDepth(0);
    raytracer.setEnvMapMode(Raytracer::NONE);

    // render signature
    if ( DO_SIGNATURE ) {
        raytracer.setAAMode(Raytracer::NONE);
        raytracer.setShadingMode(Raytracer::SCENE_MODE_SIGNATURE);

        if ( RENDER_FIRST_VIEW )
            raytracer.render(width, height, eye1, view1, up, fov, "sig1.bmp");
        if ( RENDER_SECOND_VIEW )
            raytracer.render(width, height, eye2, view2, up, fov, "sig2.bmp");
    }

    // render signature with SS AA
    if ( DO_SIGNATURE_SS ) {
        raytracer.setAAMode(Raytracer::AA_SUPER_SAMPLING);
        raytracer.setShadingMode(Raytracer::SCENE_MODE_SIGNATURE);

        if ( RENDER_FIRST_VIEW )
            raytracer.render(width, height, eye1, view1, up, fov, "sigSS1.bmp");
        if ( RENDER_SECOND_VIEW )
            raytracer.render(width, height, eye2, view2, up, fov, "sigSS2.bmp");
    }

    // render diffuse
    if ( DO_DIFFUSE ) {
        raytracer.setAAMode(Raytracer::NONE);
        raytracer.setShadingMode(Raytracer::SCENE_MODE_DIFFUSE);

        if ( RENDER_FIRST_VIEW )
            raytracer.render(width, height, eye1, view1, up, fov, "diffuse1.bmp");
        if ( RENDER_SECOND_VIEW )
            raytracer.render(width, height, eye2, view2, up, fov, "diffuse2.bmp");
    }

    // render phong
    if ( DO_PHONG ) {
        raytracer.setAAMode(Raytracer::NONE);
        raytracer.setShadingMode(Raytracer::SCENE_MODE_PHONG);

        if ( RENDER_FIRST_VIEW )
            raytracer.render(width, height, eye1, view1, up, fov, "phong1.bmp");
        if ( RENDER_SECOND_VIEW )
            raytracer.render(width, height, eye2, view2, up, fov, "phong2.bmp");
    }

    // phong with super sampling AA
    if ( DO_PHONG_SS ) {
        raytracer.setAAMode(Raytracer::AA_SUPER_SAMPLING);
        raytracer.setShadingMode(Raytracer::SCENE_MODE_PHONG);

        if ( RENDER_FIRST_VIEW )
            raytracer.render(width, height, eye1, view1, up, fov, "phongSS1.bmp");
        if ( RENDER_SECOND_VIEW )
            raytracer.render(width, height, eye2, view2, up, fov, "phongSS2.bmp");
    }

    // refraction if it's turned on
    if (REFRACTION_FLAG) {
        raytracer.setRefractionMode(REFRACTION_FLAG);
    }

    // all features enabled or turned to max
    if ( DO_FULL_FEATURED ) {
        raytracer.setAAMode(Raytracer::NONE);
        raytracer.setAAMode(Raytracer::AA_SUPER_SAMPLING);
        raytracer.setShadingMode(Raytracer::SCENE_MODE_PHONG);
        raytracer.setShadows(Raytracer::SHADOW_CAST);
//		raytracer.setShadows(Raytracer::NONE);
        raytracer.setEnvMapMode(Raytracer::ENV_MAP_CUBE_SKYBOX);
//		raytracer.setEnvMapMode(Raytracer::NONE);
        raytracer.setReflDepth(4);

        if ( raytracer.getEnvMapMode() != Raytracer::NONE ) {
            // load images

            EnvMap env;
            if ( _DEBUG ) {
                env = EnvMap(
                          "EnvMaps/DebugMaps/posx.bmp",
                          "EnvMaps/DebugMaps/posy.bmp",
                          "EnvMaps/DebugMaps/posz.bmp",
                          "EnvMaps/DebugMaps/negx.bmp",
                          "EnvMaps/DebugMaps/negy.bmp",
                          "EnvMaps/DebugMaps/negz.bmp"
                      );
            } else {
                env = EnvMap(
                          "EnvMaps/SaintLazarusChurch/posx.bmp",
                          "EnvMaps/SaintLazarusChurch/posy.bmp",
                          "EnvMaps/SaintLazarusChurch/posz.bmp",
                          "EnvMaps/SaintLazarusChurch/negx.bmp",
                          "EnvMaps/SaintLazarusChurch/negy.bmp",
                          "EnvMaps/SaintLazarusChurch/negz.bmp"
                      );
            }

            raytracer.setEnvMap(env);
        }

        // adjust lighting?
        if ( raytracer.getReflDepth() > 0 ) {
            double l0i = 0.5;
            light0->setAmbient(Colour(l0i, l0i, l0i));
        }

        if ( RENDER_FIRST_VIEW )
            raytracer.render(width, height, eye1, view1, up, fov, "all1.bmp");
        if ( RENDER_SECOND_VIEW )
            raytracer.render(width, height, eye2, view2, up, fov, "all2.bmp");
    }

    // different scenes just for the wooden monkey thing
    if ( DO_WOODEN_MONKEY_SCENES ) {
//		wmonkey_scene_1();
        wmonkey_scene_2();
        // TODO add more scenes here as required...
    }

    //render the 2nd refraction scene
    if ( REFRACTION_FLAG && DO_REFRACTION_SCENE ) {
        refraction_scene_1();
    }

    printf("Press enter to terminate...\n");
    std::string s;
    std::getline(std::cin, s);

    return 0;
}
示例#19
0
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; 

	if (argc == 3) {
		width = atoi(argv[1]);
		height = atoi(argv[2]);
	}
    
/***********************************************************Testing ********************************
    // Camera parameters.
    Point3D eye(0, 0, 1);
    Vector3D view(0, 0, -1);
    Vector3D up(0, 1, 0);
    double fov = 60;
    
    // Defines a material 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.3,0,NULL );
    Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63),
                  Colour(0.316228, 0.316228, 0.316228),
                  12.8,0.3,0,NULL);
    
    // Defines a point light source.
    raytracer.addLightSource( new PointLight(Point3D(0.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, 6.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(plane, Vector3D(0, 0, -7));
    raytracer.rotate(plane, 'z', 45);
    raytracer.scale(plane, Point3D(0, 0, 0), factor2);
    
    
    // Render the scene, feel free to make the image smaller for
    // testing purposes.
    raytracer.render(width, height, eye, view, up, fov, "view4.bmp");
    
    // 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, "view5.bmp");
***********************************************************Testing ********************************/
/***********************************************************Final Scene********************************/
    // Camera parameters.
//	Point3D eye(0, 8, -3);
//	Vector3D view(0, -1,0);
    Point3D eye(0, 0, 1);
    Vector3D view(0, 0, -1);
    
	Vector3D up(0, 1, 0);
	double fov = 60;

	// Defines a material 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.2,NULL);
//	Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63), 
//			Colour(0.316228, 0.316228, 0.316228), 
//			12.8,0.5,NULL);
    Material jade( Colour(0, 0, 0), Colour(0.47, 0.576, 0.859),
                  Colour(0.316228, 0.316228, 0.316228),
                  12.8,0.5,NULL);
    Material red( Colour(0.3, 0.3, 0.3), Colour(1, 0, 0),
                 Colour(0.628281, 0.555802, 0.366065),
                 51.2,0.2,NULL);
    
    Material white( Colour(0.3, 0.3, 0.3), Colour(1, 0.8549, 0.7255),
                 Colour(0.628281, 0.555802, 0.366065),
                 51.2,0.2,NULL);
    Material pink( Colour(0.3, 0.3, 0.3), Colour(0.9412, 0.502, 0.502),
                   Colour(0.628281, 0.555802, 0.366065),
                   51.2,0.2,NULL);
    
    Material mirror( Colour(0.0, 0.0, 0.0), Colour(0.0, 0.0, 0.0),
                 Colour(0.0, 0.0, 0.0),
                 51.2,1,NULL);
    
    Material glass( Colour(0.3, 0.3, 0.3), Colour(1, 1, 1),
                    Colour(0.628281, 0.555802, 0.366065),
                    51.2,0,1,NULL);
    glass.R_index = 1.3;
    glass.transparency_coef=1;
	// Defines a point light source.
	raytracer.addLightSource( new PointLight(Point3D(0, 0, 5),
				Colour(0.9, 0.9, 0.9) ) );

    raytracer.addLightSource( new PointLight(Point3D(0, 6, -1),
                                             Colour(0.9, 0.3, 0.1) ) );
    
    Material test( Colour(0.3, 0.3, 0.3), Colour(0.3, 0.60648, 0.22648),
                  Colour(0.628281, 0.555802, 0.366065),
                  51.2 ,0.1,NULL);
    
    Material test3( Colour(0.3, 0.3, 0.3), Colour(0.3, 0.5, 0.22648),
                  Colour(0.628281, 0.555802, 0.366065),
                  51.2,1,NULL );
    
    Material test2( Colour(0, 0, 0), Colour(0.3, 0.3, 0.3),
                   Colour(1.0, 1.0, 1.0),
                   51.2,0,NULL );
    Texture sky("/Users/bingxu/Documents/graphics/COMP3271_assignment_4_template/raytracerMacOS/sky.bmp");
    Texture board("/Users/bingxu/Documents/graphics/COMP3271_assignment_4_template/raytracerMacOS/board.bmp");
    Material starrysky(Colour(0, 0, 0),Colour(0, 0, 0),
                       Colour(0.1, 0.1, 0.1), 11.264, 0, &sky);
    
    Material board_mat(Colour(0, 0, 0),Colour(0, 0, 0),
                       Colour(0.1, 0.1, 0.1), 11.264, 1, &board);
    
   
    SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade );
    SceneDagNode* plane1 = raytracer.addObject( new UnitSquare(), &jade );
    SceneDagNode* plane2 = raytracer.addObject( new UnitSquare(), &board_mat );//the bottom
   
    
    SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &mirror);
    SceneDagNode* sphere1 = raytracer.addObject( new UnitSphere(), &white );
    SceneDagNode* mars = raytracer.addObject( new UnitSphere(), &glass );
    SceneDagNode* earth = raytracer.addObject( new UnitSphere(), &pink );
    
    SceneDagNode* cylinder1 = raytracer.addObject( new UnitFiniteCylinder(), &gold );
    SceneDagNode* cylinder2 = raytracer.addObject( new UnitFiniteCylinder(), &gold );
    SceneDagNode* cylinder3 = raytracer.addObject( new UnitFiniteCylinder(), &gold );
    SceneDagNode* cone = raytracer.addObject( new UnitFiniteCone(), &red );


        double factor1[3] = { 2.0, 2.0, 2.0 };
        double factor2[3] = {50,50,50};
        double factor3[3] = { 1.0, 1.0, 1.0};
        double factor4[3] = { 1.0, 2, 1.0};
        double factor5[3] = {0.5,0.5,0.5};
        double factor6[3] = {0.5,1.5,0.5};
        double factor7[3] = {1.0,4.0,1.0};
    //3 squares
    	raytracer.translate(plane, Vector3D(0, 0, -15));
    	raytracer.scale(plane, Point3D(0, 0, 0), factor2);
    
        raytracer.translate(plane1, Vector3D(-15, 0, 0));
        raytracer.rotate(plane1, 'y', 90);
        raytracer.scale(plane1, Point3D(0, 0, 0), factor2);
   
        raytracer.translate(plane2, Vector3D(0, -8, 0));
        raytracer.rotate(plane2, 'x', -90);
        raytracer.scale(plane2, Point3D(0, 0, 0), factor2);

    //four balls
    raytracer.translate(sphere, Vector3D(-1, -6, -2));
    raytracer.scale(sphere, Point3D(0, 0, 0), factor3);
    
    
    raytracer.translate(sphere1,Vector3D(-4.5, -6, 1));
    raytracer.scale(sphere1, Point3D(0, 0, 0), factor3);
    
    raytracer.translate(mars, Vector3D(3, -3, -1));
    raytracer.scale(mars, Point3D(0, 0, 0), factor3);

   
    raytracer.translate(earth, Vector3D(-8, -6, -2));
    raytracer.scale(earth, Point3D(0, 0, 0), factor3);
    
    
    raytracer.rotate(cylinder1, 'z', -30);
    //raytracer.rotate(cylinder1, 'x', -15);
    raytracer.translate(cylinder1, Vector3D(0, -4, -2));
    raytracer.scale(cylinder1, Point3D(0, 0, 0), factor7);
   
    raytracer.rotate(cylinder2, 'z', -30);
    raytracer.translate(cylinder2, Vector3D(1.5, -3, -2));
    raytracer.scale(cylinder2, Point3D(0, 0, 0), factor6);
    
    raytracer.rotate(cylinder3, 'z', -30);
    raytracer.translate(cylinder3, Vector3D(-1.5, -3, -2));
    raytracer.scale(cylinder3, Point3D(0, 0, 0), factor6);
    
     raytracer.rotate(cone, 'z', -30);
     raytracer.translate(cone, Vector3D(0, 2, -2));
     raytracer.scale(cone, Point3D(0, 0, 0), factor4);
    
    std::clock_t start;
    double duration;
    
    start = std::clock();
   // raytracer.render(width, height, eye, view, up, fov, "view4.bmp");
    duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
    
    //std::cout<<"The rendering duration 1 is .......: "<< duration <<'\n';
    // Render it from a different point of view.
    
    Point3D eye2(3, 1, 5);
    Vector3D view2(-10, -8, -15);

    
    std::clock_t start1;
    double duration1;
    
    start1 = std::clock();
    raytracer.render(width, height, eye2, view2, up, fov, "view5.bmp");
    duration1 = ( std::clock() - start1 ) / (double) CLOCKS_PER_SEC;
    
   // std::cout<<"The rendering duration 2 is .......: "<< duration1 <<'\n';
    
    
    /***********************************************************Final Scene********************************/

        return 0;
}
示例#20
0
文件: main.cpp 项目: vrsys/guacamole
int main(int argc, char** argv)
{
    // initialize guacamole
    gua::init(argc, argv);

    // setup scene
    gua::SceneGraph graph("main_scenegraph");

    gua::math::vec4 iron(0.560, 0.570, 0.580, 1);
    gua::math::vec4 silver(0.972, 0.960, 0.915, 1);
    gua::math::vec4 aluminium(0.913, 0.921, 0.925, 1);
    gua::math::vec4 gold(1.000, 0.766, 0.336, 1);
    gua::math::vec4 copper(0.955, 0.637, 0.538, 1);
    gua::math::vec4 chromium(0.550, 0.556, 0.554, 1);
    gua::math::vec4 nickel(0.660, 0.609, 0.526, 1);
    gua::math::vec4 titanium(0.542, 0.497, 0.449, 1);
    gua::math::vec4 cobalt(0.662, 0.655, 0.634, 1);
    gua::math::vec4 platinum(0.672, 0.637, 0.585, 1);

    auto pbrMat(gua::MaterialShaderDatabase::instance()->lookup("gua_default_material")->make_new_material());
    // pbrMat.set_uniform("Color", chromium);
    // pbrMat.set_uniform("Roughness", 0.2f);
    // pbrMat.set_uniform("Metalness", 1.0f);

    std::string directory("/opt/3d_models/Cerberus_by_Andrew_Maximov/Textures/");
    pbrMat->set_uniform("ColorMap", directory + "Cerberus_A.tga");
    pbrMat->set_uniform("MetalnessMap", directory + "Cerberus_M.tga");
    pbrMat->set_uniform("RoughnessMap", directory + "Cerberus_R.tga");
    pbrMat->set_uniform("NormalMap", directory + "Cerberus_N.negated_green.tga");

    gua::TriMeshLoader loader;

    auto transform = graph.add_node<gua::node::TransformNode>("/", "transform");
    auto cerberus(loader.create_geometry_from_file(
        "cerberus", "/opt/3d_models/Cerberus_by_Andrew_Maximov/Cerberus_LP.3ds", pbrMat, gua::TriMeshLoader::NORMALIZE_POSITION | gua::TriMeshLoader::NORMALIZE_SCALE));
    graph.add_node("/transform", cerberus);
    cerberus->set_draw_bounding_box(true);
    cerberus->rotate(90, 0.f, 1.f, 0.f);
    cerberus->rotate(90, 0.f, 0.f, 1.f);

    auto pointLight = graph.add_node<gua::node::LightNode>("/", "pointLight");
    pointLight->data.set_type(gua::node::LightNode::Type::POINT);
    pointLight->data.color = gua::utils::Color3f(1.0f, 1.0f, 1.0f);
    pointLight->data.brightness = 150.0f; // lm
    pointLight->scale(9.f);
    pointLight->translate(-2.f, 3.f, 5.f);

    auto screen = graph.add_node<gua::node::ScreenNode>("/", "screen");
    screen->data.set_size(gua::math::vec2(1.92f, 1.08f));
    screen->translate(0, 0, 1.0);

    // add mouse interaction
    gua::utils::Trackball trackball(0.01, 0.002, 0.2);

    // setup rendering pipeline and window
    // auto resolution = gua::math::vec2ui(1920, 1080);
    auto resolution = gua::math::vec2ui(2560, 1440);

    std::string skymaps_dir("/opt/guacamole/resources/skymaps/");

    for(auto const& file : {std::string(directory + "Cerberus_A.tga"),
                            std::string(directory + "Cerberus_M.tga"),
                            std::string(directory + "Cerberus_R.tga"),
                            std::string(directory + "Cerberus_N.negated_green.tga"),
                            std::string(skymaps_dir + "skymap.jpg")})
    {
        gua::TextureDatabase::instance()->load(file);
    }

    auto tiledPipe(std::make_shared<gua::PipelineDescription>());
    tiledPipe->add_pass(std::make_shared<gua::TriMeshPassDescription>());
    tiledPipe->add_pass(std::make_shared<gua::LightVisibilityPassDescription>());
    tiledPipe->add_pass(std::make_shared<gua::ResolvePassDescription>());

    auto camera = graph.add_node<gua::node::CameraNode>("/screen", "cam");
    camera->translate(0, 0, 2.0);
    camera->config.set_resolution(resolution);
    camera->config.set_screen_path("/screen");
    camera->config.set_scene_graph_name("main_scenegraph");
    camera->config.set_output_window_name("main_window");
    camera->config.set_enable_stereo(false);
    camera->set_pipeline_description(tiledPipe);

    auto window = std::make_shared<gua::GlfwWindow>();
    gua::WindowDatabase::instance()->add("main_window", window);
    window->config.set_enable_vsync(false);
    window->config.set_size(resolution);
    window->config.set_resolution(resolution);
    window->config.set_stereo_mode(gua::StereoMode::MONO);
    window->on_resize.connect([&](gua::math::vec2ui const& new_size) {
        window->config.set_resolution(new_size);
        camera->config.set_resolution(new_size);
        screen->data.set_size(gua::math::vec2(0.001 * new_size.x, 0.001 * new_size.y));
    });
    window->on_move_cursor.connect([&](gua::math::vec2 const& pos) { trackball.motion(pos.x, pos.y); });
    window->on_button_press.connect(std::bind(mouse_button, std::ref(trackball), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
    window->open();

    gua::Renderer renderer;

    // application loop
    gua::events::MainLoop loop;
    gua::events::Ticker ticker(loop, 1.0 / 500.0);

    size_t ctr{};
    ticker.on_tick.connect([&]() {
        // apply trackball matrix to object
        gua::math::mat4 modelmatrix = scm::math::make_translation(gua::math::float_t(trackball.shiftx()), gua::math::float_t(trackball.shifty()), gua::math::float_t(trackball.distance())) *
                                      gua::math::mat4(trackball.rotation());

        transform->set_transform(modelmatrix);

        if(ctr++ % 150 == 0)
            gua::Logger::LOG_WARNING << "Frame time: " << 1000.f / window->get_rendering_fps() << " ms, fps: " << window->get_rendering_fps() << std::endl;

        window->process_events();
        if(window->should_close())
        {
            renderer.stop();
            window->close();
            loop.stop();
        }
        else
        {
            renderer.queue_draw({&graph});
        }
    });

    loop.start();

    return 0;
}
示例#21
0
//升级装备
int CharData::upgradeEquipment(int eid, bool cost_gold, json_spirit::Object& robj)
{
    if (cost_gold && gold() < 50)
    {
        return HC_ERROR_NOT_ENOUGH_GOLD;
    }
    //cout<<"upgradeEquipment(), eid "<<eid<<endl;
    equipment_scroll* sp = NULL;
    EquipmentData* src_eq = m_bag.getEquipById(eid);
    if (!src_eq)
    {
        src_eq = m_generals.getEquipById(eid);
    }
    if (src_eq)
    {
        //cout<<"find scroll by src_id "<<src_eq->baseid<<endl;
        sp = Singleton<equipment_scroll_mgr>::Instance().getScrollBySrcId(src_eq->baseid);
        if (!sp)
        {
            //cout<<"not find"<<endl;
            return HC_ERROR;
        }
    }
    else
    {
        //cout<<"wrong eid"<<endl;
        return HC_ERROR;
    }
    Bag* pbag = src_eq->getContainer();
    //武将身上,判断等级是否够
    if (pbag != &m_bag && pbag && pbag->gd.get() && pbag->gd->m_level < sp->m_equipment->needLevel)
    {
        return HC_ERROR_NOT_ENOUGH_GENERAL_LEVEL;
    }
    if (m_bag.getGemCount(sp->m_gem_id) <= 0)
    {
        //cout<<"no scroll,gem id: "<<sp->m_gem_id<<endl;
        return HC_ERROR;
    }
    //扣材料
    bool success = trySubMaterial(sp, m_bag);
    if (!success)
    {
        //cout<<"trySubMaterial() return false"<<endl;
        return HC_ERROR;
    }
    //扣卷轴
    int err_code = 0;
    m_bag.addGem(sp->m_gem_id, -1, err_code);
    if (cost_gold)
    {
        if (addGold(-iUpgradeEquiptmentKeepLevelGold) < 0)
        {
            return HC_ERROR_NOT_ENOUGH_GOLD;
        }
        //金币消耗统计
        add_statistics_of_gold_cost(m_id, m_ip_address, iUpgradeEquiptmentKeepLevelGold, gold_cost_for_upgrade_equipment, m_union_id, m_server_id);
#ifdef QQ_PLAT
        gold_cost_tencent(this,iUpgradeEquiptmentKeepLevelGold,gold_cost_for_upgrade_equipment);
#endif
        NotifyCharData();
        //act统计
        act_to_tencent(this,act_new_equipt_make_special,src_eq->qLevel,src_eq->quality);
    }
    //升级装备
    src_eq->upgrade(cost_gold);

    if (src_eq->getContainer() != &m_bag)
    {
        m_weapon_attack_change = true;
        if (pbag->gd.get())
        {
            pbag->gd->updateEquipmentEffect();
        }
    }
    
    json_spirit::Object eq;
    src_eq->toObj(eq);
    robj.push_back( Pair("equipVO", eq) );

    updateEnhanceCost();
    updateEnhanceCDList();
    if (src_eq->baseEq.get())
    {
        std::string link_name = strEquipLink;
        str_replace(link_name, "$G", LEX_CAST_STR(src_eq->id));
        str_replace(link_name, "$C", LEX_CAST_STR(m_id));
        str_replace(link_name, "$N", src_eq->baseEq->name);

        addColor(link_name, src_eq->quality);
        //广播升级装备信息
        std::string notify_msg = strEquiptMakeInfo;
        str_replace(notify_msg, "$N", MakeCharNameLink(m_name));
        str_replace(notify_msg, "$G", link_name);
        GeneralDataMgr::getInstance()->broadCastSysMsg(notify_msg, -1);
    }
    
    //七日目标
    Singleton<seven_Goals_mgr>::Instance().updateGoals(*this,queryCreateDays(),goals_type_equipt,src_eq->baseid);
    
    m_trunk_tasks.updateTask(task_equipment_make, src_eq->baseid);

    
    //act统计
    act_to_tencent(this,act_new_equipt_make,src_eq->type);

    return HC_SUCCESS;
}
示例#22
0
	void GatherState::tick(float deltaTime)
	{
		string success;
		string start;

		if (canGather())
		{
			if (_actor->getBAC() > .4)
			{
				cout << _actor->getName()
						<< " drunkenly swings the tool, hits himself in the foot, and decides not to do that anymore."
						<< "\n";
				switchState("null");
			}
			else
			{
				bool canPickup = true;
				string typeName = _target->getName();
				Item* removedItem;
				if (typeName.find("gold") != string::npos)
				{
					Item gold("gold", _target->getColor(), true);
					removedItem = _target->getInventory().removeItem(gold);
					start = " lifts his pickaxe, and swings it at the rock.";
					success = " successfully mines some ";
				}
				else if (typeName.find("iron") != string::npos)
				{
					Item iron("iron", _target->getColor(), true);
					removedItem = _target->getInventory().removeItem(iron);
					start = " lifts his pickaxe, and swings it at the rock.";
					success = " successfully mines some ";
				}
				else if (typeName.find("coal") != string::npos)
				{
					Item coal("coal", _target->getColor(), true);
					removedItem = _target->getInventory().removeItem(coal);
					start = " lifts his pickaxe, and swings it at the rock.";
					success = " successfully mines some ";
				}
				else if (typeName.find("redwood") != string::npos
						|| typeName.find("oak") != string::npos
						|| typeName.find("birch") != string::npos
						|| typeName.find("cedar") != string::npos)
				{
					Item wood("wood", _target->getColor(), true);
					removedItem = _target->getInventory().removeItem(wood);
					start =
							" takes out his hatchet, and swings it at the tree.";
					success = " successfully chops some ";
				}
				else if (typeName.find("dock") != string::npos)
				{
					Item fish("fish", _target->getColor(), true);
					removedItem = _target->getInventory().removeItem(fish);
					start = " pulls out his harpoon, and jabs it at the water.";
					success = " successfully catches some ";
				}

				_actor->reduceStamina(1);

				string coloredName = Color::colorText(removedItem->getName(),
						removedItem->getColor());
				canPickup = _actor->getInventory().addItem(removedItem);
				cout << _actor->getName() << start << "\n";
				cout << _actor->getName() << success << coloredName << "\n";

				if (!canPickup)
				{
					delete removedItem;
					cout << _actor->getName()
							<< " has a full inventory, and drops "
							<< coloredName << " on the ground.\n";
					_amount = 0;
					switchState("null");
				}

				_amount--;
			}

		}

		else
		{
			_amount = 0;

			switchState("null");
		}
	}