Original Post
Hey folks!
There are a few different techniques for accomplishing a constant
game speed, regardless of framerate or the speed of your computer. All of the ones Ive seen so far involve seperating your object-updates from your object-draws. I was wondering exactly how everyone else goes about this. My code is something like this:
while (game_running) {
while (current_time > last_update + UPDATE_INTERVAL) {
update_objects()
last_update += GAME_UPDATE_INTERVAL
}
draw_objects()
}
As you can see, I have two functions: update_objects() and draw_objets(). update_objects() moves stuff around little bits at a time, and draw_objects() draws everything in its current state (location, color..).
So far my objects consist of simple shapes, like cubes and spheres. For the cube, I have a cube class with methods such as setColor(), setSize(), and draw(). The draw() method contains all the code required to draw the 6 sides of the cube and looks like this:
glBegin(GL_QUADS);
// draw side one
// ..
// draw side six
glEnd();
I wonder alot about how I would do more complex objects, like an
elevator, or a player model and things like that. Im assuming that my technique would need to be changed to handle more complex cases, since I really am a beginner and I rarely get things right the first time
I guess what I am really looking for here is just comments on what I''ve done so far; whats wrong with it, whats good about it (if anything), and how other people accomplish the things I described.
Also, since my next step will likely be to add some sort of collision detection, I would like to know what is a good way to store the polygons that make up my walls. Currently, my walls are just hardcoded polygons (I only have about 12 of them, and no floors or cielings
. I suspect that I should probably keep them in a list of some sort, but I can''t think of exactly what to do. Also, for each ploygon that I store, should I just store its 3 (or 4 or 5..) points? Or is there other useful information that I should store as well?
Ive read many articles on collision detection, but none of them
mentioned where your walls and ''objects'' come from in the first
place. I did come accross a few articles on BSP trees, but that
seems too complex for my small game (and small brain
. Im eager to get something to work with so that I can experiment with some of the better collision detection algorithms I have found.
Sorry this was so long. Big thanks to anyone who made it this far and takes time to answer!
Its not my fault I''''m the biggest and the strongest; I don''''t even exercise.