9 #ifndef Navigation_IntCoordSystem_H
10 #define Navigation_IntCoordSystem_H
21 #define KY_IntToPixelBitShift 7
22 #define KY_PixelSizeInIntCoord 128
23 #define KY_HalfPixelSizeInIntCoord 64
24 #define KY_PixelSizeInIntCoord_Float 128.0f
36 static inline KyInt32 NearestPixelCoord(
KyInt32 x) {
return IntToPixelCoord(x +
Kaim::Isel(x, KY_HalfPixelSizeInIntCoord-1, KY_HalfPixelSizeInIntCoord)); }
37 static inline KyInt32 NearestPixelCoord(
KyInt64 x) {
return IntToPixelCoord(x +
Kaim::Lsel(x, KY_HalfPixelSizeInIntCoord-1, KY_HalfPixelSizeInIntCoord)); }
39 static inline KyInt32 IntPixelSize() {
return KY_PixelSizeInIntCoord; }
41 static inline KyInt32 IntToPixelCoord(
KyInt32 intCoord) {
return intCoord >> KY_IntToPixelBitShift; }
42 static inline KyInt32 IntToPixelCoord(
KyInt64 intCoord) {
return (
KyInt32)(intCoord >> KY_IntToPixelBitShift); }
43 static inline KyInt32 PixelCoordToInt(
KyInt32 pixelCoord) {
return pixelCoord << KY_IntToPixelBitShift; }
46 static inline KyFloat32 IntegerPrecision(
KyFloat32 rasterPrecision) {
return rasterPrecision / KY_PixelSizeInIntCoord_Float; }
47 static inline KyFloat32 InvIntegerPrecision(
KyFloat32 rasterPrecision) {
return KY_PixelSizeInIntCoord_Float / rasterPrecision; }
52 return IntToNavigation(intDist, IntegerPrecision(rasterPrecision));
58 return NavigationToInt(dist, InvIntegerPrecision(rasterPrecision));
61 static inline void IntToNavigation_Pos(
const Vec2i& intPos, Vec2f& pos,
KyFloat32 rasterPrecision)
63 KyFloat32 integerPrecision = IntegerPrecision(rasterPrecision);
64 pos.x = IntToNavigation(intPos.x, integerPrecision);
65 pos.y = IntToNavigation(intPos.y, integerPrecision);
69 static inline void IntToNavigation_Pos(
const Vec3i& intPos, Vec3f& pos,
KyFloat32 rasterPrecision)
71 KyFloat32 integerPrecision = IntegerPrecision(rasterPrecision);
72 pos.x = IntToNavigation(intPos.x, integerPrecision);
73 pos.y = IntToNavigation(intPos.y, integerPrecision);
74 pos.z = IntToNavigation(intPos.z, integerPrecision);
78 static inline void PixelToNavigation_Pos(
const Vec3i& intPos, Vec3f& pos,
KyFloat32 integerPrecision)
80 pos.x = (
KyFloat32)(PixelCoordToInt(intPos.x) * integerPrecision);
81 pos.y = (
KyFloat32)(PixelCoordToInt(intPos.y) * integerPrecision);
82 pos.z = (
KyFloat32)(PixelCoordToInt(intPos.z) * integerPrecision);
86 static inline void NavigationToInt_Pos(
const Vec2f& pos, Vec2i& intPos,
KyFloat32 rasterPrecision)
88 KyFloat32 invIntegerPrecision = InvIntegerPrecision(rasterPrecision);
89 intPos.x = NavigationToInt(pos.x, invIntegerPrecision);
90 intPos.y = NavigationToInt(pos.y, invIntegerPrecision);
94 static inline void NavigationToInt_Pos(
const Vec3f& pos, Vec3i& intPos,
KyFloat32 rasterPrecision)
96 KyFloat32 invIntegerPrecision = InvIntegerPrecision(rasterPrecision);
97 intPos.x = NavigationToInt(pos.x, invIntegerPrecision);
98 intPos.y = NavigationToInt(pos.y, invIntegerPrecision);
99 intPos.z = NavigationToInt(pos.z, invIntegerPrecision);
106 return ((
KyFloat32)intDist) * integerPrecision;
111 return NearestInt(dist * invIntegerPrecision);
KyInt32 Isel(KyInt32 a, KyInt32 x, KyInt32 y)
If a is greater than 0, returns x. Otherwise, returns y.
Definition: fastmath.h:70
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
Definition: gamekitcrowddispersion.h:20
__int64 KyInt64
Type used internally to represent a 64-bit integer.
Definition: types.h:37
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
KyInt64 Lsel(KyInt64 a, KyInt64 x, KyInt64 y)
If a is greater than 0, returns x. Otherwise, returns y.
Definition: fastmath.h:80