Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rm committed Mar 23, 2024
1 parent 9eb642e commit f216899
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 26 deletions.
2 changes: 1 addition & 1 deletion examples/review/src/ReviewConfig.elm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ config =
, NoUnused.Parameters.rule
, NoUnused.Patterns.rule
, NoUnused.Variables.rule
, Simplify.rule
, Simplify.rule Simplify.defaults
, NoUnoptimizedRecursion.rule (NoUnoptimizedRecursion.optOutWithComment "IGNORE TCO")
]
2 changes: 1 addition & 1 deletion sandbox/review/src/ReviewConfig.elm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ config =
, NoUnused.Parameters.rule
, NoUnused.Patterns.rule
, NoUnused.Variables.rule
, Simplify.rule
, Simplify.rule Simplify.defaults
, NoUnoptimizedRecursion.rule (NoUnoptimizedRecursion.optOutWithComment "IGNORE TCO")
]
8 changes: 4 additions & 4 deletions src/Collision/ConvexConvex.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ addContacts : Convex -> Convex -> List Contact -> List Contact
addContacts convex1 convex2 contacts =
case findSeparatingAxis convex1 convex2 of
Just separatingAxis ->
let
reversedSeparatingAxis =
Vec3.negate separatingAxis
in
case bestFace convex1.faces separatingAxis of
Just face1 ->
let
reversedSeparatingAxis =
Vec3.negate separatingAxis
in
case bestFace convex2.faces reversedSeparatingAxis of
Just face2 ->
clipTwoFaces face1 face2 reversedSeparatingAxis contacts
Expand Down
10 changes: 6 additions & 4 deletions src/Internal/Body.elm
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,13 @@ compound shapes data =
{ id = -1
, data = data
, material = Material.default
, transform3d = transform3d
, centerOfMassTransform3d = centerOfMassTransform3d
, velocity = Vec3.zero
, angularVelocity = Vec3.zero
, transform3d = transform3d
, centerOfMassTransform3d = centerOfMassTransform3d
, mass = 0
, shapes = movedShapes
, worldShapes = Shape.shapesPlaceIn shapeTransform shapes
, force = Vec3.zero
, torque = Vec3.zero
, boundingSphereRadius = List.foldl Shape.expandBoundingSphereRadius 0 movedShapes

-- default damping
Expand All @@ -132,6 +130,10 @@ compound shapes data =
, invMass = 0
, invInertia = Mat3.zero
, invInertiaWorld = Mat3.zero

-- forces
, force = Vec3.zero
, torque = Vec3.zero
}


Expand Down
40 changes: 25 additions & 15 deletions src/Internal/Solver.elm
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,15 @@ solveEquationsGroup body1 body2 equations deltalambdaTot currentEquations =
else
deltalambdaPrev

invI1 =
body1.body.invInertiaWorld

invI2 =
body2.body.invInertiaWorld

k1 =
deltalambda * body1.body.invMass

k2 =
deltalambda * body2.body.invMass

newBody1 =
if body1.body.mass > 0 then
let
invI1 =
body1.body.invInertiaWorld

k1 =
deltalambda * body1.body.invMass
in
{ body = body1.body
, vX = body1.vX - k1 * vB.x
, vY = body1.vY - k1 * vB.y
Expand All @@ -257,6 +252,13 @@ solveEquationsGroup body1 body2 equations deltalambdaTot currentEquations =

newBody2 =
if body2.body.mass > 0 then
let
invI2 =
body2.body.invInertiaWorld

k2 =
deltalambda * body2.body.invMass
in
{ body = body2.body
, vX = body2.vX + k2 * vB.x
, vY = body2.vY + k2 * vB.y
Expand All @@ -282,7 +284,7 @@ solveEquationsGroup body1 body2 equations deltalambdaTot currentEquations =
remainingEquations


updateBodies : { dt : Float, gravity : Vec3, gravityLength : Float } -> Array (SolverBody data) -> World data -> World data
updateBodies : { ctx | dt : Float, gravity : Vec3 } -> Array (SolverBody data) -> World data -> World data
updateBodies ctx bodies world =
let
simulatedBodies =
Expand All @@ -304,7 +306,15 @@ updateBodies ctx bodies world =
in
{ world
| bodies =
Array.toList simulatedBodies
|> List.filter (\{ id } -> id + 1 > 0)
Array.foldr
(\body list ->
if body.id + 1 > 0 then
body :: list

else
list
)
[]
simulatedBodies
, simulatedBodies = simulatedBodies
}
2 changes: 1 addition & 1 deletion src/Internal/SolverBody.elm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fromBody body =
}


toBody : { dt : Float, gravity : Vec3, gravityLength : Float } -> SolverBody data -> Body data
toBody : { ctx | dt : Float, gravity : Vec3 } -> SolverBody data -> Body data
toBody { dt, gravity } { body, vX, vY, vZ, wX, wY, wZ } =
let
-- Apply damping https://code.google.com/archive/p/bullet/issues/74
Expand Down

0 comments on commit f216899

Please sign in to comment.