1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-12-23 01:00:00 +00:00

some Radar and Hud cleanup; fix in Physical

This commit is contained in:
aap 2019-06-23 13:11:41 +02:00
parent 047fa20f28
commit a5ba538968
9 changed files with 177 additions and 165 deletions

View file

@ -15,14 +15,12 @@
WRAPPER void CRadar::Draw3dMarkers() { EAXJMP(0x4A4C70); } WRAPPER void CRadar::Draw3dMarkers() { EAXJMP(0x4A4C70); }
WRAPPER int CRadar::ClipRadarPoly(CVector2D *out, CVector2D *in) { EAXJMP(0x4A64A0); } WRAPPER int CRadar::ClipRadarPoly(CVector2D *out, CVector2D *in) { EAXJMP(0x4A64A0); }
WRAPPER void CRadar::TransformRadarPointToRealWorldSpace(CVector2D *out, CVector2D *in) { EAXJMP(0x4A5300); } WRAPPER void CRadar::TransformRadarPointToRealWorldSpace(CVector2D &out, const CVector2D &in) { EAXJMP(0x4A5300); }
float &CRadar::m_RadarRange = *(float*)0x8E281C; float &CRadar::m_RadarRange = *(float*)0x8E281C;
CVector2D &CRadar::vec2DRadarOrigin = *(CVector2D*)0x6299B8;
CBlip *CRadar::ms_RadarTrace = (CBlip*)0x6ED5E0; CBlip *CRadar::ms_RadarTrace = (CBlip*)0x6ED5E0;
float CRadar::cachedSin;
float CRadar::cachedCos;
CVector2D &vec2DRadarOrigin = *(CVector2D*)0x6299B8;
int *gRadarTxdIds = (int*)0x6299C0; int *gRadarTxdIds = (int*)0x6299C0;
CSprite2d *CRadar::AsukaSprite = (CSprite2d*)0x8F1A40; CSprite2d *CRadar::AsukaSprite = (CSprite2d*)0x8F1A40;
@ -70,6 +68,13 @@ CSprite2d *CRadar::RadarSprites[RADAR_SPRITE_COUNT] = {
WeaponSprite WeaponSprite
}; };
#define RADAR_NUM_TILES (8)
#define RADAR_MIN_RANGE (120.0f)
#define RADAR_MAX_RANGE (350.0f)
#define RADAR_MIN_SPEED (0.3f)
#define RADAR_MAX_SPEED (0.9f)
#if 0 #if 0
WRAPPER void CRadar::DrawMap () { EAXJMP(0x4A4200); } WRAPPER void CRadar::DrawMap () { EAXJMP(0x4A4200); }
#else #else
@ -77,21 +82,19 @@ void CRadar::DrawMap()
{ {
if (!TheCamera.m_WideScreenOn && CHud::m_Wants_To_Draw_Hud) { if (!TheCamera.m_WideScreenOn && CHud::m_Wants_To_Draw_Hud) {
if (FindPlayerVehicle()) { if (FindPlayerVehicle()) {
if (FindPlayerVehicle()->GetSpeed().Magnitude() > 0.3f) { float speed = FindPlayerSpeed().Magnitude();
if (FindPlayerVehicle()->GetSpeed().Magnitude() > 0.9f) if (speed < RADAR_MIN_SPEED)
CRadar::m_RadarRange = 350.0f; m_RadarRange = RADAR_MIN_RANGE;
else else if (speed < RADAR_MAX_SPEED)
CRadar::m_RadarRange = (FindPlayerVehicle()->GetSpeed().Magnitude() + 0.3f) * 200.0f; m_RadarRange = (speed - RADAR_MIN_SPEED)/(RADAR_MAX_SPEED-RADAR_MIN_SPEED) * (RADAR_MAX_RANGE-RADAR_MIN_RANGE) + RADAR_MIN_RANGE;
}
else else
CRadar::m_RadarRange = 120.0f; m_RadarRange = RADAR_MAX_RANGE;
} }
else else
CRadar::m_RadarRange = 120.0f; m_RadarRange = RADAR_MIN_RANGE;
vec2DRadarOrigin.x = FindPlayerCentreOfWorld_NoSniperShift().x; vec2DRadarOrigin = CVector2D(FindPlayerCentreOfWorld_NoSniperShift());
vec2DRadarOrigin.y = FindPlayerCentreOfWorld_NoSniperShift().y; DrawRadarMap();
CRadar::DrawRadarMap();
} }
} }
#endif #endif
@ -101,7 +104,7 @@ WRAPPER void CRadar::DrawRadarMask() { EAXJMP(0x4A69C0); }
#else #else
void CRadar::DrawRadarMask() void CRadar::DrawRadarMask()
{ {
CVector2D vec2d[4] = { CVector2D corners[4] = {
CVector2D(1.0f, -1.0f), CVector2D(1.0f, -1.0f),
CVector2D(1.0f, 1.0f), CVector2D(1.0f, 1.0f),
CVector2D(-1.0f, 1.0f), CVector2D(-1.0f, 1.0f),
@ -122,19 +125,18 @@ void CRadar::DrawRadarMask()
CVector2D out[8]; CVector2D out[8];
CVector2D in; CVector2D in;
// Draw the shape we want to mask out from the radar in four segments
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
in.x = vec2d[i].x; // First point is always the corner itself
in.y = vec2d[i].y; in.x = corners[i].x;
in.y = corners[i].y;
CRadar::TransformRadarPointToScreenSpace(out, &in); TransformRadarPointToScreenSpace(out[0], in);
// Then generate a quarter of the circle
for (int j = 0; j < 7; j++) { for (int j = 0; j < 7; j++) {
CRadar::cachedCos = cos(j * (PI / 2.0f / 6.0f)); in.x = corners[i].x * cos(j * (PI / 2.0f / 6.0f));
CRadar::cachedSin = sin(j * (PI / 2.0f / 6.0f)); in.y = corners[i].y * sin(j * (PI / 2.0f / 6.0f));
TransformRadarPointToScreenSpace(out[j + 1], in);
in.x = vec2d[i].x * cachedCos;
in.y = vec2d[i].y * cachedSin;
CRadar::TransformRadarPointToScreenSpace(&out[j + 1], &in);
}; };
CSprite2d::SetMaskVertices(8, (float *)out); CSprite2d::SetMaskVertices(8, (float *)out);
@ -163,7 +165,7 @@ void CRadar::SetRadarMarkerState(int counter, int flag)
break; break;
default: default:
return; return;
}; }
if (e) if (e)
e->bHasBlip = flag; e->bHasBlip = flag;
@ -176,9 +178,9 @@ WRAPPER void CRadar::ClearBlipForEntity(eBlipType type, int32 id) { EAXJMP(0x4A5
#else #else
void CRadar::ClearBlipForEntity(eBlipType type, int32 id) void CRadar::ClearBlipForEntity(eBlipType type, int32 id)
{ {
for (int i = 0; i < 32; i++) { for (int i = 0; i < NUMRADARBLIPS; i++) {
if (type == ms_RadarTrace[i].m_eBlipType && id == ms_RadarTrace[i].m_nEntityHandle) { if (type == ms_RadarTrace[i].m_eBlipType && id == ms_RadarTrace[i].m_nEntityHandle) {
CRadar::SetRadarMarkerState(i, 0); SetRadarMarkerState(i, 0);
ms_RadarTrace[i].m_bInUse = 0; ms_RadarTrace[i].m_bInUse = 0;
ms_RadarTrace[i].m_eBlipType = 0; ms_RadarTrace[i].m_eBlipType = 0;
ms_RadarTrace[i].m_eBlipDisplay = 0; ms_RadarTrace[i].m_eBlipDisplay = 0;
@ -200,13 +202,13 @@ void CRadar::DrawRadarSection(int x, int y)
void CRadar::RequestMapSection(int x, int y) void CRadar::RequestMapSection(int x, int y)
{ {
ClipRadarTileCoords(&x, &y); ClipRadarTileCoords(&x, &y);
CStreaming::RequestModel(gRadarTxdIds[x + 8 * y] + 5500, 5); CStreaming::RequestTxd(gRadarTxdIds[x + RADAR_NUM_TILES * y], STREAMFLAGS_DONT_REMOVE|STREAMFLAGS_DEPENDENCY);
} }
void CRadar::RemoveMapSection(int x, int y) void CRadar::RemoveMapSection(int x, int y)
{ {
if (x >= 0 && x <= 7 && y >= 0 && y <= 7) if (x >= 0 && x <= 7 && y >= 0 && y <= 7)
CStreaming::RemoveModel(gRadarTxdIds[x + 8 * y] + 5500); CStreaming::RemoveTxd(gRadarTxdIds[x + RADAR_NUM_TILES * y]);
} }
#if 0 #if 0
@ -214,8 +216,8 @@ WRAPPER void CRadar::StreamRadarSections(int x, int y) { EAXJMP(0x4A6100); }
#else #else
void CRadar::StreamRadarSections(int x, int y) void CRadar::StreamRadarSections(int x, int y)
{ {
for (int i = 0; i < 8; ++i) { for (int i = 0; i < RADAR_NUM_TILES; ++i) {
for (int j = 0; j < 8; ++j) { for (int j = 0; j < RADAR_NUM_TILES; ++j) {
if ((i >= x - 1 && i <= x + 1) && (j >= y - 1 && j <= y + 1)) if ((i >= x - 1 && i <= x + 1) && (j >= y - 1 && j <= y + 1))
RequestMapSection(i, j); RequestMapSection(i, j);
else else
@ -226,29 +228,31 @@ void CRadar::StreamRadarSections(int x, int y)
#endif #endif
#if 0 #if 0
WRAPPER float CRadar::LimitRadarPoint(CVector2D *point) { EAXJMP(0x4A4F30); } WRAPPER float CRadar::LimitRadarPoint(CVector2D &point) { EAXJMP(0x4A4F30); }
#else #else
float CRadar::LimitRadarPoint(CVector2D *point) float CRadar::LimitRadarPoint(CVector2D &point)
{ {
float div; float dist, invdist;
if (point->Magnitude() > 1.0f) { dist = point.Magnitude();
div = 1.0f / point->Magnitude(); if (dist > 1.0f) {
point->x *= div; invdist = 1.0f / dist;
point->y *= div; point.x *= invdist;
point.y *= invdist;
} }
return point->Magnitude(); return dist;
} }
#endif #endif
#if 0 #if 0
WRAPPER void CRadar::TransformRealWorldToTexCoordSpace(CVector2D *out, CVector2D *in, int x, int y) { EAXJMP(0x4A5530); } WRAPPER void CRadar::TransformRealWorldToTexCoordSpace(CVector2D &out, const CVector2D &in, int x, int y) { EAXJMP(0x4A5530); }
#else #else
void CRadar::TransformRealWorldToTexCoordSpace(CVector2D *out, CVector2D *in, int x, int y) { void CRadar::TransformRealWorldToTexCoordSpace(CVector2D &out, const CVector2D &in, int x, int y)
out->x = in->x - (x * 500.0f - WORLD_MAX_X); {
out->y = -(in->y - ((8 - y) * 500.0f - WORLD_MAX_Y)); out.x = in.x - (x * 500.0f + WORLD_MIN_X);
out->x *= 0.002f; out.y = -(in.y - ((RADAR_NUM_TILES - y) * 500.0f + WORLD_MIN_Y));
out->y *= 0.002f; out.x /= 500.0f;
out.y /= 500.0f;
} }
#endif #endif
@ -257,11 +261,11 @@ WRAPPER void CRadar::DrawRadarMap() { EAXJMP(0x4A6C20); }
#else #else
void CRadar::DrawRadarMap() void CRadar::DrawRadarMap()
{ {
CRadar::DrawRadarMask(); DrawRadarMask();
int x = floorf((WORLD_MAX_X + vec2DRadarOrigin.x) * 0.002f); int x = floorf((vec2DRadarOrigin.x - WORLD_MIN_X) / 500.0f);
int y = round(7.0f - (WORLD_MAX_Y + vec2DRadarOrigin.y) * 0.002f); int y = round(7.0f - (vec2DRadarOrigin.y - WORLD_MIN_Y) / 500.0f);
CRadar::StreamRadarSections(x, y); StreamRadarSections(x, y);
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE);
RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA);
@ -274,15 +278,15 @@ void CRadar::DrawRadarMap()
RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void*)rwTEXTUREADDRESSCLAMP); RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void*)rwTEXTUREADDRESSCLAMP);
RwRenderStateSet(rwRENDERSTATETEXTUREPERSPECTIVE, (void*)FALSE); RwRenderStateSet(rwRENDERSTATETEXTUREPERSPECTIVE, (void*)FALSE);
CRadar::DrawRadarSection(x - 1, y - 1); DrawRadarSection(x - 1, y - 1);
CRadar::DrawRadarSection(x, y - 1); DrawRadarSection(x, y - 1);
CRadar::DrawRadarSection(x + 1, y - 1); DrawRadarSection(x + 1, y - 1);
CRadar::DrawRadarSection(x - 1, y); DrawRadarSection(x - 1, y);
CRadar::DrawRadarSection(x, y); DrawRadarSection(x, y);
CRadar::DrawRadarSection(x + 1, y); DrawRadarSection(x + 1, y);
CRadar::DrawRadarSection(x - 1, y + 1); DrawRadarSection(x - 1, y + 1);
CRadar::DrawRadarSection(x, y + 1); DrawRadarSection(x, y + 1);
CRadar::DrawRadarSection(x + 1, y + 1); DrawRadarSection(x + 1, y + 1);
} }
#endif #endif
@ -301,7 +305,7 @@ void CRadar::DrawBlips()
CVector2D out; CVector2D out;
CVector2D in = CVector2D(0.0f, 0.0f); CVector2D in = CVector2D(0.0f, 0.0f);
CRadar::TransformRadarPointToScreenSpace(&out, &in); TransformRadarPointToScreenSpace(out, in);
float angle; float angle;
if (TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN1) if (TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN1)
@ -309,20 +313,20 @@ void CRadar::DrawBlips()
else else
angle = FindPlayerHeading() - (PI + atan2(-TheCamera.GetForward().x, TheCamera.GetForward().y)); angle = FindPlayerHeading() - (PI + atan2(-TheCamera.GetForward().x, TheCamera.GetForward().y));
CRadar::DrawRotatingRadarSprite(CentreSprite, out.x, out.y, angle, 255); DrawRotatingRadarSprite(CentreSprite, out.x, out.y, angle, 255);
CVector2D vec2d; CVector2D vec2d;
vec2d.x = vec2DRadarOrigin.x; vec2d.x = vec2DRadarOrigin.x;
vec2d.y = M_SQRT2 * m_RadarRange + vec2DRadarOrigin.y; vec2d.y = M_SQRT2 * m_RadarRange + vec2DRadarOrigin.y;
CRadar::TransformRealWorldPointToRadarSpace(&in, &vec2d); TransformRealWorldPointToRadarSpace(in, vec2d);
CRadar::LimitRadarPoint(&in); LimitRadarPoint(in);
CRadar::TransformRadarPointToScreenSpace(&out, &in); TransformRadarPointToScreenSpace(out, in);
CRadar::DrawRadarSprite(RADAR_SPRITE_NORTH, out.x, out.y, 255); DrawRadarSprite(RADAR_SPRITE_NORTH, out.x, out.y, 255);
/* /*
DrawEntityBlip DrawEntityBlip
*/ */
for (int i = 0; i < 32; i++) { for (int i = 0; i < NUMRADARBLIPS; i++) {
if (ms_RadarTrace[i].m_bInUse) { if (ms_RadarTrace[i].m_bInUse) {
if (ms_RadarTrace[i].m_eBlipType <= BLIP_OBJECT) { if (ms_RadarTrace[i].m_eBlipType <= BLIP_OBJECT) {
CEntity *e = nil; CEntity *e = nil;
@ -341,7 +345,7 @@ void CRadar::DrawBlips()
if (e) { if (e) {
if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) { if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) {
if (CTheScripts::DbgFlag) { if (CTheScripts::DbgFlag) {
CRadar::ShowRadarMarker(e->GetPosition(), GetRadarTraceColour(ms_RadarTrace[i].m_nColor, ms_RadarTrace[i].m_bDim), ms_RadarTrace->m_Radius); ShowRadarMarker(e->GetPosition(), GetRadarTraceColour(ms_RadarTrace[i].m_nColor, ms_RadarTrace[i].m_bDim), ms_RadarTrace->m_Radius);
ms_RadarTrace[i].m_Radius = ms_RadarTrace[i].m_Radius - 0.1f; ms_RadarTrace[i].m_Radius = ms_RadarTrace[i].m_Radius - 0.1f;
if (ms_RadarTrace[i].m_Radius >= 1.0f) if (ms_RadarTrace[i].m_Radius >= 1.0f)
@ -350,17 +354,17 @@ void CRadar::DrawBlips()
} }
if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BLIP_ONLY) { if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BLIP_ONLY) {
vec2d = e->GetPosition(); vec2d = e->GetPosition();
CRadar::TransformRealWorldPointToRadarSpace(&in, &vec2d); TransformRealWorldPointToRadarSpace(in, vec2d);
float dist = CRadar::LimitRadarPoint(&in); float dist = LimitRadarPoint(in);
int a = CRadar::CalculateBlipAlpha(dist); int a = CalculateBlipAlpha(dist);
CRadar::TransformRadarPointToScreenSpace(&out, &in); TransformRadarPointToScreenSpace(out, in);
CRGBA col = CRadar::GetRadarTraceColour(ms_RadarTrace[i].m_nColor, ms_RadarTrace[i].m_bDim); CRGBA col = GetRadarTraceColour(ms_RadarTrace[i].m_nColor, ms_RadarTrace[i].m_bDim);
if (ms_RadarTrace[i].m_IconID) if (ms_RadarTrace[i].m_IconID)
CRadar::DrawRadarSprite(ms_RadarTrace[i].m_IconID, out.x, out.y, a); DrawRadarSprite(ms_RadarTrace[i].m_IconID, out.x, out.y, a);
else else
CRadar::ShowRadarTrace(out.x, out.y, ms_RadarTrace[i].m_wScale, col.r, col.g, col.b, 255); ShowRadarTrace(out.x, out.y, ms_RadarTrace[i].m_wScale, col.r, col.g, col.b, 255);
} }
} }
} }
@ -372,7 +376,7 @@ void CRadar::DrawBlips()
if (ms_RadarTrace[i].m_eBlipType != BLIP_CONTACT_POINT || ms_RadarTrace[i].m_eBlipType == BLIP_CONTACT_POINT && DisplayThisBlip(i) || !CTheScripts::IsPlayerOnAMission()) { if (ms_RadarTrace[i].m_eBlipType != BLIP_CONTACT_POINT || ms_RadarTrace[i].m_eBlipType == BLIP_CONTACT_POINT && DisplayThisBlip(i) || !CTheScripts::IsPlayerOnAMission()) {
if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) { if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) {
if (CTheScripts::DbgFlag) { if (CTheScripts::DbgFlag) {
CRadar::ShowRadarMarker(ms_RadarTrace[i].m_vecPos, CRadar::GetRadarTraceColour(ms_RadarTrace[i].m_nColor, ms_RadarTrace[i].m_bDim), ms_RadarTrace->m_Radius); ShowRadarMarker(ms_RadarTrace[i].m_vecPos, GetRadarTraceColour(ms_RadarTrace[i].m_nColor, ms_RadarTrace[i].m_bDim), ms_RadarTrace->m_Radius);
ms_RadarTrace[i].m_Radius = ms_RadarTrace[i].m_Radius - 0.1f; ms_RadarTrace[i].m_Radius = ms_RadarTrace[i].m_Radius - 0.1f;
if (ms_RadarTrace[i].m_Radius >= 1.0f) if (ms_RadarTrace[i].m_Radius >= 1.0f)
ms_RadarTrace[i].m_Radius = 5.0f; ms_RadarTrace[i].m_Radius = 5.0f;
@ -380,17 +384,17 @@ void CRadar::DrawBlips()
} }
if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BLIP_ONLY) { if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BLIP_ONLY) {
CRadar::TransformRealWorldPointToRadarSpace(&in, &ms_RadarTrace[i].m_vec2DPos); TransformRealWorldPointToRadarSpace(in, ms_RadarTrace[i].m_vec2DPos);
float dist = CRadar::LimitRadarPoint(&in); float dist = LimitRadarPoint(in);
int a = CRadar::CalculateBlipAlpha(dist); int a = CalculateBlipAlpha(dist);
CRadar::TransformRadarPointToScreenSpace(&out, &in); TransformRadarPointToScreenSpace(out, in);
CRGBA col = CRadar::GetRadarTraceColour(ms_RadarTrace[i].m_nColor, ms_RadarTrace[i].m_bDim); CRGBA col = GetRadarTraceColour(ms_RadarTrace[i].m_nColor, ms_RadarTrace[i].m_bDim);
if (CRadar::ms_RadarTrace[i].m_IconID) if (ms_RadarTrace[i].m_IconID)
CRadar::DrawRadarSprite(ms_RadarTrace[i].m_IconID, out.x, out.y, a); DrawRadarSprite(ms_RadarTrace[i].m_IconID, out.x, out.y, a);
else else
CRadar::ShowRadarTrace(out.x, out.y, ms_RadarTrace[i].m_wScale, col.r, col.g, col.b, 255); ShowRadarTrace(out.x, out.y, ms_RadarTrace[i].m_wScale, col.r, col.g, col.b, 255);
} }
} }
} }
@ -454,46 +458,44 @@ CRGBA CRadar::GetRadarTraceColour(uint32 color, bool bright)
} }
} }
void CRadar::TransformRadarPointToScreenSpace(CVector2D *out, CVector2D *in) // Radar space goes from -1.0 to 1.0 in x and y, top right is (1.0, 1.0)
void CRadar::TransformRadarPointToScreenSpace(CVector2D &out, const CVector2D &in)
{ {
out->x = in->x * SCREEN_SCALE_X(47.0f) + SCREEN_SCALE_X(47.0f + 20.0f); // FIX: game doesn't scale RADAR_LEFT here
out->y = (SCREEN_SCALE_Y(76.0f)) * 0.5f + SCREEN_HEIGHT - (SCREEN_SCALE_Y(123.0f)) - in->y * (SCREEN_SCALE_Y(76.0f)) * 0.5f; out.x = (in.x + 1.0f)*0.5f*SCREEN_SCALE_X(RADAR_WIDTH) + SCREEN_SCALE_X(RADAR_LEFT);
out.y = (1.0f - in.y)*0.5f*SCREEN_SCALE_Y(RADAR_HEIGHT) + SCREEN_SCALE_FROM_BOTTOM(RADAR_BOTTOM + RADAR_HEIGHT);
} }
#if 0 #if 0
WRAPPER void CRadar::TransformRealWorldPointToRadarSpace(CVector2D *out, CVector2D *in) { EAXJMP(0x4A50D0); } WRAPPER void CRadar::TransformRealWorldPointToRadarSpace(CVector2D &out, const CVector2D &in) { EAXJMP(0x4A50D0); }
#else #else
void CRadar::TransformRealWorldPointToRadarSpace(CVector2D *out, CVector2D *in) void CRadar::TransformRealWorldPointToRadarSpace(CVector2D &out, const CVector2D &in)
{ {
if (TheCamera.Cams[TheCamera.ActiveCam].Mode != CCam::MODE_TOPDOWN1 && TheCamera.Cams[TheCamera.ActiveCam].Mode != CCam::MODE_TOPDOWNPED) { float s, c;
if (TheCamera.GetLookDirection() != LOOKING_FORWARD) { if (TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN1 || TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWNPED) {
cachedSin = sin(atan2(-TheCamera.GetForward().x, TheCamera.GetForward().y)); s = 0.0f;
cachedCos = cos(atan2(-TheCamera.GetForward().x, TheCamera.GetForward().y)); c = 1.0f;
} } else if (TheCamera.GetLookDirection() == LOOKING_FORWARD) {
else { s = sin(atan2(-TheCamera.GetForward().x, TheCamera.GetForward().y));
CVector vecCamera; c = cos(atan2(-TheCamera.GetForward().x, TheCamera.GetForward().y));
} else {
CVector forward;
if (TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_FIRSTPERSON) { if (TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_FIRSTPERSON) {
vecCamera = TheCamera.Cams[TheCamera.ActiveCam].CamTargetEntity->m_matrix.m_matrix.up; forward = TheCamera.Cams[TheCamera.ActiveCam].CamTargetEntity->GetForward();
vecCamera.Normalise(); forward.Normalise(); // a bit useless...
} } else
else forward = TheCamera.Cams[TheCamera.ActiveCam].CamTargetEntity->GetPosition() - TheCamera.Cams[TheCamera.ActiveCam].SourceBeforeLookBehind;
vecCamera = TheCamera.GetForward();
s = sin(atan2(-forward.x, forward.y));
cachedSin = sin(atan2(-vecCamera.x, vecCamera.y)); c = cos(atan2(-forward.x, forward.y));
cachedCos = cos(atan2(-vecCamera.x, vecCamera.y));
}
}
else {
cachedSin = 0.0f;
cachedCos = 1.0f;
} }
float x = (in->x - vec2DRadarOrigin.x) * (1.0f / m_RadarRange); float x = (in.x - vec2DRadarOrigin.x) * (1.0f / m_RadarRange);
float y = (in->y - vec2DRadarOrigin.y) * (1.0f / m_RadarRange); float y = (in.y - vec2DRadarOrigin.y) * (1.0f / m_RadarRange);
out->x = cachedSin * y + cachedCos * x; out.x = s * y + c * x;
out->y = cachedCos * y - cachedSin * x; out.y = c * y - s * x;
} }
#endif #endif
@ -501,7 +503,7 @@ void CRadar::TransformRealWorldPointToRadarSpace(CVector2D *out, CVector2D *in)
WRAPPER void CRadar::DrawRadarSprite(int sprite, float x, float y, int alpha) { EAXJMP(0x4A5EF0); } WRAPPER void CRadar::DrawRadarSprite(int sprite, float x, float y, int alpha) { EAXJMP(0x4A5EF0); }
#else #else
void CRadar::DrawRadarSprite(int sprite, float x, float y, int alpha) void CRadar::DrawRadarSprite(int sprite, float x, float y, int alpha)
{ {
RadarSprites[sprite]->Draw(CRect(x - SCREEN_SCALE_X(8.0f), y - SCREEN_SCALE_Y(8.0f), x + SCREEN_SCALE_X(8.0f), y + SCREEN_SCALE_Y(8.0f)), CRGBA(255, 255, 255, alpha)); RadarSprites[sprite]->Draw(CRect(x - SCREEN_SCALE_X(8.0f), y - SCREEN_SCALE_Y(8.0f), x + SCREEN_SCALE_X(8.0f), y + SCREEN_SCALE_Y(8.0f)), CRGBA(255, 255, 255, alpha));
} }
#endif #endif
@ -520,37 +522,25 @@ void CRadar::ShowRadarTrace(float x, float y, uint32 size, uint32 red, uint32 gr
WRAPPER void CRadar::ShowRadarMarker(CVector pos, CRGBA color, float radius) { EAXJMP(0x4A59C0); } WRAPPER void CRadar::ShowRadarMarker(CVector pos, CRGBA color, float radius) { EAXJMP(0x4A59C0); }
#else #else
void CRadar::ShowRadarMarker(CVector pos, CRGBA color, float radius) { void CRadar::ShowRadarMarker(CVector pos, CRGBA color, float radius) {
float z2 = pos.z + (0.5f * color.color32) * TheCamera.m_matrix.m_matrix.at.z; float f1 = radius * 0.5f;
float y2 = (0.5f * color.color32) * TheCamera.m_matrix.m_matrix.at.y + pos.y; float f2 = radius * 1.4f;
float x2 = (0.5f * color.color32) * TheCamera.m_matrix.m_matrix.at.x + pos.x; CVector p1, p2;
float z1 = pos.z + (1.4f * color.color32) * TheCamera.m_matrix.m_matrix.at.z;
float y1 = (1.4f * color.color32) * TheCamera.m_matrix.m_matrix.at.y + pos.y;
float x1 = (1.4f * color.color32) * TheCamera.m_matrix.m_matrix.at.x + pos.x;
CTheScripts::ScriptDebugLine3D(x1, y1, z1, x2, y2, z2, color.color32, color.color32);
z2 = pos.z - (0.5f * color.color32) * TheCamera.m_matrix.m_matrix.at.x; p1 = pos + TheCamera.GetUp()*f1;
y2 = pos.y - (0.5f * color.color32) * TheCamera.m_matrix.m_matrix.at.x; p2 = pos + TheCamera.GetUp()*f2;
x2 = pos.x - (0.5f * color.color32) * TheCamera.m_matrix.m_matrix.at.x; CTheScripts::ScriptDebugLine3D(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, color.color32, color.color32);
z1 = pos.z - (1.4f * color.color32) * TheCamera.m_matrix.m_matrix.at.x;
y1 = pos.y - (1.4f * color.color32) * TheCamera.m_matrix.m_matrix.at.x;
x1 = pos.x - (1.4f * color.color32) * TheCamera.m_matrix.m_matrix.at.x;
CTheScripts::ScriptDebugLine3D(x1, y1, z1, x2, y2, z2, color.color32, color.color32);
z2 = (0.5f * color.color32) * TheCamera.m_matrix.m_matrix.right.x + pos.z; p1 = pos - TheCamera.GetUp()*f1;
y2 = (0.5f * color.color32) * TheCamera.m_matrix.m_matrix.right.x + pos.y; p2 = pos - TheCamera.GetUp()*f2;
x2 = (0.5f * color.color32) * TheCamera.m_matrix.m_matrix.right.x + pos.x; CTheScripts::ScriptDebugLine3D(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, color.color32, color.color32);
z1 = (1.4f * color.color32) * TheCamera.m_matrix.m_matrix.right.x + pos.z;
y1 = (1.4f * color.color32) * TheCamera.m_matrix.m_matrix.right.x + pos.y;
x1 = (1.4f * color.color32) * TheCamera.m_matrix.m_matrix.right.x + pos.x;
CTheScripts::ScriptDebugLine3D(x1, y1, z1, x2, y2, z2, color.color32, color.color32);
z2 = pos.z - (0.5f * color.color32) * TheCamera.m_matrix.m_matrix.right.x; p1 = pos + TheCamera.GetRight()*f1;
y2 = pos.y - (0.5f * color.color32) * TheCamera.m_matrix.m_matrix.right.x; p2 = pos + TheCamera.GetRight()*f2;
x2 = pos.x - (0.5f * color.color32) * TheCamera.m_matrix.m_matrix.right.x; CTheScripts::ScriptDebugLine3D(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, color.color32, color.color32);
z1 = pos.z - (1.4f * color.color32) * TheCamera.m_matrix.m_matrix.right.x;
y1 = pos.y - (1.4f * color.color32) * TheCamera.m_matrix.m_matrix.right.x; p1 = pos - TheCamera.GetRight()*f1;
x1 = pos.x - (1.4f * color.color32) * TheCamera.m_matrix.m_matrix.right.x; p2 = pos - TheCamera.GetRight()*f2;
CTheScripts::ScriptDebugLine3D(x1, y1, z1, x2, y2, z2, color.color32, color.color32); CTheScripts::ScriptDebugLine3D(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, color.color32, color.color32);
} }
#endif #endif
@ -577,8 +567,8 @@ void CRadar::DrawRotatingRadarSprite(CSprite2d* sprite, float x, float y, float
for (uint32 i = 0; i < 4; i++) { for (uint32 i = 0; i < 4; i++) {
oldPosn[i] = curPosn[i]; oldPosn[i] = curPosn[i];
curPosn[i].x = x + (oldPosn[i].x - x) * cosf(angle) + (oldPosn[i].y - y) * sinf(angle); curPosn[i].x = x + (oldPosn[i].x - x) * cosf(angle) + (oldPosn[i].y - y) * sinf(angle);
curPosn[i].y = y - (oldPosn[i].x - x) * sinf(angle) + (oldPosn[i].y - y) * cosf(angle); curPosn[i].y = y - (oldPosn[i].x - x) * sinf(angle) + (oldPosn[i].y - y) * cosf(angle);
} }
sprite->Draw(curPosn[2].x, curPosn[2].y, curPosn[3].x, curPosn[3].y, curPosn[0].x, curPosn[0].y, curPosn[1].x, curPosn[1].y, CRGBA(255, 255, 255, alpha)); sprite->Draw(curPosn[2].x, curPosn[2].y, curPosn[3].x, curPosn[3].y, curPosn[0].x, curPosn[0].y, curPosn[1].x, curPosn[1].y, CRGBA(255, 255, 255, alpha));

View file

@ -53,26 +53,26 @@ struct CBlip
CVector2D m_vec2DPos; CVector2D m_vec2DPos;
CVector m_vecPos; CVector m_vecPos;
int16 m_BlipIndex; int16 m_BlipIndex;
int8 m_bDim; bool m_bDim;
int8 m_bInUse; bool m_bInUse;
float m_Radius; float m_Radius;
int16 m_wScale; int16 m_wScale;
int16 m_eBlipDisplay; // eBlipDisplay int16 m_eBlipDisplay; // eBlipDisplay
int16 m_IconID; // eRadarSprite int16 m_IconID; // eRadarSprite
char gap_46[2];
}; };
static_assert(sizeof(CBlip) == 0x30, "CBlip: error"); static_assert(sizeof(CBlip) == 0x30, "CBlip: error");
// Values for screen space
#define RADAR_LEFT (40.0f)
#define RADAR_BOTTOM (47.0f)
#define RADAR_WIDTH (94.0f)
#define RADAR_HEIGHT (76.0f)
class CRadar class CRadar
{ {
static float cachedSin;
static float cachedCos;
public: public:
static float &m_RadarRange; static float &m_RadarRange;
static CVector2D &vec2DRadarOrigin; static CBlip *ms_RadarTrace; //[NUMRADARBLIPS]
static CBlip *ms_RadarTrace;
static CSprite2d *AsukaSprite; static CSprite2d *AsukaSprite;
static CSprite2d *BombSprite; static CSprite2d *BombSprite;
static CSprite2d *CatSprite; static CSprite2d *CatSprite;
@ -101,19 +101,15 @@ public:
static void DrawMap(); static void DrawMap();
static void StreamRadarSections(int x, int y); static void StreamRadarSections(int x, int y);
static int ClipRadarPoly(CVector2D *out, CVector2D *in); static int ClipRadarPoly(CVector2D *out, CVector2D *in);
static void TransformRealWorldToTexCoordSpace(CVector2D *out, CVector2D *in, int x, int y);
static void TransformRadarPointToRealWorldSpace(CVector2D *out, CVector2D *in);
static void DrawRadarSection(int x, int y); static void DrawRadarSection(int x, int y);
static void RequestMapSection(int x, int y); static void RequestMapSection(int x, int y);
static void RemoveMapSection(int x, int y); static void RemoveMapSection(int x, int y);
static void TransformRadarPointToScreenSpace(CVector2D * out, CVector2D * in);
static void DrawBlips(); static void DrawBlips();
static int CalculateBlipAlpha(float dist); static int CalculateBlipAlpha(float dist);
static CRGBA GetRadarTraceColour(uint32 color, bool bright); static CRGBA GetRadarTraceColour(uint32 color, bool bright);
static void DrawRadarMap(); static void DrawRadarMap();
static void DrawRotatingRadarSprite(CSprite2d* sprite, float x, float y, float angle, int alpha); static void DrawRotatingRadarSprite(CSprite2d* sprite, float x, float y, float angle, int alpha);
static void TransformRealWorldPointToRadarSpace(CVector2D *out, CVector2D *in); static float LimitRadarPoint(CVector2D &point);
static float LimitRadarPoint(CVector2D *point);
static void DrawRadarSprite(int sprite, float x, float y, int alpha); static void DrawRadarSprite(int sprite, float x, float y, int alpha);
static void ShowRadarMarker(CVector pos, CRGBA color, float radius); static void ShowRadarMarker(CVector pos, CRGBA color, float radius);
static void ShowRadarTrace(float x, float y, uint32 size, uint32 red, uint32 green, uint32 blue, uint32 alpha); static void ShowRadarTrace(float x, float y, uint32 size, uint32 red, uint32 green, uint32 blue, uint32 alpha);
@ -122,4 +118,8 @@ public:
static bool DisplayThisBlip(int counter); static bool DisplayThisBlip(int counter);
static void GetTextureCorners(int x, int y, CVector2D * out); static void GetTextureCorners(int x, int y, CVector2D * out);
static void ClipRadarTileCoords(int *x, int *y); static void ClipRadarTileCoords(int *x, int *y);
static void TransformRealWorldToTexCoordSpace(CVector2D &out, const CVector2D &in, int x, int y);
static void TransformRadarPointToRealWorldSpace(CVector2D &out, const CVector2D &in);
static void TransformRadarPointToScreenSpace(CVector2D &out, const CVector2D &in);
static void TransformRealWorldPointToRadarSpace(CVector2D &out, const CVector2D &in);
}; };

View file

@ -111,6 +111,7 @@ public:
static void RequestSpecialModel(int32 modelId, const char *modelName, int32 flags); static void RequestSpecialModel(int32 modelId, const char *modelName, int32 flags);
static void RequestSpecialChar(int32 charId, const char *modelName, int32 flags); static void RequestSpecialChar(int32 charId, const char *modelName, int32 flags);
static void RemoveModel(int32 id); static void RemoveModel(int32 id);
static void RemoveTxd(int32 id) { RemoveModel(id + STREAM_OFFSET_TXD); }
static bool IsTxdUsedByRequestedModels(int32 txdId); static bool IsTxdUsedByRequestedModels(int32 txdId);
static bool AddToLoadedVehiclesList(int32 modelId); static bool AddToLoadedVehiclesList(int32 modelId);

View file

@ -592,6 +592,6 @@ WRAPPER CPed *FindPlayerPed(void) { EAXJMP(0x4A1150); }
WRAPPER CVector &FindPlayerCoors(CVector &v) { EAXJMP(0x4A1030); } WRAPPER CVector &FindPlayerCoors(CVector &v) { EAXJMP(0x4A1030); }
WRAPPER CVehicle *FindPlayerVehicle(void) { EAXJMP(0x4A10C0); } WRAPPER CVehicle *FindPlayerVehicle(void) { EAXJMP(0x4A10C0); }
WRAPPER CVehicle *FindPlayerTrain(void) { EAXJMP(0x4A1120); } WRAPPER CVehicle *FindPlayerTrain(void) { EAXJMP(0x4A1120); }
WRAPPER CVector FindPlayerSpeed(void) { EAXJMP(0x4A1090); } WRAPPER CVector &FindPlayerSpeed(void) { EAXJMP(0x4A1090); }
WRAPPER CVector FindPlayerCentreOfWorld_NoSniperShift(void) { EAXJMP(0x4A11C0); } WRAPPER CVector FindPlayerCentreOfWorld_NoSniperShift(void) { EAXJMP(0x4A11C0); }
WRAPPER float FindPlayerHeading(void) { EAXJMP(0x4A1220); } WRAPPER float FindPlayerHeading(void) { EAXJMP(0x4A1220); }

View file

@ -111,6 +111,6 @@ CPed *FindPlayerPed(void);
CVector &FindPlayerCoors(CVector &v); CVector &FindPlayerCoors(CVector &v);
CVehicle *FindPlayerVehicle(void); CVehicle *FindPlayerVehicle(void);
CVehicle *FindPlayerTrain(void); CVehicle *FindPlayerTrain(void);
CVector FindPlayerSpeed(void); CVector &FindPlayerSpeed(void);
CVector FindPlayerCentreOfWorld_NoSniperShift(void); CVector FindPlayerCentreOfWorld_NoSniperShift(void);
float FindPlayerHeading(void); float FindPlayerHeading(void);

View file

@ -57,7 +57,8 @@ enum Config {
NUMCORONAS = 56, NUMCORONAS = 56,
NUMPOINTLIGHTS = 32, NUMPOINTLIGHTS = 32,
NUMONSCREENTIMERENTRIES = 1 NUMONSCREENTIMERENTRIES = 1,
NUMRADARBLIPS = 32,
}; };
#define GTA3_1_1_PATCH #define GTA3_1_1_PATCH

View file

@ -1504,7 +1504,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
else if(A->GetUp().z > 0.3f) else if(A->GetUp().z > 0.3f)
adhesion = 0.0f; adhesion = 0.0f;
else else
adhesion *= max(5.0f, 0.03f*impulseA + 1.0f); adhesion *= min(5.0f, 0.03f*impulseA + 1.0f);
} }
if(A->ApplyFriction(adhesion, aColPoints[i])) if(A->ApplyFriction(adhesion, aColPoints[i]))

View file

@ -26,4 +26,20 @@ public:
if(v.y < top) top = v.y; if(v.y < top) top = v.y;
if(v.y > bottom) bottom = v.y; if(v.y > bottom) bottom = v.y;
} }
void Translate(float x, float y){
left += x;
right += x;
bottom += y;
top += y;
}
void Grow(float r){
left -= r;
right += r;
top -= r;
bottom += r;
}
float GetWidth(void) { return right - left; }
float GetHeight(void) { return bottom - top; }
}; };

