🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Simple Math Library

Started by
6 comments, last by Trikko 16 years, 9 months ago
Hello! I'm writing an app using angelscript as script system. I need to provide commons math function to user. Does it exists a library I can include? (providing for example sin, cos, rand... etc..?) Thank you, A. Fontana
Advertisement
Just register the standard functions from math.h :)

Example:

	r = engine->RegisterGlobalFunction("float sin(float)", asFUNCTION(sinf), asCALL_CDECL); assert( r >= 0 );	r = engine->RegisterGlobalFunction("float cos(float)", asFUNCTION(cosf), asCALL_CDECL); assert( r >= 0 );


Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Quote: Original post by WitchLord
Just register the standard functions from math.h :)

Example:

	r = engine->RegisterGlobalFunction("float sin(float)", asFUNCTION(sinf), asCALL_CDECL); assert( r >= 0 );	r = engine->RegisterGlobalFunction("float cos(float)", asFUNCTION(cosf), asCALL_CDECL); assert( r >= 0 );


Regards,
Andreas


Thank you. :) I thought there was a pre-made bind (or an internal version) of these. Your scripting system works really good, and it's fast too. I call it hundred of times for seconds on my AI app :)

A. Fontana
I've not gotten around to write a lot of add-ons, but this is definitely a good candidate for a future add-on.

Another good one, would be a good 3D math package, with support for vectors, matrices, etc. The vector and matrix classes should of course be compatible with D3D and OpenGL (maybe two different packages to take care of that).

Thanks for the compliments. I've worked hard to make it as good as I can. There is still a lot more that can be done though, even in the performance department. Let me know if there's something you feel is missing.

If you feel like presenting your project to the public I'd be more than happy to link to it from the AngelScript user's page.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

It complains about function overload... sin, cos etc have actually some overload version for float, double etc... I need float only... I know a bad workaround: write a wrapper function. Does it exists a better and clean way to select one of overloads?

A. Fontana
Who's complaining? AngelScript or C++?

If it is C++ you can pick the specific function by using the asFUNCTIONPR() macro, i.e. asFUNCTIONPR(sin, (float), float).

Also, the float version usually have an f appended to the name, i.e. sinf, cosf, etc. You should be able to use those directly without any overload conflicts.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This post is old, but in case you hadn't noticed already, I've now written an add-on that registers the math functions from the standard C library. It's available in the 2.9.1 release that you can find on the site.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Good news, then I'll update my genetic arm code soon.

PS: I see my nick on 2.10.0 changelog... ;)

Thank you,
Andrea Fontana

This topic is closed to new replies.

Advertisement