Hallo, ich bin neu bei swift und OpenGL. Ich folge ein Tutorial in in Objective-C geschrieben und ich bin Umwandlung in Swift 2.0Swift - Wie man den Wert der "Get-only" -Eigenschaft ändert
Hier ist der Code
float radius = self.view.bounds.size.width/3;
GLKVector3 center = GLKVector3Make(self.view.bounds.size.width/2, self.view.bounds.size.height/2, 0);
GLKVector3 P = GLKVector3Subtract(touchPoint, center);
P = GLKVector3Make(P.x, P.y * -1, P.z);
float radius2 = radius * radius;
float length2 = P.x*P.x + P.y*P.y;
if (length2 <= radius2)
P.z = sqrt(radius2 - length2);
else
{
P.z = radius2/(2.0 * sqrt(length2));
float length = sqrt(length2 + P.z * P.z);
P = GLKVector3DivideScalar(P, length);
}
Hier mein Swift-Code ist
let radius: CGFloat = self.view.bounds.size.width/3
let center: GLKVector3 = GLKVector3Make(Float(self.view.bounds.size.width/2), Float(self.view.bounds.size.height/2), 0.0)
var P: GLKVector3 = GLKVector3Subtract(touchPoint, center)
P = GLKVector3Make(P.x, P.y * -1, P.z)
let radius2 = radius * radius
let length = P.x * P.x + P.y * P.y
if(Float(length) <= Float(radius2)){
P.z = sqrt(Float(radius2) - Float(length)) //the error is here
} else {
//other code
}
Ich kann nicht ändern der Wert von Pz, heißt es
"nicht Eigenschaft zuweisen kann: 'z' ist eine get-only-Eigenschaft"
Vielen Dank im Voraus
vielen Dank –