Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#ifndef CONVERSION_INCLUDED#define CONVERSION_INCLUDED/*conversion from:int to doubleint (modulo 100000) to int (modulo 0xFFFF)double to int rounding is done "to nearest" - hence the assembler and not simple static cast*/namespace conversion{__declspec(naked)staticint __stdcall vertex_bob2bod(int i){// bod = i / 0.65535static double MULTIPLIER = 0.65536; // == 65535 / 100000__asm {fld MULTIPLIERfidivr dword ptr [esp + 4]fistp dword ptr [esp + 4]mov eax, dword ptr [esp + 4]ret 4}}/*inlineint __stdcall vertex_bob2bod(int i){static double MULTIPLIER = 0.65535; // == 65535 / 100000return (int)(i / MULTIPLIER);}*/__declspec(naked)inlineint __stdcall vertex_bod2bob(int i){// bob = i * 0.65535static double MULTIPLIER = 0.65536; // == 65535 / 100000__asm {fld MULTIPLIERfimul dword ptr [esp + 4]fistp dword ptr [esp + 4]mov eax, dword ptr [esp + 4]ret 4}}__declspec(naked)inlineint __stdcall double2int(double d){static const double MULTIPLIER=1.52587890625E-05; // == 1 / 65535// int = right / multiplier__asm{fld qword ptr [esp + 4]fdiv MULTIPLIERfistp dword ptr [esp + 4]mov eax, dword ptr [esp + 4]ret 8}}/*inlineint __stdcall double2int(double d){static const double MULTIPLIER=1.52587890625E-05; // == 1 / 65535return (int)(d / MULTIPLIER);}*/} // namespace conversion#endif // !defined(CONVERSION_INCLUDED)