Results 1 to 3 of 3

Thread: Basic box game - Collision Detection

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    4

    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. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    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. #3
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    4

    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.

Similar Threads

  1. OpenGL c++ 2D Car Game including Collision Detection
    By NeO_Obsidian in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-29-2012, 11:42 PM
  2. Replies: 3
    Last Post: 07-14-2012, 02:14 PM
  3. Basic collision detection
    By Dardan in forum OpenGL: General
    Replies: 0
    Last Post: 02-25-2012, 08:52 AM
  4. 2D Game: Most Efficient Collision Detection
    By Bunkai.Satori in forum OpenGL ES
    Replies: 4
    Last Post: 10-15-2010, 04:50 PM
  5. OpenGl in Visual Basic 5/6, Collision detection
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-16-2001, 04:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean