I want to draw moving Chart Graph - like wave on oscilloscope. I refresh the points coordinates on every cycle BUT nothing changes on the screen - only one fully static sinusoide (blue on yellow), which do not moves
I also try to update positions with sf::Vectror2f(x, y), but the result is same unsuccessful. My code is:
#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>
#include <cmath>
using namespace std;
constexpr double pi() { return atan(1)*4; }
int main()
{
const unsigned int s = 500u;
const unsigned int N = 1000u;
sf::RenderWindow window(sf::VideoMode(s, s),
"Osc",
sf::Style::Close);
window.setVerticalSyncEnabled(true);
window.setFramerateLimit(60);
sf::VertexArray chart(sf::LinesStrip, N);
for (unsigned int i=0; i<N-1; i++){
unsigned int x = i*s/N;
unsigned int y = s/2 - (s/2-100)*sin(i*2*pi()/N);
chart.append(sf::Vertex(sf::Vector2f(x, y), sf::Color::Blue));
}
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
if (event.type == sf::Event::Closed) window.close();
// HERE?!:
unsigned int tmpy = chart[0].position.y;
for (unsigned int i=0; i<N-2; i++)
chart[i].position.y = chart[i+1].position.y;
chart[N-1].position.y = tmpy;
window.clear(sf::Color::Yellow);
window.draw(chart);
window.display();
}
return 0;
}
I just start to play with C++ and SFML.
I use Code::Blocks with TDM-GCC 4.9.2, 64 bit and SFML-2.3.1-windows-gcc-4.8.1-tdm-64-bit.zip.
My system is: Windows 7 64 bit, NVIDIA GeForce GT610