# OpenGL checking the binding box with my transformations....

This topic is 4869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi I have used from the following transformations to move my environment: glRotatef( 360 - yrot, 0,1,0 ); glTranslatef( -xpos, -walkbias - 6.0f + beeHeight, -zpos ); In my environment, i have some points that should check their positions. So i have written a function to simulate the above OpenGL transformations: void PosConvertor(float x, float y, float z) { xx=(float)cos(( 360.0 - yrot )* piover180 ) * ( x-xpos) + (float)sin(( 360.0 - yrot )* piover180 )*(z -zpos ); yy=y- walkbias - 2; zz=-(float)sin( ( 360.0 - yrot )* piover180 )* (x -xpos ) + (float)cos( ( 360.0 - yrot )* piover180 ) * ( z -zpos ); } The function posConvertor is like the OpenGL transformations that i have used in my code. I can check the position of my objects with the function posConvertor. But now i want to create a binding box and check that if i'm inside this binding box. But now i don't know that how i should use from my posConvertor function to check the boundries of my binding box. Any suggestion? -Ehsan-

##### Share on other sites
Hi there, firstly if u ever need to make sure that ur own Matrix class transforms the points correctly simple do all the transformations and render it.
[Source]glLoadIdentity();CVector3 TempX,TempY,TempZ;glBegin(GL_TRIANGLES);  ...  // for all rendered points  PosConvert(tempx,tempy,tempz);  glVertex3f(tempx,tempy,tempz);glEnd();[/Source]

Now im assuming from what you talk about that the object you want to check which should be in the bounding box is you/the camera.

Lets say we have a bounding box minx,miny,minz,maxx,maxy,maxz, now we define this bounding box like any other bounding box, and checking if a point is inside the bounding box is simple.

If (point >= min) && (point <= max) return INSIDE;

Now ur program did not state so, and thus i am assuming that the following transformations are Camera Transformations!
[Source]glRotatef( 360 - yrot, 0,1,0 );glTranslatef( -xpos, -walkbias - 6.0f + beeHeight, -zpos );[/Source]

What i mean is they have no relevance to the Game Mechanics, which means you simple need to check zpos,xpos,ypos against your bounding box.

However if your transformations are part of the Game Mechanics for example a rotating platform (like they have in quake) , then i suggest you look into matrices firstly and then you will need advanced Collision Detection like Axis Orientated Bounding Boxes, or Simple check a bounding box (AABB or OBB) by using the 6 planes.

If you need a small matrix class that can do all this if you want it.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 14
• 12
• 29
• 11
• 44
• ### Forum Statistics

• Total Topics
634856
• Total Posts
3019661
×