09-19-2004, 08:13 AM

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

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)

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

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

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)

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

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