我是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帮助.. < / p>
答案 0 :(得分:1)
是的,但您可以确切地知道模型在矩阵中的位置,因为您在glTranslatef()
之前调用glmDraw()
将它们放在那里。现在,既然知道模型的 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;