Computer Science Canada How many numbers are there on a line? |
Author: | Gooie [ Sun Dec 23, 2007 2:59 pm ] | ||||||
Post subject: | How many numbers are there on a line? | ||||||
I have been having a lot of trouble with some concepts when making something 3D. So I have another question I've been trying to wrap my head around. File I/O isn't my strong suit, but I'm getting better. How would I figure out how many numbers come after an 'f' in a line. I can't change the file, since it's output is from a 3D modeling program. (Ignore the lines with 'g' and 'v'. I've figured those out already.) Here are some examples of a model. Cube
Sphere
Here is a the section of the code I need help with, it's not everything. it's in a class though. I doubt this is difficult, I'm probably missing something obvious.
|
Author: | Clayton [ Mon Dec 24, 2007 10:27 am ] |
Post subject: | RE:How many numbers are there on a line? |
Just a note, there is such a thing as overcommenting. |
Author: | Mazer [ Mon Dec 24, 2007 10:49 am ] |
Post subject: | RE:How many numbers are there on a line? |
For readability, yes. For full marks, often no. |
Author: | Sean [ Mon Dec 24, 2007 11:24 am ] |
Post subject: | Re: How many numbers are there on a line? |
Gooie usually reduces his commenting on programs to a minimum, allowing proper use of documentation, but for this, he was just using it so others could understand what each did, and so he remembered which did what, I suspect. |
Author: | Nick [ Mon Dec 24, 2007 12:50 pm ] | ||
Post subject: | RE:How many numbers are there on a line? | ||
the problem doesn't seem to be file I/O but rather string manipulation try this:
|
Author: | Gooie [ Mon Dec 24, 2007 2:40 pm ] | ||
Post subject: | Re: RE:How many numbers are there on a line? | ||
Clayton @ December 24th, 10:27 am wrote: Just a note, there is such a thing as overcommenting.
Haha, ya I realize that now. I just was tired of not commenting at all, and not knowing what anything did, so I went a bit nuts, I need a happy medium. >.< momop @ December 24th, 12:50 pm wrote: the problem doesn't seem to be file I/O but rather string manipulation
try this:
Nice! Thanks, I'll try that. Now, all I need is a proper container for the face values. Why doesn't Turing have flexible multidimensional arrays! Why! They would be so useful. |
Author: | HeavenAgain [ Mon Dec 24, 2007 2:52 pm ] |
Post subject: | RE:How many numbers are there on a line? |
Quote: Why doesn't Turing have flexible multidimensional arrays! Why! They would be so useful. they do i think, look at the turing tut section |
Author: | Nick [ Mon Dec 24, 2007 2:55 pm ] |
Post subject: | RE:How many numbers are there on a line? |
they have multidimensional arrays and flexible arrays just not both together :\ |
Author: | Gooie [ Mon Dec 24, 2007 3:11 pm ] | ||
Post subject: | Re: RE:How many numbers are there on a line? | ||
momop @ December 24th, 12:50 pm wrote: the problem doesn't seem to be file I/O but rather string manipulation
try this:
Ok well, I tried putting that in, and it would work fine, except then LineType only captures the first word in the line. then in sequence the vector coordinates are captured. and I can't even add ": *" because then the rest of the program wouldn't work. I just need to know how to go back and reread the last line. Is there a way? |
Author: | Nick [ Mon Dec 24, 2007 3:23 pm ] | ||||
Post subject: | Re: RE:How many numbers are there on a line? | ||||
Gooie @ Mon Dec 24, 2007 3:11 pm wrote: momop @ December 24th, 12:50 pm wrote: the problem doesn't seem to be file I/O but rather string manipulation
try this:
Ok well, I tried putting that in, and it would work fine, except then LineType only captures the first word in the line. then in sequence the vector coordinates are captured. and I can't even add ": *" because then the rest of the program wouldn't work. I just need to know how to go back and reread the last line. Is there a way? you can put ":*" I read over you're program but without the rest it was a little hard to make it run however I did find a couple things to comment on 1. Quote: get : ModelFile, Vertex (VertexCounter).X
should be
2. when you create Vertex origanally you declare it as a single class/record but later you call it as though it is an array of a pointer to a class or record so instead of [code]var Vertex:^ [insert class/record name here] %it should be var Vertex:array 1.. [insert array upper here] of ^[insert class/record name here][/code then when you create a pointer it should look like this: [code]new Vertex([array number here ex. 1])[/code] and lastly to answer where and how to put ":*" it should look like this [code] get:ModelFile, LineType:*[/code] I don't know what Vertex(VertexCounter)-> X/Y/Z are for but they should also have a :* if the are reading the line |
Author: | Clayton [ Mon Dec 24, 2007 3:36 pm ] |
Post subject: | Re: RE:How many numbers are there on a line? |
HeavenAgain @ Mon Dec 24, 2007 2:52 pm wrote: Quote: Why doesn't Turing have flexible multidimensional arrays! Why! They would be so useful. they do i think, look at the turing tut sectionThey do, just not as you think they would. Multi-dimensional flexible arrays are actually a flexible array of static arrays. You can resize the first dimension all you want, just not the first. |
Author: | Gooie [ Mon Dec 24, 2007 4:22 pm ] | ||||||||||
Post subject: | Re: How many numbers are there on a line? | ||||||||||
Hm... All of this help has been much appreciated. But, honestly, I don't think I have stated my question clearly enough. I have to gather two types of information, vertexes and faces. First I need to figure out the line is face or vertex. If it's a vector it begin with a "v". Followed by three real values (X, Y, Z), each separated by a space.
I need to store each value in a flexible array of a record that has three real values it corresponding. To the information in the file.
The size of the array is figured out by a previous procedure.
If it's a face it begin with an "f". Followed by three or four integer values each separated by a space.
They are the numbers of vertexes to connect to make a face. There is a procedure earlier to find how many faces there are. Variable being "FaceCount" I don't know how I will store theses yet, or how I will collect them. If I get the whole line I can't go back and read the values. If I just get the first word to find if it's a face or vertex, then I have no idea how many values will follow. How can I collect these values? and what sort of variable should I use? |
Author: | Nick [ Mon Dec 24, 2007 6:13 pm ] |
Post subject: | RE:How many numbers are there on a line? |
well the best way in my opinion is to do something like this 1. get current line - to do this imply read the whole line when with CurrentFileWord 2. ignore the first letter, then declare the following numbers (seperated by spaces) to Vertex X,Y,Z to do number two find out where the number starts and where it ends then convert it from a string to a real (use strreal and strrealok) |
Author: | Gooie [ Mon Dec 24, 2007 7:07 pm ] |
Post subject: | Re: RE:How many numbers are there on a line? |
momop @ December 24th, 6:13 pm wrote: well the best way in my opinion is to do something like this
1. get current line - to do this imply read the whole line when with CurrentFileWord 2. ignore the first letter, then declare the following numbers (seperated by spaces) to Vertex X,Y,Z to do number two find out where the number starts and where it ends then convert it from a string to a real (use strreal and strrealok) Oh man! Thanks! I didn't know about 'strtrealok'! That pretty much solved all my problems, thanks. For a container, i think I'll use a flexible array of a record, very similar to flexible multidimensional array. |