no operator "/" matches these operands

Ok.

trying to make player shoot 360 is there something wrong or misspelled?

#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>



using namespace sf;

int main()
{
    RenderWindow window(VideoMode(800, 600), "360 shooting object");

    CircleShape circle(25.f);
    circle.setFillColor(Color::White);

    Vector2f circleCenter;
    Vector2f mousePosWindow;
    Vector2f aimDirection;
    Vector2f aimDirectionNorm;

    while(window.isOpen())
    {
        Event event;
        while(window.pollEvent(event))
        {
            if(event.type==Event::Closed) window.close();
            if(Keyboard::isKeyPressed(Keyboard::Escape)) window.close();
        }

        draw(window, circle);

        update(window, circle, circleCenter, mousePosWindow, aimDirection, aimDirectionNorm);

    }
    return 0;
}

void update(RenderWindow &window, CircleShape &shape, Vector2f circleCenter, 
    Vector2f mousePosWindow, Vector2f aimDirection, Vector2f aimDirectionNorm)
{
    circleCenter = Vector2f(shape.getPosition().x + shape.getRadius(), 
        shape.getPosition().y + shape.getRadius());
    mousePosWindow = Vector2f(Mouse::getPosition(window));
    aimDirection = mousePosWindow - circleCenter;
    aimDirectionNorm = aimDirection / sqrt(pow(aimDirection.x, 2)) + sqrt(pow(aimDirection.y, 2));

}

im using sfml error at the aimDirectionNorm part no operator matches the '/' operand what wrong with the '/' operator i don't understand

i delete some code i

john

Firstly your math is wrong

aimDirectionNorm = aimDirection / sqrt(pow(aimDirection.x, 2)) + 
    sqrt(pow(aimDirection.y, 2));

should be

aimDirectionNorm = aimDirection / sqrt(pow(aimDirection.x, 2) + 
    pow(aimDirection.y, 2));

Secondly operator/ requires a Vector2f and a float but sqrt returns a double. Because Vector2f is a template the normal double to float conversion does not happen.

Simple way to get a float would be to use sqrtf and powf

aimDirectionNorm = aimDirection / sqrtf(powf(aimDirection.x, 2) + 
    powf(aimDirection.y, 2));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

error: no operator "<" matches these operands

IntelliSense: no operator "<<" matches these operands

Error: no operator "==" matches these operands

no operator ""<<"" matches these operands error

Error : no operator " != " matches these operands

no operator "=" matches these operands error

"no operator >> matches these operands"

C++ No operator [] matches these operands

No operator "<<" matches these operands - C++

No operator "[ ]" matches these operands C++

E0349 no operator ">>" matches these operands

No Operator = Matches Operands - DX11

C++ - Error - No operator "[]" matches these operands

more than one operator "[]" matches these operands

E0349 no operator "<<" matches these operands

no operator "<<" matches these operands recursive tower of hanoi error

No operator "<" matches these operands operand types are: double < my_class

Accessing an entry in std::map causes 'no operator "[]" matches these operands'

C++ - no operator "<<" matches these operands directory_iterator()

No operator ">=" matches these operands error in c++ when using while loop

No operator "+" matches these operands, aka cannot add Array<double> to double

C++) E0349 no operator matches these operands occured

No Operator ">>" matches these operands operand types are: std::istream>>int

no operator ">>" matches these operands -- operand types are: std::istream >> const double

no operator ">>" matches these operands operand types are: std::istream >> double*

no operator matches these operands; operand types are: std::istream >> const char [5]

No operator "<<" matches these operands error between an object and a string literal

Error during implementation of operator>> :C++ no operator matches these operands operand types are: std::istream >> const double error

No operator "=" matches these operands. I have overloaded it but it doesn't seem to be working properly