Skip to content

Commit

Permalink
Merge pull request #1493 from nicolasnoble/soft-math-project
Browse files Browse the repository at this point in the history
Adding projection to soft math.
  • Loading branch information
nicolasnoble authored Dec 17, 2023
2 parents b31ea84 + ba58179 commit 86341e2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/mips/psyqo/soft-math.hh
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ FixedPoint<> matrixDeterminant3(const Matrix33 *m);
* @param x The number to compute the square root of.
* @return psyqo::FixedPoint<> The square root.
*/
psyqo::FixedPoint<> squareRoot(psyqo::FixedPoint<> x);
FixedPoint<> squareRoot(FixedPoint<> x);

/**
* @brief Computes the norm of a 3D vector.
*
* @param v The vector.
* @return psyqo::FixedPoint<> The norm.
*/
psyqo::FixedPoint<> normOfVec3(const Vec3 *v);
FixedPoint<> normOfVec3(const Vec3 *v);

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

/**
* @brief Projects a 3D point onto a 2D plane.
*
* @param v The vector to project.
* @param h The height of the plane.
* @param out The vector to store the result in.
*/
void project(const Vec3 *v, FixedPoint<> h, Vec2 *out);

} // namespace SoftMath

} // namespace psyqo
11 changes: 11 additions & 0 deletions src/mips/psyqo/src/soft-math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,14 @@ void psyqo::SoftMath::normalizeVec3(Vec3 *v) {
v->y = y;
v->z = z;
}

void psyqo::SoftMath::project(const Vec3 *v, FixedPoint<> h, Vec2 *out) {
auto x = v->x;
auto y = v->y;
auto z = v->z;
auto r = h / z;
x = x * r;
y = y * r;
out->x = x;
out->y = y;
}

0 comments on commit 86341e2

Please sign in to comment.