1
General / fatal error: Mouse.hpp: No such file or directory
« on: November 06, 2017, 04:37:58 pm »
Hello!
I try to use Mouse Class. But when i add #include <Mouse.hpp> or #include <SFML/Mouse.hpp> instuctions my compiler say me:
This's listing of my project:
Anybody help me please, where's i was wrong?
I try to use Mouse Class. But when i add #include <Mouse.hpp> or #include <SFML/Mouse.hpp> instuctions my compiler say me:
[ 50%] Building CXX object CMakeFiles/workshop2.5.dir/main.obj
D:\cpp\Projects\labs\workshop2\workshop2.5\main.cpp:5:10: fatal error: Mouse.hpp: No such file or directory
#include <Mouse.hpp>
^~~~~~~~~~~
compilation terminated.
mingw32-make.exe[2]: *** [CMakeFiles\workshop2.5.dir\build.make:63: CMakeFiles/workshop2.5.dir/main.obj] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:67: CMakeFiles/workshop2.5.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2
D:\cpp\Projects\labs\workshop2\workshop2.5\main.cpp:5:10: fatal error: Mouse.hpp: No such file or directory
#include <Mouse.hpp>
^~~~~~~~~~~
compilation terminated.
mingw32-make.exe[2]: *** [CMakeFiles\workshop2.5.dir\build.make:63: CMakeFiles/workshop2.5.dir/main.obj] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:67: CMakeFiles/workshop2.5.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2
This's listing of my project:
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
//#include <SFML/Mouse.hpp>
#include <Mouse.hpp>
#include <vector>
#include <cmath>
#include <iostream>
#include <string>
#include <set>
#include <random>
#include <ctime>
using namespace std;
using namespace sf;
constexpr unsigned BALLS_COUNT = 4;
const string WINDOW_TITLE = "Moving balls";
static const sf::Color BACKGROUND_COLOR = sf::Color(0, 0, 0);
constexpr unsigned WINDOW_WIDTH = 800;
constexpr unsigned WINDOW_HEIGHT = 600;
struct Colr
{
int red;
int green;
int blue;
bool operator<(const Colr& curr) const
{
if (red < curr.red)
{
return true;
}
else if (red == curr.red)
{
if (green < curr.green)
{
return true;
}
else if (green == curr.green)
{
return blue < curr.blue;
}
}
return false;
}
};
struct Ball
{
CircleShape shape;
Vector2f offset;
};
struct PRNG
{
std::mt19937 engine;
};
void initGenerator(PRNG& generator)
{
// Используем время с 1 января 1970 года в секундах как случайное зерно
const unsigned seed = unsigned(std::time(nullptr));
generator.engine.seed(seed);
}
// Генерирует индекс в диапазоне [0, size)
size_t random_index(PRNG& generator, int size)
{
// Создаём распределение
std::uniform_int_distribution<int> distribution(0, size - 1);
// Вычисляем псевдослучайное число: вызовем распределение как функцию,
// передав генератор произвольных целых чисел как аргумент.
return distribution(generator.engine);
}
bool checkBGColor(Colr& colr)
{
if((colr.red != BACKGROUND_COLOR.r) && (colr.green != BACKGROUND_COLOR.g) && (colr.blue != BACKGROUND_COLOR.b))
{
return 1;
}
else
{
return 0;
}
}
Colr initColor(PRNG generator, set<Colr>& isColrs)
{
Colr colr;
colr.red = random_index(generator, 256);
colr.green = random_index(generator, 256);
colr.blue = random_index(generator, 256);
if(isColrs.empty() || (isColrs.find(colr) == isColrs.end()) && checkBGColor(colr))
{
isColrs.insert(colr);
return colr;
}
else
{
initColor(generator, isColrs);
}
}
void pollEvents(RenderWindow& window)
{
Event event{};
while (window.pollEvent(event))
{
switch (event.type)
{
case Event::Closed:
window.close();
break;
case Event::Closed:
window.close();
break;
default:
break;
}
}
}
float length(const Vector2f& value)
{
return std::hypot(value.x, value.y);
}
float distance(const Ball& ball, const Ball& curr)
{
return length(ball.shape.getPosition() - curr.shape.getPosition());
}
float dot(const Vector2f& left, const Vector2f& right)
{
return left.x * right.x + left.y * right.y;
}
float sqr(float value)
{
return value * value;
}
sf::Vector2f getSpeedAfterStrike(const Ball& first, const Ball& second)
{
const Vector2f deltaSpeed = first.offset - second.offset;
const Vector2f deltaPos = first.shape.getPosition() - second.shape.getPosition();
return first.offset - deltaPos * (dot(deltaSpeed, deltaPos) / sqr(length(deltaPos)));
}
void update(vector<Ball>& balls, float deltaTime)
{
constexpr float MAX_DELTA_TIME = 0.1f;
deltaTime = std::min(deltaTime, MAX_DELTA_TIME);
for (auto& ball: balls)
{
if ((ball.shape.getPosition().x + ball.shape.getRadius() >= WINDOW_WIDTH) || (ball.shape.getPosition().y + ball.shape.getRadius() >= WINDOW_HEIGHT)
|| (ball.shape.getPosition().x - ball.shape.getRadius() <= 0) || (ball.shape.getPosition().y - ball.shape.getRadius() <= 0))
{
ball.offset = -ball.offset;
}
}
for (size_t fi = 0; fi < balls.size(); ++fi)
{
for (size_t si = fi + 1; si < balls.size(); ++si)
{
Ball& first = balls[fi];
Ball& second = balls[si];
if (distance(first, second) <= (first.shape.getRadius() + second.shape.getRadius()))
{
const Vector2f newFirstSpeed = getSpeedAfterStrike(first, second);
const Vector2f newSecondSpeed = getSpeedAfterStrike(second, first);
first.offset = newFirstSpeed;
second.offset = newSecondSpeed;
}
}
}
for (auto& ball: balls)
{
ball.shape.move(ball.offset * deltaTime);
}
}
void redrawFrame(RenderWindow& window, vector<Ball>& balls)
{
window.clear(BACKGROUND_COLOR);
for (auto& ball: balls)
{
window.draw(ball.shape);
}
window.display();
}
void initBall(PRNG generator, vector<Ball>& balls, Ball& ball, set<Colr>& isColrs)
{
const vector<float> sizes = {
40,
40,
40,
40
};
const vector<Vector2f> positions = {
{ 5* sizes.at(0), 5 * sizes.at(0) },
{ WINDOW_WIDTH - 3 * sizes.at(1), WINDOW_HEIGHT - 12 * sizes.at(1) },
{ WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 },
{ WINDOW_WIDTH - 3 * sizes.at(3), WINDOW_HEIGHT - 3 * sizes.at(3) }
};
for (int i = 0; i < BALLS_COUNT; ++i)
{
balls.at(i).offset.x = random_index(generator, 250);
balls.at(i).offset.y = random_index(generator, 250);
balls.at(i).shape.setRadius(sizes.at(i));
balls.at(i).shape.setPosition(positions.at(i));
Colr colr = initColor(generator, isColrs);
balls.at(i).shape.setFillColor(sf::Color(colr.red, colr.green, colr.blue));
balls.at(i).shape.setOrigin(balls.at(i).shape.getRadius(), balls.at(i).shape.getRadius());
}
}
void init(PRNG generator, set<Colr>& isColrs, vector<Ball>& balls, Ball& ball)
{
initBall(generator, balls, ball, isColrs);
}
int main()
{
Clock clock;
ContextSettings settings;
RenderWindow window(VideoMode({WINDOW_WIDTH, WINDOW_HEIGHT}), WINDOW_TITLE, Style::Default, settings);
vector<Ball> balls(BALLS_COUNT);
PRNG generator;
Ball ball;
set<Colr> isColrs;
initGenerator(generator);
init(generator, isColrs, balls, ball);
while (window.isOpen())
{
float deltaTime = clock.restart().asSeconds();
pollEvents(window);
update(balls, deltaTime);
redrawFrame(window, balls);
}
}
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
//#include <SFML/Mouse.hpp>
#include <Mouse.hpp>
#include <vector>
#include <cmath>
#include <iostream>
#include <string>
#include <set>
#include <random>
#include <ctime>
using namespace std;
using namespace sf;
constexpr unsigned BALLS_COUNT = 4;
const string WINDOW_TITLE = "Moving balls";
static const sf::Color BACKGROUND_COLOR = sf::Color(0, 0, 0);
constexpr unsigned WINDOW_WIDTH = 800;
constexpr unsigned WINDOW_HEIGHT = 600;
struct Colr
{
int red;
int green;
int blue;
bool operator<(const Colr& curr) const
{
if (red < curr.red)
{
return true;
}
else if (red == curr.red)
{
if (green < curr.green)
{
return true;
}
else if (green == curr.green)
{
return blue < curr.blue;
}
}
return false;
}
};
struct Ball
{
CircleShape shape;
Vector2f offset;
};
struct PRNG
{
std::mt19937 engine;
};
void initGenerator(PRNG& generator)
{
// Используем время с 1 января 1970 года в секундах как случайное зерно
const unsigned seed = unsigned(std::time(nullptr));
generator.engine.seed(seed);
}
// Генерирует индекс в диапазоне [0, size)
size_t random_index(PRNG& generator, int size)
{
// Создаём распределение
std::uniform_int_distribution<int> distribution(0, size - 1);
// Вычисляем псевдослучайное число: вызовем распределение как функцию,
// передав генератор произвольных целых чисел как аргумент.
return distribution(generator.engine);
}
bool checkBGColor(Colr& colr)
{
if((colr.red != BACKGROUND_COLOR.r) && (colr.green != BACKGROUND_COLOR.g) && (colr.blue != BACKGROUND_COLOR.b))
{
return 1;
}
else
{
return 0;
}
}
Colr initColor(PRNG generator, set<Colr>& isColrs)
{
Colr colr;
colr.red = random_index(generator, 256);
colr.green = random_index(generator, 256);
colr.blue = random_index(generator, 256);
if(isColrs.empty() || (isColrs.find(colr) == isColrs.end()) && checkBGColor(colr))
{
isColrs.insert(colr);
return colr;
}
else
{
initColor(generator, isColrs);
}
}
void pollEvents(RenderWindow& window)
{
Event event{};
while (window.pollEvent(event))
{
switch (event.type)
{
case Event::Closed:
window.close();
break;
case Event::Closed:
window.close();
break;
default:
break;
}
}
}
float length(const Vector2f& value)
{
return std::hypot(value.x, value.y);
}
float distance(const Ball& ball, const Ball& curr)
{
return length(ball.shape.getPosition() - curr.shape.getPosition());
}
float dot(const Vector2f& left, const Vector2f& right)
{
return left.x * right.x + left.y * right.y;
}
float sqr(float value)
{
return value * value;
}
sf::Vector2f getSpeedAfterStrike(const Ball& first, const Ball& second)
{
const Vector2f deltaSpeed = first.offset - second.offset;
const Vector2f deltaPos = first.shape.getPosition() - second.shape.getPosition();
return first.offset - deltaPos * (dot(deltaSpeed, deltaPos) / sqr(length(deltaPos)));
}
void update(vector<Ball>& balls, float deltaTime)
{
constexpr float MAX_DELTA_TIME = 0.1f;
deltaTime = std::min(deltaTime, MAX_DELTA_TIME);
for (auto& ball: balls)
{
if ((ball.shape.getPosition().x + ball.shape.getRadius() >= WINDOW_WIDTH) || (ball.shape.getPosition().y + ball.shape.getRadius() >= WINDOW_HEIGHT)
|| (ball.shape.getPosition().x - ball.shape.getRadius() <= 0) || (ball.shape.getPosition().y - ball.shape.getRadius() <= 0))
{
ball.offset = -ball.offset;
}
}
for (size_t fi = 0; fi < balls.size(); ++fi)
{
for (size_t si = fi + 1; si < balls.size(); ++si)
{
Ball& first = balls[fi];
Ball& second = balls[si];
if (distance(first, second) <= (first.shape.getRadius() + second.shape.getRadius()))
{
const Vector2f newFirstSpeed = getSpeedAfterStrike(first, second);
const Vector2f newSecondSpeed = getSpeedAfterStrike(second, first);
first.offset = newFirstSpeed;
second.offset = newSecondSpeed;
}
}
}
for (auto& ball: balls)
{
ball.shape.move(ball.offset * deltaTime);
}
}
void redrawFrame(RenderWindow& window, vector<Ball>& balls)
{
window.clear(BACKGROUND_COLOR);
for (auto& ball: balls)
{
window.draw(ball.shape);
}
window.display();
}
void initBall(PRNG generator, vector<Ball>& balls, Ball& ball, set<Colr>& isColrs)
{
const vector<float> sizes = {
40,
40,
40,
40
};
const vector<Vector2f> positions = {
{ 5* sizes.at(0), 5 * sizes.at(0) },
{ WINDOW_WIDTH - 3 * sizes.at(1), WINDOW_HEIGHT - 12 * sizes.at(1) },
{ WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 },
{ WINDOW_WIDTH - 3 * sizes.at(3), WINDOW_HEIGHT - 3 * sizes.at(3) }
};
for (int i = 0; i < BALLS_COUNT; ++i)
{
balls.at(i).offset.x = random_index(generator, 250);
balls.at(i).offset.y = random_index(generator, 250);
balls.at(i).shape.setRadius(sizes.at(i));
balls.at(i).shape.setPosition(positions.at(i));
Colr colr = initColor(generator, isColrs);
balls.at(i).shape.setFillColor(sf::Color(colr.red, colr.green, colr.blue));
balls.at(i).shape.setOrigin(balls.at(i).shape.getRadius(), balls.at(i).shape.getRadius());
}
}
void init(PRNG generator, set<Colr>& isColrs, vector<Ball>& balls, Ball& ball)
{
initBall(generator, balls, ball, isColrs);
}
int main()
{
Clock clock;
ContextSettings settings;
RenderWindow window(VideoMode({WINDOW_WIDTH, WINDOW_HEIGHT}), WINDOW_TITLE, Style::Default, settings);
vector<Ball> balls(BALLS_COUNT);
PRNG generator;
Ball ball;
set<Colr> isColrs;
initGenerator(generator);
init(generator, isColrs, balls, ball);
while (window.isOpen())
{
float deltaTime = clock.restart().asSeconds();
pollEvents(window);
update(balls, deltaTime);
redrawFrame(window, balls);
}
}
Anybody help me please, where's i was wrong?