Skip to content

Instantly share code, notes, and snippets.

@ameyxd
Created April 14, 2016 14:48
Show Gist options
  • Save ameyxd/95eb4b9f6e8b069def7933cf0d26918f to your computer and use it in GitHub Desktop.
Save ameyxd/95eb4b9f6e8b069def7933cf0d26918f to your computer and use it in GitHub Desktop.
Collision
bool noCollision(){
if (zPos< 2.8 && zPos > -2.8 && xPos < 2.8 && xPos > -2.8 && yPos < 1.44) // if z is in the room (1.44 is the room height)
{
if (zPos < -1.8 && zPos > -2.2) //If in the space between door and stairs
{
if (xPos < 0.1 && xPos > -0.1 && DOOROPEN) return true; //x position fits and door is open: no collision
else return false;
}
if (zPos <= -2.2) //if in the stairway or upstairs
{
if (xPos < 0.2 && xPos> -0.2) //check for clash with two walls on opposite sides of stairway
{
return true;
}
else return false;
}
if (xPos < -1.8) //check for hallroom's left wall
{
if (zPos < 0.35 && zPos > -0.35) //if in the small block on left side no collision
{
return true;
}
else return false;
}
if (xPos > 1.8) //check for hallroom's right wall
{
if (zPos < 0.35 && zPos > -0.35) //if in the small block on right side no collision
{
return true;
}
else return false;
}
if (zPos > 1.8) //check for hallroom's back wall
{
if (xPos < 0.35 && xPos > -0.35) //if in the small block on back side no collision
{
return true;
}
else return false;
}
return true;
}
else if (yPos >= 1.44) // upstairs
{
if (zPos < 0.80 && zPos > -5.8 && xPos < 2.8 && xPos > -2.8) //upstairs room size
{
if (zPos > -0.70 && xPos <-0.15){ //for three pillars in the attic
if (xPos > -2.20 && xPos < -1.65){
return false;
}
else if (xPos < 2.35 && xPos > 1.8) return false;
else if (xPos > -0.2 && xPos < 0.35) return false;
else return true;
}
if (xPos < 0.35 && xPos > -0.35) //inside railing
{
if (xPos < 0.2 && xPos > -0.2 && zPos < -2.0){
return true;
}
else if (zPos <= -4.2) return true;
else if (zPos >= -2.0){ //back railing
if (zPos < -1.8) return false;
else return true;
}
else return false;
return false;
}
if (zPos > -4.2 && zPos < -1.8){ //along railing
if (xPos < -0.7) return true;//block left and
if (xPos > 0.7) {
return true;//right sides of railing
}
else return false;
}
return true;
}
else return false;
return true;
}
else if (zPos <= -2.8 && zPos > -5.8) //check for stairs
{
if (xPos < 0.2 && xPos > -0.2) return true;
else return false;
}
else return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment