# 3D Collision Detection, is an object inside an object

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

## Recommended Posts

Hey there,

I've rendered 4 zones which have an x,y,z coordinate and are all 100.0f by 100.0f and completely flat across the 'z' axis, resulting in this:

Now, I have a struct which holds the coordinates of a player in 3D space

struct PLAYER
{
float x, y, z;
};
PLAYER Player


and I want to check if the player's coordinates are inside the more or less 2D grid, it doesn't need to check against the y axis as the player can not move up or down the y axis.

The problem is my CheckZone() function I am trying to create, so far it looks like this, but I'm struggling to work to this as I on a basic level for programming:

void Application::CheckZone()
{
Player = {Player.x, Player.y, Player.y};

float Section1[4][2] =
{
{0.0f, 0.0f},
{0.0f, 80.f},
{80.0f, 0.0f},
{80.0f, 0.0f}
};

if(Player == Section1[][])
{
//Trigger element in Section1
}


I'm getting "Error: expected an expression" from the 2 array boxes in the if statement, as well as the Player statement, I'm having trouble understanding some basic programming here, any help would be greatly appreciated

EDIT: On closer inspection the title can be mis-leading, I'm not trying to check an object against an object, instead the coordinates for the grid which are decoupled from these arrays.

Edited by Xooch

##### Share on other sites

int isin(float x,float z,float x1,float z1,float x2,float z2)

{

if (x<x1) return(0);

if (x>x2) return(0);

if (z<z1) return(0);

if (z>z2) return(0);

return(1);

}

if ( isin(player.x,player.z,0.0f,0.0f,80.0f,80.0f))
{
//    player is in region 0,0 through 80,80
}
else
{
// player is not in region 0,0 through 80,80
}

Edited by Norman Barrows

##### Share on other sites

Wonderful, thanks so much :)

##### Share on other sites

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