Example #1
0
void Case::affiche(sf::RenderWindow& app)
{
    app.draw(getTerrain());

    if (true)
    {
        sf::Sprite corner(*m_texture);

        sf::IntRect r(Case::WIDTH, Case::HEIGHT, Case::WIDTH/2, Case::HEIGHT/2);
        corner.setTextureRect(r);

        Case* ctop = m_map.getCaseAt(m_intpos.x, m_intpos.y-1);
        Case* cbottom = m_map.getCaseAt(m_intpos.x, m_intpos.y+1);
        Case* cleft = m_map.getCaseAt(m_intpos.x-1, m_intpos.y);
        Case* cright = m_map.getCaseAt(m_intpos.x+1, m_intpos.y);
        Case* ctopleft = m_map.getCaseAt(m_intpos.x-1, m_intpos.y-1);
        Case* ctopright = m_map.getCaseAt(m_intpos.x+1, m_intpos.y-1);
        Case* cbottomleft = m_map.getCaseAt(m_intpos.x-1, m_intpos.y+1);
        Case* cbottomright = m_map.getCaseAt(m_intpos.x+1, m_intpos.y+1);

        std::string top = ctop? ctop->getTerrainName() : "";
        std::string bottom = cbottom? cbottom->getTerrainName() : "";
        std::string left = cleft? cleft->getTerrainName() : "";
        std::string right = cright? cright->getTerrainName() : "";

        if (top != "" && top != m_terrainName && top == left && (!ctopleft || ctopleft->getTerrainName() != m_terrainName))
        {
            r.left = ctop->getTerrain().getTextureRect().left;
            r.top = ctop->getTerrain().getTextureRect().top + Case::HEIGHT;

            corner.setPosition(m_pos.x + Case::WIDTH/4, m_pos.y);

            corner.setTextureRect(r);
            app.draw(corner);
        }

        if (top != "" && top != m_terrainName && top == right && (!ctopright || ctopright->getTerrainName() != m_terrainName))
        {
            r.left = ctop->getTerrain().getTextureRect().left + Case::WIDTH/2;
            r.top = ctop->getTerrain().getTextureRect().top + Case::HEIGHT;

            corner.setPosition(m_pos.x + Case::WIDTH/2, m_pos.y + Case::HEIGHT/4);

            corner.setTextureRect(r);
            app.draw(corner);
        }

        if (bottom != "" && bottom != m_terrainName && bottom == left && (!cbottomleft || cbottomleft->getTerrainName() != m_terrainName))
        {
            r.left = cbottom->getTerrain().getTextureRect().left;
            r.top = cbottom->getTerrain().getTextureRect().top + Case::HEIGHT + Case::HEIGHT/2;

            corner.setPosition(m_pos.x, m_pos.y + Case::HEIGHT/4);

            corner.setTextureRect(r);
            app.draw(corner);
        }

        if (bottom != "" && bottom != m_terrainName && bottom == right && (!cbottomright || cbottomright->getTerrainName() != m_terrainName))
        {
            r.left = cbottom->getTerrain().getTextureRect().left + Case::WIDTH/2;
            r.top = cbottom->getTerrain().getTextureRect().top + Case::HEIGHT + Case::HEIGHT/2;

            corner.setPosition(m_pos.x + Case::WIDTH/4, m_pos.y + Case::HEIGHT/2);

            corner.setTextureRect(r);
            app.draw(corner);
        }
    }

    if(hasObject())
    {
        if (!m_autoTile && !m_triggerable)
        {
            app.draw(getObjet());
        }
        else if (m_triggerable)
        {
            sf::IntRect r = m_objet.getTextureRect();
            sf::IntRect s = m_objet.getTextureRect();
            r.top += (m_triggered)? 0 : Case::HEIGHT;
            m_objet.setTextureRect(r);
            app.draw(m_objet);
            m_objet.setTextureRect(s);
        }
        else if (m_autoTile)
        {
            sf::Sprite plop(*m_texture);


            sf::IntRect r = m_objet.getTextureRect();
            r.left += Case::WIDTH/2;
            r.top += Case::HEIGHT/2;
            r.width = Case::WIDTH/2;
            r.height = Case::HEIGHT/2;

            sf::Vector2i& pos = m_pos;

            bool test = true;

            bool top = test && !m_map.getCaseAt(m_intpos.x, m_intpos.y-1)->hasObject(m_objName);
            bool bottom = test && !m_map.getCaseAt(m_intpos.x, m_intpos.y+1)->hasObject(m_objName);
            bool left = test && !m_map.getCaseAt(m_intpos.x-1, m_intpos.y)->hasObject(m_objName);
            bool right = test && !m_map.getCaseAt(m_intpos.x+1, m_intpos.y)->hasObject(m_objName);

            plop.setTextureRect(sf::IntRect(r.left - (left? Case::WIDTH/2 : 0), r.top - (top? Case::HEIGHT/2 : 0), r.width, r.height));
            plop.setPosition(pos.x + 12, pos.y);
            app.draw(plop);


            plop.setTextureRect(sf::IntRect(r.left + (right? Case::WIDTH/2 : 0), r.top + (bottom? Case::HEIGHT/2 : 0), r.width, r.height));
            plop.setPosition(pos.x + 12, pos.y + 16);
            app.draw(plop);


            plop.setTextureRect(sf::IntRect(r.left - (left? Case::WIDTH/2 : 0), r.top + (bottom? Case::HEIGHT/2 : 0), r.width, r.height));
            plop.setPosition(pos.x, pos.y + 8);
            app.draw(plop);


            plop.setTextureRect(sf::IntRect(r.left + (right? Case::WIDTH/2 : 0), r.top - (top? Case::HEIGHT/2 : 0), r.width, r.height));
            plop.setPosition(pos.x+24, pos.y + 8);
            app.draw(plop);

        }
    }
}
Example #2
0
int main(int parc, char ** pars)
{
    if (parc < 3)
    {
        printf(
            "Usage: %s infile outfile [-h] [-fona]\n"
            "where:\n"
            "infile  - input png file\n"
            "outfile - outpuf file\n"
            "-h      - optional, write c header instead of bin\n"
            "-fona   - process as a font bitmap instead of linear\n", 
            pars[0]);
        exit(0);
    }
    
    int i, j, k, l;
    for (i = 3; i < parc; i++)
    {
        if (stricmp(pars[i], "-h") == 0)
        {
            gOptH = 1;
        }
        else
        if (stricmp(pars[i], "-fona") == 0)
        {
            gOptFona = 1;
        }
        else
        {
            printf("Unknown option \"%s\"\n", pars[i]);
            exit(0);
        }
    }
    
    int x, y, comp;
    stbi_uc * raw = stbi_load(pars[1], &x, &y, &comp, 4);    
    printf("%d %d %d\n", x, y, comp);
    unsigned int *p = (unsigned int *)raw;
    
    if (gOptH)
    {
        f = fopen(pars[2], "w");
    }
    else
    {
        f = fopen(pars[2], "wb");
    }              
    
    if (f == NULL)
    {
        printf("Can't open \"%s\"\n", pars[2]);
        exit(0);
    }

    if (gOptH)
    {
        int i = 0;
        while (pars[1][i])
        {
            if (!(pars[1][i] >= 'A' && pars[2][i] <= 'Z' || 
                  pars[1][i] >= 'a' && pars[2][i] <= 'z' ||
                  pars[1][i] >= '0' && pars[2][i] >= '9'))
                pars[1][i] = '_';
            i++;
        }
        fprintf(f, "const unsigned char %s[] = {\n", pars[1]);
    }
    
    if (gOptFona)
    {
        for (l = 0; l < y / 8; l++)
        {
            for (k = 0; k < x / 8; k++)
            {
                for (i = 0; i < 8; i++)
                {
                    for (j = 0; j < 8; j++)
                    {
                        plop(p[(l * 8 + i) * x + k * 8 + j] != p[0]);
                    }
                }
            }
        }
    }
    else
    {
        for (i = 0; i < x*y; i++)
        {
            plop(p[i] != p[0]);
        }
    }

    if (gOptH)
    {
        fprintf(f, "};\n");
    }
   
    fclose(f);
    return 0;
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->comboUp, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->comboDown, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->comboLeft, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->comboRight, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));

    connect(ui->combo1, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->combo2, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->combo3, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->combo4, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));

    connect(ui->combo5, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->combo6, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->combo7, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->combo8, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));

    connect(ui->combo9, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));

    connect(ui->altCombo1, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->altCombo2, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->altCombo3, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->altCombo4, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));

    connect(ui->altCombo5, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->altCombo6, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->altCombo7, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));
    connect(ui->altCombo8, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));

    connect(ui->altCombo9, SIGNAL(currentIndexChanged(int)), this, SLOT(plop()));

    ui->comboUp->setCurrentText("Pad Up");
    ui->comboDown->setCurrentText("Pad Down");
    ui->comboLeft->setCurrentText("Pad Left");
    ui->comboRight->setCurrentText("Pad Right");

    ui->combo1->setCurrentText("Pad 1");
    ui->combo2->setCurrentText("Pad 2");
    ui->combo3->setCurrentText("Pad 3");
    ui->combo4->setCurrentText("Pad 4");

    ui->combo5->setCurrentText("Pad 5");
    ui->combo6->setCurrentText("Pad 6");
    ui->combo7->setCurrentText("Pad 7");
    ui->combo8->setCurrentText("Pad 8");

    ui->combo9->setCurrentText("Pad 9");

    ui->altCombo1->setCurrentText("Pad 10");
    ui->altCombo2->setCurrentText("Pad 11");
    ui->altCombo3->setCurrentText("Pad 12");
    ui->altCombo4->setCurrentText("Pad 13");

    ui->altCombo5->setCurrentText("Pad 14");
    ui->altCombo6->setCurrentText("Pad 15");
    ui->altCombo7->setCurrentText("Pad 16");
    ui->altCombo8->setCurrentText("Pad 17");

    ui->altCombo9->setCurrentText("Pad 18");

    plop();
}
Example #4
0
int main()
{
	test();
    plop();
    return EXIT_SUCCESS;
}
Example #5
0
int main() {
	if(-1 == SDL_Init(SDL_INIT_VIDEO)) {
		std::cerr << "Unable to initialize SDL" << std::endl;
		return EXIT_FAILURE;
	}

	if(NULL == SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, SDL_OPENGL)) {
		std::cerr << "Unable to open the window and get an OpenGL context" << std::endl;
		return EXIT_FAILURE;
	}

	SDL_WM_SetCaption("OpenGL4Imacs", NULL);

	GLenum glewCode = glewInit();
	if(GLEW_OK != glewCode) {
		std::cerr << "Unable to initialize GLEW : " << glewGetErrorString(glewCode) << std::endl;
		return EXIT_FAILURE;
	}

	//initialisation

	glimac::TrackballCamera trackballCamera;

	glimac::VBO vbo;
	vbo.bind();

	glimac::gcaVertex vertexs;

