PDA

View Full Version : Problems with the camera position



-NaNo-
05-18-2012, 08:13 AM
Good day everyone! I'm new here, and I need your help!

I'm making a software that receive an image via console, wich rapresents a simple map (where colored pixels corresponds to various objects), and the algorhytm build a 3d, navigable map.
Now, my software works great, it builds the map, and I can even move my camera around using keyboard/mouse.
The problem is that the camera must start in a given position, but I can't figure out how to do this.
On the 2d map I have a green pixel, that rapresents the camera origin. I can draw the pixel in the correct position, but when I use the same coordinates to translate the world (to put my camera at the starting position), things simply don't work properly, my camera is in another position.
Here is the code used to find the camera starting position: (variables names are in Italian, but quite intuitive ^^)


for(long i=0; i!=n_pixel*3; i+=3) {
rosso=*(puntatore+i);
verde=*(puntatore+i+1);
blu=*(puntatore+i+2);
if((rosso==0)&&(verde==255)&&(blu==0)){ //when i read a green pixel I set the camera position
xInit=colonne;
distance=righe;
xpos=xInit;
zpos=distance;
}
colonne++;
if(colonne==base){
colonne=0;
righe++;
}
}

My algorhytm looks at each pixel in memory, checks the color (RGB values) and, when it finds a green pixel it save the x and z coordinates.
Using theese positions I draw the green pixel on the map, in the correct position.
Then, I use this translation to set the initial position of my camera, and to manage the keyboard movements (acting on the xpos, ypos and zpos variables)


glTranslated(-xpos,-ypos,-zpos);

But the camera isn't in the correct position...

Can you help me? If you need more code just ask!

Thanks!