Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Multiline File Reading for a 3D engine?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Gooie




PostPosted: Mon Dec 17, 2007 7:22 pm   Post subject: Multiline File Reading for a 3D engine?

I was just working on a 3D engine ( Long Shot ), and ran into a roadblock. I have never been good and File I/O. I'm trying to read a line in a file one line at a time, and I can't find any good explaination of 'seek', F10 doesn't help, and the tutorial on CompSci doesn't work for me. So how could I do this? This is what I had, its not up to my usual standard, sorry about the mess, just testing stuff.
Turing:
var ModelCount : int := 0
var FileName : string
var FileLine : string
var Vertex : array 1 .. 3 of real
var FileStream : int := Dir.Open ("./models")
var CurrentFile : int
var Temp : int := 1
loop
    FileName := Dir.Get (FileStream)
    exit when FileName = ""
    if FileName (1) = "_" then
        ModelCount += 1
        open : CurrentFile, "./models/" + FileName, get, seek
    end if
end loop
setscreen ("text")




for x : 1 .. 2
    seek : CurrentFile, x
    get : CurrentFile, FileLine
    put  FileLine
    for i : 1 .. 3
        get : CurrentFile, Vertex (i)
        put Vertex (i)
    end for
    Temp += 1
    exit when eof (CurrentFile)
end for
Dir.Close (FileStream)


Here is the file I need to get variables from. It is exported from Houdini Master.
code:

g
v -0.5 -0.5 -0.5
v 0.5 -0.5 -0.5
v 0.5 -0.5 0.5
v -0.5 -0.5 0.5
v -0.5 0.5 -0.5
v 0.5 0.5 -0.5
v 0.5 0.5 0.5
v -0.5 0.5 0.5
g
f 2 6 5 1 0.1 0.0 0.1
f 3 7 6 2 0.2 0.1 0.2
f 4 8 7 3 0.3 0.2 0.3
f 1 5 8 4 0.4 0.3 0.4
f 3 2 1 4 0.5 0.4 0.5
f 6 7 8 5 0.6 0.5 0.6


Any help is much appreciated, thanks.
Sponsor
Sponsor
Sponsor
sponsor
Saad




PostPosted: Mon Dec 17, 2007 7:56 pm   Post subject: RE:Multiline File Reading for a 3D engine?

Seek goes to a certain location within a file, eg seek : file, * goes to the eof
Although I'm quite sure you only need get for loading models and to get a line its get :file , line : *
Gooie




PostPosted: Mon Dec 17, 2007 8:32 pm   Post subject: Re: Multiline File Reading for a 3D engine?

Is there a possible way to read one line at a time? It would make things a lot easier for me. I can probably figure something out based on what you've told me though, thanks.
Saad




PostPosted: Mon Dec 17, 2007 8:35 pm   Post subject: RE:Multiline File Reading for a 3D engine?

I said it in my previous post, get :file , line : *, where line is a string
pyrnight




PostPosted: Mon Dec 17, 2007 9:55 pm   Post subject: RE:Multiline File Reading for a 3D engine?

: * is the key.
Carey




PostPosted: Tue Dec 18, 2007 2:03 pm   Post subject: RE:Multiline File Reading for a 3D engine?

As Saad said you will need to have a loop with and exit when eof (file) then a get : file, line : * this will assign the line in the file to the variable line. you can then use string manipulation to extract all the usfull data from it.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: