Skip to content

Commit 86341e2

Browse files
authored
Merge pull request #1493 from nicolasnoble/soft-math-project
Adding projection to soft math.
2 parents b31ea84 + ba58179 commit 86341e2

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/mips/psyqo/soft-math.hh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ FixedPoint<> matrixDeterminant3(const Matrix33 *m);
111111
* @param x The number to compute the square root of.
112112
* @return psyqo::FixedPoint<> The square root.
113113
*/
114-
psyqo::FixedPoint<> squareRoot(psyqo::FixedPoint<> x);
114+
FixedPoint<> squareRoot(FixedPoint<> x);
115115

116116
/**
117117
* @brief Computes the norm of a 3D vector.
118118
*
119119
* @param v The vector.
120120
* @return psyqo::FixedPoint<> The norm.
121121
*/
122-
psyqo::FixedPoint<> normOfVec3(const Vec3 *v);
122+
FixedPoint<> normOfVec3(const Vec3 *v);
123123

124124
/**
125125
* @brief Normalizes a 3D vector.
@@ -128,6 +128,15 @@ psyqo::FixedPoint<> normOfVec3(const Vec3 *v);
128128
*/
129129
void normalizeVec3(Vec3 *v);
130130

131+
/**
132+
* @brief Projects a 3D point onto a 2D plane.
133+
*
134+
* @param v The vector to project.
135+
* @param h The height of the plane.
136+
* @param out The vector to store the result in.
137+
*/
138+
void project(const Vec3 *v, FixedPoint<> h, Vec2 *out);
139+
131140
} // namespace SoftMath
132141

133142
} // namespace psyqo

src/mips/psyqo/src/soft-math.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,14 @@ void psyqo::SoftMath::normalizeVec3(Vec3 *v) {
231231
v->y = y;
232232
v->z = z;
233233
}
234+
235+
void psyqo::SoftMath::project(const Vec3 *v, FixedPoint<> h, Vec2 *out) {
236+
auto x = v->x;
237+
auto y = v->y;
238+
auto z = v->z;
239+
auto r = h / z;
240+
x = x * r;
241+
y = y * r;
242+
out->x = x;
243+
out->y = y;
244+
}

0 commit comments

Comments
 (0)