Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: fatal error: Mouse.hpp: No such file or directory  (Read 1973 times)

0 Members and 1 Guest are viewing this topic.

deekee

  • Newbie
  • *
  • Posts: 1
    • View Profile
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:

[ 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
 


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)
{
    // &#1048;&#1089;&#1087;&#1086;&#1083;&#1100;&#1079;&#1091;&#1077;&#1084; &#1074;&#1088;&#1077;&#1084;&#1103; &#1089; 1 &#1103;&#1085;&#1074;&#1072;&#1088;&#1103; 1970 &#1075;&#1086;&#1076;&#1072; &#1074; &#1089;&#1077;&#1082;&#1091;&#1085;&#1076;&#1072;&#1093; &#1082;&#1072;&#1082; &#1089;&#1083;&#1091;&#1095;&#1072;&#1081;&#1085;&#1086;&#1077; &#1079;&#1077;&#1088;&#1085;&#1086;
    const unsigned seed = unsigned(std::time(nullptr));
    generator.engine.seed(seed);
}

// &#1043;&#1077;&#1085;&#1077;&#1088;&#1080;&#1088;&#1091;&#1077;&#1090; &#1080;&#1085;&#1076;&#1077;&#1082;&#1089; &#1074; &#1076;&#1080;&#1072;&#1087;&#1072;&#1079;&#1086;&#1085;&#1077; [0, size)
size_t random_index(PRNG& generator, int size)
{
    // &#1057;&#1086;&#1079;&#1076;&#1072;&#1105;&#1084; &#1088;&#1072;&#1089;&#1087;&#1088;&#1077;&#1076;&#1077;&#1083;&#1077;&#1085;&#1080;&#1077;
    std::uniform_int_distribution<int> distribution(0, size - 1);
   
    // &#1042;&#1099;&#1095;&#1080;&#1089;&#1083;&#1103;&#1077;&#1084; &#1087;&#1089;&#1077;&#1074;&#1076;&#1086;&#1089;&#1083;&#1091;&#1095;&#1072;&#1081;&#1085;&#1086;&#1077; &#1095;&#1080;&#1089;&#1083;&#1086;: &#1074;&#1099;&#1079;&#1086;&#1074;&#1077;&#1084; &#1088;&#1072;&#1089;&#1087;&#1088;&#1077;&#1076;&#1077;&#1083;&#1077;&#1085;&#1080;&#1077; &#1082;&#1072;&#1082; &#1092;&#1091;&#1085;&#1082;&#1094;&#1080;&#1102;,
    //  &#1087;&#1077;&#1088;&#1077;&#1076;&#1072;&#1074; &#1075;&#1077;&#1085;&#1077;&#1088;&#1072;&#1090;&#1086;&#1088; &#1087;&#1088;&#1086;&#1080;&#1079;&#1074;&#1086;&#1083;&#1100;&#1085;&#1099;&#1093; &#1094;&#1077;&#1083;&#1099;&#1093; &#1095;&#1080;&#1089;&#1077;&#1083; &#1082;&#1072;&#1082; &#1072;&#1088;&#1075;&#1091;&#1084;&#1077;&#1085;&#1090;.
    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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: fatal error: Mouse.hpp: No such file or directory
« Reply #1 on: November 06, 2017, 05:28:35 pm »
Since you're using C++ you should first understand how the language and its tools work. You can't just randomly include a header and think it will just work.

SFML/Mouse.hpp simply does not exist.
But since you include SFML/Window.hpp you already get access to the mouse class anyways. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything