Skip to content

Commit 7ec9d4f

Browse files
committed
Handle pre picking.
1 parent 66f6785 commit 7ec9d4f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

examples/rtree/game.json

+20-5
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,14 @@
491491
{
492492
"name": "Obstacle",
493493
"type": "CollisionDetector::Solid"
494+
},
495+
{
496+
"name": "Physics2",
497+
"type": "Physics2::Physics2Behavior",
498+
"gravityX": 0,
499+
"gravityY": 9.8,
500+
"scaleX": 100,
501+
"scaleY": 100
494502
}
495503
]
496504
},
@@ -1182,11 +1190,18 @@
11821190
" const top = object.getAABBTop();\r",
11831191
" const right = object.getAABBRight();\r",
11841192
" const bottom = object.getAABBBottom();\r",
1185-
" for (const objectName in solidObjectLists.items) {\r",
1186-
" // Solid picking is ignored all solid are considered.\r",
1187-
" nearObjects.length = 0;\r",
1188-
" manager.getAllInstancesInRectangle(objectName, left, top, right, bottom, nearObjects);\r",
1189-
" object.separateFromObjects(nearObjects);\r",
1193+
" for (const solidObjectName in solidObjectLists.items) {\r",
1194+
" const pickedObjects = solidObjectLists.items[solidObjectName];\r",
1195+
" if (pickedObjects.length === runtimeScene.getInstancesCountOnScene(solidObjectName)) {\r",
1196+
" nearObjects.length = 0;\r",
1197+
" manager.getAllInstancesInRectangle(solidObjectName, left, top, right, bottom, nearObjects);\r",
1198+
" object.separateFromObjects(nearObjects);\r",
1199+
" }\r",
1200+
" else {\r",
1201+
" // Avoid to do intersection between pickedObjects and nearObjects\r",
1202+
" // as it is O(n²) and the naive collision is O(n).\r",
1203+
" object.separateFromObjects(pickedObjects);\r",
1204+
" }\r",
11901205
" }\r",
11911206
"}"
11921207
],

0 commit comments

Comments
 (0)