PDA

View Full Version : read an input file



zeytin
05-02-2009, 09:33 AM
hello everybody,

I need ur help, about how i can read from an input file for opengl, I wrote the code c++ but i cannot run it when i want to use it in opengl. please let me know(urgently).

thanks,
zeytin

Rosario Leonardi
05-02-2009, 09:43 AM
Can you be a little more specific? openGl have nothing to do with file system. :-S
If you want to load a 3d model from a file you should use a library (google can help you here) or study the file format and read it by yourself (obj and 3ds file are easy to parse).

zeytin
05-02-2009, 10:25 AM
hello again,

this can be an example of input file;
vertex 32 320
vertex 12 120
polyline 2 2
vertex 4 110
vertex 3 150


i wrote the code in c++, it reads all information, but i do not know how i can use the code in opengl(or whether i can use it). (i am really new, so i will appreciate for all helps).

thanks again

SANTOS_GL
05-04-2009, 03:15 AM
Hi,

Please see the below flat file, that i use to store the latitude and longitude information for a perticulat place in the map.

Here i tried to display the lat/long information, based on the mouse movement.

In the below file, # represents comment, otherwise data to be read.

# ---------------------------------------------------
# X Y D Dg Mn Se D Dg Mn Se Place Name
# ---------------------------------------------------
1503 547 N 13 04 07.5 E 77 31 10.31 Bangalore
1428 425 N 19 03 43.0 E 72 51 40.78 Mumbai
1496 223 N 28 41 26.1 E 77 15 21.09 Delhi
1677 353 N 22 40 29.4 E 88 25 04.68 Kolkata
1520 458 N 17 28 35.3 E 78 23 54.37 Hyderabad
1551 549 N 13 04 07.5 E 80 14 38.90 Chennai
#----------------------------------------------------

below is mu code to read the above file.

void readFromFile (int x, int y) {
int wxCord, wyCord,directLat,directLong;
char c;
char str[100],placeName[12];

inStream.open(latlongfile,ios::in);
if (!inStream) {
cout<<"File 'latlongfile' not found: "<<endl;
exit(0);
}
while(!inStream.eof()) {
inStream>>c;
if (c == '#') {
inStream.getline(str,100);
}
else {
inStream>>wxCord>>wyCord>>latDirection>>latDeg>>latMin>>latSec>>longDirection>>longDeg>>longMin>>longSec>>placeName;
}
if ( (x >= (wxCord-10) && x <= (wxCord+10)) && ( y >= (wyCord-10) && y <= (wyCord+10))) {
if(latDirection == 'S' || latDirection == 'W')
directLat *=-1;
if(longDirection == 'S' || longDirection == 'W')
directLong *=-1;

latitude = directLat * (latDeg + (latMin/60) + (latSec/3600));
longitude = directLong * (longDeg + (longMin/60) + (longSec/3600));
strcpy(::placeName,placeName);
if (hits == 1) {
xx = hits;
lat1 = latitude;
long1 = longitude;
strcpy(srcPlaceName1,placeName);
}
else {
lat2 = latitude;
long2 = longitude;
strcpy(dstPlaceName2,placeName);
dist = distanceBetweenPoints(lat1, long1, lat2, long2);
}

inStream.close();
break;
}
}

so once the values from the mouse movement is read, it is compared with the flat file X and Y, and particular place lat/long is calculated and displayed on the screen.

if any doubts let me know.

thanks,
SantoS