关于GLM网格中的碰撞检测
About collision detection in GLM mesh
我是opengl和glm的新手,目前我正在其中做一个类项目,我上传了两个对象汽车,如下
void CARMODEL:: drawmodel_box()
{
glPushMatrix();
glTranslatef(carx,cary ,carz);
if (!pmodel1){
pmodel1 = glmReadOBJ("Car.obj");
}
glmDraw(pmodel1, GLM_SMOOTH | GLM_TEXTURE | GLM_MATERIAL);
glPopMatrix();
}
void OpponentCarModel::drawopponentmodel()
{
glPushMatrix();
srand(time(NULL));
opcarx=rand() % 7-3+(double)rand()/(RAND_MAX+1)*(1-0)+0;
glTranslatef(opcarx,0,-20);
if (!pmodel2){
pmodel2 = glmReadOBJ("car.obj");
}
glmDraw(pmodel2, GLM_SMOOTH | GLM_TEXTURE | GLM_MATERIAL);
glPopMatrix();
}
现在,一切都很好,现在我来谈谈碰撞检测部分,我不确定如何在两辆车之间进行,因为我不知道它们的坐标或顶点,所以plz有帮助。。
没错,但您可以确切地知道模型在矩阵中的位置,因为您在glmDraw()
之前调用glTranslatef()
来将它们放置在那里。现在,既然知道了模型的x,y,z坐标,就可以开始检查简单的碰撞了。
但是,如果你正在寻找更真实/复杂的碰撞检测,你应该打开glm.h
并检查GLMmodel
结构的定义,因为它存储了在屏幕上绘制模型所需的一切,包括顶点信息、法线、纹理坐标等:
/* GLMmodel: Structure that defines a model.
*/
typedef struct _GLMmodel {
char* pathname; /* path to this model */
char* mtllibname; /* name of the material library */
GLuint numvertices; /* number of vertices in model */
GLfloat* vertices; /* array of vertices */
GLuint numnormals; /* number of normals in model */
GLfloat* normals; /* array of normals */
GLuint numtexcoords; /* number of texcoords in model */
GLfloat* texcoords; /* array of texture coordinates */
GLuint numfacetnorms; /* number of facetnorms in model */
GLfloat* facetnorms; /* array of facetnorms */
GLuint numtriangles; /* number of triangles in model */
GLMtriangle* triangles; /* array of triangles */
GLuint nummaterials; /* number of materials in model */
GLMmaterial* materials; /* array of materials */
GLuint numgroups; /* number of groups in model */
GLMgroup* groups; /* linked list of groups */
GLfloat position[3]; /* position of the model */
} GLMmodel;
相关文章:
- 落砂模拟碰撞检测C++和SFML
- SFML 中的重力和碰撞检测
- 我的碰撞检测中的奇怪行为
- 如何为球形物体和三角形地形提供高效的碰撞检测和响应
- 圆形与方形碰撞检测以及需要响应C++ |OpenGL。我的问题就是这个"I need to keep the circle outside the square"
- 在Qt3D中进行碰撞检测的预期方法(或好方法)是什么?
- 在碰撞检测方面苦苦挣扎.如何正确检测碰撞?
- 三角形-三角形碰撞检测问题
- 不同类别之间的C SFML碰撞检测
- 使用D3DXVECTOR C 的碰撞检测,发生碰撞后该怎么办
- 当我发生碰撞检测时,矢量迭代器不兼容
- 如何使用灵活的碰撞库在两个点云或点云与机器人末端执行器模型之间进行碰撞检测
- 优化碰撞检测C
- 使用碰撞检测来增加SFML 2.4中的游戏分数的问题
- 使用OnComponentHit UE4 C++进行碰撞检测
- 体素世界中的碰撞检测
- 使用C 中的单元格 /图块 /网格进行碰撞检测的最佳数据结构
- 如何进行正确的二维网格到圆碰撞检测
- 关于GLM网格中的碰撞检测
- 分组网格上的Ogre碰撞检测