about the tutorial 10
Every lesson gets progressively more c++, though here and there there might not be any need to code c++ specific code since the code is so simple.
Lesson 10 is just such a lesson, if you want to c++ify it, then go right ahead.
Lesson 10 is just such a lesson, if you want to c++ify it, then go right ahead.
www.flashbang.se | www.thegeekstate.com | nehe.gamedev.net | glAux fix for lesson 6 | [twitter]thegeekstate[/twitter]
Still talking about that tutorial (tutorial 10), in the world.txt file, what does the variables A1, A2 ... D1, D2 represent?
they are just wall polygons poorly named.
www.flashbang.se | www.thegeekstate.com | nehe.gamedev.net | glAux fix for lesson 6 | [twitter]thegeekstate[/twitter]
when defining tesselated meshes, why do we often use triangles instead of quads?
Because it's easier to work with triangles, and besides quads are really just two triangles anyway.
www.flashbang.se | www.thegeekstate.com | nehe.gamedev.net | glAux fix for lesson 6 | [twitter]thegeekstate[/twitter]
@franc82: the best idea for stairs (I'm not exactly sure what you mean by platforms, but I imagine they are just quads with a different y-component) is to expand the datastructures of the tutorial. It's been years since I read this tutorial, so mind you this may not work perfectly in the context:
I personally prefer quads over triangles, so my (personal) advise would be to add a structure for a quad, which could consist of either 4 vertices, or 2 triangles (but this is 6 vertices, so it would cost you more memory).
In this context (although I dont like C, I personally would go for object-oriented C++), you could do it like this:
Now, you could make a function that will add stairs. This function should create a number of quads (or if you want solid stairs, first make a 'cube' structure which consists of 4 quads). Just think about how a stair is made. Basically, its just quads with a high width and small length, where each quad is a bit higher than the last, and a bit further away from you. So you could just initialize a lot of quads of the same size, and use glTranslatef(0.2f, 0.2f, 0.0f) (these numbers are fictional and depend on the size and position of your stairs) between the drawing of each quad, to make sure every quad is translated relative to the last one.
Maybe I can make it more obvious by a little drawing:
Suppose this is your floor, ending in a stair:
you see? The three lines looking like -- are the stairs. These are the quads I was talking about, notice they are of the same size. Only the position is different, but if you start at the bottom one, you'll notice the relative position between each quad and the next is the same. So if the x-axis is pointing to the right in this picture, and the y-axis is pointing up, and each -- is 1.0f in width, you would do this:
So as I said, you want to make a function out of this. It could look like this:
I'm not sure if the above code is totally correct, since I tend to write in a totally different way. This is certainly not the best way to do it, but I just continued in the style of the tutorial. I hope this helps you out a bit. Good luck!
P.S.: one thing you might want to do, (this is C++, OOP) is create classes out of the vertex, triangle and quad struct, and add proper functions that will fill in the vertex data based on parameters like width, height, center. This will make your programming life 90% easier, and it REALLY cuts down on the code. The functions might be a bit though at this stage though, so it's up to you.
Edit: fixed some stuff to make it more readable
I personally prefer quads over triangles, so my (personal) advise would be to add a structure for a quad, which could consist of either 4 vertices, or 2 triangles (but this is 6 vertices, so it would cost you more memory).
In this context (although I dont like C, I personally would go for object-oriented C++), you could do it like this:
typedef struct tagQUAD // Build Our Quad Structure{ VERTEX vertex[4]; // 4 vertices to make up a quad} QUAD;
Now, you could make a function that will add stairs. This function should create a number of quads (or if you want solid stairs, first make a 'cube' structure which consists of 4 quads). Just think about how a stair is made. Basically, its just quads with a high width and small length, where each quad is a bit higher than the last, and a bit further away from you. So you could just initialize a lot of quads of the same size, and use glTranslatef(0.2f, 0.2f, 0.0f) (these numbers are fictional and depend on the size and position of your stairs) between the drawing of each quad, to make sure every quad is translated relative to the last one.
Maybe I can make it more obvious by a little drawing:
Suppose this is your floor, ending in a stair:
-- -- -----------------------
you see? The three lines looking like -- are the stairs. These are the quads I was talking about, notice they are of the same size. Only the position is different, but if you start at the bottom one, you'll notice the relative position between each quad and the next is the same. So if the x-axis is pointing to the right in this picture, and the y-axis is pointing up, and each -- is 1.0f in width, you would do this:
glPushMatrix(); (remember the current matrix)// draw first quadglTranslatef(1.0f, 1.0f, 0.0f);// draw second quad (which is basically the first quad again)glTranslatef(1.0f, 1.0f, 0.0f);// draw third quad (which is basically the first quad again)// etc.. do this for the number of quads you need for your stairsglPopMatrix(); // because we've used glTranslatef, we want to use this function to make sure we start drawing from the origin again after the stairs are drawn
So as I said, you want to make a function out of this. It could look like this:
// step_width is the size of one step of the staircase over the x-axis// step_depth is the size of one step of the staircase over the z-axis// number_of_steps is well, the number of steps in your stairs// staircase_height is the total height of your stairsvoid draw_stairs(float step_width, float step_depth, int number_of_steps, float staircase_height){ QUAD step; // This quad will be made once, and used for all the stairs float height_step = staircase_height / (float)number_of_steps; // Calculate how much higher each step is than the last // Here you fill in the vertices of the quad. I'm not going to do this for you, but all you need here are step_width and step_depth, use these for the x and z values of the vertices, and leave y to 0. glPushMatrix(); // For cancelling out the glTranslates we're doing to do glBegin(GL_QUADS) for (int i = 0; i < number_of_steps; i++) // Loop through all the steps { glTranslatef(0.0f, height_step, step_depth); glVertex3fv(&step.vertex[0]); glVertex3fv(&step.vertex[1]); glVertex3fv(&step.vertex[2]); glVertex3fv(&step.vertex[3]); } glEnd(); glPopMatrix(); // reset back to the state we had at glPushMatrix();}
I'm not sure if the above code is totally correct, since I tend to write in a totally different way. This is certainly not the best way to do it, but I just continued in the style of the tutorial. I hope this helps you out a bit. Good luck!
P.S.: one thing you might want to do, (this is C++, OOP) is create classes out of the vertex, triangle and quad struct, and add proper functions that will fill in the vertex data based on parameters like width, height, center. This will make your programming life 90% easier, and it REALLY cuts down on the code. The functions might be a bit though at this stage though, so it's up to you.
Edit: fixed some stuff to make it more readable
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement