如何比较场景工具包中两个球体的大小?

时间:2016-08-03 05:33:10

标签: swift collision-detection scenekit renderer

我的项目中有2个球在同一个位置。 firstSphere更小,tempSphere更大。

编辑: firstShape将比tempShape增长更多。当我暂停firstShape时,我试图测试'如果firstShape.scale == tempShape.scale'

//Create Shape
let firstShapeGeo = SCNSphere(radius: shapeRadius)
firstShape.geometry = firstShapeGeo
let shapeMaterial = SCNMaterial()
shapeMaterial.diffuse.contents = UIColor(colorLiteralRed: 0.2, green: 0.8, blue: 0.9, alpha: 1.0)
firstShapeGeo.materials = [shapeMaterial]
firstShape.position = SCNVector3Make(0, 0, 0)
scene.rootNode.addChildNode(firstShape)
firstShape.name = "\(shapeNumber)"

// Create Temp Shape
tempShapeRadius = shapeRadius + 1.0

let tempShapeGeo = SCNSphere(radius: tempShapeRadius)
tempShape.geometry = tempShapeGeo
let tempShapeMaterial = SCNMaterial()
tempShapeMaterial.diffuse.contents = UIColor(colorLiteralRed: 0.2, green: 0.8, blue: 0.9, alpha: 0.5)
tempShapeGeo.materials = [tempShapeMaterial]
firstShape.position = SCNVector3Make(0, 0, 0)
scene.rootNode.addChildNode(tempShape)

这就是我如何发展firstSphere

let grow = SCNAction.scale(to: tempShapeRadius * 2 + 1, duration: 1)
let shrink = SCNAction.scale(to: tempShapeRadius, duration: 1)

let sequence = SCNAction.sequence([grow, shrink])
firstShape.run(SCNAction.repeatForever(sequence))

使用SCNAction.scale,较小的球体变得越来越大,所以我不相信半径实际上在变化。不确定这是否是您需要知道的。

任何帮助将不胜感激!谢谢!

1 个答案:

答案 0 :(得分:1)

为两个球体指定相同的半径。将scale的{​​{1}}设置为任意值,使其所需的数量大于tempShape的初始值。现在您只需要比较firstShape

假设您希望scale球体的大小是可调球体的3倍。

tempShape