This commit is contained in:
Nayla Hanegan 2024-01-27 04:44:26 -05:00
commit 0af9a3ae8f
212 changed files with 50301 additions and 41718 deletions

View file

@ -86,6 +86,7 @@ add_library(common
IOFile.h
JitRegister.cpp
JitRegister.h
JsonUtil.h
Lazy.h
LinearDiskCache.h
Logging/ConsoleListener.h

View file

@ -0,0 +1,26 @@
// Copyright 2024 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <span>
#include <picojson.h>
// Ideally this would use a concept like, 'template <std::ranges::range Range>' to constrain it,
// but unfortunately we'd need to require clang 15 for that, since the ranges library isn't
// fully implemented until then, but this should suffice.
template <typename Range>
picojson::array ToJsonArray(const Range& data)
{
picojson::array result;
result.reserve(std::size(data));
for (const auto& value : data)
{
result.emplace_back(static_cast<double>(value));
}
return result;
}

View file

@ -250,11 +250,7 @@ Matrix33 Matrix33::Inverted() const
{
const auto m = [this](int x, int y) { return data[y + x * 3]; };
const auto det = m(0, 0) * (m(1, 1) * m(2, 2) - m(2, 1) * m(1, 2)) -
m(0, 1) * (m(1, 0) * m(2, 2) - m(1, 2) * m(2, 0)) +
m(0, 2) * (m(1, 0) * m(2, 1) - m(1, 1) * m(2, 0));
const auto invdet = 1 / det;
const auto invdet = 1 / Determinant();
Matrix33 result;
@ -273,6 +269,15 @@ Matrix33 Matrix33::Inverted() const
return result;
}
float Matrix33::Determinant() const
{
const auto m = [this](int x, int y) { return data[y + x * 3]; };
return m(0, 0) * (m(1, 1) * m(2, 2) - m(2, 1) * m(1, 2)) -
m(0, 1) * (m(1, 0) * m(2, 2) - m(1, 2) * m(2, 0)) +
m(0, 2) * (m(1, 0) * m(2, 1) - m(1, 1) * m(2, 0));
}
Matrix44 Matrix44::Identity()
{
Matrix44 mtx = {};
@ -360,4 +365,17 @@ void Matrix44::Multiply(const Matrix44& a, const Vec4& vec, Vec4* result)
result->data = MatrixMultiply<4, 4, 1>(a.data, vec.data);
}
float Matrix44::Determinant() const
{
const auto& m = data;
return m[12] * m[9] * m[6] * m[3] - m[8] * m[13] * m[6] * m[3] - m[12] * m[5] * m[10] * m[3] +
m[4] * m[13] * m[10] * m[3] + m[8] * m[5] * m[14] * m[3] - m[4] * m[9] * m[14] * m[3] -
m[12] * m[9] * m[2] * m[7] + m[8] * m[13] * m[2] * m[7] + m[12] * m[1] * m[10] * m[7] -
m[0] * m[13] * m[10] * m[7] - m[8] * m[1] * m[14] * m[7] + m[0] * m[9] * m[14] * m[7] +
m[12] * m[5] * m[2] * m[11] - m[4] * m[13] * m[2] * m[11] - m[12] * m[1] * m[6] * m[11] +
m[0] * m[13] * m[6] * m[11] + m[4] * m[1] * m[14] * m[11] - m[0] * m[5] * m[14] * m[11] -
m[8] * m[5] * m[2] * m[15] + m[4] * m[9] * m[2] * m[15] + m[8] * m[1] * m[6] * m[15] -
m[0] * m[9] * m[6] * m[15] - m[4] * m[1] * m[10] * m[15] + m[0] * m[5] * m[10] * m[15];
}
} // namespace Common

View file

@ -392,6 +392,7 @@ public:
static void Multiply(const Matrix33& a, const Vec3& vec, Vec3* result);
Matrix33 Inverted() const;
float Determinant() const;
Matrix33& operator*=(const Matrix33& rhs)
{
@ -432,6 +433,8 @@ public:
// For when a vec4 isn't needed a multiplication function that takes a Vec3 and w:
Vec3 Transform(const Vec3& point, float w) const;
float Determinant() const;
Matrix44& operator*=(const Matrix44& rhs)
{
Multiply(*this, rhs, this);