I'm trying to create collision for my OpenGL application.
I have code that successfully tests whether my camera is inside my 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 HELP 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 now I'm stuck. I'm not sure how to move the camera outside of the platform if it goes inside. If the camera is inside the platform, all 3 tests are performed.