简体   繁体   中英

Check collision between two bounding boxes in Away3D?

I need to do some simple collision detection in Away3D. I found the away3d.bounds.AxisAlignedBoundingBox class, but it seems I can only check collisions between the bounding box and a Vector.

Is there any way to check the collision between two bounding boxes?

if you are using/can upgrade to 4.4.x, look into Mesh.worldBounds, particularly wordBounds.overlap(someOtherWorldBounds).

Example (away3d setup elided):

// setup objects and materials
cubeMaterial:ColorMaterial;
cube:Mesh;

sphereMaterial:ColorMaterial;
sphere:Mesh;

collideMaterial:ColorMaterial;

cubeMaterial = new ColorMaterial(0x3333FF);
cube = new Mesh(new CubeGeometry(), cubeMaterial);
cube.x = -100;
cube.showBounds = true;

sphereMaterial = new ColorMaterial(0xFF3333);
sphere = new Mesh(new SphereGeometry(), sphereMaterial);
sphere.x = 100;
sphere.showBounds = true;

collideMaterial = new ColorMaterial(0x33FF33);

in your enterFrame handler:

// process your object movement here
if (cube.worldBounds.overlaps(sphere.worldBounds) cube.material = collideMaterial;
else cube.material = cubeMaterial;
view.render();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM