Skip to content

Commit 0252549

Browse files
Merge branch 'master' of https://github.com/DK22Pac/plugin-sdk
2 parents 43b6927 + e701be1 commit 0252549

File tree

12 files changed

+560
-117
lines changed

12 files changed

+560
-117
lines changed

plugin_III/game_III/CVector.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,17 @@
55
Do not delete this comment block. Respect others' work!
66
*/
77
#include "CVector.h"
8+
9+
CVector2D CVector::To2D() const {
10+
return CVector2D(x, y);
11+
}
12+
13+
void CVector::From2D(const CVector2D& vec2d, float zValue) {
14+
x = vec2d.x;
15+
y = vec2d.y;
16+
z = zValue;
17+
}
18+
19+
CVector::CVector(const CVector2D& vec2d, float zValue) {
20+
From2D(vec2d, zValue);
21+
}

plugin_III/game_III/CVector.h

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "RenderWare.h"
1111
#include <math.h>
1212

13+
class CVector2D;
14+
1315
class CVector {
1416
public:
1517
float x, y, z;
@@ -38,6 +40,11 @@ class CVector {
3840
this->z = a.x * b.y - b.x * a.y;
3941
}
4042

43+
CVector(const CVector2D& vec2d, float zValue = 0.0f);
44+
45+
CVector2D To2D() const;
46+
void From2D(const CVector2D& vec2d, float zValue = 0.0f);
47+
4148
inline float Heading() const {
4249
return std::atan2(-x, y);
4350
}
@@ -104,8 +111,12 @@ class CVector {
104111
this->z /= divisor;
105112
}
106113

107-
const bool operator!=(CVector const& right) const {
108-
return x != right.x || y != right.y || z != right.z;
114+
inline bool operator==(const CVector& other) {
115+
return x == other.x && y == other.y && z == other.z;
116+
}
117+
118+
inline bool operator!=(const CVector& other) {
119+
return x != other.x || y != other.y || z != other.z;
109120
}
110121

111122
CVector Normalise() {
@@ -144,6 +155,10 @@ class CVector {
144155
}
145156
}
146157

158+
inline bool IsNormalized() const {
159+
return std::fabs(MagnitudeSqr() - 1.0f) < 0.001f;
160+
}
161+
147162
inline RwV3d ToRwV3d() const {
148163
return{ x, y, z };
149164
}
@@ -160,6 +175,11 @@ class CVector {
160175
return x == 0.0f && y == 0.0f && z == 0.0f;
161176
}
162177

178+
inline void Zero() {
179+
x = 0.0f;
180+
y = 0.0f;
181+
z = 0.0f;
182+
}
163183
};
164184

165185
inline CVector operator-(const CVector& vecOne, const CVector& vecTwo) {
@@ -178,23 +198,27 @@ inline CVector operator*(float multiplier, const CVector& vec) {
178198
return CVector(vec.x * multiplier, vec.y * multiplier, vec.z * multiplier);
179199
}
180200

181-
inline float DistanceBetweenPoints(const CVector &pointOne, const CVector &pointTwo) {
182-
CVector diff = pointTwo - pointOne;
183-
return diff.Magnitude();
201+
inline CVector operator*(const CVector& vecOne, const CVector& vecTwo) {
202+
return CVector(vecOne.x * vecTwo.x, vecOne.y * vecTwo.y, vecOne.z * vecTwo.z);
184203
}
185204

186205
inline CVector operator/(const CVector& left, float right) {
187206
return CVector(left.x / right, left.y / right, left.z / right);
188207
}
189208

190-
inline float DotProduct(const CVector& v1, const CVector& v2) {
191-
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
192-
}
193-
194209
inline CVector operator*(const RwMatrix& mat, const CVector& vec) {
195210
return CVector(mat.right.x * vec.x + mat.up.x * vec.y + mat.at.x * vec.z + mat.pos.x,
196-
mat.right.y * vec.x + mat.up.y * vec.y + mat.at.y * vec.z + mat.pos.y,
197-
mat.right.z * vec.x + mat.up.z * vec.y + mat.at.z * vec.z + mat.pos.z);
211+
mat.right.y * vec.x + mat.up.y * vec.y + mat.at.y * vec.z + mat.pos.y,
212+
mat.right.z * vec.x + mat.up.z * vec.y + mat.at.z * vec.z + mat.pos.z);
213+
}
214+
215+
inline float DistanceBetweenPoints(const CVector &pointOne, const CVector &pointTwo) {
216+
CVector diff = pointTwo - pointOne;
217+
return diff.Magnitude();
218+
}
219+
220+
inline float DotProduct(const CVector& v1, const CVector& v2) {
221+
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
198222
}
199223

200224
inline CVector CrossProduct(const CVector& v1, const CVector& v2) {

plugin_III/game_III/CVector2D.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Plugin-SDK (Grand Theft Auto 3) source file
3+
Authors: GTA Community. See more here
4+
https://github.com/DK22Pac/plugin-sdk
5+
Do not delete this comment block. Respect others' work!
6+
*/
7+
#include "CVector2D.h"
8+
#include "CVector.h"
9+
10+
CVector CVector2D::To3D(float zValue) const {
11+
return CVector(x, y, zValue);
12+
}
13+
14+
void CVector2D::From3D(const CVector& vec3d) {
15+
x = vec3d.x;
16+
y = vec3d.y;
17+
}
18+
19+
CVector2D::CVector2D(CVector const& src) {
20+
x = src.x; y = src.y;
21+
}

plugin_III/game_III/CVector2D.h

Lines changed: 69 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
#include "PluginBase.h"
1010
#include <math.h>
11-
#include "CVector.h"
11+
12+
class CVector;
1213

1314
class CVector2D {
1415
public:
@@ -26,76 +27,104 @@ class CVector2D {
2627
x = src.x; y = src.y;
2728
}
2829

29-
inline CVector2D(CVector const& src) {
30-
x = src.x; y = src.y;
31-
}
30+
CVector2D(CVector const& src);
31+
CVector To3D(float zValue = 0.0f) const;
32+
void From3D(const CVector& vec3d);
3233

33-
inline float Magnitude() {
34-
return sqrtf(this->x * this->x + this->y * this->y);
34+
inline float Magnitude() const {
35+
return sqrtf(x * x + y * y);
3536
}
3637

37-
inline float MagnitudeSqr() {
38-
return this->x * this->x + this->y * this->y;
38+
inline float MagnitudeSqr() const {
39+
return x * x + y * y;
3940
}
4041

4142
inline void Sum(CVector2D &a, CVector2D &b) {
42-
this->x = a.x + b.x;
43-
this->y = a.y + b.y;
43+
x = a.x + b.x;
44+
y = a.y + b.y;
4445
}
4546

4647
inline void Difference(CVector2D &a, CVector2D &b) {
47-
this->x = a.x - b.x;
48-
this->y = a.y - b.y;
48+
x = a.x - b.x;
49+
y = a.y - b.y;
4950
}
5051

5152
inline void operator=(const CVector2D& right) {
52-
this->x = right.x;
53-
this->y = right.y;
53+
x = right.x;
54+
y = right.y;
55+
}
56+
57+
inline CVector2D operator-() {
58+
return CVector2D(-x, -y);
5459
}
5560

5661
inline void operator+=(const CVector2D& right) {
57-
this->x += right.x;
58-
this->y += right.y;
62+
x += right.x;
63+
y += right.y;
5964
}
6065

6166
inline void operator-=(const CVector2D& right) {
62-
this->x -= right.x;
63-
this->y -= right.y;
67+
x -= right.x;
68+
y -= right.y;
6469
}
6570

6671
inline void operator *= (float multiplier) {
67-
this->x *= multiplier;
68-
this->y *= multiplier;
72+
x *= multiplier;
73+
y *= multiplier;
6974
}
7075

7176
inline void operator*=(const CVector2D& right) {
72-
this->x *= right.x;
73-
this->y *= right.y;
77+
x *= right.x;
78+
y *= right.y;
7479
}
7580

7681
inline void operator /= (float divisor) {
77-
this->x /= divisor;
78-
this->y /= divisor;
82+
x /= divisor;
83+
y /= divisor;
7984
}
8085

8186
inline bool operator!=(const CVector2D& right) {
82-
return this->x != right.x && this->y != right.y;
87+
return x != right.x || y != right.y;
8388
}
8489

8590
inline bool operator==(const CVector2D& right) {
86-
return this->x == right.x && this->y == right.y;
91+
return x == right.x && y == right.y;
8792
}
8893

89-
void Normalise() {
94+
inline void Normalise() {
9095
float sq = x * x + y * y;
9196
float invsqrt = 1.0f / sqrt(sq);
92-
this->x *= invsqrt;
93-
this->y *= invsqrt;
97+
x *= invsqrt;
98+
y *= invsqrt;
99+
}
100+
101+
inline float NormaliseAndMag() {
102+
float magSqr = MagnitudeSqr();
103+
if (magSqr > 0.0f) {
104+
float mag = std::sqrt(magSqr);
105+
float invMag = 1.0f / mag;
106+
x *= invMag;
107+
y *= invMag;
108+
return mag;
109+
}
110+
return 0.0f;
111+
}
112+
113+
inline void Zero() {
114+
x = 0.0f;
115+
y = 0.0f;
116+
}
117+
118+
inline bool IsZero() const {
119+
return x == 0.0f && y == 0.0f;
120+
}
121+
122+
inline bool IsNormalized() {
123+
return std::fabs(MagnitudeSqr() - 1.0f) < 0.001f;
94124
}
95125

96-
void Zero() {
97-
this->x = 0.0f;
98-
this->y = 0.0f;
126+
inline float Heading() {
127+
return std::atan2(-x, y);
99128
}
100129
};
101130

@@ -131,3 +160,11 @@ inline float DistanceBetweenPoints(const CVector2D& pointOne, const CVector2D& p
131160
CVector2D diff = pointTwo - pointOne;
132161
return diff.Magnitude();
133162
}
163+
164+
inline float DotProduct(const CVector2D& a, const CVector2D& b) {
165+
return a.x * b.x + a.y * b.y;
166+
}
167+
168+
inline float CrossProduct(const CVector2D& a, const CVector2D& b) {
169+
return a.x * b.y - a.y * b.x;
170+
}

plugin_sa/game_sa/CVector.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@
66
*/
77
#include "CVector.h"
88

9-
CVector::CVector()
9+
CVector::CVector(float X, float Y, float Z)
1010
{
11+
((void(__thiscall *)(CVector *, float, float, float))0x420B10)(this, X, Y, Z);
12+
}
1113

14+
CVector::CVector(const CVector2D& vec2d, float zValue) {
15+
From2D(vec2d, zValue);
1216
}
1317

14-
CVector::CVector(float X, float Y, float Z)
15-
{
16-
((void(__thiscall *)(CVector *, float, float, float))0x420B10)(this, X, Y, Z);
18+
CVector2D CVector::To2D() const {
19+
return CVector2D(x, y);
20+
}
21+
22+
void CVector::From2D(const CVector2D& vec2d, float zValue) {
23+
x = vec2d.x;
24+
y = vec2d.y;
25+
z = zValue;
1726
}
1827

1928
// Returns length of vector

0 commit comments

Comments
 (0)