View file

@ -856,7 +856,11 @@ void CHud::Draw()
*/ */
if (CHud::m_ItemToFlash == ITEM_RADAR && CTimer::GetFrameCounter() & 8 || CHud::m_ItemToFlash != ITEM_RADAR) { if (CHud::m_ItemToFlash == ITEM_RADAR && CTimer::GetFrameCounter() & 8 || CHud::m_ItemToFlash != ITEM_RADAR) {
CRadar::DrawMap(); CRadar::DrawMap();
CHud::Sprites[HUD_RADARDISC].Draw(CRect(SCREEN_SCALE_X(16.0f), SCREEN_SCALE_FROM_BOTTOM(123.0f + 4.0f), SCREEN_SCALE_X(94.0f + 20.0f + 5.0f), SCREEN_SCALE_FROM_BOTTOM(-76.0f + 123.0f - 6.0f)), CRGBA(0, 0, 0, 255)); CRect rect(0.0f, 0.0f, SCREEN_SCALE_X(RADAR_WIDTH), SCREEN_SCALE_Y(RADAR_HEIGHT));
// FIX: game doesn't scale RADAR_LEFT here
rect.Translate(SCREEN_SCALE_X(RADAR_LEFT), SCREEN_SCALE_FROM_BOTTOM(RADAR_BOTTOM + RADAR_HEIGHT));
rect.Grow(4.0f);
CHud::Sprites[HUD_RADARDISC].Draw(rect, CRGBA(0, 0, 0, 255));
CRadar::DrawBlips(); CRadar::DrawBlips();
} }
} }