Miscellaneous Utility Functions

  • Dbl2Float() - Provides safe type casting from double to float with an indication of overflow returned in the valid parameter. Depending on machine/compiler settings, the following code may throw an under/over-flow exception or quietly return an undefined value:

// unsafe

float val = (float)_tcstod(pNptr, ppEndptr);

A safer method would be:

BOOL valid = false;

float val = Dbl2Flt(_tcstod(pNptr, ppEndptr), &valid);

  • Dbl2Int() - Provides safe type casting from double to int with an indication of overflow returned in the valid parameter.
  • mod() - This function returns the mathematical modulo operation and handles negatives correctly. The standard math functions fmod() and fmodf() and the operator % will return negative results if the first operand is negative. This function will always return a positive remainder.
  • SinCos() - Returns both the sine and cosine of the angle specified, as floats. This function uses assembly language on Intel CPUs.
  • Sin() - Returns the sine of the angle specified as a float. This function uses assembly language on Intel CPUs.
  • Cos() - Returns the cosine of the angle specified as a float. This function uses assembly language on Intel CPUs.
  • Sqrt() - Returns the square root of the argument specified as a float. This function uses assembly language on Intel CPUs.
  • sramp() - This function makes a kind of straight-segment S curve. The parameters are x, a, b, d. The algorithm is as follows:
    • for a+d < x < b-d sramp(x) = x
    • for a-d < x < a+d sramp() makes a smooth transition (parabolic) from sramp' = 0 to sramp' = 1
    • for b-d < x < b+d sramp() makes a smooth transition (parabolic) from sramp' = 1 to sramp' = 0

  • IsDebugging() - Returns true if 3ds Max is running under the debugger; otherwise false.
  • NumberOfProcessors() - Returns the number of processors in the machine 3ds Max is running on.
  • IsWindows9x() - Returns true if 3ds Max is running on Windows 9x (95 or 98); otherwise false.
  • IsWindows98or2000() - Returns true if 3ds Max is running on Windows 98 or Windows 2000; otherwise false.
  • GetScreenWidth() - Returns the width of the screen (taking into consideration if multiple monitors are in use).
  • GetScreenHeight() - Returns the height of the screen (taking into consideration if multiple monitors are in use).

See Also