Nugget
Loading...
Searching...
No Matches
soft-math.hh
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2023 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include "fixed-point.hh"
30#include "psyqo/matrix.hh"
31#include "psyqo/trigonometry.hh"
32#include "psyqo/vector.hh"
33
34namespace psyqo {
35
36namespace SoftMath {
37
38enum class Axis { X, Y, Z };
46void generateRotationMatrix33(Matrix33 *m, Angle t, Axis a, const Trig<> &trig);
47[[deprecated("Use the reference version instead")]] static inline void generateRotationMatrix33(Matrix33 *m, Angle t,
48 Axis a,
49 const Trig<> *trig) {
50 generateRotationMatrix33(m, t, a, *trig);
51}
52
60[[nodiscard]] Matrix33 generateRotationMatrix33(Angle t, Axis a, const Trig<> &trig);
61[[nodiscard]] [[deprecated("Use the reference version instead")]] static inline Matrix33 generateRotationMatrix33(
62 Angle t, Axis a, const Trig<> *trig) {
63 return generateRotationMatrix33(t, a, *trig);
64}
65
73void multiplyMatrix33(const Matrix33 &m1, const Matrix33 &m2, Matrix33 *out);
74[[deprecated("Use the reference version instead")]] static inline void multiplyMatrix33(const Matrix33 *m1,
75 const Matrix33 *m2,
76 Matrix33 *out) {
77 multiplyMatrix33(*m1, *m2, out);
78}
79
87[[nodiscard]] Matrix33 multiplyMatrix33(const Matrix33 &m1, const Matrix33 &m2);
88[[nodiscard]] [[deprecated("Use the reference version instead")]] static inline Matrix33 multiplyMatrix33(
89 const Matrix33 *m1, const Matrix33 *m2) {
90 return multiplyMatrix33(*m1, *m2);
91}
92
99void scaleMatrix33(Matrix33 *m, FixedPoint<> s);
100
108void matrixVecMul3(const Matrix33 &m, const Vec3 &v, Vec3 *out);
109[[deprecated("Use the reference version instead")]] static inline void matrixVecMul3(const Matrix33 *m, const Vec3 *v,
110 Vec3 *out) {
111 matrixVecMul3(*m, *v, out);
112}
113
121void matrixVecMul3xy(const Matrix33 &m, const Vec3 &v, Vec2 *out);
122[[deprecated("Use the reference version instead")]] static inline void matrixVecMul3xy(const Matrix33 *m, const Vec3 *v,
123 Vec2 *out) {
124 matrixVecMul3xy(*m, *v, out);
125}
126
134[[nodiscard]] FixedPoint<> matrixVecMul3z(const Matrix33 &m, const Vec3 &v);
135[[nodiscard]] [[deprecated("Use the reference version instead")]] static inline FixedPoint<> matrixVecMul3z(
136 const Matrix33 *m, const Vec3 *v) {
137 return matrixVecMul3z(*m, *v);
138}
139
147void crossProductVec3(const Vec3 &v1, const Vec3 &v2, Vec3 *out);
148[[deprecated("Use the reference version instead")]] static inline void crossProductVec3(const Vec3 *v1, const Vec3 *v2,
149 Vec3 *out) {
150 crossProductVec3(*v1, *v2, out);
151}
152
160[[nodiscard]] Vec3 crossProductVec3(const Vec3 &v1, const Vec3 &v2);
161[[nodiscard]] [[deprecated("Use the reference version instead")]] static inline Vec3 crossProductVec3(const Vec3 *v1,
162 const Vec3 *v2) {
163 return crossProductVec3(*v1, *v2);
164}
165
172[[nodiscard]] FixedPoint<> matrixDeterminant3(const Matrix33 &m);
173[[nodiscard]] [[deprecated("Use the reference version instead")]] static inline FixedPoint<> matrixDeterminant3(
174 const Matrix33 *m) {
175 return matrixDeterminant3(*m);
176}
177
184[[nodiscard]] FixedPoint<> squareRoot(FixedPoint<> x, FixedPoint<> y);
185
192[[nodiscard]] static inline FixedPoint<> squareRoot(FixedPoint<> x) { return squareRoot(x, x / 2); }
193
202[[nodiscard]] FixedPoint<> inverseSquareRoot(FixedPoint<> x, FixedPoint<> y);
203
210[[nodiscard]] static inline FixedPoint<> inverseSquareRoot(FixedPoint<> x) { return inverseSquareRoot(x, x * 2); }
211
218[[nodiscard]] FixedPoint<> normOfVec3(const Vec3 &v);
219[[nodiscard]] [[deprecated("Use the reference version instead")]] static inline FixedPoint<> normOfVec3(const Vec3 *v) {
220 return normOfVec3(*v);
221}
222
228void normalizeVec3(Vec3 *v);
229
235void fastNormalizeVec3(Vec3 *v);
236
244void project(const Vec3 *v, FixedPoint<> h, Vec2 *out);
245
246} // namespace SoftMath
247
248} // namespace psyqo
A trigonometry table.
Definition trigonometry.hh:74
uint32_t t
Definition cop0.c:79
uint32_t out
Definition cpu.c:62
Axis
Definition math.h:59
void fastNormalizeVec3(Vec3 *v)
Normalizes a 3D vector, using a faster but less accurate algorithm.
Definition soft-math.cpp:341
FixedPoint inverseSquareRoot(FixedPoint<> x, FixedPoint<> y)
Computes the inverse square root of a fixed point number, given an approximative hint.
void generateRotationMatrix33(Matrix33 *m, Angle t, Axis a, const Trig<> &trig)
Generate a rotation matrix for a given angle and axis.
Definition soft-math.cpp:32
void project(const Vec3 *v, FixedPoint<> h, Vec2 *out)
Projects a 3D point onto a 2D plane.
Definition soft-math.cpp:355
void scaleMatrix33(Matrix33 *m, FixedPoint<> s)
Scale a 3x3 matrix by a scalar.
FixedPoint squareRoot(FixedPoint<> x, FixedPoint<> y)
Computes the square root of a fixed point number, given an approximative hint.
FixedPoint matrixVecMul3z(const Matrix33 &m, const Vec3 &v)
Multiply a 3x3 matrix by a 3D vector, returning only the z component.
Definition soft-math.cpp:231
FixedPoint matrixDeterminant3(const Matrix33 &m)
Compute the determinant of a 3x3 matrix.
Definition soft-math.cpp:276
void normalizeVec3(Vec3 *v)
Normalizes a 3D vector.
Definition soft-math.cpp:327
void matrixVecMul3(const Matrix33 &m, const Vec3 &v, Vec3 *out)
Multiply a 3x3 matrix by a 3D vector.
Definition soft-math.cpp:179
void matrixVecMul3xy(const Matrix33 &m, const Vec3 &v, Vec2 *out)
Multiply a 3x3 matrix by a 3D vector, returning only the x and y components.
Definition soft-math.cpp:209
void crossProductVec3(const Vec3 &v1, const Vec3 &v2, Vec3 *out)
Compute the cross product of two 3D vectors.
Definition soft-math.cpp:244
FixedPoint normOfVec3(const Vec3 &v)
Computes the norm of a 3D vector.
Definition soft-math.cpp:319
Axis
Definition soft-math.hh:38
void multiplyMatrix33(const Matrix33 &m1, const Matrix33 &m2, Matrix33 *out)
Multiply two 3x3 matrices.
Definition soft-math.cpp:131
Definition cdrom-loader.hh:39
FixedPoint< 10 > Angle
A fixed point angle.
Definition trigonometry.hh:48
Vector< 3 > Vec3
Definition vector.hh:234
Vector< 2 > Vec2
Definition vector.hh:233
char * s
Definition string.c:48
Definition matrix.hh:33