improve nametags and djui_hud_world_pos_to_screen_pos

- Fix a bug where nametags could be seen when the player is not in view
- Make nametags use the head Y value at all times
- fixed djui_hud_world_pos_to_screen_pos in some screen sizes with RESOLUTION_DJUI
- made djui_hud_world_pos_to_screen_pos calculate viewport offset (for the credits)
This commit is contained in:
Isaac0-dev 2024-11-29 10:49:12 +10:00
parent 7c2f055a86
commit 608c0e04ed
2 changed files with 35 additions and 3 deletions

View file

@ -642,8 +642,38 @@ bool djui_hud_world_pos_to_screen_pos(Vec3f pos, Vec3f out) {
out[0] *= fovCoeff;
out[1] *= fovCoeff;
out[0] += djui_hud_get_screen_width() / 2.0f;
out[1] += djui_hud_get_screen_height() / 2.0f;
f32 screenWidth, screenHeight;
if (sResolution == RESOLUTION_N64) {
screenWidth = GFX_DIMENSIONS_ASPECT_RATIO * SCREEN_HEIGHT;
screenHeight = SCREEN_HEIGHT;
} else {
u32 windowWidth, windowHeight;
WAPI.get_dimensions(&windowWidth, &windowHeight);
screenWidth = (f32) windowWidth;
screenHeight = (f32) windowHeight;
}
out[0] += screenWidth / 2.0f;
out[1] += screenHeight / 2.0f;
extern Vp *D_8032CE74;
if (D_8032CE74) {
Vp_t *viewport = &D_8032CE74->vp;
f32 width = viewport->vscale[0] / 2.0f;
f32 height = viewport->vscale[1] / 2.0f;
f32 x = (viewport->vtrans[0] / 4.0f) - width / 2.0f;
f32 y = SCREEN_HEIGHT - ((viewport->vtrans[1] / 4.0f) + height / 2.0f);
f32 xDiff = screenWidth / SCREEN_WIDTH;
f32 yDiff = screenHeight / SCREEN_HEIGHT;
width *= xDiff;
height *= yDiff;
x = x * xDiff - 1;
y = (screenHeight - y * yDiff) - height;
out[0] = x + (out[0] * (width / screenWidth));
out[1] = y + (out[1] * (height / screenHeight));
}
return true;
}

View file

@ -80,10 +80,12 @@ void nametags_render(void) {
continue;
}
if (!djui_hud_world_pos_to_screen_pos(m->marioObj->header.gfx.pos, (Vec3f){})) { continue; }
Vec3f pos;
Vec3f out;
vec3f_copy(pos, m->marioBodyState->headPos);
pos[1] = m->pos[1] + 180;
pos[1] += 100;
if (djui_hud_world_pos_to_screen_pos(pos, out) &&
(i != 0 || (i == 0 && m->action != ACT_FIRST_PERSON))) {