Skip to content

Commit 0ef0de1

Browse files
authored
Merge pull request #27 from Winster332/fix/weld-joint
Bugfix weld-joint from C++
2 parents 0add322 + 2be8e96 commit 0ef0de1

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/box2dx/Box2D.NetStandard/Common/Mat33.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ internal Vector3 Solve33(Vector3 b)
6464
{
6565
float det = Vector3.Dot(ex, Vector3.Cross(ey, ez));
6666
//Debug.Assert(det != 0.0f);
67-
det = 1.0f / det;
67+
if (det != 0.0f)
68+
{
69+
det = 1.0f / det;
70+
}
6871
var x = new Vector3();
6972
x.X = det * Vector3.Dot(b, Vector3.Cross(ey, ez));
7073
x.Y = det * Vector3.Dot(ex, Vector3.Cross(b, ez));
@@ -82,14 +85,17 @@ internal Vector2 Solve22(Vector2 b)
8285
float a11 = ex.X, a12 = ey.X, a21 = ex.Y, a22 = ey.Y;
8386
float det = a11 * a22 - a12 * a21;
8487
//Debug.Assert(det != 0.0f);
85-
det = 1.0f / det;
88+
if (det != 0.0f)
89+
{
90+
det = 1.0f / det;
91+
}
8692
var x = new Vector2();
8793
x.X = det * (a22 * b.X - a12 * b.Y);
8894
x.Y = det * (a11 * b.Y - a21 * b.X);
8995
return x;
9096
}
9197

92-
internal void GetInverse22(Mat33 M)
98+
internal Mat33 GetInverse22(Mat33 M)
9399
{
94100
float a = ex.X, b = ey.X, c = ex.Y, d = ey.Y;
95101
float det = a * d - b * c;
@@ -107,9 +113,11 @@ internal void GetInverse22(Mat33 M)
107113
M.ez.X = 0.0f;
108114
M.ez.Y = 0.0f;
109115
M.ez.Z = 0.0f;
116+
117+
return M;
110118
}
111119

112-
internal void GetSymInverse33(Mat33 M)
120+
internal Mat33 GetSymInverse33(Mat33 M)
113121
{
114122
float det = Vector3.Dot(ex, Vector3.Cross(ey, ez));
115123
if (det != 0.0f)
@@ -132,6 +140,8 @@ internal void GetSymInverse33(Mat33 M)
132140
M.ez.X = M.ex.Z;
133141
M.ez.Y = M.ey.Z;
134142
M.ez.Z = det * (a11 * a22 - a12 * a12);
143+
144+
return M;
135145
}
136146
}
137147
}

src/box2dx/Box2D.NetStandard/Dynamics/Joints/Joint.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Box2DX Copyright (c) 2009 Ihar Kalasouski http://code.google.com/p/box2dx
3535
using Box2D.NetStandard.Dynamics.Joints.Prismatic;
3636
using Box2D.NetStandard.Dynamics.Joints.Pulley;
3737
using Box2D.NetStandard.Dynamics.Joints.Revolute;
38+
using Box2D.NetStandard.Dynamics.Joints.Weld;
3839
using Box2D.NetStandard.Dynamics.Joints.Wheel;
3940
using Box2D.NetStandard.Dynamics.World;
4041
using Box2D.NetStandard.Dynamics.World.Callbacks;
@@ -198,7 +199,8 @@ internal static Joint Create(JointDef def)
198199
RevoluteJointDef d => new RevoluteJoint(d),
199200
PulleyJointDef d => new PulleyJoint(d),
200201
GearJointDef d => new GearJoint(d),
201-
WheelJointDef d => new WheelJoint(d)
202+
WheelJointDef d => new WheelJoint(d),
203+
WeldJointDef d => new WeldJoint(d)
202204
};
203205
}
204206

src/box2dx/Box2D.NetStandard/Dynamics/Joints/Weld/WeldJoint.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ internal override void InitVelocityConstraints(in SolverData data)
122122

123123
if (Stiffness > 0.0f)
124124
{
125-
K.GetInverse22(m_mass);
125+
m_mass = K.GetInverse22(m_mass);
126126

127127
float invM = iA + iB;
128128

@@ -143,13 +143,13 @@ internal override void InitVelocityConstraints(in SolverData data)
143143
}
144144
else if (K.ez.Z == 0.0f)
145145
{
146-
K.GetInverse22(m_mass);
146+
m_mass = K.GetInverse22(m_mass);
147147
m_gamma = 0.0f;
148148
m_bias = 0.0f;
149149
}
150150
else
151151
{
152-
K.GetSymInverse33(m_mass);
152+
m_mass = K.GetSymInverse33(m_mass);
153153
m_gamma = 0.0f;
154154
m_bias = 0.0f;
155155
}

0 commit comments

Comments
 (0)