Make world offset calculation more accurate

Noticed that after some time groups with a parallax different than 100 were incorrectly rendered in the editor
This commit is contained in:
12pm 2019-04-03 01:05:38 +02:00
parent 1cbb800c7f
commit 4efc0e3b82
5 changed files with 22 additions and 23 deletions

View file

@ -91,7 +91,7 @@ void CHud::OnInit()
RenderTools()->SelectSprite(g_pData->m_Weapons.m_aId[i].m_pSpriteCursor);
RenderTools()->QuadContainerAddSprite(m_HudQuadContainerIndex, 64.f);
}
// the flags
RenderTools()->SelectSprite(SPRITE_FLAG_RED);
RenderTools()->QuadContainerAddSprite(m_HudQuadContainerIndex, 0.f, 0.f, 8.f, 16.f);
@ -196,8 +196,8 @@ void CHud::RenderScoreHud()
bool RecreateTeamScore[2] = { str_comp(aScoreTeam[0], m_aScoreInfo[0].m_aScoreText) != 0, str_comp(aScoreTeam[1], m_aScoreInfo[1].m_aScoreText) != 0 };
int FlagCarrier[2] = {
m_pClient->m_Snap.m_pGameDataObj->m_FlagCarrierRed,
int FlagCarrier[2] = {
m_pClient->m_Snap.m_pGameDataObj->m_FlagCarrierRed,
m_pClient->m_Snap.m_pGameDataObj->m_FlagCarrierBlue
};
@ -220,7 +220,7 @@ void CHud::RenderScoreHud()
{
// draw box
if(RecreateRect)
{
{
if(m_aScoreInfo[t].m_RoundRectQuadContainerIndex != -1)
Graphics()->DeleteQuadContainer(m_aScoreInfo[t].m_RoundRectQuadContainerIndex);
@ -277,8 +277,8 @@ void CHud::RenderScoreHud()
if(m_aScoreInfo[t].m_OptionalNameTextContainerIndex != -1)
TextRender()->DeleteTextContainer(m_aScoreInfo[t].m_OptionalNameTextContainerIndex);
float w = TextRender()->TextWidth(0, 8.0f, pName, -1);
float w = TextRender()->TextWidth(0, 8.0f, pName, -1);
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, min(Whole - w - 1.0f, Whole - ScoreWidthMax - ImageSize - 2 * Split), StartY + (t + 1)*20.0f - 2.0f, 8.0f, TEXTFLAG_RENDER);
Cursor.m_LineWidth = -1;
@ -435,7 +435,7 @@ void CHud::RenderScoreHud()
int ID = apPlayerInfo[t]->m_ClientID;
if(ID >= 0 && ID < MAX_CLIENTS)
{
const char *pName = m_pClient->m_aClients[ID].m_aName;
const char *pName = m_pClient->m_aClients[ID].m_aName;
if(RecreateRect)
{
mem_copy(m_aScoreInfo[t].m_aPlayerNameText, pName, sizeof(m_aScoreInfo[t].m_aPlayerNameText));
@ -479,7 +479,7 @@ void CHud::RenderScoreHud()
if(m_aScoreInfo[t].m_TextRankContainerIndex != -1)
TextRender()->DeleteTextContainer(m_aScoreInfo[t].m_TextRankContainerIndex);
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, Whole - ScoreWidthMax - ImageSize - Split - PosSize, StartY + t * 20 + (18.f - 10.f) / 2.f, 10.0f, TEXTFLAG_RENDER);
Cursor.m_LineWidth = -1;
@ -521,7 +521,7 @@ void CHud::RenderWarmupTimer()
void CHud::MapscreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup)
{
float Points[4];
RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX/100.0f, pGroup->m_ParallaxY/100.0f,
RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX, pGroup->m_ParallaxY,
pGroup->m_OffsetX, pGroup->m_OffsetY, Graphics()->ScreenAspect(), 1.0f, Points);
Graphics()->MapScreen(Points[0], Points[1], Points[2], Points[3]);
}
@ -705,7 +705,7 @@ void CHud::RenderCursor()
MapscreenToGroup(m_pClient->m_pCamera->m_Center.x, m_pClient->m_pCamera->m_Center.y, Layers()->GameGroup());
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
// render cursor
int QuadOffset = NUM_WEAPONS * 10 + 40 + (m_pClient->m_Snap.m_pLocalCharacter->m_Weapon%NUM_WEAPONS);
Graphics()->SetColor(1.f, 1.f, 1.f, 1.f);
@ -759,13 +759,13 @@ void CHud::RenderHealthAndAmmo(const CNetObj_Character *pCharacter)
// render gui stuff
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
int QuadOffset = pCharacter->m_Weapon%NUM_WEAPONS * 10;
Graphics()->RenderQuadContainer(m_HudQuadContainerIndex, QuadOffset, min(pCharacter->m_AmmoCount, 10));
QuadOffset = NUM_WEAPONS * 10;
Graphics()->RenderQuadContainer(m_HudQuadContainerIndex, QuadOffset, min(pCharacter->m_Health, 10));
QuadOffset += 10 + min(pCharacter->m_Health, 10);
if(min(pCharacter->m_Health, 10) < 10)
Graphics()->RenderQuadContainer(m_HudQuadContainerIndex, QuadOffset, 10 - min(pCharacter->m_Health, 10));

View file

@ -49,7 +49,7 @@ void CMapLayers::EnvelopeUpdate()
void CMapLayers::MapScreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup, float Zoom)
{
float Points[4];
RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX/100.0f, pGroup->m_ParallaxY/100.0f,
RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX, pGroup->m_ParallaxY,
pGroup->m_OffsetX, pGroup->m_OffsetY, Graphics()->ScreenAspect(), Zoom, Points);
Graphics()->MapScreen(Points[0], Points[1], Points[2], Points[3]);
}

