Nirtcpp 2.0.0
Nirtcpp is a high-performance c++ graphics engine.
nirt::core Namespace Reference

Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace. More...

Classes

class  aabbox3d
 Axis aligned bounding box in 3d dimensional space. More...
 
class  array
 Self reallocating template array (like stl vector) with additional features. More...
 
class  CMatrix4
 4x4 matrix. Mostly used as transformation matrix for 3d calculations. More...
 
class  dimension2d
 Specifies a 2 dimensional size. More...
 
union  FloatIntUnion32
 
class  irrAllocator
 Very simple allocator implementation, containers using it can be used across dll boundaries. More...
 
class  irrAllocatorFast
 Fast allocator, only to be used in containers inside the same memory heap. More...
 
class  line2d
 2D line between two points with intersection methods. More...
 
class  line3d
 3D line between two points with intersection methods. More...
 
class  list
 Doubly linked list template. More...
 
class  map
 map template for associative arrays using a red-black tree More...
 
class  plane3d
 Template plane class with some intersection testing methods. More...
 
class  quaternion
 Quaternion class for representing rotations. More...
 
class  rect
 Rectangle template. More...
 
class  string
 Very simple string class with some useful features. More...
 
class  triangle3d
 3d triangle template class for doing collision detection and other things. More...
 
class  vector2d
 2d vector template class with lots of operators and methods. More...
 
class  vector3d
 3d vector template class with lots of operators and methods. More...
 

Typedefs

using vector3df = vector3d< f32 >
 using type alias for a f32 3d vector.
 
using vector3di = vector3d< s32 >
 using type alias for an integer 3d vector.
 
using vector2df = vector2d< f32 >
 using type alias for f32 2d vector.
 
using vector2di = vector2d< s32 >
 using type alias for integer 2d vector.
 
using triangle3df = triangle3d< f32 >
 using type alias for a f32 3d triangle.
 
using triangle3di = triangle3d< s32 >
 using type alias for an integer 3d triangle.
 
using rectf = rect< f32 >
 Rectangle with float values.
 
using recti = rect< s32 >
 Rectangle with int values.
 
using position2df = vector2d< f32 >
 
using position2di = vector2d< s32 >
 
using plane3df = plane3d< f32 >
 using type alias for a f32 3d plane.
 
using plane3di = plane3d< s32 >
 using type alias for an integer 3d plane.
 
using matrix4 = CMatrix4< f32 >
 using type alias for f32 matrix
 
using line3df = line3d< f32 >
 using type alias for an f32 line.
 
using line3di = line3d< s32 >
 using type alias for an integer line.
 
using line2df = line2d< f32 >
 using type alias for an f32 line.
 
using line2di = line2d< s32 >
 using type alias for an integer line.
 
using stringc = string< c8 >
 using type alias for character strings
 
using stringw = string< wchar_t >
 using type alias for wide character strings
 
