0

Hi,

I am writing a game in C++ and OpenGL. My whole environment is based on cubes so I guessed bounding box collisions were best. I can currently move around and my program is detecting collisions (I used this tutorial: http://www.3dcodingtutorial.com/Collision-Detection/Collision-Boxes.html). Now I want to make it so that when the camera hits a bounding box it slides along it (like in any FPS game).

My update camera procedure looks like this:

void updateCamera()
{
    glRotatef(xrot,1.0,0.0,0.0);  //rotate the camera on the x-axis (left and right)
    glRotatef(yrot,0.0,1.0,0.0);  //rotate the camera on the y-axis (up and down)


    glTranslated(-xpos,-ypos,-zpos); //translate the screen to the position of the camera
}

Thanks,

James

2
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by jamesl22
0

Your camera has some position associated with it, check that position for potential collision and if collision moving up should mean a slight sliding to the right or left depending on the view vector

0

Hi,

What code would I use in order to check for collisions. I have my camera point set up and the min/max values for x,y,z of the objects. But I am unsure of how to compare these two. Can you give me an exaple.

Thanks

0

Use that min/max values to setup a bounding box for your camera. Then it would be the same comparison as your other bounding box collision test.

0

My setupbox procedure is giving me a segfault and I can't find what is wrong. Here is the code:

struct Vector3
{

    float x;
    float y;
    float z;

};

struct tBoundingBox
{
      Vector3    max;
      Vector3    min;
};

const int cubes = 2;

tBoundingBox boxArray[cubes];

int currentArray;

void setupBox(float minx, float maxx, float miny, float maxy, float minz, float maxz)
{
   boxArray[currentArray].min.x  =  minx;
   boxArray[currentArray].max.x  =  maxx;
   boxArray[currentArray].min.y  =  miny;
   boxArray[currentArray].max.y  =  maxy;
   boxArray[currentArray].min.z  =  minz;
   boxArray[currentArray].max.z  =  maxz;

   if (currentArray == cubes)
   {
     currentArray = 0;
     return;
   }
   else
   {
     currentArray++;
     return;
   }
}

What is wrong? The code is called twice per frame when the cubes are drawn. (2 cubes are drawn)

Edited by jamesl22: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.