Hello.
So I have a problem with rotating vector of vertices. I've included a simple example and some screen shots.
#include <iostream>
#include <SFML/Graphics.hpp>
class BackGround : public sf::Drawable, public sf::Transformable
{
public:
typedef std::vector<sf::Vertex> VertVec;
BackGround() = delete;
BackGround(sf::Image &im)
:m_pType(sf::PrimitiveType::Points)
{
m_vertices.reserve(im.getSize().x * im.getSize().y);
for(int y = 0; y < im.getSize().y; ++y)
{
for (int x = 0; x < im.getSize().x; ++x)
{
sf::Vertex vert(sf::Vector2f(x+0.5f,y+0.5f));
vert.color = im.getPixel(x,y);
m_vertices.push_back(vert);
}
}
}
~BackGround(){}
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
// apply the entity's transform -- combine it with the one that was passed by the caller
states.transform *= getTransform(); // getTransform() is defined by sf::Transformable
// apply the texture
states.texture = &m_texture;
// you may also override states.shader or states.blendMode if you want
// draw the vertex array
target.draw(&m_vertices[0],m_vertices.size(),m_pType, states);
}
sf::Texture m_texture;
VertVec m_vertices;
sf::PrimitiveType m_pType;
};
int main()
{
sf::RenderWindow win(sf::VideoMode(800,600),"PSIMPL",sf::Style::Close);
sf::Image im,im2;
im.loadFromFile("animage.png");
BackGround bVert(im);
bVert.setOrigin(400,300);
bVert.move(400,300);
while(win.isOpen())
{
sf::Event e;
while (win.pollEvent(e))
{
if(e.type == sf::Event::Closed)
{
win.close();
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::P))
{
im2 = win.capture();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
bVert.move(sf::Vector2f(-1,0));
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
bVert.move(sf::Vector2f(1,0));
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
bVert.rotate(1);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
bVert.rotate(-1);
}
win.clear();
win.draw(bVert);
win.display();
}
im2.saveToFile("animage2.png");
return 0;
}
Hopefully you can see that on rotation holes appear between the vertices. It gets worse between 45 degree increments before getting better at 90 degee steps. It seems like some kind of rounding error but I am unsure how I can compensate, or if I can. It only seems to occur on rotation and not translation. Am I going about this the right way?
I'm only playing around really, seeing how far SFML is coming but I'm hoping to make a destructible terrain type thingy and I thought that keeping a screens worth of vertices would be ideal. The other option would be rendertexture but I think that would be fairly slow for my purposes.
This is happening with cutting edge master from github, mesa 10.2.3, arch linux and xf86-video-ati 1:7.4.0-2.