Results 1 to 4 of 4

Thread: Terrain and camera problems

  1. #1
    Guest

    Terrain and camera problems

    Hi! I'm having some difficulties with camera position in my scene. I've read the pixels from 128x128 bitmap and set it to the matrix height_field
    Code :
    bitmap->LoadFromFile("teren.bmp");
        for(int i = 0; i < AREA_SIZE; i++)
        {
        	for(int j = 0; j < AREA_SIZE; j++)
            {
                height_field[i][j][0]= float(j)*step;
                height_field[i][j][1]= (float)GetRValue(bitmap->Canvas->Pixels[j][i]);//[(i*(AREA_SIZE+j)*3];
                height_field[i][j][2]= -float(i)*step;
                }
        }
    then I have call a function that would draw triangle strip (maybe you have better solution)

    Code :
    for (int z = 0; z < AREA_SIZE-1; z++)
    	{
     
            glEnable(GL_TEXTURE_2D);
            glBindTexture(GL_TEXTURE_2D, texture1);
     
            glBegin(GL_TRIANGLE_STRIP);
    		for (int x = 0; x < AREA_SIZE-1; x++)
    		{
    			// vertex 0
    			glColor3f(height_field[x][z][1]/255.0f, height_field[x][z][1]/255.0f, height_field[x][z][1]/255.0f);
    			glTexCoord2f(0.0f, 0.0f);
    			glVertex3f(height_field[x][z][0], height_field[x][z][1], height_field[x][z][2]);
     
    			// vertex 1
    			glTexCoord2f(1.0f, 0.0f);
    			glColor3f(height_field[x+1][z][1]/255.0f, height_field[x+1][z][1]/255.0f, height_field[x+1][z][1]/255.0f);
    			glVertex3f(height_field[x+1][z][0], height_field[x+1][z][1], height_field[x+1][z][2]);
     
    			// vertex 2
    			glTexCoord2f(0.0f, 1.0f);
    			glColor3f(height_field[x][z+1][1]/255.0f, height_field[x][z+1][1]/255.0f, height_field[x][z+1][1]/255.0f);
    			glVertex3f(height_field[x][z+1][0], height_field[x][z+1][1], height_field[x][z+1][2]);
     
    			//vertex 3
    			glColor3f(height_field[x+1][z+1][1]/255.0f, height_field[x+1][z+1][1]/255.0f, height_field[x+1][z+1][1]/255.0f);
    			glTexCoord2f(1.0f, 1.0f);
    			glVertex3f(height_field[x+1][z+1][0], height_field[x+1][z+1][1], height_field[x+1][z+1][2]);
      		}
    		glEnd();
    	}
    }
    And at the end I would like to point my camera in the center of the map

    Code :
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
     
        gluPerspective(60.0f,(GLfloat)w/(GLfloat)h,0.1f,1000.0f);
        float temp = (AREA_SIZE*step)*0.5;
        glTranslatef(-temp,
            -height_field[AREA_SIZE/2][AREA_SIZE/2][1]-10,
            -temp);
     
        glTranslatef(XP2, YP2, ZP2);
     
        glRotatef(XO2,1.0,0.0,0.0);
        glRotatef(YO2,0.0,1.0,0.0);
        glRotatef(ZO2,0.0,0.0,1.0);
     
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    where step is a distance between 2 coordinates x and z, XP2, YP2, ZP2, XO2, YO2, ZO2 are assigned to some sliders so i can move my terrain around.

    The problem is that I can't see my terrain. It's somewhere outside the window. I tried to change everything, but the problem is always the same. Could you tell me where is the bug?

    Thanks in advance!
    Piotr

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: Terrain and camera problems

    Hi !

    You say "at the end" you would like to setup the camera, I hope this does not mean that you try to render the triangles first and then setup the camera in your code ? because that will not work.

    Mikael

  3. #3
    Guest

    Re: Terrain and camera problems

    Hi! I tried to do many things. When I don't do anything with camera settings - just leave a perspective, the terrain is rendering from the center of a screen. So I want to move camera first to the oposite direction that terrain is build. so i should see the terrain. right? but i can't see anything

  4. #4
    Guest

    Re: Terrain and camera problems

    I think I have found what was the problem... I moved the terrain to far
    Code :
    float temp = (AREA_SIZE*step)*0.5;
     
           glTranslatef(-temp,
            -height_field[AREA_SIZE/2][AREA_SIZE/2][1]-10,
            -temp);
    when I put
    Code :
    float temp = (AREA_SIZE*step)*0.5;
     
           glTranslatef(-temp,
            -height_field[AREA_SIZE/2][AREA_SIZE/2][1]-10,
            -10);
    I can see the terrain

    Thanks anyway!

Similar Threads

  1. How to handle the 'camera' and terrain collision
    By Dan M in forum OpenGL: General
    Replies: 3
    Last Post: 05-15-2010, 12:32 PM
  2. Camera Problems!
    By imported_Shweta in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-10-2005, 11:11 AM
  3. attach camera to terrain PLEASE HELP
    By incus in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 12-01-2002, 07:48 PM
  4. terrain engine problems
    By Baloo in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-17-2001, 12:21 PM
  5. if camera collides with terrain
    By martinzwigl in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-23-2001, 11:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean