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

Commit 3744e8c

Browse files
committed
Add GetRadRotated() and GetDegRotated()
1 parent 1fe943e commit 3744e8c

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

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)

System/Vector.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,13 @@ namespace RTE {
6060

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

63-
Vector & Vector::RadRotate(const float angle) {
63+
Vector Vector::GetRadRotated(const float angle) {
64+
Vector returnVector = *this;
6465
const float adjustedAngle = -angle;
65-
const float newX = m_X * std::cos(adjustedAngle) - m_Y * std::sin(adjustedAngle);
66-
const float newY = m_X * std::sin(adjustedAngle) + m_Y * std::cos(adjustedAngle);
67-
m_X = newX;
68-
m_Y = newY;
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
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

System/Vector.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,33 @@ namespace RTE {
217217
/// <returns>The absolute angle in degrees, in the interval [-90, 270).</returns>
218218
float GetAbsDegAngle() const { return GetAbsRadAngle() / c_PI * 180.0F; }
219219

220+
/// <summary>
221+
/// Returns a Vector rotated relatively by an angle in radians.
222+
/// </summary>
223+
/// <param name="angle">The angle in radians to rotate by. Positive angles rotate counter-clockwise, and negative angles clockwise.</param>
224+
/// <returns>a Vector rotated relatively to this Vector .</returns>
225+
Vector GetRadRotated(const float angle);
226+
220227
/// <summary>
221228
/// Rotate this Vector relatively by an angle in radians.
222229
/// </summary>
223230
/// <param name="angle">The angle in radians to rotate by. Positive angles rotate counter-clockwise, and negative angles clockwise.</param>
224231
/// <returns>Vector reference to this after the operation.</returns>
225-
Vector & RadRotate(const float angle);
232+
Vector & RadRotate(const float angle) { *this = GetRadRotated(angle); return *this; }
233+
234+
/// <summary>
235+
/// Returns a Vector rotated relatively by an angle in degrees.
236+
/// </summary>
237+
/// <param name="angle">The angle in degrees to rotate by. Positive angles rotate counter-clockwise, and negative angles clockwise.</param>
238+
/// <returns>a Vector rotated relatively to this Vector .</returns>
239+
Vector GetDegRotated(const float angle) { return GetRadRotated(angle * c_PI / 180.0F); };
226240

227241
/// <summary>
228242
/// Rotate this Vector relatively by an angle in degrees.
229243
/// </summary>
230244
/// <param name="angle">The angle in degrees to rotate by. Positive angles rotate counter-clockwise, and negative angles clockwise.</param>
231245
/// <returns>Vector reference to this after the operation.</returns>
232-
Vector & DegRotate(const float angle) { return RadRotate(angle * c_PI / 180.0F); }
246+
Vector & DegRotate(const float angle) { *this = GetDegRotated(angle); return *this; }
233247

234248
/// <summary>
235249
/// Set this Vector to an absolute rotation based on the absolute rotation of another Vector.

0 commit comments

Comments
 (0)