New Update – Relative Motion, Accepted Object Hierarchy, and More!
February 16, 2009
So, now that I’ve decided on the object hierarchy, I’ve began working on the player’s simplistic 2D motion up, down, and the turning. (Forward moves in the direction you’re facing). Well, I’ve decided on creating the viewport as only a fraction of the entire map (viewport isn’t exactly the correct word, as I’m not using the predefined viewport type), and so, when the player moves around the screen, the background changes, because there’s more of the world to explore than what is initially visible. The way I’ve decided to do this is not as deterministic as forcing the player to be in the center of the screen (which would essentially imply that the player never moves, but rather his movements move every other object), but rather to scroll the background at a factor of the player’s speed. Depending on how far we want the background to be (or, more technically, on the size of the image), we can adjust this factor through a simple #define. This gives somewhat of a parallax effect, as it looks that the foreground is moving at a different rate than the background.
Well, the obvious problem with this, is if the background is moving relative to the player’s motion, what happens to all the other objects? Well, the way I’ve decided to implement it, is to pass a pointer to the ObjectCore upon the creation of the BackgroundObject, and when the background moves (more shortly), it calls a function in the ObjectCore that iterates through all Objects and moves them by a factor similar to that of the background’s movement relative to the ship. Note that the background’s movement is triggered by the movement of the Player object (which incidentally also has a pointer to the ObjectCore, and calls objectCore->getBackground()->move(); when the player decides to move their ship).
The next thing (and something I’ve been stuck on for quite a portion of the day) is how I can create generic function pointers. I’ve found somewhat cryptic tutorials using google, and it’s something that was never covered in my studies (yet), so it’s somewhat of a new frontier. Essentially, I need to define a struct with a pointer to a function with unknown arguments, a long, and a pointer to a struct of the same type. This is used as a sort of event clock, so that a function can be executed once that long reaches 0 – basically, a timer. I know absolutely nothing of threading and Sleep() or other such commands, so I’m sure there’s an easier way to do this that I’m missing, which is something I’ll surely look into. But right now, I need to figure out how (or if it’s possible) to create and use generic function pointers. I know one way to do it could be to create different pointers for different functions and only allow certain functions to be used, however I think it would be a lot nicer if I could generalize the process and allow for use of ANY function.