Subversion Repositories spk

Rev

Rev 273 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 273 Rev 283
Line 12... Line 12...
12
*/
12
*/
13
 
13
 
14
namespace conversion
14
namespace conversion
15
{
15
{
16
#ifdef _WIN64
16
#ifdef _WIN64
-
 
17
	// Constants for conversions
-
 
18
	constexpr double MULTIPLIER_BOB_TO_BOD = 0.65536; // == 65535 / 100000
-
 
19
	constexpr double MULTIPLIER_BOD_TO_BOB = 0.65536; // == 65535 / 100000
-
 
20
	constexpr double MULTIPLIER_DOUBLE_TO_INT = 1.52587890625E-05; // == 1 / 65535
17
 
21
 
-
 
22
	// Divide and round a double value
-
 
23
	inline double divideAndRound(double value) {
-
 
24
		return std::round(value / MULTIPLIER_DOUBLE_TO_INT);
-
 
25
	}
-
 
26
 
-
 
27
	// Convert double to int with rounding
-
 
28
	inline int double2int(double d) {
-
 
29
		return static_cast<int>(divideAndRound(d));
-
 
30
	}
-
 
31
 
-
 
32
	// Convert vertex from bob to bod
-
 
33
	inline int vertex_bob2bod(int i) {
-
 
34
		return static_cast<int>(i / MULTIPLIER_BOB_TO_BOD + 0.5);
-
 
35
	}
-
 
36
 
-
 
37
	// Convert vertex from bod to bob
-
 
38
	inline int vertex_bod2bob(int i) {
-
 
39
		return static_cast<int>(std::round(i * MULTIPLIER_BOD_TO_BOB));
-
 
40
	}
-
 
41
 
-
 
42
	/*
18
	static inline double __fastcall divideAndRound(double value) {
43
	static inline double __fastcall divideAndRound(double value) {
19
		const double MULTIPLIER = 1.52587890625E-05; // == 1 / 65535
44
		const double MULTIPLIER = 1.52587890625E-05; // == 1 / 65535
20
 
45
 
21
		value /= MULTIPLIER;
46
		value /= MULTIPLIER;
22
		return std::round(value);
47
		return std::round(value);
23
	}
48
	}
24
 
49
 
25
	static inline int __stdcall double2int(double d)
50
	static inline int __stdcall double2int(double d)
26
	{
51
	{
27
		return static_cast<int>(divideAndRound(d));
52
		return static_cast<int>(divideAndRound(d));
28
	}
53
	}
29
 
54
 
30
	static int __stdcall vertex_bob2bod(int i)
55
	static int __stdcall vertex_bob2bod(int i)
31
	{
56
	{
32
		// bod = i / 0.65535
57
		// bod = i / 0.65535
33
		static double MULTIPLIER = 0.65536; // == 65535 / 100000
58
		static double MULTIPLIER = 0.65536; // == 65535 / 100000
34
		return static_cast<int>(i / MULTIPLIER + 0.5f);
59
		return static_cast<int>(i / MULTIPLIER + 0.5f);
35
	}
60
	}
36
 
61
 
37
	static inline int __stdcall vertex_bod2bob(int i)
62
	static inline int __stdcall vertex_bod2bob(int i)
38
	{
63
	{
39
		// bob = i * 0.65535
64
		// bob = i * 0.65535
40
		static double MULTIPLIER = 0.65536; // == 65535 / 100000
65
		static double MULTIPLIER = 0.65536; // == 65535 / 100000
41
 
66
 
42
		double result = MULTIPLIER * i;
67
		double result = MULTIPLIER * i;
43
		return static_cast<int>(std::round(result));
68
		return static_cast<int>(std::round(result));
44
	}
69
	}
45
 
70
	*/
46
#else
71
#else
47
 
72
 
48
__declspec(naked)
73
__declspec(naked)
49
static 
74
static 
50
int __stdcall vertex_bob2bod(int i)
75
int __stdcall vertex_bob2bod(int i)