Ios 从GLKVector3提取X和Y?网间网操作系统
假设我有一个GLKVector3,并且只想将x和y值读取为CGPoints-我如何才能做到这一点?在中,有类型定义:Ios 从GLKVector3提取X和Y?网间网操作系统,ios,objective-c,opengl-es,glkit,Ios,Objective C,Opengl Es,Glkit,假设我有一个GLKVector3,并且只想将x和y值读取为CGPoints-我如何才能做到这一点?在中,有类型定义: 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的v属性
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
的v
属性,它是float[3]
数组{x,y,z}
i、 e:
对于向量类型的不同用途,还有浮点属性x、y、z
或更不相关的r、g、b
或s、t、p
:
CGPoint p = CGPointMake(vector.x,vector.y);
在中,有类型定义:
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
的v
属性,它是float[3]
数组{x,y,z}
i、 e:
对于向量类型的不同用途,还有浮点属性x、y、z
或更不相关的r、g、b
或s、t、p
:
CGPoint p = CGPointMake(vector.x,vector.y);
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);
但是请注意,
CGPoint
由CGFloat
组成,在64位环境中可能是双精度。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);
但是请注意,CGPoint
由CGFloat
组成,在64位环境中可能是双精度。关于64位的好观点——如果需要转换这两种方式和/或写出可能在不同设备架构上读取的数据,您需要小心。关于64位的好观点——如果您需要需要转换两种方式和/或写出可能在不同设备架构上读取的数据。