1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-07 03:13:49 +00:00

Implement LookAt functionality.

This commit is contained in:
Sergey Lipskiy 2014-10-11 15:16:51 +07:00
parent 81c15fde15
commit 59d19c647d
5 changed files with 48 additions and 17 deletions

View File

@ -72,8 +72,10 @@ void F3D_MoveMem( u32 w0, u32 w1 )
gSPLight( w1, LIGHT_8 ); gSPLight( w1, LIGHT_8 );
break; break;
case G_MV_LOOKATX: case G_MV_LOOKATX:
gSPLookAt(w1, 0);
break; break;
case G_MV_LOOKATY: case G_MV_LOOKATY:
gSPLookAt(w1, 1);
break; break;
} }
} }

View File

@ -33,16 +33,14 @@ void F3DEX2_MoveMem( u32 w0, u32 w1 )
RSP.PC[RSP.PCi] += 8; RSP.PC[RSP.PCi] += 8;
break; break;
case G_MV_LIGHT: case G_MV_LIGHT:
u32 offset = _SHIFTR( w0, 8, 8 ) << 3;
if (offset >= 48)
{ {
gSPLight( w1, (offset - 24) / 24); const u32 offset = (_SHIFTR(w0, 5, 11))&0x7F8;
const u32 n = offset / 24;
if (n < 2)
gSPLookAt(w1, n);
else
gSPLight(w1, n - 1);
} }
/* else
{
// Do lookat stuff
}*/
break; break;
} }
} }

View File

@ -268,4 +268,6 @@ void RSP_Init()
gDP.loadTile = &gDP.tiles[7]; gDP.loadTile = &gDP.tiles[7];
gSP.textureTile[0] = &gDP.tiles[0]; gSP.textureTile[0] = &gDP.tiles[0];
gSP.textureTile[1] = &gDP.tiles[1]; gSP.textureTile[1] = &gDP.tiles[1];
gSP.lookat[0].x = gSP.lookat[1].x = 1.0f;
gSP.lookatEnable = false;
} }

43
gSP.cpp
View File

@ -326,15 +326,22 @@ void gSPProcessVertex( u32 v )
gSPLightVertex(v); gSPLightVertex(v);
if (gSP.geometryMode & G_TEXTURE_GEN) { if (gSP.geometryMode & G_TEXTURE_GEN) {
float fLightDir[3] = {vtx.nx, vtx.ny, vtx.nz}; f32 fLightDir[3] = {vtx.nx, vtx.ny, vtx.nz};
TransformVectorNormalize(fLightDir, gSP.matrix.projection); TransformVectorNormalize(fLightDir, gSP.matrix.projection);
f32 x, y;
if (gSP.lookatEnable) {
x = DotProduct(&gSP.lookat[0].x, fLightDir);
y = DotProduct(&gSP.lookat[1].x, fLightDir);
} else {
x = fLightDir[0];
y = fLightDir[1];
}
if (gSP.geometryMode & G_TEXTURE_GEN_LINEAR) { if (gSP.geometryMode & G_TEXTURE_GEN_LINEAR) {
vtx.s = acosf(fLightDir[0]) * 325.94931f; vtx.s = acosf(x) * 325.94931f;
vtx.t = acosf(fLightDir[1]) * 325.94931f; vtx.t = acosf(y) * 325.94931f;
} else { // G_TEXTURE_GEN } else { // G_TEXTURE_GEN
vtx.s = (fLightDir[0] + 1.0f) * 512.0f; vtx.s = (x + 1.0f) * 512.0f;
vtx.t = (fLightDir[1] + 1.0f) * 512.0f; vtx.t = (y + 1.0f) * 512.0f;
} }
} }
} }
@ -525,7 +532,7 @@ void gSPForceMatrix( u32 mptr )
void gSPLight( u32 l, s32 n ) void gSPLight( u32 l, s32 n )
{ {
n--; --n;
u32 address = RSP_SegmentToPhysical( l ); u32 address = RSP_SegmentToPhysical( l );
if ((address + sizeof( Light )) > RDRAMSize) { if ((address + sizeof( Light )) > RDRAMSize) {
@ -564,8 +571,28 @@ void gSPLight( u32 l, s32 n )
#endif #endif
} }
void gSPLookAt( u32 l ) void gSPLookAt( u32 _l, u32 _n )
{ {
u32 address = RSP_SegmentToPhysical(_l);
if ((address + sizeof(Light)) > RDRAMSize) {
#ifdef DEBUG
DebugMsg(DEBUG_HIGH | DEBUG_ERROR, "// Attempting to load light from invalid address\n");
DebugMsg(DEBUG_HIGH | DEBUG_HANDLED, "gSPLookAt( 0x%08X, LOOKAT_%i );\n",
l, n);
#endif
return;
}
Light *light = (Light*)&RDRAM[address];
gSP.lookat[_n].x = light->x;
gSP.lookat[_n].y = light->y;
gSP.lookat[_n].z = light->z;
gSP.lookatEnable = (_n == 0) || (_n == 1 && light->x != 0 && light->y != 0);
Normalize(&gSP.lookat[_n].x);
} }
void gSPVertex( u32 a, u32 n, u32 v0 ) void gSPVertex( u32 a, u32 n, u32 v0 )

4
gSP.h
View File

@ -106,6 +106,8 @@ struct gSPInfo
u32 vertexi; u32 vertexi;
SPLight lights[8]; SPLight lights[8];
SPLight lookat[2];
bool lookatEnable;
struct struct
{ {
@ -156,7 +158,7 @@ void gSPDMAMatrix( u32 matrix, u8 index, u8 multiply );
void gSPViewport( u32 v ); void gSPViewport( u32 v );
void gSPForceMatrix( u32 mptr ); void gSPForceMatrix( u32 mptr );
void gSPLight( u32 l, s32 n ); void gSPLight( u32 l, s32 n );
void gSPLookAt( u32 l ); void gSPLookAt( u32 l, u32 n );
void gSPVertex( u32 v, u32 n, u32 v0 ); void gSPVertex( u32 v, u32 n, u32 v0 );
void gSPCIVertex( u32 v, u32 n, u32 v0 ); void gSPCIVertex( u32 v, u32 n, u32 v0 );
void gSPDMAVertex( u32 v, u32 n, u32 v0 ); void gSPDMAVertex( u32 v, u32 n, u32 v0 );