Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 5b829c4

Browse files
authored
Merge pull request #236 from cortex-command-community/vector-update
Vector class update
2 parents a87ae03 + 893350b commit 5b829c4

File tree

11 files changed

+114
-164
lines changed

11 files changed

+114
-164
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
141141

142142
- `FLAC` audio files can now be loaded through lua and ini.
143143

144+
- Added new lua `Vector` functions: `GetRadRotated(angle)` and `GetDegRotated(angle)`. They return a rotated copy of the vector without modifying it.
145+
144146
### Changed
145147

146148
- Codebase now uses the C++17 standard.

Entities/HDFirearm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ void HDFirearm::Update()
787787
(m_Supported ? 1.0F : m_NoSupportFactor) * RandomNormalNum();
788788
tempNozzle = m_MuzzleOff.GetYFlipped(m_HFlipped);
789789
tempNozzle.DegRotate(degAimAngle + shake);
790-
roundVel.SetIntXY(pRound->GetFireVel(), 0);
790+
roundVel.SetXY(pRound->GetFireVel(), 0);
791791
roundVel.DegRotate(degAimAngle + shake);
792792

793793
Vector particlePos;
@@ -851,7 +851,7 @@ void HDFirearm::Update()
851851
pShell->SetPos(m_Pos + tempEject);
852852

853853
// ##@#@@$ TEMP
854-
shellVel.SetIntXY(pRound->GetShellVel(), 0);
854+
shellVel.SetXY(pRound->GetShellVel(), 0);
855855
shellVel.DegRotate(degAimAngle + 150 * (m_HFlipped ? -1 : 1) + shellSpread);
856856
pShell->SetVel(m_Vel + shellVel);
857857
pShell->SetRotAngle(m_Rotation.GetRadAngle());

Entities/SLTerrain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ void SLTerrain::ApplyMovableObject(MovableObject *pMObject)
11201120
pTempBitmap = m_spTempBitmap16;
11211121

11221122
// The position of the upper left corner of the temporary bitmap in the scene
1123-
Vector bitmapScroll = pMOSprite->GetPos().GetFloored() - (pTempBitmap->w / 2);
1123+
Vector bitmapScroll = pMOSprite->GetPos().GetFloored() - Vector(pTempBitmap->w / 2, pTempBitmap->w / 2);
11241124

11251125
Box notUsed;
11261126

Managers/FrameMan.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -972,23 +972,23 @@ namespace RTE {
972972
case Players::PlayerTwo:
973973
// If both splits, or just VSplit, then in upper right quadrant
974974
if ((m_VSplit && !m_HSplit) || (m_VSplit && m_HSplit)) {
975-
screenOffset.SetIntXY(GetResX() / 2, 0);
975+
screenOffset.SetXY(GetResX() / 2, 0);
976976
} else {
977977
// If only HSplit, then lower left quadrant
978-
screenOffset.SetIntXY(0, GetResY() / 2);
978+
screenOffset.SetXY(0, GetResY() / 2);
979979
}
980980
break;
981981
case Players::PlayerThree:
982982
// Always lower left quadrant
983-
screenOffset.SetIntXY(0, GetResY() / 2);
983+
screenOffset.SetXY(0, GetResY() / 2);
984984
break;
985985
case Players::PlayerFour:
986986
// Always lower right quadrant
987-
screenOffset.SetIntXY(GetResX() / 2, GetResY() / 2);
987+
screenOffset.SetXY(GetResX() / 2, GetResY() / 2);
988988
break;
989989
default:
990990
// Always upper left corner
991-
screenOffset.SetIntXY(0, 0);
991+
screenOffset.SetXY(0, 0);
992992
break;
993993
}
994994
}

Managers/LuaMan.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ int LuaMan::Create() {
510510
.def("Reset", &Vector::Reset)
511511
.def("RadRotate", &Vector::RadRotate)
512512
.def("DegRotate", &Vector::DegRotate)
513+
.def("GetRadRotated", &Vector::GetRadRotated)
514+
.def("GetDegRotated", &Vector::GetDegRotated)
513515
.def("AbsRotateTo", &Vector::AbsRotateTo)
514516
.def_readwrite("X", &Vector::m_X)
515517
.def_readwrite("Y", &Vector::m_Y)

Managers/SceneMan.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ bool SceneMan::CastMaterialRay(const Vector &start, const Vector &ray, unsigned
18491849
foundPixel = true;
18501850
result.SetXY(intPos[X], intPos[Y]);
18511851
// Save last ray pos
1852-
m_LastRayHitPos.SetIntXY(intPos[X], intPos[Y]);
1852+
m_LastRayHitPos.SetXY(intPos[X], intPos[Y]);
18531853
break;
18541854
}
18551855

@@ -1981,7 +1981,7 @@ bool SceneMan::CastNotMaterialRay(const Vector &start, const Vector &ray, unsign
19811981
foundPixel = true;
19821982
result.SetXY(intPos[X], intPos[Y]);
19831983
// Save last ray pos
1984-
m_LastRayHitPos.SetIntXY(intPos[X], intPos[Y]);
1984+
m_LastRayHitPos.SetXY(intPos[X], intPos[Y]);
19851985
break;
19861986
}
19871987

@@ -2309,7 +2309,7 @@ bool SceneMan::CastStrengthRay(const Vector &start, const Vector &ray, float str
23092309
foundPixel = true;
23102310
result.SetXY(intPos[X], intPos[Y]);
23112311
// Save last ray pos
2312-
m_LastRayHitPos.SetIntXY(intPos[X], intPos[Y]);
2312+
m_LastRayHitPos.SetXY(intPos[X], intPos[Y]);
23132313
break;
23142314
}
23152315
}
@@ -2429,7 +2429,7 @@ bool SceneMan::CastWeaknessRay(const Vector &start, const Vector &ray, float str
24292429
foundPixel = true;
24302430
result.SetXY(intPos[X], intPos[Y]);
24312431
// Save last ray pos
2432-
m_LastRayHitPos.SetIntXY(intPos[X], intPos[Y]);
2432+
m_LastRayHitPos.SetXY(intPos[X], intPos[Y]);
24332433
break;
24342434
}
24352435

