samedi 7 janvier 2023

No operator "+=" matches these operands [duplicate]

So I am making physics engine and I have written my own math.h file and it is giving me error when I use few operators between vectors and floats..

It should just apply force on entities from list but it is giving error.

Here is my math.h file

#ifndef MATH_H
#define MATH_H

struct vec2
{
    float x, y;
};

inline
vec2 operator-(vec2 &a)
{
    vec2 c = {};

    c.x = -a.x;
    c.y = -a.y;

    return c;
}

inline 
vec2 operator+(vec2 &a, vec2 &b)
{
    vec2 c = {};

    c.x = a.x + b.x;
    c.y = a.y + b.y;

    return c;
}

inline
vec2 operator-(vec2 &a, vec2 &b)
{
    vec2 c = {};

    c.x = a.x - b.x;
    c.y = a.y - b.y;

    return c;
}

inline
vec2 operator*(vec2 &a, vec2 &b)
{
    vec2 c = {};

    c.x = a.x * b.x;
    c.y = a.y * b.y;

    return c;
}

inline
vec2 operator*(float &a, vec2 &b)
{
    vec2 c = {};

    c.x = a * b.x;
    c.y = a * b.y;

    return c;
}

inline
vec2 operator*(vec2 &a, float &b)
{
    vec2 c = {};

    c.x = a.x * b;
    c.y = a.y * b;

    return c;
}


inline
vec2 operator/(vec2 &a, vec2 &b)
{
    vec2 c = {};

    c.x = a.x / b.x;
    c.y = a.y / b.y;

    return c;
}

inline
vec2 operator/(vec2 &a, float &b)
{
    vec2 c = {};

    c.x = a.x / b;
    c.y = a.y / b;

    return c;
}

inline
vec2 operator/(float &a, vec2 &b)
{
    vec2 c = {};

    c.x = b.x / a;
    c.y = b.y / a;

    return c;
}

inline
vec2 operator+=(vec2& a, vec2& b)
{
    vec2 c = {};
    a.x += b.x;
    a.y += b.y;

    return c;
}

inline
vec2 operator+=(float a, vec2& b)
{
    vec2 c = {};
    a += b.x;
    a += b.y;

    return c;
}

inline
vec2 operator+=(vec2& a, float b)
{
    vec2 c = {};
    a.x += b;
    a.y += b;

    return c;
}




#endif

Here is my entity struct :

struct Entity
{
    vec2 Position, Velocity, Force;
    float Mass;
};

Here is my loop where I get bug :


for (int i = 0; i < entites.size(); i++)
    {
        entites[i].Force += entites[i].Mass * Gravity;

    }

I thought it would apply force to objects but it is giving me bug..

Aucun commentaire:

Enregistrer un commentaire