This commit is contained in:
Irlan 2018-06-24 15:33:00 -03:00
parent 725b771d39
commit 1835d38373
4 changed files with 22 additions and 33 deletions

View File

@ -50,8 +50,6 @@ static inline bool ImGui_GLFW_GL_Init(GLFWwindow* w, bool install_callbacks)
#else
// error
#endif
return false;
}

View File

@ -51,7 +51,6 @@ protected:
friend class b3Cloth;
friend class b3ClothSolver;
friend class b3Particle;
friend class b3Force;
static b3Force* Create(const b3ForceDef* def);
static void Destroy(b3Force* f);

View File

@ -26,7 +26,7 @@
struct b3SparseSymMat33
{
//
b3SparseSymMat33(u32 m, u32 n);
b3SparseSymMat33(u32 m);
//
~b3SparseSymMat33();
@ -44,7 +44,6 @@ struct b3SparseSymMat33
void SetZero();
u32 M;
u32 N;
u32* row_ptrs;
u32 value_capacity;
u32 value_count;
@ -52,11 +51,9 @@ struct b3SparseSymMat33
u32* value_columns;
};
inline b3SparseSymMat33::b3SparseSymMat33(u32 m, u32 n)
inline b3SparseSymMat33::b3SparseSymMat33(u32 m)
{
B3_ASSERT(m == n);
M = m;
N = n;
row_ptrs = (u32*)b3Alloc((M + 1) * sizeof(u32));
memset(row_ptrs, 0, (M + 1) * sizeof(u32));
value_count = 0;
@ -75,7 +72,7 @@ inline b3SparseSymMat33::~b3SparseSymMat33()
inline const b3Mat33& b3SparseSymMat33::operator()(u32 i, u32 j) const
{
B3_ASSERT(i < M);
B3_ASSERT(j < N);
B3_ASSERT(j < M);
// Ensure i, and j is on the upper triangle
if (i > j)
@ -103,7 +100,7 @@ inline const b3Mat33& b3SparseSymMat33::operator()(u32 i, u32 j) const
inline b3Mat33& b3SparseSymMat33::operator()(u32 i, u32 j)
{
B3_ASSERT(i < M);
B3_ASSERT(j < N);
B3_ASSERT(j < M);
// Ensure i, and j is on the upper triangle
if (i > j)
@ -140,9 +137,15 @@ inline b3Mat33& b3SparseSymMat33::operator()(u32 i, u32 j)
}
// Shift the values
u32 right_count = value_count - row_value_begin - row_value_k;
memcpy(value_columns + row_value_begin + row_value_k + 1, value_columns + row_value_begin + row_value_k, right_count * sizeof(u32));
memcpy(values + row_value_begin + row_value_k + 1, values + row_value_begin + row_value_k, right_count * sizeof(b3Mat33));
for (u32 row_value = value_count; row_value > row_value_begin + row_value_k; --row_value)
{
values[row_value] = values[row_value - 1];
value_columns[row_value] = value_columns[row_value - 1];
}
// Insert the value
value_columns[row_value_begin + row_value_k] = j;
++value_count;
// Shift the row pointers
for (u32 row_ptr_index = i + 1; row_ptr_index < M + 1; ++row_ptr_index)
@ -150,17 +153,13 @@ inline b3Mat33& b3SparseSymMat33::operator()(u32 i, u32 j)
++row_ptrs[row_ptr_index];
}
// Insert the value
value_columns[row_value_begin + row_value_k] = j;
++value_count;
// Return the value
// Return the inserted value
return values[row_value_begin + row_value_k];
}
inline void b3SparseSymMat33::Diagonal(b3DiagMat33& out) const
{
B3_ASSERT(N == out.n);
B3_ASSERT(M == out.n);
for (u32 row = 0; row < M; ++row)
{
@ -196,11 +195,11 @@ inline void b3SparseSymMat33::SetZero()
inline void b3Mul(b3DenseVec3& out, const b3SparseSymMat33& A, const b3DenseVec3& v)
{
B3_ASSERT(A.N == out.n);
B3_ASSERT(A.M == out.n);
out.SetZero();
for (u32 row = 0; row < A.N; ++row)
for (u32 row = 0; row < A.M; ++row)
{
u32 row_value_begin = A.row_ptrs[row];
u32 row_value_count = A.row_ptrs[row + 1] - row_value_begin;

View File

@ -151,10 +151,10 @@ void b3ClothSolver::Solve(float32 dt, const b3Vec3& gravity)
b3DenseVec3 sy(m_particleCount);
b3DenseVec3 sx0(m_particleCount);
b3SparseSymMat33 dfdx(m_particleCount, m_particleCount);
b3SparseSymMat33 dfdx(m_particleCount);
dfdx.SetZero();
b3SparseSymMat33 dfdv(m_particleCount, m_particleCount);
b3SparseSymMat33 dfdv(m_particleCount);
dfdv.SetZero();
m_solverData.x = &sx;
@ -211,7 +211,7 @@ void b3ClothSolver::Solve(float32 dt, const b3Vec3& gravity)
// b = h * (f0 + h * dfdx * v0 + dfdx * y)
// A
b3SparseSymMat33 A(m_particleCount, m_particleCount);
b3SparseSymMat33 A(m_particleCount);
// b
b3DenseVec3 b(m_particleCount);
@ -284,15 +284,8 @@ void b3ClothSolver::Compute_A_b(b3SparseSymMat33& A, b3DenseVec3& b) const
// A = M - h * dfdv - h * h * dfdx
// A = 0
// Set the upper triangle zero
for (u32 i = 0; i < m_particleCount; ++i)
{
for (u32 j = i; j < m_particleCount; ++j)
{
A(i, j).SetZero();
}
}
A.SetZero();
// A += M
for (u32 i = 0; i < m_particleCount; ++i)
{