问题描述
我正在制作一个基于 gluT 的 OpenGL 应用程序,其中有一些行星和一艘从单独的输入文件加载的宇宙飞船。边界框的计算已经实现,我知道如何检查边界框之间的碰撞,但我不知道如何从 gluT 获取单词空间坐标。据我所知,如果边界框坐标在世界空间中,我只能检查碰撞,但我在本地有这些。
这是边界框计算器:
void calc_bounding_Box(struct Model* model)
{
int i;
double x,y,z;
double min_x,max_x,min_y,max_y,min_z,max_z;
if (model->n_vertices == 0) { return;}
min_x = model->vertices[0].x;
max_x = model->vertices[0].x;
min_y = model->vertices[0].y;
max_y = model->vertices[0].y;
min_z = model->vertices[0].z;
max_z = model->vertices[0].z;
for (i = 0; i < model->n_vertices; ++i) {
x = model->vertices[i].x;
y = model->vertices[i].y;
z = model->vertices[i].z;
if (x < min_x) {min_x = x;}
else if (x > max_x) { max_x = x;}
if (y < min_y) {min_y = y; }
else if (y > max_y) { max_y = y;}
if (z < min_z) { min_z = z;}
else if (z > max_z) {max_z = z;}
}
// setting the coordinates of the bounding Box for the specific model
model->Box.minX=min_x;
model->Box.minY=min_y;
model->Box.minZ=min_z;
model->Box.maxX=max_x;
model->Box.maxY=max_y;
model->Box.maxZ=max_z;
}
这是我绘制模型边界框坐标的代码:
void draw_bounding_Box(const Model *model) {
gllinewidth(1);
glBegin(GL_LInes);
glVertex3d(model->Box.minX,model->Box.minY,model->Box.minZ);
glVertex3d(model->Box.maxX,model->Box.maxY,model->Box.maxZ);
glEnd();
}
在 glVertex3d(...)
之前有 glMatrixMode(GL_MODELVIEW); glLoadIdentity();
,所以我想坐标在这里转换成世界空间,我需要这些坐标来检查边界框碰撞,但我不知道如何取回这些坐标。
无论如何,我想用这个概念检查碰撞:
Box1 = (x:(xmin1,xmax1),y:(ymin1,ymax1),z:(zmin1,zmax1))
Box2 = (x:(xmin2,xmax2),y:(ymin2,ymax2),z:(zmin2,zmax2))
isOverlapping3D(Box1,Box2) = isOverlapping1D(Box1.x,Box2.x) and
isOverlapping1D(Box1.y,Box2.y) and
isOverlapping1D(Box1.z,Box2.z)
在一个 GLEW 项目中,我正在检查片段着色器中的碰撞,情况很清楚,但我不熟悉 gluT。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)