2

I have a bunch of Z coordinates in an array. I want to create geometry using these values, thus I created an array of SCNVector3. X and Y values will be calculated using a simple nested loop, but the Z values will come from my array.

Xcode is telling me: Cannot assign value of type '(x: Float, y: Float, z: Float)' to type SCNVector3

Am I making a bonehead mistake here?

My code right now is:

var width = 10
var height = 20
var zDepth = [Float]()  
var verts = [SCNVector3]()  
var i = 0  
for y in 0 ..< height {  
    for x in 0 ..< width {  
        if i < (width*height) {  
            vert[i] = (x: Float(x), y: Float(y), z: zDepth[i])  
            i += 1  
        }
    }
}
NoOneHere
  • 109
  • 1
  • 9

1 Answers1

1

for what platform is this?

if it is for mac os, then you have to use CGFloat not Float

EDIT:

you can't assign a tuple to vector3. in your code you need to initialize a new vector3 and assign it to your array

var width = 10
var height = 20
var zDepth = [Float]()
var verts = [SCNVector3]()
var i = 0
for y in 0 ..< height {
    for x in 0 ..< width {
        if i < (width*height) {
            verts[i] = SCNVector3(x: Float(x), y: Float(y), z: zDepth[i])
            i += 1
        }
    }
}

EDIT2: i took out cgfloat (i keep thinking in cgfloats)

Mec Os
  • 131
  • 1
  • 8
  • This is for iOS. When I tried CGFloat, the error was the same except it said CGFloat instead. Come to think of it, I didn't actually compile it because I just assumed it wasn't going to compile. The app I'm coding in is definitely an iOS app that I've already been running on my device. This is just a new portion of the code, so I'm assuming Xcode is set up correctly. – NoOneHere Mar 18 '18 at 01:39
  • oh, i get it now. you can't assign "(x: Float(x), y: Float(y), z: zDepth[i])" because it is a tuple not a scnvector3 – Mec Os Mar 18 '18 at 03:27