Results 1 to 4 of 4

Thread: Terrain and camera problems

  1. #1

    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 :
        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++)
            glBindTexture(GL_TEXTURE_2D, texture1);
    		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]);
    And at the end I would like to point my camera in the center of the map

    Code :
        float temp = (AREA_SIZE*step)*0.5;
        glTranslatef(XP2, YP2, ZP2);
    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!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001

    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.


  3. #3

    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

    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;
    when I put
    Code :
    float temp = (AREA_SIZE*step)*0.5;
    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