Question

Say I have a GLKVector3 and want to read only the x and y values as CGPoints - how can I do this ?

Was it helpful?

Solution

In the GLKVector3 doc, there is type definition:

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

There for there are 3 options:

GLKVector3's v attribute which is a float[3] array of {x,y,z}

i.e.:

GLKVector3 vector;

...

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

CGPoint p = CGPointMake(x,y); 

Then there are also float attributes x,y,z or less relevant r,g,b or s,t,p for different uses of the vector type:

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

OTHER TIPS

GLKVector3 is declared as

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

So the easiest and most readable way to convert is:

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

Note however that CGPoint consist of CGFloats which might be a double in 64-Bit environments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top