gpt4 book ai didi

iOS:如何从 opengl 模型 View 和投影矩阵获取屏幕坐标(X,Y 点)?

转载 作者:行者123 更新时间:2023-12-01 19:54:48 25 4
gpt4 key购买 nike

我有模型 View 矩阵、项目 View 矩阵和位置槽以及方形顶点。我想获取 iPhone 屏幕中正方形的屏幕坐标(X、Y 点)。

static GLfloat rectVerts[] = {-0.1f,  -0.1f, 0.0f,-0.1f,
0.1f, 0.0f,0.1f, 0.1f,
0.0f,0.1f, -0.1f, 0.0f
,0.0f,0.0f,0.0f,1.0f};
GLKVector4 position_Vector = GLKVector4MakeWithArray(rectVerts);

float p_clip[4];
for (int i=0;i<4;i++){
p_clip[i]=0;
}
for (int i=0;i<4;i++){
for (int j=0;j<12;j++){
p_clip[i] += ( modelViewprojection.m[i + j] * position_Vector.v[j]);
}
}
float p_ndc[4];
p_ndc[0] = p_clip[0] / p_clip[3];
p_ndc[1] = p_clip[1] / p_clip[3];
p_ndc[2] = p_clip[2] / p_clip[3];
p_ndc[3] = p_clip[3] / p_clip[3];

GLint view[4]={0};
glGetIntegerv(GL_VIEWPORT,view);
CGRect rect = CGRectMake(view[0], view[1], view[2], view[3]);
float x = (rect.origin.x + rect.size.width) * (p_ndc[0] + 1) /2;
NSLog(@"Test x = %f",x);

引用附件 enter image description here

最佳答案

只需遵循转换步骤:

p_clip = P · MV · p
p_ndc = p_clip/p_clip.w
p_viewport.xy = viewport.xy + viewport.wh · (p_ndc.xy + 1) / 2

关于iOS:如何从 opengl 模型 View 和投影矩阵获取屏幕坐标(X,Y 点)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43318811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com