Hey guys,
I'm making a small 2d game using c++, OpenGl, and Glut.
I need help using a class to create objects
and then using display() to translate them on the screen accordingly.
Pseudocode that I'm using:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
class Wall {
public:
Wall (float tempposx, float tempposy){
float posx;
float posy;
posx = tempposx;
posy = tempposy;
}
};
Wall newWallone(0.5,0.5); //create new wall with posx,posy
Wall newWalltwo(0.6,0.6);
To display the polygon for my player I use the following code (placed in the void display):
I would like to know how to translate the 2 new walls using gltranslate but without having to write pushmatrix, popmatrix and having to manually write it for each wall. I would like a class or a function to do this for me once I declare a new wall and its position.
Your question is about program organization. However, someone who is writing OpenGL code should already have a good grasp on that before even starting with OpenGL.
So, until you to figure it out, either use push/pop matrix or give up on OpenGL temporarily.
I would estimate that we can't help you because the real answer to your question depends on many circumstances.
Kevin, thank you for the reply. I will look further into program organisation and C++ in general. However, it would greatly help me if you could instruct me on how write a method that an instance calls to translate itself with its own posx, posy.
In addition, I will try using member variables. However I believe that member variables only handles its variables (posx,posy); it does not add any functionality (translation) to the instance.
Sorry for my English and lack of knowledge :3
Olivier
Now, first, what do you mean by 'translate walls'? I mean, you could to that but, as far as I know, walls shouldn't be moving except in some surrealistic art.
Hi Kevin,
Moving walls would indeed make for pretty interesting art. By translating the walls I meant displaying them at their fixed positions. Sorry for the confusion. :D
Thanks to the help of the c++ irc I was able to get what I needed.
Using member variables to handle the positions of each instance of a wall:
This works great and I will now look into creating an array of all the instances and than be able to display all the walls in one line of code. Pseudocode: allwalls.display_wall();
If you could aim me in the right direction to be able to render all the instances all at once I would appreciate it greatly.