![]() |
|
|
(#1)
|
||
|
Posts: n/a
|
OpenGL Program / Loop Help -
2006.01.04, 07:05 PM
Howdy all,
I'm having some trouble making a loop in an OpenGL program. I used "OneSadCookie's" GLUT tutorial to build the "moving box" program. Then I decided I'd try to re-program how the box moved. Originally it used an opengl command that moved everything on the screen one way, using coordinates. (At least, I think that's how it was supposed to work.) Anyway, I changed it so that it would update all the boxes vertex coordinates relative to the bottom left corner of the box. I added a simple function that would take the variable "boxSpeed", the amount of pixels to move the box diagonally. Then, based on that number and the current position of the box, I'd redraw the box. However, things didn't work out as planned. The box would move once, at the start of the program, but not again. I realized that I'd forgotten to install some sort of looping mechanism into the main loop. I tried inserting a basic "while 2 > 1" loop, just to test it. Unfortunatly the program would then get stuck during startup, while the app was still bouncing in the dock. I think the problem here is, I'm just not thinking logically. I'm not realizing exactly which parts (ie: which functions) need to be looped or not. Here is the code: Quote:
Oh yes, and a special thanks to OneSadCookie, for his wonderful GLUT introduction. 'Jones |
|
|
|
|
|
(#2)
|
|
|
Moderator
Posts: 710
Join Date: 2004.09
Location: Colorado
|
2006.01.04, 07:18 PM
The problem you are having is increaseXY(5); is only being called once before you enter your main loop, try moving that command to inside your draw function.
|
|
|
|
|
(#3)
|
|
|
Posts: n/a
|
2006.01.04, 07:23 PM
Thanks! It works great now!
|
|
|
|
|
(#4)
|
||
|
Posts: n/a
|
2006.01.04, 09:20 PM
Ok, new problem.
I just added a new screen-edge collision detection system and I'm having trouble getting it to work properly. Maybe I'm just really bad at this ( ), but I'm not sure why it's not working. For some reason, the box just shoots off the left edge of the screen. Here's the new code. Quote:
|
|
|
|
|
|
(#5)
|
|
|
Moderator
Posts: 710
Join Date: 2004.09
Location: Colorado
|
2006.01.04, 09:40 PM
try
void check_boxPosition() { if (box_bottomLeft_Y > 480 - 128.0) { box_hit_Top = 1; box_hit_Bottom = 0; } if (box_bottomLeft_Y < 0.0) { box_hit_Bottom = 1; box_hit_Top = 0; } Personally I always account for overflows, when dealing with collision detection its good to get into the habit because very very rarely will you have a whole value to do a precise ==. The reason you were having a problem is you were using "=" instead of "==", "=" sets the value to the right side, the "==" compares the two values. Let me know if that works, if not I will look over the code a bit more closely |
|
|
|
|
(#6)
|
|
|
Posts: n/a
|
2006.01.04, 10:36 PM
Doh! Why didn't I remember that "==" stuff.
*smashes head against wall* It works wonderful now, by the way. Thanks for your help, kodex! |
|
|
|
| Thread Tools | |
| Display Modes | |
|
|