Jump to content
  • Advertisement
Sign in to follow this  
Death100

Loading a Model from a file

This topic is 4134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been trying to make a class that will load a model format i'ved named the .cheese format. However I can't get it to work... Heres the code:
struct coord {
       float x, y, z;
};
//this is the loadmodel class
class MODEL {
      public:
             //this will load .cheese
            bool LoadCheese(const char *filename) {
                 //variables
                 FILE *file;
                 
                 //openfile
                 file = fopen(filename, "r");
                 if (file == NULL) {
                          return FALSE; //if we can't load the file return FALSE
                 }
                 
                 //turn this file into coords
                 for (int i = 0; i == 200; i++) {
                     fscanf(file, "%f %f %f", coords.x, coords.y, coords.z);
                 }
                 
                 //succesful load
                 return TRUE;
            }
            
            //this will draw the model
            void Draw() {
                 glPointSize(30);
                 //accese coord array to draw points
                 glBegin(GL_POINTS);
                                     for (int i = 0; i == 200; i++) {
                                         cout << coords.x;
                                         glVertex3f(coords.x, coords.y, coords.z);
                                     }
                 glEnd();
            }
      private:
              coord coords[200];
};
Anybody know what i'm doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
I think your for loops are incorrect, try < instead of ==.


for (int i = 0; i == 200; i++)


probably translates into:


int i = 0;
while( i == 200 )
{
// do stuff here
i++;
}


which of course won't work.

Share this post


Link to post
Share on other sites
when i change the == to < and run the program I get a runtime error. It's probably something to do with the fscanf, because if i remove the loops the same thing happens.

Update:
Definatly somehting to do with the file or fscanf. When i remove it it runs without error

heres what's in file.cheese


1.000000 1.000000 1.000000

Share this post


Link to post
Share on other sites
fscanf takes pointers so try changing it to this:

fscanf(file, "%f %f %f", &coords.x, &coords.y, &coords.z );

Also make sure you actually have 200 coords in the file.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!