Jump to content

  • Log In with Google      Sign In   
  • Create Account


3D Collision Detection, is an object inside an object


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 26 April 2013 - 08:52 PM

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, 26 April 2013 - 08:53 PM.


Sponsor:

#2 Norman Barrows   Crossbones+   -  Reputation: 2058

Like
0Likes
Like

Posted 27 April 2013 - 08:16 AM

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, 27 April 2013 - 08:16 AM.

Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 


#3 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 27 April 2013 - 09:48 AM

Wonderful, thanks so much :)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS