Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[orx-force-2d] Add alpha parameter to solve method
  • Loading branch information
edwinRNDR committed Jul 1, 2026
commit 1c88615d5f226072fb2fd0eee4b85344f2bc5283
8 changes: 5 additions & 3 deletions orx-force-2d/src/commonMain/kotlin/ForceSimulation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ class Body(
}
}

suspend fun solve(dt: Double) {
suspend fun solve(dt: Double, alpha: Double) {

for (i in nodes.indices) {
nodes[i].prevPosition = nodes[i].position

if (!static) {
nodes[i].position += nodes[i].velocity * dt
nodes[i].position += nodes[i].velocity * dt * alpha
}
}

Expand Down Expand Up @@ -290,6 +290,8 @@ class ForceSimulation(val bodies: MutableList<Body> = mutableListOf()) {

var context: CoroutineContext = Dispatchers.Default

var alpha = 1.0

private fun partitionPairs(pairs: List<Pair<Int, Int>>): List<List<Pair<Int, Int>>> {
val batches = mutableListOf<MutableList<Pair<Int, Int>>>()
val usedInBatch = mutableListOf<MutableSet<Int>>()
Expand Down Expand Up @@ -354,7 +356,7 @@ class ForceSimulation(val bodies: MutableList<Body> = mutableListOf()) {

bodies.map { body ->
async {
body.solve(sdt)
body.solve(sdt, alpha)
}
}.awaitAll()

Expand Down
4 changes: 4 additions & 0 deletions orx-force-2d/src/commonMain/kotlin/quadtree/QuadTreeNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ internal class QuadTreeNode(
return
}

if (xmax - xmin < 1E-6 || ymax - ymin < 1E-6) {
return
}

if (children == null) {
children = arrayOfNulls(4)
val existingNode = node!!
Expand Down