using inttofloat = union { u32 u
 
using dimension2df = dimension2d< f32 >
 using type alias for an f32 dimension.
 
using dimension2du = dimension2d< u32 >
 using type alias for an unsigned integer dimension.
 
using dimension2di = dimension2d< s32 >
 using type alias for an integer dimension. More...
 
using aabbox3df = aabbox3d< f32 >
 using type alias for a f32 3d bounding box.
 
using aabbox3di = aabbox3d< s32 >
 using type alias for an integer 3d bounding box.
 

Enumerations

enum  EIntersectionRelation3D {
  ISREL3D_FRONT = 0 , ISREL3D_BACK , ISREL3D_PLANAR , ISREL3D_SPANNING ,
  ISREL3D_CLIPPED
}
 Enumeration for intersection relations of 3d objects.
 
enum  eLocaleID { NIRT_LOCALE_ANSI = 0 , NIRT_LOCALE_GERMAN = 1 }
 
enum  eAllocStrategy { ALLOC_STRATEGY_SAFE = 0 , ALLOC_STRATEGY_DOUBLE = 1 , ALLOC_STRATEGY_SQRT = 2 }
 defines an allocation strategy (used only by nirt::array so far)
 

Functions

template<class S , class T >
vector3d< T > operator* (const S scalar, const vector3d< T > &vector)
 Function multiplying a scalar and a vector component-wise.
 
template<class S , class T >
vector2d< T > operator* (const S scalar, const vector2d< T > &vector)
 
template<class T >
CMatrix4< T > operator* (const T scalar, const CMatrix4< T > &mat)
 
s32 isdigit (s32 c)
 some standard function ( to remove dependencies )
 
NIRTCPP_API void utf8ToWchar (const char *in, wchar_t *out, const u64 len)
 Convert this utf-8-encoded string to the platform's wchar. More...
 
NIRTCPP_API void wcharToUtf8 (const wchar_t *in, char *out, const u64 len)
 Convert this wchar string to utf-8. More...
 
f32 radToDeg (f32 radians)
 Utility function to convert a radian value to degrees. More...
 
f64 radToDeg (f64 radians)
 Utility function to convert a radian value to degrees. More...
 
f32 degToRad (f32 degrees)
 Utility function to convert a degrees value to radians. More...
 
f64 degToRad (f64 degrees)
 Utility function to convert a degrees value to radians. More...
 
template<class T >
const T & min_ (const T &a, const T &b)
 returns minimum of two values. Own implementation to get rid of the STL (VS6 problems)
 
template<class T >
const T & min_ (const T &a, const T &b, const T &c)
 returns minimum of three values. Own implementation to get rid of the STL (VS6 problems)
 
template<class T >
const T & max_ (const T &a, const T &b)
 returns maximum of two values. Own implementation to get rid of the STL (VS6 problems)
 
template<class T >
const T & max_ (const T &a, const T &b, const T &c)
 returns maximum of three values. Own implementation to get rid of the STL (VS6 problems)
 
template<class T >
abs_ (const T &a)
 returns abs of two values. Own implementation to get rid of STL (VS6 problems)
 
template<class T >
lerp (const T &a, const T &b, const f32 t)
 
template<class T >
const T clamp (const T &value, const T &low, const T &high)
 clamps a value between low and high
 
template<class T1 , class T2 >
void swap (T1 &a, T2 &b)
 swaps the content of the passed parameters
 
template<class T >
roundingError ()
 
template<>
f32 roundingError ()
 
template<>
f64 roundingError ()
 
template<>
s32 roundingError ()
 
template<>
u32 roundingError ()
 
template<class T >
relativeErrorFactor ()
 
template<>
f32 relativeErrorFactor ()
 
template<>
f64 relativeErrorFactor ()
 
template<class T >
bool equals (const T a, const T b, const T tolerance=roundingError< T >())
 returns if a equals b, taking possible rounding errors into account
 
template<class T >
bool equalsRelative (const T a, const T b, const T factor=relativeErrorFactor< T >())
 
bool equalsByUlp (f32 a, f32 b, int maxUlpDiff)
 We compare the difference in ULP's (spacing between floating-point numbers, aka ULP=1 means there exists no float between).
 
bool iszero (const f64 a, const f64 tolerance=ROUNDING_ERROR_f64)
 returns if a equals zero, taking rounding errors into account
 
bool iszero (const f32 a, const f32 tolerance=ROUNDING_ERROR_f32)
 returns if a equals zero, taking rounding errors into account
 
bool isnotzero (const f32 a, const f32 tolerance=ROUNDING_ERROR_f32)
 returns if a equals not zero, taking rounding errors into account
 
bool iszero (const s32 a, const s32 tolerance=0)
 returns if a equals zero, taking rounding errors into account
 
bool iszero (const u32 a, const u32 tolerance=0)
 returns if a equals zero, taking rounding errors into account
 
s32 s32_min (s32 a, s32 b)
 
s32 s32_max (s32 a, s32 b)
 
s32 s32_clamp (s32 value, s32 low, s32 high)
 
u32 IR (f32 x)
 
f32 FR (u32 x)
 Floating-point representation of an integer value.
 
f32 FR (s32 x)
 
REALINLINE u32 if_c_a_else_b (const s32 condition, const u32 a, const u32 b)
 conditional set based on mask and arithmetic shift
 
REALINLINE u16 if_c_a_else_b (const s16 condition, const u16 a, const u16 b)
 conditional set based on mask and arithmetic shift
 
REALINLINE u32 if_c_a_else_0 (const s32 condition, const u32 a)
 conditional set based on mask and arithmetic shift
 
REALINLINE void setbit_cond (u32 &state, s32 condition, u32 mask)
 
f32 round_ (f32 x)
 
REALINLINE f32 squareroot (const f32 f)
 
REALINLINE f64 squareroot (const f64 f)
 
REALINLINE s32 squareroot (const s32 f)
 
REALINLINE f64 reciprocal_squareroot (const f64 x)
 
REALINLINE f32 reciprocal_squareroot (const f32 f)
 
REALINLINE s32 reciprocal_squareroot (const s32 x)
 
REALINLINE f32 reciprocal (const f32 f)
 
REALINLINE f64 reciprocal (const f64 f)
 
REALINLINE f32 reciprocal_approxim (const f32 f)
 
REALINLINE s32 floor32 (f32 x)
 
REALINLINE s32 ceil32 (f32 x)
 
REALINLINE s32 round32 (f32 x)
 
f32 f32_max3 (const f32 a, const f32 b, const f32 c)
 
f32 f32_min3 (const f32 a, const f32 b, const f32 c)
 
f32 fract (f32 x)
 
template<class T >
void heapsink (T *array, s32 element, s32 max)
 Sinks an element into the heap.
 
template<class T >
void heapsort (T *array_, s32 size)
 Sorts an array with size 'size' using heapsort.
 
u32 strtoul10 (const char *in, const char **out=0)
 Convert a simple string of base 10 digits into an unsigned 32 bit integer. More...
 
s32 strtol10 (const char *in, const char **out=0)
 Convert a simple string of base 10 digits into a signed 32 bit integer. More...
 
u32 ctoul16 (char in)
 Convert a hex-encoded character to an unsigned integer. More...
 
u32 strtoul16 (const char *in, const char **out=0)
 Convert a simple string of base 16 digits into an unsigned 32 bit integer. More...
 
u32 strtoul8 (const char *in, const char **out=0)
 Convert a simple string of base 8 digits into an unsigned 32 bit integer. More...
 
u32 strtoul_prefix (const char *in, const char **out=0)
 Convert a C-style prefixed string (hex, oct, integer) into an unsigned 32 bit integer. More...
 
f32 strtof10 (const char *in, const char **out=0)
 Converts a sequence of digits into a whole positive floating point value. More...
 
const char * fast_atof_move (const char *in, f32 &result)
 Provides a fast function for converting a string into a float. More...
 
float fast_atof (const char *floatAsString, const char **out=0)
 Convert a string to a floating point number. More...
 
s32 isFileExtension (const io::path &filename, const io::path &ext0, const io::path &ext1, const io::path &ext2)
 search if a filename has a proper extension
 
bool hasFileExtension (const io::path &filename, const io::path &ext0, const io::path &ext1="", const io::path &ext2="")
 search if a filename has a proper extension
 
io::pathcutFilenameExtension (io::path &dest, const io::path &source)
 cut the filename extension from a source file path and store it in a dest file path
 
io::pathgetFileNameExtension (io::path &dest, const io::path &source)
 get the filename extension from a file path
 
io::pathdeletePathFromFilename (io::path &filename)
 delete path from filename
 
io::pathdeletePathFromPath (io::path &filename, s32 pathCount)
 trim paths
 
s32 isInSameDirectory (const io::path &path, const io::path &file)
 
s32 isspace (s32 c)
 
s32 isupper (s32 c)
 

Variables

NIRTCPP_API const matrix4 IdentityMatrix
 global const identity matrix
 
const s32 ROUNDING_ERROR_S32 = 0
 Rounding error constant often used when comparing f32 values.
 
const f32 ROUNDING_ERROR_f32 = 0.000001f
 
const f64 ROUNDING_ERROR_f64 = 0.00000001
 
const f32 PI = 3.14159265359f
 Constant for PI.
 
const f32 RECIPROCAL_PI = 1.0f/PI
 Constant for reciprocal of PI.
 
const f32 HALF_PI = PI/2.0f
 Constant for half of PI.
 
const f64 PI64 = 3.1415926535897932384626433832795028841971693993751
 Constant for 64bit PI.
 
const f64 RECIPROCAL_PI64 = 1.0/PI64
 Constant for 64bit reciprocal of PI.
 
const f32 DEGTORAD = PI / 180.0f
 32bit Constant for converting from degrees to radians
 
const f32 RADTODEG = 180.0f / PI
 32bit constant for converting from radians to degrees (formally known as GRAD_PI)
 
const f64 DEGTORAD64 = PI64 / 180.0
 64bit constant for converting from degrees to radians (formally known as GRAD_PI2)
 
const f64 RADTODEG64 = 180.0 / PI64
 64bit constant for converting from radians to degrees
 
s32 s
 
f32 f
 
NIRTCPP_API nirt::core::stringc LOCALE_DECIMAL_POINTS
 
const float fast_atof_table [17]
 

Detailed Description

Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace.

Typedef Documentation

◆ dimension2di

using type alias for an integer dimension.

There are few cases where negative dimensions make sense. Please consider using dimension2du instead.

◆ position2df

Deprecated:
position2d is now a synonym for vector2d, but vector2d should be used directly.

◆ position2di

Deprecated:
position2d is now a synonym for vector2d, but vector2d should be used directly.

Function Documentation

◆ ctoul16()

u32 nirt::core::ctoul16 ( char  in)
inline

Convert a hex-encoded character to an unsigned integer.

Parameters
[in]inThe digit to convert. Only digits 0 to 9 and chars A-F,a-f will be considered.
Returns
The unsigned integer value of the digit. 0xffffffff if the input is not hex

◆ degToRad() [1/2]

f32 nirt::core::degToRad ( f32  degrees)
inline

Utility function to convert a degrees value to radians.

Provided as it can be clearer to write degToRad(X) than DEGTORAD * X

Parameters
degreesThe degrees value to convert to radians.

◆ degToRad() [2/2]

f64 nirt::core::degToRad ( f64  degrees)
inline

Utility function to convert a degrees value to radians.

Provided as it can be clearer to write degToRad(X) than DEGTORAD * X

Parameters
degreesThe degrees value to convert to radians.

◆ equalsRelative()

template<class T >
bool nirt::core::equalsRelative ( const T  a,
const T  b,
const T  factor = relativeErrorFactor<T>() 
)
inline

returns if a equals b, taking relative error in form of factor this particular function does not involve any division.

◆ fast_atof()

float nirt::core::fast_atof ( const char *  floatAsString,
const char **  out = 0 
)
inline

Convert a string to a floating point number.

Parameters
floatAsStringThe string to convert.
outOptional pointer to the first character in the string that wasn't used to create the float value.
Returns
Float value parsed from the input string

◆ fast_atof_move()

const char * nirt::core::fast_atof_move ( const char *  in,
f32 result 
)
inline

Provides a fast function for converting a string into a float.

This is not guaranteed to be as accurate as atof(), but is approximately 6 to 8 times as fast.

Parameters
[in]inThe string to convert.
[out]resultThe resultant float will be written here.
Returns
Pointer to the first character in the string that wasn't used to create the float value.

◆ IR()

u32 nirt::core::IR ( f32  x)
inline

code is taken from IceFPU Integer representation of a floating-point value.

◆ isInSameDirectory()

s32 nirt::core::isInSameDirectory ( const io::path path,
const io::path file 
)
inline

looks if file is in the same directory of path. returns offset of directory. 0 means in same directory. 1 means file is direct child of path

◆ lerp()

template<class T >
T nirt::core::lerp ( const T &  a,
const T &  b,
const f32  t 
)
inline

returns linear interpolation of a and b with ratio t

Returns
: a if t==0, b if t==1, and the linear interpolation else

◆ radToDeg() [1/2]

f32 nirt::core::radToDeg ( f32  radians)
inline

Utility function to convert a radian value to degrees.

Provided as it can be clearer to write radToDeg(X) than RADTODEG * X

Parameters
radiansThe radians value to convert to degrees.

◆ radToDeg() [2/2]

f64 nirt::core::radToDeg ( f64  radians)
inline

Utility function to convert a radian value to degrees.

Provided as it can be clearer to write radToDeg(X) than RADTODEG * X

Parameters
radiansThe radians value to convert to degrees.

◆ strtof10()

f32 nirt::core::strtof10 ( const char *  in,
const char **  out = 0 
)
inline

Converts a sequence of digits into a whole positive floating point value.

Only digits 0 to 9 are parsed. Parsing stops at any other character, including sign characters or a decimal point.

Parameters
inthe sequence of digits to convert.
out(optional) will be set to point at the first non-converted character.
Returns
The whole positive floating point representation of the digit sequence.

◆ strtol10()

s32 nirt::core::strtol10 ( const char *  in,
const char **  out = 0 
)
inline

Convert a simple string of base 10 digits into a signed 32 bit integer.

Parameters
[in]inThe string of digits to convert. Only a leading - or + followed by digits 0 to 9 will be considered. Parsing stops at the first non-digit.
[out]out(optional) If provided, it will be set to point at the first character not used in the calculation.
Returns
The signed integer value of the digits. If the string specifies too many digits to encode in an s32 then +INT_MAX or -INT_MAX will be returned.

◆ strtoul10()

u32 nirt::core::strtoul10 ( const char *  in,
const char **  out = 0 
)
inline

Convert a simple string of base 10 digits into an unsigned 32 bit integer.

Parameters
[in]inThe string of digits to convert. No leading chars are allowed, only digits 0 to 9. Parsing stops at the first non-digit.
[out]out(optional) If provided, it will be set to point at the first character not used in the calculation.
Returns
The unsigned integer value of the digits. If the string specifies too many digits to encode in an u32 then INT_MAX will be returned.

◆ strtoul16()

u32 nirt::core::strtoul16 ( const char *  in,
const char **  out = 0 
)
inline

Convert a simple string of base 16 digits into an unsigned 32 bit integer.

Parameters
[in]inThe string of digits to convert. No leading chars are allowed, only digits 0 to 9 and chars A-F,a-f are allowed. Parsing stops at the first illegal char.
[out]out(optional) If provided, it will be set to point at the first character not used in the calculation.
Returns
The unsigned integer value of the digits. If the string specifies too many digits to encode in an u32 then INT_MAX will be returned.

◆ strtoul8()

u32 nirt::core::strtoul8 ( const char *  in,
const char **  out = 0 
)
inline

Convert a simple string of base 8 digits into an unsigned 32 bit integer.

Parameters
[in]inThe string of digits to convert. No leading chars are allowed, only digits 0 to 7 are allowed. Parsing stops at the first illegal char.
[out]out(optional) If provided, it will be set to point at the first character not used in the calculation.
Returns
The unsigned integer value of the digits. If the string specifies too many digits to encode in an u32 then INT_MAX will be returned.

◆ strtoul_prefix()

u32 nirt::core::strtoul_prefix ( const char *  in,
const char **  out = 0 
)
inline

Convert a C-style prefixed string (hex, oct, integer) into an unsigned 32 bit integer.

Parameters
[in]inThe string of digits to convert. If string starts with 0x the hex parser is used, if only leading 0 is used, oct parser is used. In all other cases, the usual unsigned parser is used.
[out]out(optional) If provided, it will be set to point at the first character not used in the calculation.
Returns
The unsigned integer value of the digits. If the string specifies too many digits to encode in an u32 then INT_MAX will be returned.

◆ utf8ToWchar()

NIRTCPP_API void nirt::core::utf8ToWchar ( const char *  in,
wchar_t *  out,
const u64  len 
)

Convert this utf-8-encoded string to the platform's wchar.

The resulting string is always NULL-terminated and well-formed.

Parameters
lenThe size of the output buffer in bytes.

◆ wcharToUtf8()

NIRTCPP_API void nirt::core::wcharToUtf8 ( const wchar_t *  in,
char *  out,
const u64  len 
)

Convert this wchar string to utf-8.

The resulting string is always NULL-terminated and well-formed.

Parameters
lenThe size of the output buffer in bytes.

Variable Documentation

◆ fast_atof_table

const float nirt::core::fast_atof_table[17]
Initial value:
= {
0.f,
0.1f,
0.01f,
0.001f,
0.0001f,
0.00001f,
0.000001f,
0.0000001f,
0.00000001f,
0.000000001f,
0.0000000001f,
0.00000000001f,
0.000000000001f,
0.0000000000001f,
0.00000000000001f,
0.000000000000001f,
0.0000000000000001f
}

◆ LOCALE_DECIMAL_POINTS

NIRTCPP_API nirt::core::stringc nirt::core::LOCALE_DECIMAL_POINTS
extern

Selection of characters which count as decimal point in fast_atof By default Nirtcpp considers "." as the decimal point in numbers. But sometimes you might run into situations where floats were written in a local format with another decimal point like ",". Best solution is usually to fix those cases by converting the input. But if you don't have that choice you can set this to ".,". WARNING: This is not thread-safe, so don't change while there's a chance of another thread using fast_atof functions at the same time.