Jump to content
  • Advertisement
Sign in to follow this  
Tim Lawton

3D Collision Detection, is an object inside an object

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

If you intended to correct an error in the post then please contact us.

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: 

gridfromabove.png

 

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!