Ich habe den folgenden Code:Wie verbinden Sie zwei SCNSpheres im 3D-Raum mit dem Bézier-Pfad in Swift?
func createScene(){
count += 1
let sphereGeom = SCNSphere(radius: 1.5)
sphereGeom.firstMaterial?.diffuse.contents = UIColor.redColor()
let path = UIBezierPath()
path.moveToPoint(CGPoint(x: 0, y: 0))
let radius = 3.0
var radians = Double(0)
var yPosition = Float(5.4)
while count <= 20 {
if radians >= 2{
radians -= 2
}
let sphereNode = SCNNode(geometry: sphereGeom)
let angle = Double(radians * M_PI)
let xPosition = Float(radius * cos(angle))
let zPosition = Float(radius * sin(angle))
sphereNode.position = SCNVector3(xPosition, yPosition, zPosition)
let cgX = CGFloat(xPosition)
let cgY = CGFloat(yPosition)
path.addQuadCurveToPoint(CGPoint(x: cgX, y: cgY), controlPoint: CGPoint(x: (cgX/2), y: (cgY/2)))
path.addLineToPoint(CGPoint(x: (cgX - (cgX * 0.01)), y: cgY))
path.addQuadCurveToPoint(CGPoint(x: 1, y: 0), controlPoint: CGPoint(x: (cgX/2), y: ((cgY/2) - (cgY * 0.01))))
let shape = SCNShape(path: path, extrusionDepth: 3.0)
shape.firstMaterial?.diffuse.contents = UIColor.blueColor()
let shapeNode = SCNNode(geometry: shape)
shapeNode.eulerAngles.y = Float(-M_PI_4)
self.rootNode.addChildNode(shapeNode)
count += 1
radians += 0.5556
yPosition -= 1.35
self.rootNode.addChildNode(sphereNode)
}
Ich möchte einen Bézier-Pfad hinzuzufügen, jede Kugel zum nächsten verbindet, eine Spirale zu schaffen, die Helix hinunter. Aus irgendeinem Grund, wenn ich diesen Code hinzufüge, erscheint die Form nicht einmal. Aber wenn ich größere x- und y-Werte verwende, sehe ich den Pfad gut, aber er ist nicht auf die Größe der Kugeln ausgerichtet. Ich verstehe nicht, warum es verschwindet, wenn ich versuche es kleiner zu machen.