99 lines
2.5 KiB
C
99 lines
2.5 KiB
C
#pragma once
|
|
|
|
#include "dvc_config.h"
|
|
|
|
DV_CORE_BEGIN_NAMESPACE
|
|
|
|
typedef int64_t ifloat_t;
|
|
//typedef int64_t ifloat2_t[2];
|
|
//typedef int64_t ifloat3_t[3];
|
|
|
|
#define IFLOAT_SHIFT (16)
|
|
#define IFLOAT_SCALE ((float64_t)(1<<IFLOAT_SHIFT))
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
inline ifloat_t ifloat_init(float32_t a)
|
|
{
|
|
return (ifloat_t)((float64_t)a * IFLOAT_SCALE + 0.5);
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
inline ifloat_t ifloat_init(int32_t a)
|
|
{
|
|
return (int64_t)(a)<< IFLOAT_SHIFT;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
inline float32_t ifloat_get_float(ifloat_t a)
|
|
{
|
|
return (float32_t)((float64_t)a/ IFLOAT_SCALE);
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
inline ifloat_t ifloat_multiply(ifloat_t a, ifloat_t b)
|
|
{
|
|
return (ifloat_t)((a * b) >> IFLOAT_SHIFT);
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
//inline void ifloat3_add(ifloat3_t& a, const ifloat3_t& b)
|
|
//{
|
|
// a[0] += b[0]; a[1] += b[1]; a[2] += b[2];
|
|
//}
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
//inline void ifloat3_sub(ifloat3_t& a, const ifloat3_t& b)
|
|
//{
|
|
// a[0] -= b[0]; a[1] -= b[1]; a[2] -= b[2];
|
|
//}
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
//inline void ifloat3_cpy(ifloat3_t& a, const ifloat3_t& b)
|
|
//{
|
|
// a[0] = b[0]; a[1] = b[1]; a[2] = b[2];
|
|
//}
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
struct ifloat2_t
|
|
{
|
|
ifloat_t x, y;
|
|
|
|
ifloat2_t() : x(0ll), y(0ll) {}
|
|
ifloat2_t(const ifloat2_t& other) : x(other.x), y(other.y) {}
|
|
ifloat2_t(float32_t _x, float32_t _y) : x(ifloat_init(_x)), y(ifloat_init(_y)) {}
|
|
};
|
|
|
|
struct ifloat3_t
|
|
{
|
|
ifloat_t x, y, z;
|
|
|
|
inline void add(const ifloat3_t& other) {
|
|
x += other.x;
|
|
y += other.y;
|
|
z += other.z;
|
|
}
|
|
|
|
inline void sub(const ifloat3_t& other) {
|
|
x -= other.x;
|
|
y -= other.y;
|
|
z -= other.z;
|
|
}
|
|
|
|
inline ifloat_t operator [] (const size_t i) const {
|
|
return *(&x + i);
|
|
}
|
|
|
|
inline ifloat_t& operator [] (const size_t i) {
|
|
return *(&x + i);
|
|
}
|
|
|
|
ifloat3_t() : x(0ll), y(0ll), z(0ll) {}
|
|
ifloat3_t(const ifloat3_t& other) : x(other.x), y(other.y), z(other.z) {}
|
|
ifloat3_t(float32_t _x, float32_t _y, float32_t _z) : x(ifloat_init(_x)), y(ifloat_init(_y)), z(ifloat_init(_z)) {}
|
|
ifloat3_t(ifloat_t _x, ifloat_t _y, ifloat_t _z) : x(_x), y(_y), z(_z) {}
|
|
};
|
|
|
|
|
|
DV_CORE_END_NAMESPACE
|
|
|