Quote:Original post by Steedie
lol thought that might not explain it properly
Right, I'll do my best to explain it fully. I've got a GL window open thats running several objects moving around in a 30x28 space.
I'm trying to work out the best way to implement some AI search algorithms, and thinking the best way to start off going about it is by splitting the space that the objects move about in, into a grid.
So I want to make an array with all the possible points in that the objects could be at, hence wanting to go on the X value, between -30 and 30. Then on the Y axis -28 to 28.
Once I've got this set up, I can then go about using this array with all the points in for the search algorithm implementation.
I hope that explains it better, explaining things has never been my strong point :P
What is the search algorithm you are planning to use? (Is it a well known one, with a name that could be looked up in Wikipedia, say?)
What should the size of the array be? Why?
What should the element type of the array be? Why? (I.e., what kind of thing do you want to store within each position in the array?)
For a given element of the array, what value should be there? Why? (I.e., for each column of each row of the array, ask the question: "which thing, of the kind from the previous question, should be here?")
Also, those #defines are NOT "constant values". C++ (and, for some time now, C) offers a built-in language feature for defining constant values, which looks almost exactly like you'd expect...
//Screen Widthconst int SCREEN_WIDTH = 60;const int HALF_WIDTH = SCREEN_WIDTH / 2;//Screen Heightconst int SCREEN_HEIGHT = 56;const int HALF_HEIGHT = SCREEN_HEIGHT / 2;
and the results have (a) a type and (b) a scope, because they are real values - real *concepts in your program* - as opposed to mere #defines, which are instructions to a text search-and-replace engine.
You'll notice I defined the HALF_ constants in terms of the other values. This is for two reasons here:
1) Because you should normally do things like this anyway: when two constants should have a mathematical relationship, expose that relationship when you set them. That way, (a) if you need to change the constants, you can't forget to update one when you update the other; (b) you document the relationship - it's right there, so the person reading the code can see what it is and whether it makes sense.
2) To illustrate that you can do this just fine with real constants, without any mucking around with extra parentheses or anything. Macros have problems with these because they are just instructions to a text search-and-replace engine (without extra parentheses, things can get messed up because of order of operations, along with the context into which the "constant" is inserted).
Don't use automated text search-and-replace hacks. Use a built-in feature of the language. Please. :)