@@ -2555,15 +2555,15 @@ MOID SceneMan::CastMORay(const Vector &start, const Vector &ray, MOID ignoreMOID
25552555
else
25562556
{
25572557
// Save last ray pos
2558-
m_LastRayHitPos.SetIntXY(intPos[X], intPos[Y]);
2558+
m_LastRayHitPos.SetXY(intPos[X], intPos[Y]);
25592559
return hitMOID;
25602560
}
25612561
}
25622562
// Legit hit
25632563
else
25642564
{
25652565
// Save last ray pos
2566-
m_LastRayHitPos.SetIntXY(intPos[X], intPos[Y]);
2566+
m_LastRayHitPos.SetXY(intPos[X], intPos[Y]);
25672567
return hitMOID;
25682568
}
25692569
}
@@ -2575,7 +2575,7 @@ MOID SceneMan::CastMORay(const Vector &start, const Vector &ray, MOID ignoreMOID
25752575
if (hitTerrain != g_MaterialAir && hitTerrain != ignoreMaterial)
25762576
{
25772577
// Save last ray pos
2578-
m_LastRayHitPos.SetIntXY(intPos[X], intPos[Y]);
2578+
m_LastRayHitPos.SetXY(intPos[X], intPos[Y]);
25792579
return g_NoMOID;
25802580
}
25812581
}
@@ -2686,7 +2686,7 @@ bool SceneMan::CastFindMORay(const Vector &start, const Vector &ray, MOID target
26862686
// Found target MOID, so save result and report success
26872687
resultPos.SetXY(intPos[X], intPos[Y]);
26882688
// Save last ray pos
2689-
m_LastRayHitPos.SetIntXY(intPos[X], intPos[Y]);
2689+
m_LastRayHitPos.SetXY(intPos[X], intPos[Y]);
26902690
return true;
26912691
}
26922692

@@ -2697,7 +2697,7 @@ bool SceneMan::CastFindMORay(const Vector &start, const Vector &ray, MOID target
26972697
if (hitTerrain != g_MaterialAir && hitTerrain != ignoreMaterial)
26982698
{
26992699
// Save last ray pos
2700-
m_LastRayHitPos.SetIntXY(intPos[X], intPos[Y]);
2700+
m_LastRayHitPos.SetXY(intPos[X], intPos[Y]);
27012701
return false;
27022702
}
27032703
}
@@ -2831,7 +2831,7 @@ float SceneMan::CastObstacleRay(const Vector &start, const Vector &ray, Vector &
28312831
hitObstacle = true;
28322832
obstaclePos.SetXY(intPos[X], intPos[Y]);
28332833
// Save last ray pos
2834-
m_LastRayHitPos.SetIntXY(intPos[X], intPos[Y]);
2834+
m_LastRayHitPos.SetXY(intPos[X], intPos[Y]);
28352835
break;
28362836
}
28372837
else

