2013-10-20 47 views

回答

3

GLKVector3 doc,有類型定義:

union _GLKVector3 
{ 
    struct { float x, y, z; }; 
    struct { float r, g, b; }; 
    struct { float s, t, p; }; 
     float v[3]; 
}; 
typedef union _GLKVector3 GLKVector3; 

有用於有3個選項:

GLKVector3v屬性,它是一個float[3]陣列的{x,y,z}

即:

GLKVector3 vector; 

... 

float x = vector.v[0]; 
float y = vector.v[1]; 
float z = vector.v[2]; 

CGPoint p = CGPointMake(x,y); 

然後也有浮動屬性x,y,z以下相關r,g,bs,t,p爲載體類型的不同用途:

CGPoint p = CGPointMake(vector.x,vector.y); 
1

GLKVector3被聲明爲

union _GLKVector3 
{ 
    struct { float x, y, z; }; 
    struct { float r, g, b; }; 
    struct { float s, t, p; }; 
    float v[3]; 
}; 
typedef union _GLKVector3 GLKVector3; 

所以轉換的最容易和最易讀的方式是:

GLKVector3 someVector; 
… 
CGPoint somePoint = CGPointMake(someVector.x,someVector.y); 

但請注意,CGPointCGFloat組成,這可能是64位環境中的兩倍。

+0

關於64位的好處 - 如果您需要轉換兩種方式和/或寫出可能在不同設備架構上讀取的數據,則需要小心。 – rickster