I have a simple DrawFloor() method here that came with my book. It doesn't share what the algorithm is here... it just plots down some code and moves on. I tried doing this on paper. The camera is at (0,0,0) and it seems like 5 lines are ahead, and five lines are behind. I'm assuming whatever the extent is, it'll be double in the scene. I knocked it down to an extent of 5 instead of 20, and I thought it would clear some things up, but I'm lost in keeping track with where each line is being drawn. I would like to know what the pattern is anyway. This is along the XZ plane. If you can share what it is doing, I will email a cookie. Thanks, my mind is always wondering what algorithm was used before the code. This book is known for some code dumps.
Here's a second code dump for your mind to boggle on. If there's an explanation on this second one too, I would be greatful. The end result draws a ground similar to the above, but it also places a 128x128 texture and it continues to repeat until the last line is drawn. I would like to see the pattern of these algorithms instead of code dumps. It is a good book but... argh! Are there any good sites that explain this kind of stuff?Code:void DrawGround(void) { GLfloat fExtent = 5.0f; GLfloat fStep = 1.0f; GLfloat y = -0.4f; GLint iLine; glBegin(GL_LINES); for (iLine = -fExtent; iLine <= fExtent; iLine += fStep) { glVertex3f(iLine, y, fExtent); glVertex3f(iLine, y, -fExtent); glVertex3f(fExtent, y, iLine); glVertex3f(-fExtent, y, iLine); } glEnd(); }
Code:void DrawGround(void) { GLfloat fExtent = 20.0f; GLfloat fStep = 1.0f; GLfloat y = -0.4f; GLint iStrip, iRun; GLfloat s = 0.0f; GLfloat t = 0.0f; GLfloat texStep = 1.0f / (fExtent * .075f); glBindTexture(GL_TEXTURE_2D, g_texState[TEX_GRASS]); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); for(iStrip = -fExtent; iStrip <= fExtent; iStrip += fStep) { t = 0.0f; glBegin(GL_TRIANGLE_STRIP); for(iRun = fExtent; iRun >= -fExtent; iRun -= fStep) { glTexCoord2f(s, t); //glNormal3f(0.0f, 1.0f, 0.0f); // All Point up glVertex3f(iStrip, y, iRun); glTexCoord2f(s + texStep, t); //glNormal3f(0.0f, 1.0f, 0.0f); // All Point up glVertex3f(iStrip + fStep, y, iRun); t += texStep; } glEnd(); s += texStep; } }



LinkBack URL
About LinkBacks