Managers/UInputMan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ namespace RTE {
808808
int mickeyX;
809809
int mickeyY;
810810
get_mouse_mickeys(&mickeyX, &mickeyY);
811-
m_RawMouseMovement.SetIntXY(mickeyX, mickeyY);
811+
m_RawMouseMovement.SetXY(mickeyX, mickeyY);
812812

813813
// TODO: Add sensitivity slider to settings menu
814814
m_RawMouseMovement *= m_MouseSensitivity;

Menus/GibEditorGUI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ void GibEditorGUI::Update()
697697
if (m_pCurrentGib && m_DrawCurrentGib)
698698
{
699699
Vector gibPos = g_SceneMan.SnapPosition(m_CursorPos - m_CursorOffset, m_GridSnapping);
700-
gibPos.SetIntX(gibPos.m_X);
701-
gibPos.SetIntY(gibPos.m_Y);
700+
gibPos.SetX(static_cast<int>(gibPos.m_X));
701+
gibPos.SetY(static_cast<int>(gibPos.m_Y));
702702

703703
m_pCurrentGib->SetPos(gibPos);
704704
m_pCurrentGib->Update();

Menus/PieMenuGUI.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ void PieMenuGUI::Update()
10831083
Vector separator;
10841084
for (vector<Slice *>::iterator sItr = m_AllSlices.begin(); sItr != m_AllSlices.end(); ++sItr)
10851085
{
1086-
separator.SetIntXY(m_InnerRadius + m_Thickness + 2, 0);
1086+
separator.SetXY(m_InnerRadius + m_Thickness + 2, 0);
10871087
separator.RadRotate((*sItr)->m_AreaStart);
10881088
// Draw four so that the result will be at least 2px thick, no matter what angle
10891089
line(m_pBGBitmap, centerX, centerY, centerX + separator.GetCeilingIntX(), centerY + separator.GetCeilingIntY(), g_MaskColor);
@@ -1095,7 +1095,7 @@ void PieMenuGUI::Update()
10951095
// Indicate the highlighted segment, only if it is also enabled?
10961096
if (m_pHoveredSlice && m_pHoveredSlice->m_Enabled)
10971097
{
1098-
separator.SetIntXY(m_InnerRadius + (m_Thickness / 2), 0);
1098+
separator.SetXY(m_InnerRadius + (m_Thickness / 2), 0);
10991099
separator.RadRotate(m_pHoveredSlice->m_MidAngle);
11001100
// floodfill(m_pBGBitmap, centerX + separator.GetFloorIntX(), centerY + separator.GetFloorIntY(), 122);
11011101
floodfill(m_pBGBitmap, centerX + separator.GetFloorIntX(), centerY + separator.GetFloorIntY(), m_pHoveredSlice->m_Enabled ? g_BlackColor : g_RedColor);
@@ -1350,7 +1350,7 @@ void PieMenuGUI::Draw(BITMAP *pTargetBitmap, const Vector &targetPos) const
13501350
// If we have the disabled etc frames, then use em if applicable
13511351
pIcon = (*sItr)->m_Icon.GetBitmaps8()[(!((*sItr)->m_Enabled) && (*sItr)->m_Icon.GetFrameCount() > PIS_DISABLED) ? PIS_DISABLED : (((*sItr) == m_pHoveredSlice && (*sItr)->m_Icon.GetFrameCount() > PIS_SELECTED) ? PIS_SELECTED : PIS_NORMAL)];
13521352
// Position and draw the icon bitmap
1353-
iconPos.SetIntXY(m_InnerRadius + (m_Thickness / 2), 0);
1353+
iconPos.SetXY(m_InnerRadius + (m_Thickness / 2), 0);
13541354
iconPos.RadRotate((*sItr)->m_MidAngle);
13551355
iconPos += Vector(1, 1);
13561356
draw_sprite(pTargetBitmap, pIcon, drawPos.m_X + iconPos.m_X - (pIcon->w / 2), drawPos.m_Y + iconPos.m_Y - (pIcon->h / 2));

System/Vector.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace RTE {
3434

3535
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3636

37-
Vector & Vector::SetMagnitude(float newMag) {
37+
Vector & Vector::SetMagnitude(const float newMag) {
3838
if (IsZero()) {
3939
SetXY(newMag, 0.0F);
4040
} else {
@@ -45,7 +45,7 @@ namespace RTE {
4545

4646
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4747

48-
Vector & Vector::CapMagnitude(float capMag) {
48+
Vector & Vector::CapMagnitude(const float capMag) {
4949
if (capMag == 0) { Reset(); }
5050
if (GetMagnitude() > capMag) { SetMagnitude(capMag); }
5151
return *this;
@@ -60,14 +60,13 @@ namespace RTE {
6060

6161
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
6262

63-
Vector & Vector::RadRotate(float angle) {
64-
angle = -angle;
65-
const float tempX = m_X * std::cos(angle) - m_Y * std::sin(angle);
66-
const float tempY = m_X * std::sin(angle) + m_Y * std::cos(angle);
67-
m_X = tempX;
68-
m_Y = tempY;
63+
Vector Vector::GetRadRotated(const float angle) {
64+
Vector returnVector = *this;
65+
const float adjustedAngle = -angle;
66+
returnVector.m_X = m_X * std::cos(adjustedAngle) - m_Y * std::sin(adjustedAngle);
67+
returnVector.m_Y = m_X * std::sin(adjustedAngle) + m_Y * std::cos(adjustedAngle);
6968

70-
return *this;
69+
return returnVector;
7170
}
7271

7372
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -83,7 +82,7 @@ namespace RTE {
8382
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8483

8584
Vector & Vector::operator=(const std::deque<Vector> &rhs) {
86-
Clear();
85+
Reset();
8786
if (!rhs.empty()) {
8887
for (const Vector &vector : rhs) {
8988
*this += vector;

0 commit comments

Comments
 (0)