|
@@ -29,6 +29,11 @@
|
|
#include "math/mathTypes.h"
|
|
#include "math/mathTypes.h"
|
|
#include "math/mRandom.h"
|
|
#include "math/mRandom.h"
|
|
|
|
|
|
|
|
+#include "vector_ScriptBinding.h"
|
|
|
|
+#include "matrix_ScriptBinding.h"
|
|
|
|
+#include "random_ScriptBinding.h"
|
|
|
|
+#include "box_ScriptBinding.h"
|
|
|
|
+
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// TypePoint2I
|
|
// TypePoint2I
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////
|
|
@@ -344,375 +349,5 @@ ConsoleSetType( TypeBox3F )
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-//----------------------------------------------------------------------------
|
|
|
|
-
|
|
|
|
-ConsoleFunctionGroupBegin( VectorMath, "Vector manipulation functions.");
|
|
|
|
-
|
|
|
|
-ConsoleFunction( VectorAdd, const char*, 3, 3, "( vecA , vecB ) Use the VectorAdd function to add two vectors of up to three elements each to each other\n"
|
|
|
|
- "@param vecA A vector of up to three elements.\n"
|
|
|
|
- "@param vecB A vector of up to three elements.\n"
|
|
|
|
- "@return Returns the result of vecA + vecB.\n"
|
|
|
|
- "@sa vectorSub")
|
|
|
|
-{
|
|
|
|
- VectorF v1(0,0,0),v2(0,0,0);
|
|
|
|
- dSscanf(argv[1],"%g %g %g",&v1.x,&v1.y,&v1.z);
|
|
|
|
- dSscanf(argv[2],"%g %g %g",&v2.x,&v2.y,&v2.z);
|
|
|
|
- VectorF v;
|
|
|
|
- v = v1 + v2;
|
|
|
|
- char* returnBuffer = Con::getReturnBuffer(256);
|
|
|
|
- dSprintf(returnBuffer,256,"%g %g %g",v.x,v.y,v.z);
|
|
|
|
- return returnBuffer;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunction( VectorSub, const char*, 3, 3, "( vecA , vecB ) Use the VectorSub function to subtract vecB from vecA.\n"
|
|
|
|
- "@param vecA Left side vector in subtraction equation.\n"
|
|
|
|
- "@param vecB Right side vector in subtraction equation.\n"
|
|
|
|
- "@return Returns a new vector equivalent to: \"vecA - vecB\".\n"
|
|
|
|
- "@sa vectorAdd")
|
|
|
|
-{
|
|
|
|
- VectorF v1(0,0,0),v2(0,0,0);
|
|
|
|
- dSscanf(argv[1],"%g %g %g",&v1.x,&v1.y,&v1.z);
|
|
|
|
- dSscanf(argv[2],"%g %g %g",&v2.x,&v2.y,&v2.z);
|
|
|
|
- VectorF v;
|
|
|
|
- v = v1 - v2;
|
|
|
|
- char* returnBuffer = Con::getReturnBuffer(256);
|
|
|
|
- dSprintf(returnBuffer,256,"%g %g %g",v.x,v.y,v.z);
|
|
|
|
- return returnBuffer;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunction( VectorScale, const char*, 3, 3, "( vec , scale ) Use the VectorScale function to scale the vector vec by the scalar scale.\n"
|
|
|
|
- "@param vec A vector of up to three elements.\n"
|
|
|
|
- "@param scale A numeric value (integer or floating-point) representing the scaling factor.\n"
|
|
|
|
- "@return Returns a scaled version of the vector vec, equivalent to: ( scale * X ) ( scale * Y ) ( scale * Z )\".\n"
|
|
|
|
- "@sa VectorNormalize")
|
|
|
|
-{
|
|
|
|
- VectorF v(0,0,0);
|
|
|
|
- dSscanf(argv[1],"%g %g %g",&v.x,&v.y,&v.z);
|
|
|
|
- v *= dAtof(argv[2]);
|
|
|
|
- char* returnBuffer = Con::getReturnBuffer(256);
|
|
|
|
- dSprintf(returnBuffer,256,"%g %g %g",v.x,v.y,v.z);
|
|
|
|
- return returnBuffer;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunction( VectorNormalize, const char*, 2, 2, "( vec ) Use the VectorNormalize function to calculated the unit vector equivalent of the vector vec.\n"
|
|
|
|
- "@param vec A vector of up to three elements.\n"
|
|
|
|
- "@return Returns the unit vector equivalent of the vector vec.\n"
|
|
|
|
- "@sa VectorScale")
|
|
|
|
-{
|
|
|
|
- VectorF v(0,0,0);
|
|
|
|
- dSscanf(argv[1],"%g %g %g",&v.x,&v.y,&v.z);
|
|
|
|
- if (v.len() != 0)
|
|
|
|
- v.normalize();
|
|
|
|
- char* returnBuffer = Con::getReturnBuffer(256);
|
|
|
|
- dSprintf(returnBuffer,256,"%g %g %g",v.x,v.y,v.z);
|
|
|
|
- return returnBuffer;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunction( VectorDot, F32, 3, 3, "( vecA , vecB ) Use the VectorCross function to calculate the dot product of two unit vectors of up to three elements each. Warning! Be sure to always normalize both vecA and vecB before attempting to find the dot product. Calculating a dot product using un-normalized vectors (non- unit vectors) will result in meaningless results.\n"
|
|
|
|
- "If the return value is < 0, the inner-angle between the vectors is > 90 degrees. If the return value is == 0, the inner-angle between the vectors is == 90 degrees. If the return value is > 0, the inner-angle between the vectors is < 90 degrees.\n"
|
|
|
|
- "@param vecA A unit-vector of up to three elements.\n"
|
|
|
|
- "@param vecB A unit-vector of up to three elements.\n"
|
|
|
|
- "@return Returns a scalar value equal to the result of vecA . vecB. This value which will always be a single floating-point value in the range [ -1 , +1 ].\n"
|
|
|
|
- "@sa VectorCross")
|
|
|
|
-{
|
|
|
|
- VectorF v1(0,0,0),v2(0,0,0);
|
|
|
|
- dSscanf(argv[1],"%g %g %g",&v1.x,&v1.y,&v1.z);
|
|
|
|
- dSscanf(argv[2],"%g %g %g",&v2.x,&v2.y,&v2.z);
|
|
|
|
- return mDot(v1,v2);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunction(VectorCross, const char*, 3, 3, "( vecA , vecB ) Use the VectorCross function to calculate the cross product of two vectors of up to three elements each.\n"
|
|
|
|
- "Remember, the resultant vector will always be an right angles (orthogonal) to both input vectors.\n"
|
|
|
|
- "@param vecA A vector of up to three elements.\n"
|
|
|
|
- "@param vecB A vector of up to three elements.\n"
|
|
|
|
- "@return Returns the result of vecA x vecB.\n"
|
|
|
|
- "@sa VectorDot")
|
|
|
|
-{
|
|
|
|
- VectorF v1(0,0,0),v2(0,0,0);
|
|
|
|
- dSscanf(argv[1],"%g %g %g",&v1.x,&v1.y,&v1.z);
|
|
|
|
- dSscanf(argv[2],"%g %g %g",&v2.x,&v2.y,&v2.z);
|
|
|
|
- VectorF v;
|
|
|
|
- mCross(v1,v2,&v);
|
|
|
|
- char* returnBuffer = Con::getReturnBuffer(256);
|
|
|
|
- dSprintf(returnBuffer,256,"%g %g %g",v.x,v.y,v.z);
|
|
|
|
- return returnBuffer;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunction(VectorDist, F32, 3, 3, "( vecA , vecB ) Use the VectorDist function to calculate distance between two vectors of up to three elements each.\n"
|
|
|
|
- "@param vecA A vector of up to three elements.\n"
|
|
|
|
- "@param vecB A vector of up to three elements.\n"
|
|
|
|
- "@return Returns the result of \" |Xa - Xb| |Ya - Yb| |Za - Zb| \".\n"
|
|
|
|
- "@sa VectorLen")
|
|
|
|
-{
|
|
|
|
- VectorF v1(0,0,0),v2(0,0,0);
|
|
|
|
- dSscanf(argv[1],"%g %g %g",&v1.x,&v1.y,&v1.z);
|
|
|
|
- dSscanf(argv[2],"%g %g %g",&v2.x,&v2.y,&v2.z);
|
|
|
|
- VectorF v = v2 - v1;
|
|
|
|
- return mSqrt((v.x * v.x) + (v.y * v.y) + (v.z * v.z));
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunction(VectorLen, F32, 2, 2, "( vec ) Use the VectorLen function to calculate the length of vector vec.\n"
|
|
|
|
- "@param vec A vector of up to three elements.\n"
|
|
|
|
- "@return Returns a scalar representing the length of the vector vec.\n"
|
|
|
|
- "@sa VectorDist")
|
|
|
|
-{
|
|
|
|
- VectorF v(0,0,0);
|
|
|
|
- dSscanf(argv[1],"%g %g %g",&v.x,&v.y,&v.z);
|
|
|
|
- return mSqrt((v.x * v.x) + (v.y * v.y) + (v.z * v.z));
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunction( VectorOrthoBasis, const char*, 2, 2, "( vec ) Use the VectorOrthoBasis function to calculate a 3x3 Row-Major formated matrix representing the orthogonal basis for the vector vec.\n"
|
|
|
|
- "@param vec A four element vector of the form \"AxisX AxisY AxisZ theta\", where theta is the angle of rotation about the vector formed by the prior three values.\n"
|
|
|
|
- "@return Returns a 3x3 Row-Major formated matrix")
|
|
|
|
-{
|
|
|
|
- AngAxisF aa;
|
|
|
|
- dSscanf(argv[1],"%g %g %g %g", &aa.axis.x,&aa.axis.y,&aa.axis.z,&aa.angle);
|
|
|
|
- MatrixF mat;
|
|
|
|
- aa.setMatrix(&mat);
|
|
|
|
- Point3F col0, col1, col2;
|
|
|
|
- mat.getColumn(0, &col0);
|
|
|
|
- mat.getColumn(1, &col1);
|
|
|
|
- mat.getColumn(2, &col2);
|
|
|
|
- char* returnBuffer = Con::getReturnBuffer(256);
|
|
|
|
- dSprintf(returnBuffer,256,"%g %g %g %g %g %g %g %g %g",
|
|
|
|
- col0.x, col0.y, col0.z, col1.x, col1.y, col1.z, col2.x, col2.y, col2.z);
|
|
|
|
- return returnBuffer;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunctionGroupEnd(VectorMath);
|
|
|
|
-
|
|
|
|
-ConsoleFunctionGroupBegin(MatrixMath, "Matrix manipulation functions.");
|
|
|
|
-
|
|
|
|
-ConsoleFunction( MatrixCreate, const char*, 3, 3, "( posVec , rotVec ) Use the matrixCreate function to create a transform matrix from a three-element floating-point translation vector and a four-element floating-point rotation vector.\n"
|
|
|
|
- "@param posVec A three-element floating-point translation vector: \"PosX PosY PosZ\".\n"
|
|
|
|
- "@param rotVec A four-element floating-point rotation vector: \"RotX RotY RotZ\".\n"
|
|
|
|
- "@param These re rotations about the specified axes.\n"
|
|
|
|
- "@return Returns a transform matrix of the form \"PosX PosY PosZ RotX RotY RotZ theta\".\n"
|
|
|
|
- "@sa MatrixCreateFromEuler")
|
|
|
|
-{
|
|
|
|
- Point3F pos;
|
|
|
|
- dSscanf(argv[1], "%g %g %g", &pos.x, &pos.y, &pos.z);
|
|
|
|
-
|
|
|
|
- AngAxisF aa(Point3F(0,0,0),0);
|
|
|
|
- dSscanf(argv[2], "%g %g %g %g", &aa.axis.x, &aa.axis.y, &aa.axis.z, &aa.angle);
|
|
|
|
- aa.angle = mDegToRad(aa.angle);
|
|
|
|
-
|
|
|
|
- char* returnBuffer = Con::getReturnBuffer(256);
|
|
|
|
- dSprintf(returnBuffer, 255, "%g %g %g %g %g %g %g",
|
|
|
|
- pos.x, pos.y, pos.z,
|
|
|
|
- aa.axis.x, aa.axis.y, aa.axis.z,
|
|
|
|
- aa.angle);
|
|
|
|
- return returnBuffer;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunction( MatrixCreateFromEuler, const char*, 2, 2, " ( rotVec ) Use the MatrixCreateFromEuler function to calculate a transform matrix from a three-element floating-point rotation vector.\n"
|
|
|
|
- "@param rotVec A three-element floating-point rotation vector: \"RotX RotY RotZ\". These are rotations about the specified axes.\n"
|
|
|
|
- "@return Returns a transform matrix of the form \"0 0 0 X Y Z theta\".\n"
|
|
|
|
- "@sa MatrixCreate")
|
|
|
|
-{
|
|
|
|
- EulerF rot;
|
|
|
|
- dSscanf(argv[1], "%g %g %g", &rot.x, &rot.y, &rot.z);
|
|
|
|
-
|
|
|
|
- QuatF rotQ(rot);
|
|
|
|
- AngAxisF aa;
|
|
|
|
- aa.set(rotQ);
|
|
|
|
-
|
|
|
|
- char* ret = Con::getReturnBuffer(256);
|
|
|
|
- dSprintf(ret, 255, "0 0 0 %g %g %g %g",aa.axis.x,aa.axis.y,aa.axis.z,aa.angle);
|
|
|
|
- return ret;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-ConsoleFunction( MatrixMultiply, const char*, 3, 3, "( transformA , transformB ) Use the MatrixMultiply function to multiply two seven-element transform matrices to produce a new seven element matrix.\n"
|
|
|
|
- "@param transformA A seven-element transform matrix of the form \"PosX PosY PosZ RotX RotY RotZ theta\".\n"
|
|
|
|
- "@param transformB A seven-element transform matrix of the form \"PosX PosY PosZ RotX RotY RotZ theta\".\n"
|
|
|
|
- "@return Returns a seven-element matrix resulting from transiformA x transformB.\n"
|
|
|
|
- "@sa MatrixMulPoint, MatrixMulVector")
|
|
|
|
-{
|
|
|
|
- Point3F pos1;
|
|
|
|
- AngAxisF aa1(Point3F(0,0,0),0);
|
|
|
|
- dSscanf(argv[1], "%g %g %g %g %g %g %g", &pos1.x, &pos1.y, &pos1.z, &aa1.axis.x, &aa1.axis.y, &aa1.axis.z, &aa1.angle);
|
|
|
|
-
|
|
|
|
- MatrixF temp1(true);
|
|
|
|
- aa1.setMatrix(&temp1);
|
|
|
|
- temp1.setColumn(3, pos1);
|
|
|
|
-
|
|
|
|
- Point3F pos2;
|
|
|
|
- AngAxisF aa2(Point3F(0,0,0),0);
|
|
|
|
- dSscanf(argv[2], "%g %g %g %g %g %g %g", &pos2.x, &pos2.y, &pos2.z, &aa2.axis.x, &aa2.axis.y, &aa2.axis.z, &aa2.angle);
|
|
|
|
-
|
|
|
|
- MatrixF temp2(true);
|
|
|
|
- aa2.setMatrix(&temp2);
|
|
|
|
- temp2.setColumn(3, pos2);
|
|
|
|
-
|
|
|
|
- temp1.mul(temp2);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- Point3F pos;
|
|
|
|
- AngAxisF aa(temp1);
|
|
|
|
-
|
|
|
|
- aa.axis.normalize();
|
|
|
|
- temp1.getColumn(3, &pos);
|
|
|
|
-
|
|
|
|
- char* ret = Con::getReturnBuffer(256);
|
|
|
|
- dSprintf(ret, 255, "%g %g %g %g %g %g %g",
|
|
|
|
- pos.x, pos.y, pos.z,
|
|
|
|
- aa.axis.x, aa.axis.y, aa.axis.z,
|
|
|
|
- aa.angle);
|
|
|
|
- return ret;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-ConsoleFunction( MatrixMulVector, const char*, 3, 3, "( transform , vector ) Use the MatrixMulVector function to multiply a seven-element transform matrix with a three-element matrix.\n"
|
|
|
|
- "@param transform A seven-element transform matrix of the form \"PosX PosY PosZ RotX RotY RotZ theta\".\n"
|
|
|
|
- "@param vector A three-element vector.\n"
|
|
|
|
- "@return Returns three-element resulting from vector * transform.\n"
|
|
|
|
- "@sa MatrixMulPoint, MatrixMultiply")
|
|
|
|
-{
|
|
|
|
- Point3F pos1;
|
|
|
|
- AngAxisF aa1(Point3F(0,0,0),0);
|
|
|
|
- dSscanf(argv[1], "%g %g %g %g %g %g %g", &pos1.x, &pos1.y, &pos1.z, &aa1.axis.x, &aa1.axis.y, &aa1.axis.z, &aa1.angle);
|
|
|
|
-
|
|
|
|
- MatrixF temp1(true);
|
|
|
|
- aa1.setMatrix(&temp1);
|
|
|
|
- temp1.setColumn(3, pos1);
|
|
|
|
-
|
|
|
|
- Point3F vec1;
|
|
|
|
- dSscanf(argv[2], "%g %g %g", &vec1.x, &vec1.y, &vec1.z);
|
|
|
|
-
|
|
|
|
- Point3F result;
|
|
|
|
- temp1.mulV(vec1, &result);
|
|
|
|
-
|
|
|
|
- char* ret = Con::getReturnBuffer(256);
|
|
|
|
- dSprintf(ret, 255, "%g %g %g", result.x, result.y, result.z);
|
|
|
|
- return ret;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunction( MatrixMulPoint, const char*, 3, 3, "( transform , point ) Use the MatrixMulPoint function to multiply a seven element transform matrix by a three element point vector, producing a three element position vector.\n"
|
|
|
|
- "@param transform A seven-element transform matrix.\n"
|
|
|
|
- "@param point A three-element point/position vector.\n"
|
|
|
|
- "@return Returns a three-element position vector.\n"
|
|
|
|
- "@sa MatrixMultiply, MatrixMulVector")
|
|
|
|
-{
|
|
|
|
- Point3F pos1;
|
|
|
|
- AngAxisF aa1(Point3F(0,0,0),0);
|
|
|
|
- dSscanf(argv[1], "%g %g %g %g %g %g %g", &pos1.x, &pos1.y, &pos1.z, &aa1.axis.x, &aa1.axis.y, &aa1.axis.z, &aa1.angle);
|
|
|
|
-
|
|
|
|
- MatrixF temp1(true);
|
|
|
|
- aa1.setMatrix(&temp1);
|
|
|
|
- temp1.setColumn(3, pos1);
|
|
|
|
-
|
|
|
|
- Point3F vec1;
|
|
|
|
- dSscanf(argv[2], "%g %g %g", &vec1.x, &vec1.y, &vec1.z);
|
|
|
|
-
|
|
|
|
- Point3F result;
|
|
|
|
- temp1.mulP(vec1, &result);
|
|
|
|
-
|
|
|
|
- char* ret = Con::getReturnBuffer(256);
|
|
|
|
- dSprintf(ret, 255, "%g %g %g", result.x, result.y, result.z);
|
|
|
|
- return ret;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunctionGroupEnd(MatrixMath);
|
|
|
|
-
|
|
|
|
//------------------------------------------------------------------------------
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
-ConsoleFunction( getBoxCenter, const char*, 2, 2, "( box ) Use the getBoxCenter function to find the centroid of a cube (box).\n"
|
|
|
|
- "@param box A vector containing two three-element floating-point position vectors: \"X1 Y1 Z1 X2 Y2 Z2\".\n"
|
|
|
|
- "@return Returns a vector containing a three-element floating-point position vector equal to the centroid of the area defined by box")
|
|
|
|
-{
|
|
|
|
- Box3F box;
|
|
|
|
- box.mMin.set(0,0,0);
|
|
|
|
- box.mMax.set(0,0,0);
|
|
|
|
- dSscanf(argv[1],"%g %g %g %g %g %g",
|
|
|
|
- &box.mMin.x,&box.mMin.y,&box.mMin.z,
|
|
|
|
- &box.mMax.x,&box.mMax.y,&box.mMax.z);
|
|
|
|
- Point3F p;
|
|
|
|
- box.getCenter(&p);
|
|
|
|
- char* returnBuffer = Con::getReturnBuffer(256);
|
|
|
|
- dSprintf(returnBuffer,256,"%g %g %g",p.x,p.y,p.z);
|
|
|
|
- return returnBuffer;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-//------------------------------------------------------------------------------
|
|
|
|
-ConsoleFunctionGroupBegin(RandomNumbers, "Functions relating to the generation of random numbers.");
|
|
|
|
-
|
|
|
|
-ConsoleFunction(setRandomSeed, void, 1, 2, "( startSeed ) Use the setRandomSeed function to initialize the random number generator with the initial seed of startSeed.\n"
|
|
|
|
- "@param startSeed The new starting seed value for the random generator.\n"
|
|
|
|
- "@return No return value.\n"
|
|
|
|
- "@sa getRandom, getRandomSeed")
|
|
|
|
-{
|
|
|
|
- U32 seed = Platform::getRealMilliseconds();
|
|
|
|
- if (argc == 2)
|
|
|
|
- seed = dAtoi(argv[1]);
|
|
|
|
- RandomLCG::setGlobalRandSeed(seed);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunction(getRandomSeed, S32, 1, 1, "() Use the getRandomSeed function to get the current seed for the random generator.\n"
|
|
|
|
- "You can re-seed the generator with this value to allow you to recreate a random sequence. Merely save the seed and execute your random sequence. Later, to reproduce this sequence re-seed the generator with setRandomSeed and your saved value. Then, the generator will produce the same random sequence that followed the call to getRandomSeed.\n"
|
|
|
|
- "@return Returns an integer value representing the current seed of the random generator.\n"
|
|
|
|
- "@sa getRandom, setRandomSeed")
|
|
|
|
-{
|
|
|
|
- return gRandGen.getSeed();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-S32 mRandI( const S32 i1, const S32 i2)
|
|
|
|
-{
|
|
|
|
- return gRandGen.randRangeI(i1, i2);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-F32 mRandF(const F32 f1, const F32 f2)
|
|
|
|
-{
|
|
|
|
- return gRandGen.randRangeF(f1, f2);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunction(getRandom, F32, 1, 3, "([ min ],[ max ]) Use the getRandom function to get a random floating-point or integer value. This function comes in three forms.\n"
|
|
|
|
- "The first getRandom() takes no arguments and will return a random floating-point value in the range of 0.0 to 1.0. The second getRandom( max ) takes one argument representing the max integer value this will return. It will return an integer value between 0 and max. The third getRandom( min , max ) takes two arguments representing the min and max integer values this will return. It will return an integer value between min and max. Only the no-args version will return a floating point.\n"
|
|
|
|
- "@param min Minimum inclusive integer value to return.\n"
|
|
|
|
- "@param max Maximum inclusive integer value to return.\n"
|
|
|
|
- "@return If no arguments are passed, will return a floating-point value between 0.0 and 1.0. If one argument is passed, will return an integer value between 0 and max inclusive. If two arguments are passed, will return an integer value between min and max inclusive.\n"
|
|
|
|
- "@sa getRandomSeed")
|
|
|
|
-{
|
|
|
|
- if (argc == 2)
|
|
|
|
- return F32(gRandGen.randRangeI(0,getMax( dAtoi(argv[1]), 0 )));
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- if (argc == 3)
|
|
|
|
- {
|
|
|
|
- S32 min = dAtoi(argv[1]);
|
|
|
|
- S32 max = dAtoi(argv[2]);
|
|
|
|
- if (min > max)
|
|
|
|
- {
|
|
|
|
- S32 t = min;
|
|
|
|
- min = max;
|
|
|
|
- max = t;
|
|
|
|
- }
|
|
|
|
- return F32(gRandGen.randRangeI(min,max));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return gRandGen.randF();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunction(getRandomF, F32, 3, 3, "(min, max) Gets a random floating-point number from min to max.\n"
|
|
|
|
- "@param min The minimum range of the random floating-point number.\n"
|
|
|
|
- "@param max The maximum range of the random floating-point number.\n"
|
|
|
|
- "@return A random floating-point number from min to max.\n" )
|
|
|
|
-{
|
|
|
|
- F32 min = dAtof(argv[1]);
|
|
|
|
- F32 max = dAtof(argv[2]);
|
|
|
|
-
|
|
|
|
- if ( min > max )
|
|
|
|
- {
|
|
|
|
- const F32 temp = min;
|
|
|
|
- min = max;
|
|
|
|
- max = temp;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return min + (gRandGen.randF() * (max-min));
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-ConsoleFunctionGroupEnd(RandomNumbers);
|
|
|
|
-//------------------------------------------------------------------------------
|
|
|