View file

@ -17,7 +17,7 @@
void CNamePlates::MapscreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup)
{
float Points[4];
RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX / 100.0f, pGroup->m_ParallaxY / 100.0f, pGroup->m_OffsetX, pGroup->m_OffsetY, Graphics()->ScreenAspect(), 1.0f, Points);
RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX, pGroup->m_ParallaxY, pGroup->m_OffsetX, pGroup->m_OffsetY, Graphics()->ScreenAspect(), 1.0f, Points);
Graphics()->MapScreen(Points[0], Points[1], Points[2], Points[3]);
}

View file

@ -146,7 +146,7 @@ void CRenderTools::QuadContainerAddSprite(int QuadContainerIndex, float Size, bo
void CRenderTools::QuadContainerAddSprite(int QuadContainerIndex, float X, float Y, float Width, float Height)
{
IGraphics::CQuadItem QuadItem(X, Y, Width, Height);
Graphics()->QuadContainerAddQuads(QuadContainerIndex, &QuadItem, 1);
Graphics()->QuadContainerAddQuads(QuadContainerIndex, &QuadItem, 1);
}
void CRenderTools::DrawRoundRectExt(float x, float y, float w, float h, float r, int Corners)
@ -334,7 +334,7 @@ void CRenderTools::RenderTee(CAnimState *pAnim, CTeeRenderInfo *pInfo, int Emote
//Graphics()->TextureSet(data->images[IMAGE_CHAR_DEFAULT].id);
Graphics()->TextureSet(pInfo->m_Texture);
// first pass we draw the outline
// second pass we draw the filling
for(int p = 0; p < 2; p++)
@ -453,8 +453,8 @@ void CRenderTools::MapscreenToWorld(float CenterX, float CenterY, float Parallax
{
float Width, Height;
CalcScreenParams(1150*1000, 1500, 1050, Aspect, &Width, &Height);
CenterX *= ParallaxX;
CenterY *= ParallaxY;
CenterX *= ParallaxX/100.0f;
CenterY *= ParallaxY/100.0f;
Width *= Zoom;
Height *= Zoom;
pPoints[0] = OffsetX+CenterX-Width/2;

View file

@ -170,8 +170,7 @@ void CLayerGroup::Mapping(float *pPoints)
{
m_pMap->m_pEditor->RenderTools()->MapscreenToWorld(
m_pMap->m_pEditor->m_WorldOffsetX, m_pMap->m_pEditor->m_WorldOffsetY,
m_ParallaxX/100.0f, m_ParallaxY/100.0f,
m_OffsetX, m_OffsetY,
m_ParallaxX, m_ParallaxY, m_OffsetX, m_OffsetY,
m_pMap->m_pEditor->Graphics()->ScreenAspect(), m_pMap->m_pEditor->m_WorldZoom, pPoints);
pPoints[0] += m_pMap->m_pEditor->m_EditorOffsetX;
@ -2874,7 +2873,7 @@ void CEditor::DoMapEditor(CUIRect View)
RenderTools()->MapscreenToWorld(
m_WorldOffsetX, m_WorldOffsetY,
1.0f, 1.0f, 0.0f, 0.0f, Aspect, 1.0f, aPoints);
100.0f, 100.0f, 0.0f, 0.0f, Aspect, 1.0f, aPoints);
if(i == 0)
{
@ -2916,7 +2915,7 @@ void CEditor::DoMapEditor(CUIRect View)
RenderTools()->MapscreenToWorld(
m_WorldOffsetX, m_WorldOffsetY,
1.0f, 1.0f, 0.0f, 0.0f, Aspect, 1.0f, aPoints);
100.0f, 100.0f, 0.0f, 0.0f, Aspect, 1.0f, aPoints);
CUIRect r;
r.x = aPoints[0];
@ -5870,7 +5869,7 @@ void CEditor::ZoomMouseTarget(float ZoomFactor)
float aPoints[4];
RenderTools()->MapscreenToWorld(
m_WorldOffsetX, m_WorldOffsetY,
1.0f, 1.0f, 0.0f, 0.0f, Graphics()->ScreenAspect(), m_WorldZoom, aPoints);
100.0f, 100.0f, 0.0f, 0.0f, Graphics()->ScreenAspect(), m_WorldZoom, aPoints);
float WorldWidth = aPoints[2]-aPoints[0];
float WorldHeight = aPoints[3]-aPoints[1];