Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

my 3d walkaround - need a little help

This topic is 5972 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been working on a really simple 3d walkaround in OpenGL, and everything works except for one thing. I have been trying for a couple weeks to fix this glitch, but I cannot figure it out and nobody I have asked so far has been able to. I have 3 classes. One is a face class, which draws and stores information for one face of a cube. Another is a block class, which draws and stores information for its 6 faces. Another is a map class, which at the current moment is simply a matrix of 20x20 blocks. The 3 classes are relatively short, so I will post them. The problem is in the map class. The face and block classes work totally fine, but the map classes'' problem is in its draw function, and I do not know how to fix it. Here are the classes: enum BLOCKTYPE_DTP { OPEN_GROUND, HALLWAY, INLET, SOLID_BLOCK, BACK_SOLID, FRONT_SOLID, RIGHT_SOLID, LEFT_SOLID, SIDE_HALLWAY, TOP_LEFT_CORNER, TOP_RIGHT_CORNER, BOTTOM_LEFT_CORNER, BOTTOM_RIGHT_CORNER }; struct FACE { GLuint *myTexture; //not being used at the moment double myX[4], myY[4], myZ[4]; double myRGB[3]; //not being used at the moment bool doesExist; FACE ( ) { for(int x = 0; x < 4; x++) { myX[x] = 0; myY[x] = 0; myZ[x] = 0; if(x < 3) myRGB[x] = 0; } myTexture = NULL; doesExist = true; } void DrawFace ( void ) { glNormal3f( 0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer glTexCoord2f(0, 0); glVertex3f(myX[0], myY[0], myZ[0]); // Point 1 glTexCoord2f(0, 1); glVertex3f(myX[1], myY[1], myZ[1]); // Point 2 glTexCoord2f(1, 1); glVertex3f(myX[2], myY[2], myZ[2]); // Point 3 glTexCoord2f(1, 0); glVertex3f(myX[3], myY[3], myZ[3]); // Point 4 } }; struct BLOCK_DTP { FACE *myFace[6]; ifstream myLoad; BLOCKTYPE_DTP myBlockType; bool hasCeiling; BLOCK_DTP ( ) { for(int x = 0; x < 6; x++) { myFace[x] = new FACE; } myBlockType = SOLID_BLOCK; hasCeiling = true; } void SetCeilingStatus ( bool ceiling ) { hasCeiling = ceiling; if(hasCeiling) myFace[2]->doesExist = true; else myFace[2]->doesExist = false; } void SetBlockType ( BLOCKTYPE_DTP newType ) { myBlockType = newType; switch(myBlockType) { case OPEN_GROUND: myFace[0]->doesExist = false; myFace[1]->doesExist = false; myFace[4]->doesExist = false; myFace[5]->doesExist = false; myFace[3]->doesExist = true; break; case HALLWAY: myFace[0]->doesExist = false; myFace[1]->doesExist = false; myFace[4]->doesExist = true; myFace[5]->doesExist = true; myFace[3]->doesExist = true; break; case INLET: myFace[0]->doesExist = false; myFace[1]->doesExist = true; myFace[4]->doesExist = true; myFace[5]->doesExist = true; myFace[3]->doesExist = true; break; case SOLID_BLOCK: myFace[0]->doesExist = true; myFace[1]->doesExist = true; myFace[2]->doesExist = true; //this is the only type that references [2] myFace[3]->doesExist = true; myFace[4]->doesExist = true; myFace[5]->doesExist = true; break; case BACK_SOLID: myFace[0]->doesExist = false; myFace[4]->doesExist = false; myFace[5]->doesExist = false; myFace[1]->doesExist = true; myFace[3]->doesExist = true; break; case FRONT_SOLID: myFace[1]->doesExist = false; myFace[4]->doesExist = false; myFace[5]->doesExist = false; myFace[0]->doesExist = true; myFace[3]->doesExist = true; break; case RIGHT_SOLID: myFace[0]->doesExist = false; myFace[1]->doesExist = false; myFace[5]->doesExist = false; myFace[4]->doesExist = true; myFace[3]->doesExist = true; break; case LEFT_SOLID: myFace[0]->doesExist = false; myFace[1]->doesExist = false; myFace[4]->doesExist = false; myFace[5]->doesExist = true; myFace[3]->doesExist = true; break; case SIDE_HALLWAY: myFace[4]->doesExist = false; myFace[5]->doesExist = false; myFace[0]->doesExist = true; myFace[1]->doesExist = true; myFace[3]->doesExist = true; break; case TOP_LEFT_CORNER: myFace[0]->doesExist = false; myFace[4]->doesExist = false; myFace[1]->doesExist = true; myFace[5]->doesExist = true; myFace[3]->doesExist = true; break; case TOP_RIGHT_CORNER: myFace[0]->doesExist = false; myFace[5]->doesExist = false; myFace[1]->doesExist = true; myFace[4]->doesExist = true; myFace[3]->doesExist = true; break; case BOTTOM_LEFT_CORNER: myFace[1]->doesExist = false; myFace[4]->doesExist = false; myFace[0]->doesExist = true; myFace[5]->doesExist = true; myFace[3]->doesExist = true; break; case BOTTOM_RIGHT_CORNER: myFace[1]->doesExist = false; myFace[5]->doesExist = false; myFace[0]->doesExist = true; myFace[4]->doesExist = true; myFace[3]->doesExist = true; break; } } void LoadFaces ( char *filename ) { myLoad.open(filename); for(int x = 0; !myLoad.eof(); x++) { myLoad >> myFace[x]->myX[0] >> myFace[x]->myX[1] >> myFace[x]->myX[2] >> myFace[x]->myX[3]; myLoad >> myFace[x]->myY[0] >> myFace[x]->myY[1] >> myFace[x]->myY[2] >> myFace[x]->myY[3]; myLoad >> myFace[x]->myZ[0] >> myFace[x]->myZ[1] >> myFace[x]->myZ[2] >> myFace[x]->myZ[3]; } myLoad.close(); } void DisplayFaces ( void ) { for(int x = 0; x < 6; x++) { if(myFace[x]->doesExist) { myFace[x]->DrawFace(); } } } }; struct MAP3D_DTP { BLOCK_DTP *myBlock[20][20]; ifstream myLoadMap; MAP3D_DTP ( ) { for(int x = 0; x < 20; x++) { for(int y = 0; y < 20; y++) { myBlock[x][y] = new BLOCK_DTP; myBlock[x][y]->LoadFaces("block.dat"); } } } void LoadMap ( char *filename ) { myLoadMap.open(filename); int loadNum; for(int x = 0; !myLoadMap.eof() && x < 20; x++) { for(int y = 0; !myLoadMap.eof() && y < 20; y++) { myLoadMap >> loadNum; myBlock[x][y]->SetBlockType((BLOCKTYPE_DTP)loadNum); } } myLoadMap.close(); } void DisplayMap ( void ) { for(int x = 0; x < 20; x++) { for(int y = 0; y < 20; y++) { myBlock[x][y]->DisplayFaces(); glTranslatef(1.0f, 0.0f, 0.0f); } glTranslatef(-20.0f, 0.0f, 1.0f); } } }; Those are my classes. For some reason the glTranslatef() is not working in my map classes'' draw function. All the blocks are being drawn in one spot. Here is where I actually do the drawing: int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); // Reset The Current Matrix glTranslatef(0.0f,0.0f,-5.0f); /*z is a global user controlled depth variable controlled by the user when he/she presses the up and down arrows, simply to move forward and backward*/ glTranslatef(0.0f,0.0f,z); // Translate Into/Out Of The Screen By z glBindTexture(GL_TEXTURE_2D, texture[filter]); glBegin(GL_QUADS); myMap->DisplayMap(); glEnd(); return TRUE; // Everything Went OK } You might be saying, "well where did you load the map?" I did that in WinMain(). So dont worry. I did load the map, so thats not the problem. Anyways, anybody know how to fix whats happening to me? If you need a complete list of my code...I can send it to you or post it. A horse is a horse. There is no excuse for Hungarian notation. DavidP - a CBoardian dragon288@juno.com

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!