# Thread: Basic box game - Collision Detection

1. ## Basic box game - Collision Detection

Im making a basic box game which involves moving boxes around a maze and pushing other boxes, im new to collision detection but am able to get my head around it. The thing I can't get my head around though is why this function won't work.

note: This isn't the final function it is just the basic outline of what needs to be done.. once this works i'll be able to do it all.

typedef struct {
float x;
float y;
float z;
} point3D;

typedef struct {
point3D min;
point3D max;
} boundingBox;

boundingBox * wallBox[9];
boundingBox * playerBox;

//and then I had two functions that gave each boundingBox its values

int collisionWall(){
int i;
for(i = 0; i < 9; i++){
if(wallBox[i].min.x; =< playerBox.min.x{
return 1;
}
return 0;
}
}
}
The errors I get are...

Error 1 error C2231: '.min' : left operand points to 'struct', use '->'

Error 2 error C2231: '.min' : left operand points to 'struct', use '->'

Error 3 error C2059: syntax error : '<'

Error 4 error C2059: syntax error : '}'

2. ## Re: Basic box game - Collision Detection

Hmm, this is not exactly OpenGL specific and you would probably have been better off asking this in a general C/C++ programming forum, but here goes:

The compiler basically already tells you what is wrong:

Error 1 error C2231: '.min' : left operand points to 'struct', use '->'
you have declared:

Code :
boundingBox * wallBox[9];

so wallBox is an array of pointers to objects of type bounding box. When accessing structure members through a pointer you need to use the '->' operator instead of '.':

Code :
for(int i = 0; i < 9; ++i)
{
if(wallBox[i]->min.x <= playerBox->min.x)
{
// ...
}
}

Error 3 error C2059: syntax error : '<'
Error 4 error C2059: syntax error : '}'
These are plain syntax errors. '=<' is not a valid operator in C/C++, you probably want '<='. There is an extra '}' at the end and you have ';' in the if condition that don't belong there.

3. ## Re: Basic box game - Collision Detection

Ah thanks man, I do have more openGL stuff later on in my code but yes your right this error wasn't really to do with that so I should find a c forum instead. Sorry. and thanks alot for the help.

James.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•