[COMPLETED 075A] Sin, cos, tan
[COMPLETED 075A] Sin, cos, tan
It would be really useful to be able to use the trigonometrical functions (or whatever they are called) sin, cos, and tan in scripting. At least I didn't find any way to use them, so I guess they're not there.
Pain is only psychological.
that's a very good point.
(bookmarks this page for RF2)
(bookmarks this page for RF2)
RF2 site: http://realityfactory2.sourceforge.net/
RF2 tasks: http://sourceforge.net/pm/?group_id=179085
RF2 tasks: http://sourceforge.net/pm/?group_id=179085
RFwithPhysics never officially came out so these kin of commands weren't implemented in the current source.
If QoD wants to add them here's the command (you will probably have to change some variable's name):
The code is by Nout naturally.
If QoD wants to add them here's the command (you will probably have to change some variable's name):
Code: Select all
case 119: //value = Math(Function, Value1);
//value = Math(Function, Value1,Value2);
{
strcpy(string1, arguments[0].str());
if (!stricmp(string1,"abs"))
{
PARMCHECK(2);
returnValue = (int)(abs(arguments[1].intValue()));
}
else if (!stricmp(string1,"fabs"))
{
PARMCHECK(2);
returnValue = (float)(fabs(arguments[1].floatValue()));
}
else if (!stricmp(string1,"ceil"))
{
PARMCHECK(2);
returnValue = (int)(ceil(arguments[1].floatValue()));
}
else if (!stricmp(string1,"floor"))
{
PARMCHECK(2);
returnValue = (int)(floor(arguments[1].floatValue()));
}
else if (!stricmp(string1,"mod"))
{
PARMCHECK(3);
returnValue = (float)(fmod(arguments[1].floatValue(), arguments[2].floatValue()));
}
else if (!stricmp(string1,"sqrt"))
{
PARMCHECK(2);
returnValue = (float)(sqrt(arguments[1].floatValue()));
}
else if (!stricmp(string1,"min"))
{
int val1 = arguments[1].intValue();
if(arguments.entries()>2)
{
for(int i=2; i < int(arguments.entries()); i++)
{
int val2 = arguments[i].intValue();
if (val1 > val2)
val1 = val2;
}
}
returnValue = (int)val1;
}
else if (!stricmp(string1,"max"))
{
int val1 = arguments[1].intValue();
if(arguments.entries()>2)
{
for(int i=2; i < int(arguments.entries()); i++)
{
int val2 = arguments[i].intValue();
if (val1 < val2)
val1 = val2;
}
}
returnValue = (int)val1;
}
else if (!stricmp(string1,"fmin"))
{
float val1 = arguments[1].floatValue();
if(arguments.entries()>2)
{
for(int i=2; i < int(arguments.entries()); i++)
{
float val2 = arguments[i].floatValue();
if (val1 > val2)
val1 = val2;
}
}
returnValue = (float)val1;
}
else if (!stricmp(string1,"fmax"))
{
float val1 = arguments[1].floatValue();
if(arguments.entries()>2)
{
for(int i=2; i < int(arguments.entries()); i++)
{
float val2 = arguments[i].floatValue();
if (val1 < val2)
val1 = val2;
}
}
returnValue = (float)val1;
}
else if (!stricmp(string1,"pow"))
{
PARMCHECK(3);
returnValue = (float)(pow(arguments[1].floatValue(), arguments[2].floatValue()));
}
else if (!stricmp(string1,"cos"))
{
PARMCHECK(2);
returnValue = (float)(cos(arguments[1].floatValue()));
}
else if (!stricmp(string1,"sin"))
{
PARMCHECK(2);
returnValue = (float)(sin(arguments[1].floatValue()));
}
else if (!stricmp(string1,"tan"))
{
PARMCHECK(2);
returnValue = (float)(tan(arguments[1].floatValue()));
}
else if (!stricmp(string1,"acos"))
{
PARMCHECK(2);
returnValue = (float)(acos(arguments[1].floatValue()));
}
else if (!stricmp(string1,"asin"))
{
PARMCHECK(2);
returnValue = (float)(sin(arguments[1].floatValue()));
}
else if (!stricmp(string1,"atan"))
{
PARMCHECK(2);
returnValue = (float)(tan(arguments[1].floatValue()));
}
else if (!stricmp(string1,"atoi"))
{
PARMCHECK(2);
returnValue = (int)(atoi(arguments[1].str()));
}
else if (!stricmp(string1,"atof"))
{
PARMCHECK(2);
returnValue = (float)(atof(arguments[1].str()));
}
else
{
char szBug[128];
sprintf(szBug,"Math function %s does not exist!",string1);
CCD->Engine()->ReportError(szBug, true);
exit(0);
}
return true;
}