stumped with a map loading problem

Started by
10 comments, last by brandonman 16 years, 3 months ago
Hey, I'm working on an FPS right now and everything's been going good. I got started on loading in a map for an indoors environment, walls and such. I made the walls real short for now so I knew that the loading was ok, by getting a bird's eye view so to speak. Well, turns out it isn't working. Really odd too. Screen: Image Hosted by ImageShack.us<br/> map text file:

1 1 1 1 1 1 1 1 1 1 
1 0 0 0 0 0 0 0 0 1 
1 0 0 0 0 0 0 0 0 1 
1 0 0 0 0 0 0 0 0 1 
1 0 0 0 0 0 0 0 0 1 
1 0 0 0 0 0 0 0 0 1 
1 0 0 0 0 0 0 0 0 1 
1 0 0 0 0 0 0 0 0 1 
1 0 0 0 0 0 0 0 0 1 
1 1 1 1 1 1 1 1 1 1 


loading:

	vector<int> map;
//other stuff here

	ifstream file("map.txt");
	int temp;
	while(file >> temp){
		map.push_back(temp);
	}

	for(int i=0; i < (int)map.size(); i++){
		cout << map<<" ";
	}



It has to be in the drawing, because a cout to the console shows me the array is loaded flawlessly. drawing:

      for(int x=0;x<9;x++)
      {
      for(int y=0;y<9;y++)
      {
      if(map[x*y]==1)
      {
 	cubes.draw(x,0,y,1,1,1); //a function I made for my engine. Just renders a cube. The variables passed, in order, are x coord, y coord, z coord, length(on z axis), width(on x axis) and height.
}
}
}



that's all the important code. any ideas?
Advertisement
for(int y=0;y<9;x++){   for(int x=0;x<9;y++)   {      if(map[y*9 + x]==1)      { 	cubes.draw(x,0,y,1,1,1); //a function I made for my engine. Just renders a cube. The variables passed, in order, are x coord, y coord, z coord, length(on z axis), width(on x axis) and height.      }   }}
that gave me a "cataclysm engine.exe has stoppped working" message. I tried initializing x and y as globals. any ideas?
Swap "y++" and "x++" in Visage's code.
did what was recomended and got this. I'm stumped. I can't think well on this problem...
Free Image Hosting at www.ImageShack.us
Maybe you're doing something funny with translations when rendering your cube. You could try posting the code to the draw() function so we can peruse through that.
bi-FreeSoftware
It looks to me like you've got the wrong array bounds.

The map file is 10x10, but in your loops you've got
for(int x=0;x<9;x++)
-- That is, you're only looping over 9 of the 10 map coordinates.

Try changing...

for(int x=0;x<9;x++)     {     for(int y=0;y<9;y++)     {


to:

for(int x=0;x<10;x++)     {     for(int y=0;y<10;y++)     {


...and see what happens.
Quote:Original post by tasen
It looks to me like you've got the wrong array bounds.

The map file is 10x10, but in your loops you've got
for(int x=0;x<9;x++)
-- That is, you're only looping over 9 of the 10 map coordinates.

Try changing...

for(int x=0;x<9;x++)     {     for(int y=0;y<9;y++)     {


to:

for(int x=0;x<10;x++)     {     for(int y=0;y<10;y++)     {


...and see what happens.


The pattern I'm seeing proves this to be true. The first 9 characters read correctly, you you get the beginnings of a straight line. then, however, you miss one column, and all goes titties up.

Then, the line goes diagonally, since the error of skipping 1 character per row results in a staggered line, almost a perfect diagonal. Because the right hand column only gets drawn once every 10 lines its not showing.

Fix this error and, hopefully, there are no further bugs.
I just wanted to see if he would actually do it. Also, this test will rule out any problems with system services.
no luck changing to <10.
Here's the draw function.

void cube::draw(int x,int y,int z,int l,int w,int h){   glBegin(GL_QUADS);   		glColor3f(0.0f,1.0f,0.0f);			// Set The Color To Green		glVertex3f( x+l, y+h,z);			// Top Right Of The Quad (Top)		glVertex3f(x, y+h,z);			// Top Left Of The Quad (Top)		glVertex3f(x, y+h, z+l);			// Bottom Left Of The Quad (Top)		glVertex3f(x+l, y+h, z+l);			// Bottom Right Of The Quad (Top)		glVertex3f( x+1,y, z+l);			// Top Right Of The Quad (Bottom)		glVertex3f(x,y, z+l);			// Top Left Of The Quad (Bottom)		glVertex3f(x,y,z);			// Bottom Left Of The Quad (Bottom)		glVertex3f( x+1,y,z);			// Bottom Right Of The Quad (Bottom)		glVertex3f( x+1, y+h, z+l);			// Top Right Of The Quad (Front)		glVertex3f(x, y+h, z+1);			// Top Left Of The Quad (Front)		glVertex3f(x,y, z+1);			// Bottom Left Of The Quad (Front)		glVertex3f( x+1,y, z+l);			// Bottom Right Of The Quad (Front)		glVertex3f( x+1,y,z);			// Bottom Left Of The Quad (Back)		glVertex3f(x,y,z);			// Bottom Right Of The Quad (Back)		glVertex3f(x, y+h,z);			// Top Right Of The Quad (Back)		glVertex3f(x+1, y+h,z);			// Top Left Of The Quad (Back)		glVertex3f(x, y+h, z+l);			// Top Right Of The Quad (Left)		glVertex3f(x, y+h,z);			// Top Left Of The Quad (Left)		glVertex3f(x,y,z);			// Bottom Left Of The Quad (Left)		glVertex3f(x,y, z+1);			// Bottom Right Of The Quad (Left)		glVertex3f( x+1, y+h,z);			// Top Right Of The Quad (Right)		glVertex3f( x+1, y+h, z+l);			// Top Left Of The Quad (Right)		glVertex3f( x+1,y, z+l);			// Bottom Left Of The Quad (Right)		glVertex3f( x+1,y,z);			// Bottom Right Of The Quad (Right)	glEnd();						// Done Drawing The Quad}
I recommend actually finding out when the individual cubes are created.

This topic is closed to new replies.

Advertisement