c++ - 3D collision in OpenGL -


i'm trying create collision opengl application.

i have code tests whether camera inside platform object:

void checkinsideplatform() { float halfw = gymplatform -> getw() / 2; float height = gymplatform -> geth(); float halfd = gymplatform -> getd() / 2; float platformright = gymplatform -> getx() + halfw + 1; float platformtop = gymplatform -> gety() + height + 1; float platformfront = gymplatform -> getz() - halfd - 1;  if(testplatformcollision()) {     //below code doesnt work (need here)     if(mycamera -> curpos -> x < platformright)     {         mycamera -> curpos -> platformright;     }     if(mycamera -> curpos -> z > platformfront)     {         mycamera -> curpos -> platformfront;     }     if(mycamera -> curpos -> y < platformtop)     {         mycamera -> curpos -> platformtop;     } } }  bool testplatformcollision() { float halfw = gymplatform -> getw() / 2; float height = gymplatform -> geth(); float halfd = gymplatform -> getd() / 2; float platformleft = gymplatform -> getx() - halfw - 1; float platformright = gymplatform -> getx() + halfw + 1; float platformtop = gymplatform -> gety() + height + 1; float platformfront = gymplatform -> getz() - halfd - 1; float platformback = gymplatform -> getz() + halfd + 1;  if((mycamera -> curpos -> x > platformleft) && (mycamera -> curpos -> x < platformright)) {     if((mycamera -> curpos -> z > platformfront) && (mycamera -> curpos -> z < platformback))     {         if(mycamera -> curpos -> y < platformtop)         {             return true;         }        } }  return false; } 

but i'm stuck. i'm not sure how move camera outside of platform if goes inside. if camera inside platform, 3 tests performed.

you need perform collision resolution. collision resolution act of resolving collision, , quite bit more involved performing boolean iscolliding function.

additional information search be: separating axis test (sat). since you're dealing aabbs (presumably) can quite put simple resolution moves camera outside.

here's quick description: find direction camera should move outside of box. direction should shortest path possible move outside. find distance move, , perform move operation.

of course actual implementation gets little more involved.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -