【问题标题】:Check collision between two bounding boxes in Away3D?检查 Away3D 中两个边界框之间的碰撞?
【发布时间】:2012-07-25 03:27:22
【问题描述】:

我需要在 Away3D 中进行一些简单的碰撞检测。我找到了away3d.bounds.AxisAlignedBoundingBox 类,但似乎我只能检查边界框和向量之间的冲突。

有没有办法检查两个边界框之间的碰撞?

【问题讨论】:

标签: actionscript-3 bounding-box away3d aabb


【解决方案1】:

如果您正在使用/可以升级到 4.4.x, 查看 Mesh.worldBounds,特别是 wordBounds.overlap(someOtherWorldBounds)。

示例(省略了 away3d 设置):

// 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);

在您的 enterFrame 处理程序中:

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

【讨论】:

    猜你喜欢
    • 2013-02-21
    • 2015-02-01
    • 2014-02-04
    • 1970-01-01
    • 2015-02-02
    • 1970-01-01
    • 2014-07-19
    • 1970-01-01
    • 2011-04-21
    相关资源
    最近更新 更多