mirror of
https://github.com/RetroDECK/Supermodel.git
synced 2024-11-25 23:25:40 +00:00
address review
This commit is contained in:
parent
519d695f57
commit
5f97e5af6c
|
@ -176,8 +176,8 @@ namespace Legacy3D {
|
||||||
// Microsoft doesn't provide isnan() and isinf()
|
// Microsoft doesn't provide isnan() and isinf()
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
#define ISNAN(x) (_isnan(x))
|
#define ISNAN(x) (_isnanf(x))
|
||||||
#define ISINF(x) (!_finite(x))
|
#define ISINF(x) (!_finitef(x))
|
||||||
#else
|
#else
|
||||||
#define ISNAN(x) (std::isnan(x))
|
#define ISNAN(x) (std::isnan(x))
|
||||||
#define ISINF(x) (std::isinf(x))
|
#define ISINF(x) (std::isinf(x))
|
||||||
|
@ -812,7 +812,7 @@ void CLegacy3D::DescendNodePtr(UINT32 nodeAddr)
|
||||||
// Draws viewports of the given priority
|
// Draws viewports of the given priority
|
||||||
void CLegacy3D::RenderViewport(UINT32 addr, int pri, bool wideScreen)
|
void CLegacy3D::RenderViewport(UINT32 addr, int pri, bool wideScreen)
|
||||||
{
|
{
|
||||||
static const GLfloat color[8][3] = {
|
static constexpr GLfloat color[8][3] = {
|
||||||
{ 0.0, 0.0, 0.0 }, // off
|
{ 0.0, 0.0, 0.0 }, // off
|
||||||
{ 0.0, 0.0, 1.0 }, // blue
|
{ 0.0, 0.0, 1.0 }, // blue
|
||||||
{ 0.0, 1.0, 0.0 }, // green
|
{ 0.0, 1.0, 0.0 }, // green
|
||||||
|
@ -825,7 +825,7 @@ void CLegacy3D::RenderViewport(UINT32 addr, int pri, bool wideScreen)
|
||||||
|
|
||||||
// Translate address and obtain pointer
|
// Translate address and obtain pointer
|
||||||
const UINT32 *vpnode = TranslateCullingAddress(addr);
|
const UINT32 *vpnode = TranslateCullingAddress(addr);
|
||||||
if (NULL == vpnode)
|
if (nullptr == vpnode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Recursively process next viewport
|
// Recursively process next viewport
|
||||||
|
@ -852,8 +852,8 @@ void CLegacy3D::RenderViewport(UINT32 addr, int pri, bool wideScreen)
|
||||||
int vpHeight = (vpnode[0x14]>>18)&0x3FFF; // height (14.2)
|
int vpHeight = (vpnode[0x14]>>18)&0x3FFF; // height (14.2)
|
||||||
|
|
||||||
// Field of view and clipping
|
// Field of view and clipping
|
||||||
GLfloat vpTopAngle = asinf(Util::UintAsFloat(vpnode[0x0E])); // FOV Y upper half-angle (radians)
|
GLfloat vpTopAngle = asinf(Util::Uint32AsFloat(vpnode[0x0E])); // FOV Y upper half-angle (radians)
|
||||||
GLfloat vpBotAngle = asinf(Util::UintAsFloat(vpnode[0x12])); // FOV Y lower half-angle
|
GLfloat vpBotAngle = asinf(Util::Uint32AsFloat(vpnode[0x12])); // FOV Y lower half-angle
|
||||||
GLfloat fovYDegrees = (vpTopAngle+vpBotAngle)*(float)(180.0/M_PI);
|
GLfloat fovYDegrees = (vpTopAngle+vpBotAngle)*(float)(180.0/M_PI);
|
||||||
// TO-DO: investigate clipping planes
|
// TO-DO: investigate clipping planes
|
||||||
|
|
||||||
|
@ -876,15 +876,15 @@ void CLegacy3D::RenderViewport(UINT32 addr, int pri, bool wideScreen)
|
||||||
viewportY = yOffs + (GLint) ((float)(384-(vpY+vpHeight))*yRatio);
|
viewportY = yOffs + (GLint) ((float)(384-(vpY+vpHeight))*yRatio);
|
||||||
viewportWidth = (GLint) ((float)vpWidth*xRatio);
|
viewportWidth = (GLint) ((float)vpWidth*xRatio);
|
||||||
viewportHeight = (GLint) ((float)vpHeight*yRatio);
|
viewportHeight = (GLint) ((float)vpHeight*yRatio);
|
||||||
gluPerspective(fovYDegrees,(GLfloat)vpWidth/(GLfloat)vpHeight,0.1f,1e5); // use Model 3 viewport ratio
|
gluPerspective(fovYDegrees,(GLdouble)vpWidth/(GLdouble)vpHeight,0.1,1e5); // use Model 3 viewport ratio
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lighting (note that sun vector points toward sun -- away from vertex)
|
// Lighting (note that sun vector points toward sun -- away from vertex)
|
||||||
lightingParams[0] = *(float *) &vpnode[0x05]; // sun X
|
lightingParams[0] = Util::Uint32AsFloat(vpnode[0x05]); // sun X
|
||||||
lightingParams[1] = *(float *) &vpnode[0x06]; // sun Y
|
lightingParams[1] = Util::Uint32AsFloat(vpnode[0x06]); // sun Y
|
||||||
lightingParams[2] = *(float *) &vpnode[0x04]; // sun Z
|
lightingParams[2] = Util::Uint32AsFloat(vpnode[0x04]); // sun Z
|
||||||
lightingParams[3] = *(float *) &vpnode[0x07]; // sun intensity
|
lightingParams[3] = Util::Uint32AsFloat(vpnode[0x07]); // sun intensity
|
||||||
lightingParams[4] = (float) ((vpnode[0x24]>>8)&0xFF) * (1.0f/255.0f); // ambient intensity
|
lightingParams[4] = (float) ((vpnode[0x24]>>8)&0xFF) * (float)(1.0/255.0); // ambient intensity
|
||||||
lightingParams[5] = 0.0; // reserved
|
lightingParams[5] = 0.0; // reserved
|
||||||
|
|
||||||
// Spotlight
|
// Spotlight
|
||||||
|
@ -893,8 +893,8 @@ void CLegacy3D::RenderViewport(UINT32 addr, int pri, bool wideScreen)
|
||||||
spotEllipse[1] = (float) ((vpnode[0x1D]>>3)&0x1FFF); // spotlight Y
|
spotEllipse[1] = (float) ((vpnode[0x1D]>>3)&0x1FFF); // spotlight Y
|
||||||
spotEllipse[2] = (float) ((vpnode[0x1E]>>16)&0xFFFF); // spotlight X size (16-bit? May have fractional component below bit 16)
|
spotEllipse[2] = (float) ((vpnode[0x1E]>>16)&0xFFFF); // spotlight X size (16-bit? May have fractional component below bit 16)
|
||||||
spotEllipse[3] = (float) ((vpnode[0x1D]>>16)&0xFFFF); // spotlight Y size
|
spotEllipse[3] = (float) ((vpnode[0x1D]>>16)&0xFFFF); // spotlight Y size
|
||||||
spotRange[0] = 1.0f/(*(float *) &vpnode[0x21]); // spotlight start
|
spotRange[0] = 1.0f/Util::Uint32AsFloat(vpnode[0x21]); // spotlight start
|
||||||
spotRange[1] = *(float *) &vpnode[0x1F]; // spotlight extent
|
spotRange[1] = Util::Uint32AsFloat(vpnode[0x1F]); // spotlight extent
|
||||||
spotColor[0] = color[spotColorIdx][0]; // spotlight color
|
spotColor[0] = color[spotColorIdx][0]; // spotlight color
|
||||||
spotColor[1] = color[spotColorIdx][1];
|
spotColor[1] = color[spotColorIdx][1];
|
||||||
spotColor[2] = color[spotColorIdx][2];
|
spotColor[2] = color[spotColorIdx][2];
|
||||||
|
@ -913,17 +913,17 @@ void CLegacy3D::RenderViewport(UINT32 addr, int pri, bool wideScreen)
|
||||||
spotEllipse[3] *= yRatio;
|
spotEllipse[3] *= yRatio;
|
||||||
|
|
||||||
// Fog
|
// Fog
|
||||||
fogParams[0] = (float) ((vpnode[0x22]>>16)&0xFF) * (1.0f/255.0f); // fog color R
|
fogParams[0] = (float) ((vpnode[0x22]>>16)&0xFF) * (float)(1.0/255.0); // fog color R
|
||||||
fogParams[1] = (float) ((vpnode[0x22]>>8)&0xFF) * (1.0f/255.0f); // fog color G
|
fogParams[1] = (float) ((vpnode[0x22]>>8)&0xFF) * (float)(1.0/255.0); // fog color G
|
||||||
fogParams[2] = (float) ((vpnode[0x22]>>0)&0xFF) * (1.0f/255.0f); // fog color B
|
fogParams[2] = (float) ((vpnode[0x22]>>0)&0xFF) * (float)(1.0/255.0); // fog color B
|
||||||
fogParams[3] = *(float *) &vpnode[0x23]; // fog density
|
fogParams[3] = Util::Uint32AsFloat(vpnode[0x23]); // fog density
|
||||||
fogParams[4] = (float) (INT16) (vpnode[0x25]&0xFFFF)*(1.0f/255.0f); // fog start
|
fogParams[4] = (float) (INT16) (vpnode[0x25]&0xFFFF) * (float)(1.0/255.0); // fog start
|
||||||
if (ISINF(fogParams[3]) || ISNAN(fogParams[3]) || ISINF(fogParams[4]) || ISNAN(fogParams[4])) // Star Wars Trilogy
|
if (ISINF(fogParams[3]) || ISNAN(fogParams[3]) || ISINF(fogParams[4]) || ISNAN(fogParams[4])) // Star Wars Trilogy
|
||||||
fogParams[3] = fogParams[4] = 0.0f;
|
fogParams[3] = fogParams[4] = 0.0f;
|
||||||
|
|
||||||
// Unknown light/fog parameters
|
// Unknown light/fog parameters
|
||||||
//GLfloat scrollFog = (float) (vpnode[0x20]&0xFF) * (1.0f/255.0f); // scroll fog
|
//GLfloat scrollFog = (float) (vpnode[0x20]&0xFF) * (float)(1.0/255.0); // scroll fog
|
||||||
//GLfloat scrollAtt = (float) (vpnode[0x24]&0xFF) * (1.0f/255.0f); // scroll attenuation
|
//GLfloat scrollAtt = (float) (vpnode[0x24]&0xFF) * (float)(1.0/255.0); // scroll attenuation
|
||||||
//printf("scrollFog = %g, scrollAtt = %g\n", scrollFog, scrollAtt);
|
//printf("scrollFog = %g, scrollAtt = %g\n", scrollFog, scrollAtt);
|
||||||
//printf("Fog: R=%02X G=%02X B=%02X density=%g (%X) %d start=%g\n", ((vpnode[0x22]>>16)&0xFF), ((vpnode[0x22]>>8)&0xFF), ((vpnode[0x22]>>0)&0xFF), fogParams[3], vpnode[0x23], (fogParams[3]==fogParams[3]), fogParams[4]);
|
//printf("Fog: R=%02X G=%02X B=%02X density=%g (%X) %d start=%g\n", ((vpnode[0x22]>>16)&0xFF), ((vpnode[0x22]>>8)&0xFF), ((vpnode[0x22]>>0)&0xFF), fogParams[3], vpnode[0x23], (fogParams[3]==fogParams[3]), fogParams[4]);
|
||||||
|
|
||||||
|
@ -936,7 +936,7 @@ void CLegacy3D::RenderViewport(UINT32 addr, int pri, bool wideScreen)
|
||||||
InitMatrixStack(matrixBase);
|
InitMatrixStack(matrixBase);
|
||||||
|
|
||||||
// Safeguard: weird coordinate system matrices usually indicate scenes that will choke the renderer
|
// Safeguard: weird coordinate system matrices usually indicate scenes that will choke the renderer
|
||||||
if (NULL != matrixBasePtr)
|
if (nullptr != matrixBasePtr)
|
||||||
{
|
{
|
||||||
float m21, m32, m13;
|
float m21, m32, m13;
|
||||||
|
|
||||||
|
|
|
@ -554,7 +554,7 @@ void CNew3D::DescendCullingNode(UINT32 addr)
|
||||||
|
|
||||||
if (!m_offset) { // Step 1.5+
|
if (!m_offset) { // Step 1.5+
|
||||||
|
|
||||||
float modelScale = Util::UintAsFloat(node[1]);
|
float modelScale = Util::Uint32AsFloat(node[1]);
|
||||||
if (modelScale > std::numeric_limits<float>::min()) {
|
if (modelScale > std::numeric_limits<float>::min()) {
|
||||||
m_nodeAttribs.currentModelScale = modelScale;
|
m_nodeAttribs.currentModelScale = modelScale;
|
||||||
}
|
}
|
||||||
|
@ -574,9 +574,9 @@ void CNew3D::DescendCullingNode(UINT32 addr)
|
||||||
|
|
||||||
// apply translation vector
|
// apply translation vector
|
||||||
if (node[0x00] & 0x10) {
|
if (node[0x00] & 0x10) {
|
||||||
float x = Util::UintAsFloat(node[0x04 - m_offset]);
|
float x = Util::Uint32AsFloat(node[0x04 - m_offset]);
|
||||||
float y = Util::UintAsFloat(node[0x05 - m_offset]);
|
float y = Util::Uint32AsFloat(node[0x05 - m_offset]);
|
||||||
float z = Util::UintAsFloat(node[0x06 - m_offset]);
|
float z = Util::Uint32AsFloat(node[0x06 - m_offset]);
|
||||||
m_modelMat.Translate(x, y, z);
|
m_modelMat.Translate(x, y, z);
|
||||||
}
|
}
|
||||||
// multiply matrix, if specified
|
// multiply matrix, if specified
|
||||||
|
@ -832,16 +832,16 @@ void CNew3D::RenderViewport(UINT32 addr)
|
||||||
m_LODBlendTable = (LODBlendTable*)TranslateCullingAddress(vpnode[0x17] & 0xFFFFFF);
|
m_LODBlendTable = (LODBlendTable*)TranslateCullingAddress(vpnode[0x17] & 0xFFFFFF);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
vp->angle_left = -atan2f(Util::UintAsFloat(vpnode[12]), Util::UintAsFloat(vpnode[13])); // These values work out as the normals for the clipping planes.
|
vp->angle_left = -atan2f(Util::Uint32AsFloat(vpnode[12]), Util::Uint32AsFloat(vpnode[13])); // These values work out as the normals for the clipping planes.
|
||||||
vp->angle_right = atan2f(Util::UintAsFloat(vpnode[16]), -Util::UintAsFloat(vpnode[17])); // Sometimes these values (dirt devils,lost world) are totally wrong
|
vp->angle_right = atan2f(Util::Uint32AsFloat(vpnode[16]), -Util::Uint32AsFloat(vpnode[17])); // Sometimes these values (dirt devils,lost world) are totally wrong
|
||||||
vp->angle_top = atan2f(Util::UintAsFloat(vpnode[14]), Util::UintAsFloat(vpnode[15])); // and don't work for the frustum values exactly.
|
vp->angle_top = atan2f(Util::Uint32AsFloat(vpnode[14]), Util::Uint32AsFloat(vpnode[15])); // and don't work for the frustum values exactly.
|
||||||
vp->angle_bottom = -atan2f(Util::UintAsFloat(vpnode[18]), -Util::UintAsFloat(vpnode[19])); // Perhaps they are just used for culling and not rendering.
|
vp->angle_bottom = -atan2f(Util::Uint32AsFloat(vpnode[18]), -Util::Uint32AsFloat(vpnode[19])); // Perhaps they are just used for culling and not rendering.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
float cv = Util::UintAsFloat(vpnode[0x8]); // 1/(left-right)
|
float cv = Util::Uint32AsFloat(vpnode[0x8]); // 1/(left-right)
|
||||||
float cw = Util::UintAsFloat(vpnode[0x9]); // 1/(top-bottom)
|
float cw = Util::Uint32AsFloat(vpnode[0x9]); // 1/(top-bottom)
|
||||||
float io = Util::UintAsFloat(vpnode[0xa]); // top / bottom (ratio) - ish
|
float io = Util::Uint32AsFloat(vpnode[0xa]); // top / bottom (ratio) - ish
|
||||||
float jo = Util::UintAsFloat(vpnode[0xb]); // left / right (ratio)
|
float jo = Util::Uint32AsFloat(vpnode[0xb]); // left / right (ratio)
|
||||||
|
|
||||||
vp->angle_left = (0.0f - jo) / cv;
|
vp->angle_left = (0.0f - jo) / cv;
|
||||||
vp->angle_right = (1.0f - jo) / cv;
|
vp->angle_right = (1.0f - jo) / cv;
|
||||||
|
@ -855,10 +855,10 @@ void CNew3D::RenderViewport(UINT32 addr)
|
||||||
CalcFrustumPlanes(m_planes, vp->projectionMatrix); // we need to calc a 'projection matrix' to get the correct frustum planes for clipping
|
CalcFrustumPlanes(m_planes, vp->projectionMatrix); // we need to calc a 'projection matrix' to get the correct frustum planes for clipping
|
||||||
|
|
||||||
// Lighting (note that sun vector points toward sun -- away from vertex)
|
// Lighting (note that sun vector points toward sun -- away from vertex)
|
||||||
vp->lightingParams[0] = Util::UintAsFloat(vpnode[0x05]); // sun X
|
vp->lightingParams[0] = Util::Uint32AsFloat(vpnode[0x05]); // sun X
|
||||||
vp->lightingParams[1] = -Util::UintAsFloat(vpnode[0x06]); // sun Y (- to convert to ogl cordinate system)
|
vp->lightingParams[1] = -Util::Uint32AsFloat(vpnode[0x06]); // sun Y (- to convert to ogl cordinate system)
|
||||||
vp->lightingParams[2] = -Util::UintAsFloat(vpnode[0x04]); // sun Z (- to convert to ogl cordinate system)
|
vp->lightingParams[2] = -Util::Uint32AsFloat(vpnode[0x04]); // sun Z (- to convert to ogl cordinate system)
|
||||||
vp->lightingParams[3] = std::max(0.f, std::min(Util::UintAsFloat(vpnode[0x07]), 1.0f)); // sun intensity (clamp to 0-1)
|
vp->lightingParams[3] = std::max(0.f, std::min(Util::Uint32AsFloat(vpnode[0x07]), 1.0f)); // sun intensity (clamp to 0-1)
|
||||||
vp->lightingParams[4] = (float)((vpnode[0x24] >> 8) & 0xFF) * (float)(1.0 / 255.0); // ambient intensity
|
vp->lightingParams[4] = (float)((vpnode[0x24] >> 8) & 0xFF) * (float)(1.0 / 255.0); // ambient intensity
|
||||||
vp->lightingParams[5] = 0.0f; // reserved
|
vp->lightingParams[5] = 0.0f; // reserved
|
||||||
|
|
||||||
|
@ -874,8 +874,8 @@ void CNew3D::RenderViewport(UINT32 addr)
|
||||||
vp->spotEllipse[2] = (float)((vpnode[0x1E] >> 16) & 0xFFFF); // spotlight X size (16-bit)
|
vp->spotEllipse[2] = (float)((vpnode[0x1E] >> 16) & 0xFFFF); // spotlight X size (16-bit)
|
||||||
vp->spotEllipse[3] = (float)((vpnode[0x1D] >> 16) & 0xFFFF); // spotlight Y size
|
vp->spotEllipse[3] = (float)((vpnode[0x1D] >> 16) & 0xFFFF); // spotlight Y size
|
||||||
|
|
||||||
vp->spotRange[0] = 1.0f / Util::UintAsFloat(vpnode[0x21]); // spotlight start
|
vp->spotRange[0] = 1.0f / Util::Uint32AsFloat(vpnode[0x21]); // spotlight start
|
||||||
vp->spotRange[1] = Util::UintAsFloat(vpnode[0x1F]); // spotlight extent
|
vp->spotRange[1] = Util::Uint32AsFloat(vpnode[0x1F]); // spotlight extent
|
||||||
|
|
||||||
vp->spotColor[0] = color[spotColorIdx][0]; // spotlight color
|
vp->spotColor[0] = color[spotColorIdx][0]; // spotlight color
|
||||||
vp->spotColor[1] = color[spotColorIdx][1];
|
vp->spotColor[1] = color[spotColorIdx][1];
|
||||||
|
@ -909,7 +909,7 @@ void CNew3D::RenderViewport(UINT32 addr)
|
||||||
vp->fogParams[0] = (float)((vpnode[0x22] >> 16) & 0xFF) * (float)(1.0 / 255.0); // fog color R
|
vp->fogParams[0] = (float)((vpnode[0x22] >> 16) & 0xFF) * (float)(1.0 / 255.0); // fog color R
|
||||||
vp->fogParams[1] = (float)((vpnode[0x22] >> 8) & 0xFF) * (float)(1.0 / 255.0); // fog color G
|
vp->fogParams[1] = (float)((vpnode[0x22] >> 8) & 0xFF) * (float)(1.0 / 255.0); // fog color G
|
||||||
vp->fogParams[2] = (float)((vpnode[0x22] >> 0) & 0xFF) * (float)(1.0 / 255.0); // fog color B
|
vp->fogParams[2] = (float)((vpnode[0x22] >> 0) & 0xFF) * (float)(1.0 / 255.0); // fog color B
|
||||||
vp->fogParams[3] = std::abs(Util::UintAsFloat(vpnode[0x23])); // fog density - ocean hunter uses negative values, but looks the same
|
vp->fogParams[3] = std::abs(Util::Uint32AsFloat(vpnode[0x23])); // fog density - ocean hunter uses negative values, but looks the same
|
||||||
vp->fogParams[4] = (float)(INT16)(vpnode[0x25] & 0xFFFF)* (float)(1.0 / 255.0); // fog start
|
vp->fogParams[4] = (float)(INT16)(vpnode[0x25] & 0xFFFF)* (float)(1.0 / 255.0); // fog start
|
||||||
|
|
||||||
// Avoid Infinite and NaN values for Star Wars Trilogy
|
// Avoid Infinite and NaN values for Star Wars Trilogy
|
||||||
|
|
|
@ -35,5 +35,5 @@ UINT32 R3DFloat::Convert16BitProFloat(UINT32 a1)
|
||||||
|
|
||||||
float R3DFloat::ToFloat(UINT32 a1)
|
float R3DFloat::ToFloat(UINT32 a1)
|
||||||
{
|
{
|
||||||
return Util::UintAsFloat(a1);
|
return Util::Uint32AsFloat(a1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,10 @@ namespace Util
|
||||||
{
|
{
|
||||||
#if __cplusplus >= 202002L
|
#if __cplusplus >= 202002L
|
||||||
#include <bit>
|
#include <bit>
|
||||||
#define FloatAsInt(x) std::bit_cast<int>(x)
|
#define FloatAsInt32(x) std::bit_cast<int32_t>(x)
|
||||||
#define IntAsFloat(x) std::bit_cast<float>(x)
|
#define Int32AsFloat(x) std::bit_cast<float>(x)
|
||||||
#define UintAsFloat(x) std::bit_cast<float>(x)
|
#define Uint32AsFloat(x) std::bit_cast<float>(x)
|
||||||
#elif 1
|
#else
|
||||||
template <class Dest, class Source>
|
template <class Dest, class Source>
|
||||||
inline Dest bit_cast(Source const& source) {
|
inline Dest bit_cast(Source const& source) {
|
||||||
static_assert(sizeof(Dest) == sizeof(Source), "size of destination and source objects must be equal");
|
static_assert(sizeof(Dest) == sizeof(Source), "size of destination and source objects must be equal");
|
||||||
|
@ -22,39 +22,9 @@ inline Dest bit_cast(Source const& source) {
|
||||||
std::memcpy(&dest, &source, sizeof(dest));
|
std::memcpy(&dest, &source, sizeof(dest));
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
#define FloatAsInt(x) bit_cast<int,float>(x)
|
#define FloatAsInt32(x) bit_cast<int32_t,float>(x)
|
||||||
#define IntAsFloat(x) bit_cast<float,int>(x)
|
#define Int32AsFloat(x) bit_cast<float,int32_t>(x)
|
||||||
#define UintAsFloat(x) bit_cast<float,unsigned int>(x)
|
#define Uint32AsFloat(x) bit_cast<float,uint32_t>(x)
|
||||||
#else
|
|
||||||
inline int FloatAsInt(const float x)
|
|
||||||
{
|
|
||||||
union {
|
|
||||||
float f;
|
|
||||||
int i;
|
|
||||||
} uc;
|
|
||||||
uc.f = x;
|
|
||||||
return uc.i;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline float IntAsFloat(const int i)
|
|
||||||
{
|
|
||||||
union {
|
|
||||||
int i;
|
|
||||||
float f;
|
|
||||||
} iaf;
|
|
||||||
iaf.i = i;
|
|
||||||
return iaf.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline float UintAsFloat(const unsigned int i)
|
|
||||||
{
|
|
||||||
union {
|
|
||||||
unsigned int u;
|
|
||||||
float f;
|
|
||||||
} iaf;
|
|
||||||
iaf.u = i;
|
|
||||||
return iaf.f;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
} // Util
|
} // Util
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue