MS3D MilkShape Format - The
Where going to start
at the very beginning as we do with any other file format! Basically
create a test file, which in this case is going to be a cube! Then we'll
start about just reading in some of the informaiton and examining the data as
we get it, check that we get what we expect. Such as I know that when I
exported the cube, it only has 8 vertices, one for each of the corner.....so
of course if you open box.ms3d and suddenly start getting all sorts of crazy
numbers back, then you can assume something isn't quiet right.
During the early
stages of any file format, when your just reading in the data and dumping it
to a txt file, you'll find that its standard c/c++, so you can compile this
part on almost any platform. Late on when we want to actually start
using this data, then we'll move onto using some of the graphics librarys,
like DirectX or openGl.
|Complete Code - Download
#include <stdio.h> // fopen(..), sprintf(..)
#include <stdarg.h> // va_start, va_end
//Saving debug information to a log file
void dprintf(const char *fmt, ...)
// Try to print in the allocated space.
vsprintf (buf, fmt, parms);
// Send debug info out to the debugger
// Write the information out to a txt file
FILE *fp = fopen("output.txt", "a+");
fprintf(fp, "%s", buf);
dprintf("Welcome to the ms3d tutorial...\n");
// Lets open the test ms3d file we are using, called box.ms3d
FILE * fp = fopen("box.ms3d", "rb");
// Temp buffer to store our data in, as we read it in
// Lets read in the first 4 characters of the file are, and see what
// they look like
int r = // The total number of items readed is returned.
fread ( buf, // void * buffer,
4, // size
1, // count,
fp ); // FILE * stream
// Log them to our debug txt file
dprintf("%c %c %c %c\n", buf,buf,buf,buf);
// Close our File!
Welcome to the ms3d tutorial...
M S 3 D