Advertisement Jump to content
Sign in to follow this  
wilberolive

Math Conversion Problems

This topic is 1792 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to use my own Vector class and am running into issues.

 

I have two functions in my Vector class that allow it to multiple with a float in any order like this.

friend Vector operator+ (const Vector& t, float f) {return Vector(t.x+f,t.y+f,t.z+f);}
friend Vector operator+ (float f, const Vector& t) {return Vector(t.x+f,t.y+f,t.z+f);}

I don't know how to register this with AngelScript so that I can multiple a Vector with a float in any order. I've tried registering it like this, but it gives an error that it failed to register the second function. I'm guessing because I've declared opMul already with the same declaration?

engine->RegisterObjectMethod("Vector", "Vector opMul(float f)", asFUNCTIONPR(operator*, (const Vector&, float), Vector), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod("Vector", "Vector opMul(float f)", asFUNCTIONPR(operator*, (float, const Vector&), Vector), asCALL_CDECL_OBJLAST);

If I comment out either line above, so I'm only registering one of the functions (doesn't matter which one), then it works in script in the order of Vector * float. But it fails if I try to do float * Vector. I get an error that says "No conversion from 'Vector' to math type available."

 

How can I set up my Vector class so I can multiply if by a float in any order, i.e. Vector * float or float * Vector?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!