This commit is contained in:
Ian Curtis 2016-06-19 21:43:09 +00:00
parent c2b1db11f8
commit 85c4d85562
6 changed files with 64 additions and 34 deletions

View file

@ -5,6 +5,7 @@
#include <cmath>
#include <algorithm>
#include <limits>
#include "R3DFloat.h"
#define MAX_RAM_POLYS 100000
#define MAX_ROM_POLYS 500000
@ -403,7 +404,7 @@ void CNew3D::DescendCullingNode(UINT32 addr)
if (m_nodeAttribs.currentClipStatus != Clip::INSIDE) {
float distance = ToFloat(Convert16BitProFloat(node[9 - m_offset] & 0xFFFF));
float distance = R3DFloat::GetFloat16(node[9 - m_offset] & 0xFFFF);
CalcBox(distance, bbox);
TransformBox(m_modelMat, bbox);
@ -578,7 +579,6 @@ void CNew3D::InitMatrixStack(UINT32 matrixBaseAddr, Mat4& mat)
m[CMINDEX(2, 0)] =-1.0; m[CMINDEX(2, 1)] = 0.0; m[CMINDEX(2, 2)] = 0.0; m[CMINDEX(2, 3)] = 0.0;
m[CMINDEX(3, 0)] = 0.0; m[CMINDEX(3, 1)] = 0.0; m[CMINDEX(3, 2)] = 0.0; m[CMINDEX(3, 3)] = 1.0;
mat.LoadMatrix(m);
// Set matrix base address and apply matrix #0 (coordinate system matrix)
@ -1198,33 +1198,6 @@ void CNew3D::CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX
newY += ((oldPage + page) & 1) * 1024; // max page 0-1
}
UINT32 CNew3D::ConvertProFloat(UINT32 a1)
{
int exponent = (a1 & 0x7E000000) >> 25;
if (exponent <= 31) { // positive
exponent += 127;
}
else { // negative exponent
exponent -= 64;
exponent += 127;
}
int mantissa = (a1 & 0x1FFFFFF) >> 2;
return (a1 & 0x80000000) | (exponent << 23) | mantissa;
}
UINT32 CNew3D::Convert16BitProFloat(UINT32 a1)
{
return ConvertProFloat(a1 << 15);
}
float CNew3D::ToFloat(UINT32 a1)
{
return *(float*)(&a1);
}
void CNew3D::CalcFrustumPlanes(Plane p[6], const float* matrix)
{
// Left Plane

View file

@ -180,10 +180,6 @@ private:
void CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX, int& newY);
UINT32 ConvertProFloat(UINT32 a1); // return float in hex or integer format
UINT32 Convert16BitProFloat(UINT32 a1);
float ToFloat(UINT32 a1); // integer float to actual IEEE 754 float
/*
* Data
*/

View file

@ -0,0 +1,39 @@
#include "Types.h"
#include "R3DFloat.h"
float R3DFloat::GetFloat16(UINT16 f)
{
return ToFloat(Convert16BitProFloat(f));
}
float R3DFloat::GetFloat32(UINT32 f)
{
return ToFloat(ConvertProFloat(f));
}
UINT32 R3DFloat::ConvertProFloat(UINT32 a1)
{
int exponent = (a1 & 0x7E000000) >> 25;
if (exponent <= 31) { // positive
exponent += 127;
}
else { // negative exponent
exponent -= 64;
exponent += 127;
}
int mantissa = (a1 & 0x1FFFFFF) >> 2;
return (a1 & 0x80000000) | (exponent << 23) | mantissa;
}
UINT32 R3DFloat::Convert16BitProFloat(UINT32 a1)
{
return ConvertProFloat(a1 << 15);
}
float R3DFloat::ToFloat(UINT32 a1)
{
return *(float*)(&a1);
}

View file

@ -0,0 +1,14 @@
#ifndef _R3DFLOAT_H_
#define _R3DFLOAT_H_
namespace R3DFloat
{
float GetFloat16(UINT16 f);
float GetFloat32(UINT32 f);
UINT32 ConvertProFloat(UINT32 a1); // return float in hex or integer format
UINT32 Convert16BitProFloat(UINT32 a1);
float ToFloat(UINT32 a1); // integer float to actual IEEE 754 float
}
#endif

View file

@ -316,6 +316,7 @@ xcopy /D /Y "$(ProjectDir)\SDL\$(Platform)\$(Configuration)\SDL.dll" "$(TargetDi
<ClCompile Include="..\Src\Graphics\New3D\Model.cpp" />
<ClCompile Include="..\Src\Graphics\New3D\New3D.cpp" />
<ClCompile Include="..\Src\Graphics\New3D\PolyHeader.cpp" />
<ClCompile Include="..\Src\Graphics\New3D\R3DFloat.cpp" />
<ClCompile Include="..\Src\Graphics\New3D\R3DShader.cpp" />
<ClCompile Include="..\Src\Graphics\New3D\Texture.cpp" />
<ClCompile Include="..\Src\Graphics\New3D\TextureSheet.cpp" />
@ -538,6 +539,7 @@ xcopy /D /Y "$(ProjectDir)\SDL\$(Platform)\$(Configuration)\SDL.dll" "$(TargetDi
<ClInclude Include="..\Src\Graphics\New3D\Plane.h" />
<ClInclude Include="..\Src\Graphics\New3D\PolyHeader.h" />
<ClInclude Include="..\Src\Graphics\New3D\R3DData.h" />
<ClInclude Include="..\Src\Graphics\New3D\R3DFloat.h" />
<ClInclude Include="..\Src\Graphics\New3D\R3DShader.h" />
<ClInclude Include="..\Src\Graphics\New3D\Texture.h" />
<ClInclude Include="..\Src\Graphics\New3D\TextureSheet.h" />

View file

@ -425,6 +425,9 @@
<ClCompile Include="..\Src\Util\Format.cpp">
<Filter>Source Files\Util</Filter>
</ClCompile>
<ClCompile Include="..\Src\Graphics\New3D\R3DFloat.cpp">
<Filter>Source Files\Graphics\New</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<MASM Include="..\Src\CPU\68K\Turbo68K\Turbo68K.asm">
@ -787,6 +790,9 @@
<ClInclude Include="..\Src\Graphics\New3D\Plane.h">
<Filter>Source Files\Graphics\New</Filter>
</ClInclude>
<ClInclude Include="..\Src\Graphics\New3D\R3DFloat.h">
<Filter>Source Files\Graphics\New</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\Src\Debugger\ReadMe.txt">