Wintermute Engine Forum
Wintermute Engine => Scripts, plugins, utilities, goodies => Topic started by: Jerrot on June 12, 2003, 10:54:56 PM

(http://wme.jerrot.de/images/new.gif) 20031219: Since WME supports math functions now, this library became obsolete. So now this thread is only a example how to create your own libraries with C++.
Hiya,
so  you're not just a game designer, but also a genius, right ? ;)
OK, here is your math functions dll for WME!
http://wme.jerrot.de/mathdll11.zip
Usage:
Example:
external "math.dll" cdecl double math_pow(double,double);
Game.Msg("pow(2,8) = " + math_pow(2,8));
Supported functions :
int math_abs(int mynumber)
double math_acos(double mynumber)
double math_asin(double mynumber)
double math_atan(double mynumber)
double math_atan2(double mynumber1, double mynumber2)
double math_cos(double mynumber)
double math_cosh(double mynumber)
double math_exp(double mynumber)
double math_fabs(double mynumber)
double math_fmod(double mynumber1, double mynumber2)
double math_log(double mynumber)
double math_log10(double mynumber)
double math_pow(double mynumber1, double mynumber2)
double math_sin(double mynumber)
double math_sinh(double mynumber)
double math_tan(double mynumber)
double math_tanh(double mynumber)
double math_sqrt(double mynumber)
double DegToRad(double mynumber)
double RadToDeg(double mynumber)
Version history:
20030612  [v1.0]
 initial release
20030613  [v1.1]
 added DegToRad() and RadToDeg()
C++ Sourcecode is included in the archive, but for the case my server burns up, here it is :
#include <math.h>
#define PI 3.1415926535f
extern "C" __declspec(dllexport) int math_abs(int mynumber)
{
return abs(mynumber);
}
extern "C" __declspec(dllexport) double math_acos(double mynumber)
{
return acos(mynumber);
}
extern "C" __declspec(dllexport) double math_asin(double mynumber)
{
return asin(mynumber);
}
extern "C" __declspec(dllexport) double math_atan(double mynumber)
{
return atan(mynumber);
}
extern "C" __declspec(dllexport) double math_atan2(double mynumber1, double mynumber2)
{
return atan2(mynumber1,mynumber2);
}
extern "C" __declspec(dllexport) double math_cos(double mynumber)
{
return cos(mynumber);
}
extern "C" __declspec(dllexport) double math_cosh(double mynumber)
{
return cosh(mynumber);
}
extern "C" __declspec(dllexport) double math_exp(double mynumber)
{
return exp(mynumber);
}
extern "C" __declspec(dllexport) double math_fabs(double mynumber)
{
return fabs(mynumber);
}
extern "C" __declspec(dllexport) double math_fmod(double mynumber1, double mynumber2)
{
return fmod(mynumber1,mynumber2);
}
extern "C" __declspec(dllexport) double math_log(double mynumber)
{
return log(mynumber);
}
extern "C" __declspec(dllexport) double math_log10(double mynumber)
{
return log10(mynumber);
}
extern "C" __declspec(dllexport) double math_pow(double mynumber1, double mynumber2)
{
return pow(mynumber1,mynumber2);
}
extern "C" __declspec(dllexport) double math_sin(double mynumber)
{
return sin(mynumber);
}
extern "C" __declspec(dllexport) double math_sinh(double mynumber)
{
return sinh(mynumber);
}
extern "C" __declspec(dllexport) double math_tan(double mynumber)
{
return tan(mynumber);
}
extern "C" __declspec(dllexport) double math_tanh(double mynumber)
{
return tanh(mynumber);
}
extern "C" __declspec(dllexport) double math_sqrt(double mynumber)
{
return sqrt(mynumber);
}
extern "C" __declspec(dllexport) double DegToRad(double mynumber)
{
return mynumber * (PI / 180.0f);
}
extern "C" __declspec(dllexport) double RadToDeg(double mynumber)
{
return mynumber * (180.0f / PI);
}
Have fun,
Jerrot!

it doesn't work for me. Wintermute gives me a compilation error (script error). I don't know how to use it.

it doesn't work for me. Wintermute gives me a compilation error (script error). I don't know how to use it.
1) You need at least the 1.0.022 version of WME (if you didn't already, please download the latest build)
2) Put Jerrot's math.dll to the same folder where is the wme.exe file
3) in a script, you need to declare the function you want to use, like the example above:
external "math.dll" cdecl double math_pow(double,double);
4) Now you can call the math_pow function from the script, e.g.
Game.Msg("pow(2,8) = " + math_pow(2,8));

Slightly offtopic again :[
But are you Jerrot going to release other "libraries" to WME, do you have any plans?

Slightly offtopic again :[
Slightly ?? ;)
But are you Jerrot going to release other "libraries" to WME, do you have any plans?
[offtopic]
Ehm  I am not a "real coder" ! I just tried this one because McCoy asked for it  and it's just include, copy, paste! So there are no plans  but I start off scripting my own game soon, therefore I'm sure I will need some strange features again... 8)
If you have any ideas for future releases  just tell us your ideas in the wishlist board, I'm always looking for new ideas... ;)
[/offtopic]

v1.1 released (added DegToRad() and RadToDeg() ), see above.

Nice Work.
Thank you for that GREAT Plugin ;)
Take a look at http://adan.iefactory.com/wintermute/mates.htm

Take a look at http://adan.iefactory.com/wintermute/mates.htm
Wow, it even seems to be better described than I did... ;D

Deleted the file from my server and updated subject and the first message in this thread (see above).