Please help aboout Bounding Box Collision

Hello. This is my first post here in cplusplus.I'm desperately in need of help right now cause I don't know how to make collision. I'm doing a maze game with 3d walls and the box as the player. I just want to know what the easiest way of doing a collision system (Showing the codes would be better). I'm really new to programming so sorry if I sound a bit noobish. Any would be appreciated :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
 #include <stdio.h>
#include <conio.h>
#include <cstdlib>
#include <glut.h>

void GameScene()

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

{

glMaterialfv(GL_FRONT, GL_DIFFUSE, BrownD);
glMaterialfv(GL_FRONT, GL_AMBIENT, Brown);
//floor
glPushMatrix();
glTranslatef(7.5f,7.5f,0.0);
glScalef(15.0,15.0,1.0);
glColor3f(1.0,1.0,1.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

//START FROM LEFT TO RIGHT

//////////////////////////////////////////////////////
//LEFT SIDE
////////////////////////////////////////////////////
glMaterialfv(GL_FRONT, GL_DIFFUSE, RedD);
glMaterialfv(GL_FRONT, GL_AMBIENT, Red);
//cube 1
glPushMatrix();
glTranslatef(0.5,8.0,1.0);
glScalef(1.0,2.0,depth);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

//cube 2
glPushMatrix();
glTranslatef(1.5,12.0,1.0);
glScalef(1.0,2.0,depth);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

//cube 3     -----------
glPushMatrix();
glTranslatef(2.5,8.5,1.0);
glScalef(1.0,13.0,depth);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

//cube 4
glPushMatrix();
glTranslatef(4.0,10.5,1.0);
glScalef(2.0,1.0,depth);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

//cube 5
glPushMatrix();
glTranslatef(4.0,2.5,1.0);
glScalef(2.0,1.0,depth);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

//cube 6
glPushMatrix();
glTranslatef(5.5,10.0,1.0);
glScalef(1.0,6.0,depth);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

//cube 7
glPushMatrix();
glTranslatef(5.5,3.5,1.0);
glScalef(1.0,3.0,depth);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();
///////////////////////////////////////
//RIGHT SIDE
////////////////////////////////////////

//cube 8
glPushMatrix();
glTranslatef(8.5,12.0,1.0);
glScalef(1.0,6.0,depth);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

//cube 9
glPushMatrix();
glTranslatef(13.0,14.0,1.0);
glScalef(4.0,2.0,depth);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

//cube 10
glPushMatrix();
glTranslatef(13.0,10.0,1.0);
glScalef(4.0,2.0,depth);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

//cube 11
glPushMatrix();
glTranslatef(10.5,6.0,1.0);
glScalef(5.0,2.0,depth);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

//cube 12
glPushMatrix();
glTranslatef(10.5,2.5,1.0);
glScalef(5.0,1.0,depth);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

//cube 13
glPushMatrix();
glTranslatef(12.0,1.5,1.0);
glScalef(2.0,3.0,depth);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

/////////////////////////////////////
//END OF SCENE
////////////////////////////////////

//CHARACTER (WHITE BOX)
glMaterialfv(GL_FRONT, GL_DIFFUSE, WhiteD);
glMaterialfv(GL_FRONT, GL_AMBIENT, White);
glPushMatrix();
glTranslatef(charposx,charposy,1.0);
glScalef(1.0,1.0,1.0);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();

//GOAL OBJECT (PINK BOX)
glMaterialfv(GL_FRONT, GL_DIFFUSE, PinkD);
glMaterialfv(GL_FRONT, GL_AMBIENT, Pink);
glPushMatrix();
glTranslatef(1.5,14.5,1.0);
glScalef(1.0,1.0,1.0);
glColor3f(0.0,1.0,0.0);
glutSolidCube(1);
  glEnd();
glPopMatrix();


///////////////////////////////////
//COLLISION DETECTION
////////////////////////////////
float halfposx1 = charposx + 0.5;
float halfposx2 = charposx - 0.5;
//BOUNDARY
if (halfposx1 >16.0)
charposx -=0.5;
if (halfposx2 < -1.0)
charposx +=0.5;

if (charposy >15.0)
charposy -=0.5;
if (charposy < 0.0)
charposy +=0.5;

////////
//
if(charposx <=1)
{
	if(charposy <=9  && charposy >=7)
		charposy += 0.05;
	if(charposy >=7 && charposy <=9)
		charposy -= 0.05;
}
glutSwapBuffers();
}
}
Topic archived. No new replies allowed.