Reputation: 1424
i am new to opengl and glm , currently i am doing a class project in it, i upload two object cars as follows
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();
}
Now , everything went fine upto now , now i come to the collision detection part , i am not sure how to do it here between two car, since i don't know their coordinate or vertices , so plz help..
Upvotes: 0
Views: 1146
Reputation: 93410
Right, but you can know exactly where the models are placed in the matrix because you call glTranslatef()
before glmDraw()
to place them there. Now, since you know the x,y,z coordinates of the models, you can start checking for simple collisions.
But if you are looking for a more real/complex collision detection you should open glm.h
and check the definition of the GLMmodel
structure because it stores everything needed to draw the model on the screen, including vertices information, normals, texture coordinates, and others:
/* 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;
Upvotes: 1