Salut à tous,
Je conçois en ce moment un système de projection basé sur le Mode 7.
Lorsque je décide d'inclure la librairie <math.h>, j'ai une erreur d'affichage grotesque, il n'y a que la moitié de mon rendu qui s'affiche :
Alors que lorsque je retire "#include <math.h>", tout se redraw parfaitement..
Je ne comprends absolument pas l'erreur.. Voici mon code :
#include <math.h>
#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
unsigned int WIDTHSCREEN = 800, HEIGHTSCREEN = 600;
sf::RenderWindow app(sf::VideoMode(WIDTHSCREEN, HEIGHTSCREEN), "Rotozoom", sf::Style::Titlebar);
app.setFramerateLimit(60);
sf::RenderWindow render(sf::VideoMode(WIDTHSCREEN, HEIGHTSCREEN), "Render", sf::Style::Titlebar);
render.setFramerateLimit(60);
sf::Clock clock;
std::vector<sf::VertexArray>vecLines;
std::vector<sf::VertexArray>vecQuads;
sf::Vector2f m_position = {100,100};
float angle = 0.0f;
double speedMove = 20;
for (unsigned int i = 0 ; i < HEIGHTSCREEN ; i++)
{
sf::VertexArray line(sf::Lines, WIDTHSCREEN);
for (unsigned int k = 0 ; k < WIDTHSCREEN ; k++)
line[k].position = {0, i};
vecLines.push_back(line);
}
std::vector<std::vector<unsigned int>>vecMap =
{
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0}
};
unsigned int blocSize = 32;
for (unsigned int y = 0 ; y < vecMap.size() ; y++)
{
for (unsigned int x = 0 ; x < vecMap[y].size() ; x++)
{
if (vecMap[y][x])
{
sf::VertexArray quad(sf::Quads, 4);
quad[0].position = {x*blocSize, y*blocSize};
quad[1].position = {x*blocSize+blocSize, y*blocSize};
quad[2].position = {x*blocSize+blocSize, y*blocSize+blocSize};
quad[3].position = {x*blocSize, y*blocSize+blocSize};
for (unsigned int c = 0 ; c < 4 ; c++)
x%2 ? quad[c].color = sf::Color::Red : quad[c].color = sf::Color::Blue;
vecQuads.push_back(quad);
}
}
}
double scale = 200;
while (app.isOpen())
{
sf::Event event;
while (app.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
app.close();
break;
case sf::Event::KeyReleased:
if (event.key.code == sf::Keyboard::Escape)
app.close();
break;
}
}
render.clear();
for (unsigned int y = 0 ; y < HEIGHTSCREEN ; y++)
{
unsigned int l = 0;
for (unsigned int x = 0 ; x < WIDTHSCREEN ; x++)
{
for (unsigned int i = 0 ; i < vecQuads.size() ; i++)
{
double xDistance = abs(WIDTHSCREEN/2-x);
if (x==vecQuads[i][0].position.x && y>=vecQuads[i][0].position.y && y<= vecQuads[i][3].position.y)
{
vecLines[y][l].position.x = WIDTHSCREEN/2;
vecLines[y][l].position.y = y/2;
vecLines[y][l].color = vecQuads[i][0].color;
if (x<WIDTHSCREEN/2)
vecLines[y][l].position.x = x - (y*xDistance/scale);
if (x>WIDTHSCREEN/2)
vecLines[y][l].position.x = x + (y*xDistance/scale);
l++;
}
if (x==vecQuads[i][1].position.x && y>=vecQuads[i][0].position.y && y<= vecQuads[i][2].position.y)
{
vecLines[y][l].color = vecQuads[i][1].color;
vecLines[y][l].position.y = y/2;
vecLines[y][l].position.x = WIDTHSCREEN/2;
if (x<WIDTHSCREEN/2)
vecLines[y][l].position.x = x - (y*xDistance/scale);
if (x>WIDTHSCREEN/2)
vecLines[y][l].position.x = x + (y*xDistance/scale);
l++;
}
}
}
}
app.clear();
for (auto& vvec : vecQuads)
app.draw(vvec);
for (auto& vvec : vecLines)
render.draw(vvec);
app.display();
render.display();
}
}
Si je retire le "math.h", ça projette sans problème ma perspective, si je l'inclu, la moitié ne s'affiche plus du tout..
Merci à vous !