mirror of
https://github.com/blawar/GLideN64.git
synced 2024-06-25 22:09:35 +00:00
Add matix element conversion functions.
This commit is contained in:
parent
b0647a64d1
commit
3ff1478103
|
@ -1,5 +1,6 @@
|
|||
#include <math.h>
|
||||
#include "3DMath.h"
|
||||
#include "GBI.h"
|
||||
|
||||
void MultMatrix(float m0[4][4], float m1[4][4], float dest[4][4])
|
||||
{
|
||||
|
@ -143,3 +144,15 @@ void CopyMatrix( float m0[4][4], float m1[4][4] )
|
|||
memcpy( m0, m1, 16 * sizeof( float ) );
|
||||
#endif // WIN32_ASM
|
||||
}
|
||||
|
||||
float GetFloatMatrixElement(s16 _int, u16 _fract)
|
||||
{
|
||||
const s32 element = (_int << 16) | _fract;
|
||||
return _FIXED2FLOAT(element, 16);
|
||||
}
|
||||
|
||||
std::pair<s16, u16> GetIntMatrixElement(f32 _elem)
|
||||
{
|
||||
const s32 value = static_cast<s32>(_elem * 65536.0f);
|
||||
return std::pair<s16, u16>(static_cast<s16>(value >> 16), static_cast<u16>(value & 0xFFFF));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#ifndef _3DMATH_H
|
||||
#define _3DMATH_H
|
||||
#include <utility>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
#include <Types.h>
|
||||
|
@ -38,4 +39,7 @@ inline float DotProduct(const float v0[3], const float v1[3])
|
|||
return dot;
|
||||
}
|
||||
|
||||
float GetFloatMatrixElement(s16 _int, u16 _fract);
|
||||
std::pair<s16, u16> GetIntMatrixElement(f32 _elem);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -69,11 +69,6 @@
|
|||
#define _SHIFTR( v, s, w ) \
|
||||
(((u32)v >> s) & ((0x01 << w) - 1))
|
||||
|
||||
union s32u32 {
|
||||
s32 s;
|
||||
u32 u;
|
||||
};
|
||||
|
||||
// BG flags
|
||||
#define G_BGLT_LOADBLOCK 0x0033
|
||||
#define G_BGLT_LOADTILE 0xfff4
|
||||
|
|
|
@ -1,23 +1,15 @@
|
|||
#include "RSP.h"
|
||||
#include "GBI.h"
|
||||
#include "3DMath.h"
|
||||
|
||||
void RSP_LoadMatrix( f32 mtx[4][4], u32 address )
|
||||
{
|
||||
s32u32 value;
|
||||
|
||||
struct _N64Matrix
|
||||
{
|
||||
s16 integer[4][4];
|
||||
u16 fraction[4][4];
|
||||
} *n64Mat = (struct _N64Matrix *)&RDRAM[address];
|
||||
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
{
|
||||
value.s = (s32)n64Mat->integer[i][j^1] << 16;
|
||||
value.u += n64Mat->fraction[i][j^1];
|
||||
mtx[i][j] = _FIXED2FLOAT(value.s,16);
|
||||
}
|
||||
for (u32 i = 0; i < 4; i++)
|
||||
for (u32 j = 0; j < 4; j++)
|
||||
mtx[i][j] = GetFloatMatrixElement(n64Mat->integer[i][j ^ 1], n64Mat->fraction[i][j ^ 1]);
|
||||
}
|
||||
|
|
27
src/gSP.cpp
27
src/gSP.cpp
|
@ -1572,25 +1572,22 @@ void gSPInsertMatrix( u32 where, u32 num )
|
|||
{
|
||||
DebugMsg(DEBUG_NORMAL, "gSPInsertMatrix(%u, %u);\n", where, num);
|
||||
|
||||
s32u32 value;
|
||||
f32 fraction, integer;
|
||||
|
||||
if ((where & 0x3) || (where > 0x3C))
|
||||
return;
|
||||
|
||||
for(int i = 0; i < 2;i++)
|
||||
{
|
||||
// integer elements of the matrix to be changed
|
||||
const u16 * pData = reinterpret_cast<u16*>(&num);
|
||||
const u32 index = (where < 0x20) ? (where >> 1) : ((where - 0x20) >> 1);
|
||||
for (u32 i = 0; i < 2; i++) {
|
||||
if (where < 0x20) {
|
||||
value.s = (s32)(gSP.matrix.combined[0][(where >> 1) + i] * 65536.0f);
|
||||
value.u = value.u & 0x0000FFFF + (s32)(_SHIFTR( num, 16 * (1 - i), 16 ) << 16);
|
||||
gSP.matrix.combined[0][(where >> 1) + i] = _FIXED2FLOAT( value.s, 16 );
|
||||
}
|
||||
// fractional elements of the matrix to be changed
|
||||
else {
|
||||
value.s = (s32)(gSP.matrix.combined[0][((where - 0x20) >> 1) + i] * 65535.0f) ;
|
||||
value.u = value.u & 0xFFFF0000 + _SHIFTR( num, 16 * (1 - i), 16 );
|
||||
gSP.matrix.combined[0][((where - 0x20) >> 1) + i] = _FIXED2FLOAT( value.s, 16 );
|
||||
// integer elements of the matrix to be changed
|
||||
const s16 integer = static_cast<s16>(pData[i ^ 1]);
|
||||
const s32 fract = static_cast<s32>(gSP.matrix.combined[0][index + i] * 65536.0f);
|
||||
gSP.matrix.combined[0][index + i] = GetFloatMatrixElement(integer, static_cast<u16>(fract&0xFFFF));
|
||||
} else {
|
||||
// fractional elements of the matrix to be changed
|
||||
const s32 integer = static_cast<s32>(gSP.matrix.combined[0][index + i]);
|
||||
const u16 fract = pData[i ^ 1];
|
||||
gSP.matrix.combined[0][index + i] = GetFloatMatrixElement(static_cast<s16>(integer), fract);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,22 +122,17 @@ void ZSortBOSS_ClearBuffer( u32, u32 )
|
|||
static
|
||||
void StoreMatrix( f32 mtx[4][4], u32 address )
|
||||
{
|
||||
s32u32 value;
|
||||
|
||||
struct _N64Matrix
|
||||
{
|
||||
s16 integer[4][4];
|
||||
u16 fraction[4][4];
|
||||
} *n64Mat = (struct _N64Matrix *)&RDRAM[address];
|
||||
|
||||
int i, j;
|
||||
float intpart, fractpart;
|
||||
|
||||
for(i = 0; i < 4; i++) {
|
||||
for(j = 0; j < 4; j++) {
|
||||
value.s = (s32)(mtx[i][j] * 65536.0f);
|
||||
n64Mat->fraction[i][j^1] = (u16)(value.u & 0x0000FFFF);
|
||||
n64Mat->integer[i][j^1] = (s16)(value.s >> 16);
|
||||
for (u32 i = 0; i < 4; i++) {
|
||||
for (u32 j = 0; j < 4; j++) {
|
||||
const auto element = GetIntMatrixElement(mtx[i][j]);
|
||||
n64Mat->fraction[i][j^1] = element.second;
|
||||
n64Mat->integer[i][j^1] = element.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user