Skip to content

Commit

Permalink
Handle pre picking.
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H committed Dec 28, 2022
1 parent 66f6785 commit 7ec9d4f
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions examples/rtree/game.json
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@
{
"name": "Obstacle",
"type": "CollisionDetector::Solid"
},
{
"name": "Physics2",
"type": "Physics2::Physics2Behavior",
"gravityX": 0,
"gravityY": 9.8,
"scaleX": 100,
"scaleY": 100
}
]
},
Expand Down Expand Up @@ -1182,11 +1190,18 @@
" const top = object.getAABBTop();\r",
" const right = object.getAABBRight();\r",
" const bottom = object.getAABBBottom();\r",
" for (const objectName in solidObjectLists.items) {\r",
" // Solid picking is ignored all solid are considered.\r",
" nearObjects.length = 0;\r",
" manager.getAllInstancesInRectangle(objectName, left, top, right, bottom, nearObjects);\r",
" object.separateFromObjects(nearObjects);\r",
" for (const solidObjectName in solidObjectLists.items) {\r",
" const pickedObjects = solidObjectLists.items[solidObjectName];\r",
" if (pickedObjects.length === runtimeScene.getInstancesCountOnScene(solidObjectName)) {\r",
" nearObjects.length = 0;\r",
" manager.getAllInstancesInRectangle(solidObjectName, left, top, right, bottom, nearObjects);\r",
" object.separateFromObjects(nearObjects);\r",
" }\r",
" else {\r",
" // Avoid to do intersection between pickedObjects and nearObjects\r",
" // as it is O(n²) and the naive collision is O(n).\r",
" object.separateFromObjects(pickedObjects);\r",
" }\r",
" }\r",
"}"
],
Expand Down

0 comments on commit 7ec9d4f

Please sign in to comment.