   Problem related to collision detection
  Hi there,My constant doubts may be irritating you but my project is in final stage and I've only one day left....:(So I loaded an F-16 into my projet..scaled it...rotated and now it's working but there is a problem with collision detection I have put obstacles in the way in the form of cubes....Now my collision detection Algorithm which was using camera co-ordinates earlier is no longer efficient as the F-16 is something like a big plus........I want to use following algorithm for collision detection:detect collision with the point(x',y',zmax)<nose of the plane)   if yes then return trueelse if collision with (xmax,y,z)<right wing coordinates) || with <left wing co-ordinates>if yes then trueelse rturn falseBut the greatest problem is how do I find those coordinates.....As f-16 is in the form of an obj file from where I've imported it as a GLMmodel.....Plz make the suggestions in the simplest form so that a newbie can understand them properly....   
  Yeah using the camera for collision is not a good idea. I would recommend looking into doing a bounding box. This bounding box is essentially an invisible rectangle (or cube if you're doing 3d) that surrounds the object. You use the rectangle to check if it collides with another one, and then react accordingly. If you want to use different boxes for the body of the plane, and one each for the wings, feel free, but it will take a lot of work.Did a quick search, and found this article which may help you: http://www.gamedev.net/reference/articles/article735.asp   ;  hmmm...No answers still....plz help guyz...OK here is a solution I just found...I will search through all the vertices in my glmmodel and find out maximun x,y,z values and from them I will try to figure out the extreme points....but there is one more problem...When I search I will get the coordinates of obj model...not the ones i am using, as I am using translate function to get the model at the right place...So Is there any way to get the coordinates of obj model as they will be in drawing.....PLz PLz help there is so less time and this is the last obstacle in my way....Plz experts out there help....   ;Quote:Original post by sudhanshu1990hmmm...No answers still....plz help guyz...OK here is a solution I just found...I will search through all the vertices in my glmmodel and find out maximun x,y,z values and from them I will try to figure out the extreme points....but there is one more problem...When I search I will get the coordinates of obj model...not the ones i am using, as I am using translate function to get the model at the right place...So Is there any way to get the coordinates of obj model as they will be in drawing.....PLz PLz help there is so less time and this is the last obstacle in my way....Plz experts out there help....If you know the size of the plane before you mess with it, you should be able to do a pretty close guess of the location of the wings, then you can just apply your transforms to it to get a rough location. This isn't exactly optimal, but as you have a short amount of time it should work.   ;  huh......I don't think I can solve it alone frieI tried to read the values of vertices from .obj model in order to get  maximum as well as minimum coordinates...(was trying to use BB method) but I am not even able to read the values of vertics a printf with <model>->vertices[0] produces a garbage value..!!!So as you can see I am not even able to start with the collision detection...let me put the code related to the collision detection here....[SOURCE]//Global Variablesfloat carlocx=0.0, carlocy=-0.5, carlocz=42.0, graus=180;   //Location of f16GLfloat objxmaxval,objxminval,objzmaxval,objxmaxindx,objxminindx,objzmaxindx;   //variables to store min and max values of vetices of shipGLfloat x=0.0f,y=2.0f,z=50.0f,angle=0.0; //Position of cameraGLfloat lx=0.0f,ly=0.0f,lz=-1.0f;GLMmodel* f16;//Drawing the f16void drawcar(void)   {GLfloat tilt=8.0;glPushMatrix();glTranslatef(carlocx,carlocy,carlocz);glScalef(0.3,0.3,0.3);glRotatef(graus, 0.0, 1.0, 0.0);glRotatef(-3.0,0.0,0.0,1.0);if(orient!=0){tilt=orient*tilt;glPushMatrix();if(orient<0){glRotatef(tilt,0.0,0.0,1.0);////printf("\n%f",tilt);}else{glRotatef(tilt,0.0,0.0,1.0);////printf("\n%f",tilt);}glCallList(displayList);glPopMatrix();}else{glCallList(displayList);}glPopMatrix();}// Function to calculate min max vertices of f16void initcarpoints(void){int x=0,y=1,z=2,i;objxmaxval=f16->vertices[0];objxminval=f16->vertices[0];objzmaxval=f16->vertices[2]; // Here I have problem It produces garbagefor(i=0;i<f16->numvertices;i+=3){x=i;y=i+1;z=i+2;if(f16->vertices[x]<objxminval){objxminval=f16->vertices[x];objxminindx=x;printf("\n First check");}if(f16->vertices[x]>objxmaxval){objxmaxval=f16->vertices[x];objxmaxindx=x;printf("\nSecond check");}if(f16->vertices[z]>objzmaxval){objzmaxval=f16->vertices[z];objzmaxindx=z;printf("\n Third Check");}}//printf("\n\n MAx points:%f,%f",objxmaxval,objzmaxval);//printf("\n\n Min Pont: %f",objxminval); but all I get the garbage values}bool collision(BoundingBox b,GLfloat objx,GLfloat objy,GLfloat objz){if(objx>=b.min.x && objx<=b.max.x  && objz>=b.min.z && objz<=b.max.z)return true;elsereturn false;}bool collisiondetect(GLfloat x,GLfloat y,GLfloat z){int i;bool res=false;for(i=0;i<16;i++)res=res|| collision(boundingbox,x,y,z);return res;}Function to move the ship forward activates when 'W' is pressedvoid moveMeFlat(int i){GLfloat camerax,cameray=y,cameraz;camerax = carlocx + i*(lx)*0.1;cameraz = carlocz + i*(lz)*0.1+OFFSET;if(collisiondetect(camerax,cameray,cameraz)==false){carlocx = carlocx + i*(lx)*0.1;carlocz = carlocz + i*(lz)*0.1;x = x + i*(lx)*0.1;z = z + i*(lz)*0.1;//printf("\n CAr: %f\n%f\n%f",carlocx,carlocy,carlocz);glLoadIdentity();gluLookAt(x, y, z,  x + lx,y + ly,z + lz,0.0f,1.0f,0.0f);}}And the main function:int main(int argc, char **argv) {// por inicializacao aquiint i;//printf("\n Enter the name of player: ");gets(playername);glutInit(&argc, argv);glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);glutInitWindowPosition(50,50);glutInitWindowSize(640,360);glutCreateWindow("Sudh");glutKeyboardFunc(processNormalKeys);glutSpecialFunc(SpecialKeys);initboundingbox();//glEnable(GL_MULTISAMPLE);glutReshapeFunc(myreshape);glutIdleFunc(display);glutTimerFunc(1000,mytimer,1);glutDisplayFunc(display);myinit();// alguns settings para OpenLGglLightfv(GL_LIGHT0, GL_POSITION, lightPos);glEnable(GL_DEPTH_TEST);glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glEnable(GL_COLOR_MATERIAL);f16 = (GLMmodel*)malloc(sizeof(GLMmodel));f16 = glmReadOBJ("C:/Documents and Settings/Administrator/Desktop/glm-example/objs/f16.obj");displayList=glGenLists(2);glNewList(displayList,GL_COMPILE);//glmList(f16, GLM_SMOOTH);glmDraw(f16, GLM_SMOOTH);//glmUnitize(f16);glEndList();initcarpoints();printf("\n\n MAx points:%d,%d",objxmaxindx,objzmaxindx);printf("\n\n Min Pont: %d",objxminindx);printf("\n\n no of vertices %f-> %f-> %f",f16->vertices[0],f16->vertices[1],f16->vertices[2]);for(i=0;i<16;i++){//printf("%f\n",boundingbox.min.x);//printf("%f\n",boundingbox.min.y);//printf("%f\n",boundingbox.min.z);//printf("%f\n",boundingbox.max.x);//printf("%f\n",boundingbox.max.y);//printf("%f\n",boundingbox.max.z);}//printf("\n%f",maximum(-5,-5+3));    glutMainLoop();return 0;}[/SOURCE]So that's it I am not able to find out the problem...Plz help me with this...Any suggestion to make code more efficient are also welcome.....Plz do comment....And plz plz plz help....me out   ;Quote:Original post by sudhanshu1990huh......I don't think I can solve it alone frieI tried to read the values of vertices from .obj model in order to get  maximum as well as minimum coordinates...(was trying to use BB method) but I am not even able to read the values of vertics a printf with <model>->vertices[0] produces a garbage value..!!!So as you can see I am not even able to start with the collision detection...let me put the code related to the collision detection here....*** Source Snippet Removed ***[/source]So that's it I am not able to find out the problem...Plz help me with this...Any suggestion to make code more efficient are also welcome.....Plz do comment....And plz plz plz help....me outif you have the model you should be able to go into some modeling software and just hard code in the points for a duct tape fix.   