//////////////////*******demo/********///////////////////////////////////////////////////////////////////////////////////////
	std::vector<gca::K_blade> grassmann;
	gca::GCA_vector x(1, 0, 0, 1.0);
	gca::GCA_vector y;
	y << 0, 1, 0, 1.0;
	gca::GCA_vector z(0, 0, 1, 1.0);
	gca::GCA_vector o(0, 0, 0, 1.0);

	vertexs.getBlade(x^o, glm::vec3(1, 0, 0)); //le balde, puis la couleur
	vertexs.getBlade(y^o, glm::vec3(0, 1, 0));
	vertexs.getBlade(z^o, glm::vec3(0, 0, 1));

	plop();

	gca::GCA_vector a (3, 5, -1, 1.);
	gca::GCA_vector b(1.2, -2.7, -0.1, 1.);
	gca::GCA_vector c;
	c<< -4.1, 0.2, 2.8, 1.; 

	gca::GCA_scalar factor(3);

	a = factor^a;

	gca::GCA_bivector l = a ^ b;
	gca::GCA_antibivector antil = ~l;

	gca::GCA_trivector p = l^c;
	gca::GCA_trivector copyP(-p);
	gca::GCA_trivector otherPlan(1, 1, 1, 1);

	gca::GCA_bivector croisementPlan = ~p^~otherPlan;

	std::cout<<"point a :"<< a<<std::endl;
	std::cout<<"~a :"<< ~a<<std::endl;
	std::cout<<"point b :"<< b<<std::endl;
	std::cout<<"point c :"<< c<<std::endl;
	std::cout<<"droite l (a^b) "<< l<<std::endl;
	std::cout<<"antibivector de l"<< antil<<std::endl;
	std::cout<<"plan p (l^c)"<< p<<std::endl;
	std::cout<<"copyP = -p"<<copyP<<std::endl;
	std::cout<<"~copyP"<<~copyP<<std::endl;
	std::cout<<"otherPlan"<<otherPlan<<std::endl;
	std::cout<<"~p^~otherPlan"<<croisementPlan<<std::endl;
	std::cout<<"~(~p^~otherPlan)"<<~croisementPlan<<std::endl;

	vertexs.getBlade(a, glm::vec3(1, 0, 0));
	vertexs.getBlade(b, glm::vec3(1, 0, 0));
	vertexs.getBlade(c, glm::vec3(1, 0, 0));
	vertexs.getBlade(l, glm::vec3(1, 1, 0));
	vertexs.getBlade(p, glm::vec3(1, 1, 1));
	vertexs.getBlade(otherPlan, glm::vec3(0, 1, 1));
	vertexs.getBlade(~croisementPlan, glm::vec3(0.5, 0.5, 0.));


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	glBufferData(GL_ARRAY_BUFFER, vertexs.getVertexCount() * sizeof(glimac::ShapeVertex), vertexs.getDataPointer(), GL_STATIC_DRAW);
	
	glBindBuffer(GL_ARRAY_BUFFER, 0); //on debind le vbo

	glimac::VAO vao;
	vao.bind();
	vbo.bind();
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(	 0, // Index de l'attribut: 0 dans notre cas, l'index de la position
							 3, // Nombre de composantes de l'attribut: 2 car on à 2 float par position
							 GL_FLOAT, // Type des composantes de l'attribut: GL_FLOAT pour les float
							 GL_FALSE, // A mettre à GL_TRUE
							 sizeof(glimac::ShapeVertex), // nombre de float à parcourire depuis la position initiale pour atteintre les prochaine coordonnées (2 de position + 3 de couleurs=5)
							 (const GLvoid*) (0 * sizeof(GLfloat))); // A mettre à 0 ou NULL pour l'instant	
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(	 1, // Index de l'attribut: 0 dans notre cas, l'index de la position
							 3, // Nombre de composantes de l'attribut: 3 car on à 3 float par couleur
							 GL_FLOAT, // Type des composantes de l'attribut: GL_FLOAT pour les float
							 GL_FALSE, // la normailsation est faite par la carte graphique
							 sizeof(glimac::ShapeVertex), // nombre de float à parcourire depuis la position initiale pour atteintre les prochaine coordonnées (2 de position + 3 de couleurs=5)
							 (const GLvoid*) (3 * sizeof(GLfloat))); // Un sommet est stocké dans le VBO sous la forme x y r g b. Le décalage est donc de 2 flottants car il y x y juste avant la couleur. Il faut donc passer à la fonction la valeur (const GLvoid*) (2 * sizeof(GLfloat))	
	
	glBindBuffer(GL_ARRAY_BUFFER, 0); //on debind le vbo
	glBindVertexArray(0);			//on debind le vao


	//shader
	
	glimac::Program programShader = glimac::loadProgram( "../shader/3D.vs.glsl", "../shader/color3D.fs.glsl");
	
	programShader.use();

	GLint location1 = glGetUniformLocation(programShader.getGLId(), "uMVPMatrix");
	GLint location2 = glGetUniformLocation(programShader.getGLId(), "uMVMatrix");
	GLint location3 = glGetUniformLocation(programShader.getGLId(), "uNormalMatrix");

	glEnable(GL_DEPTH_TEST); //permet d'activer le test de profondeur du GPU.


	int sourisX, sourisY;
	bool done = false;
	while(!done) {
		Uint32 tStart = SDL_GetTicks();

		// Rendering code goes here

		glm::mat4 ProjMatrix = glm::perspective(70.f, (float)WINDOW_WIDTH/(float)WINDOW_HEIGHT, 0.1f, 100.f);
		glm::mat4 MVMatrix = glm::translate(glm::mat4(1.f), glm::vec3(0,0,-5));
		MVMatrix *= trackballCamera.getViewMatrix();
		glm::mat4 NormalMatrix = glm::transpose(glm::inverse(MVMatrix));



		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		vao.bind();

			glUniformMatrix4fv(location1, 1, 0, glm::value_ptr(ProjMatrix * MVMatrix /* RotateTerre*/));
			glUniformMatrix4fv(location2, 1, 0, glm::value_ptr(MVMatrix /* RotateTerre*/));
			glUniformMatrix4fv(location3, 1, 0, glm::value_ptr(NormalMatrix));

			glDrawArrays(GL_LINES, 0, vertexs.getVertexCount());
			

		glBindVertexArray(0);			//on debind le vao

		// Application code goes here

		SDL_Event e;
		while(SDL_PollEvent(&e)) {
			switch(e.type) {
				default:
				break;

				case SDL_MOUSEBUTTONDOWN:
					switch(e.button.button){
						case SDL_BUTTON_WHEELDOWN:
							trackballCamera.moveFront(-0.1);
						break;

						case SDL_BUTTON_WHEELUP:
							trackballCamera.moveFront(0.1);
						break;

						case SDL_BUTTON_RIGHT:
							sourisX = e.button.x;
							sourisY = e.button.y;
						break;
					}
				break;

				case SDL_QUIT:
					done = true;
				break;
			}
		}

		int x, y;
		if(SDL_GetMouseState(&x, &y) & SDL_BUTTON(3))
		{	
			trackballCamera.rotateLeft(y - sourisY);
			trackballCamera.rotateUp(x - sourisX);

			sourisX = x;
			sourisY = y;
		}

		

		// Mise à jour de la fenêtre (synchronisation implicite avec OpenGL)
		SDL_GL_SwapBuffers();

		Uint32 tEnd = SDL_GetTicks();
		Uint32 d = tEnd - tStart;
		if(d < FRAME_DURATION) {
			SDL_Delay(FRAME_DURATION - d);
		}
	}

	SDL_Quit();

	return EXIT_SUCCESS;
}
Example #6
0
int main (int argc, char **argv)
{
	unsigned long temps;
	int cuts = 0;
	struct timeval t1, t2;

	if (argc != 3)
	{
		fprintf (stderr, "Usage: %s  <nbcities ( MAXNBCITIES = %d )> <seed> \n", argv[0], MAXNBCITIES) ;
		exit (1) ;
	}

	NbCities = atoi (argv[1]) ;
	seed = atoi(argv[2]);

	minimum = INT_MAX ;

	//	printf ("NbCities = %3d\n", NbCities) ;

	init_queue (&listeTaches) ;
	genmap () ;

	gettimeofday(&t1,NULL);

	{
		Path_t path;
		int i;

		for(i = 0; i < MAXNBCITIES; i++)
			path[i] = -1 ;

		/* Ville de d�part : Ville 0 */
		path [0] = 0;

		tsp_partiel (1, 0, path, &cuts);
	}

	gettimeofday(&t2,NULL);

	temps = TIME_DIFF(t1,t2);
	//	printf("time = %ld.%03ldms (%d coupures)\n", temps/1000, temps%1000, cuts);

	gettimeofday(&t1,NULL);

	{
		int j;
		Path_t path;
		int hops, len, nbjobs;
		cuts = 0;

		nbjobs = get_nbjobs(&listeTaches);

#pragma omp parallel for private (path, hops, len) schedule (static, 50)
		for (j = 0; j < nbjobs; j++)
		{
			if (get_job(&listeTaches, j, path, &hops, &len))
				plop(hops, len, path, &cuts);
		}
	}

	gettimeofday(&t2,NULL);
	temps = TIME_DIFF(t1,t2);
	printf("minimum = %d time = %ld ms (%d coupures)\n", minimum, temps, cuts);
	return 0 ;
}