📄 lodutil.cpp
字号:
#include "header.h"
#include "LODutil.h"
void readObjectDescription (char *str, CStreamIO &file)
{
int i;
char c;
char *savestr = str;
while (1) {
if (file.read ("%c", &c) == -1) {
*str = '\0';
return;
}
if (c != ' ' && c != '\t') {
*str++ = c;
break;
}
}
if (savestr[0] == '\n') {
strcpy (savestr, "No Description");
return;
}
file.readline (str, GL_MAX_DESCRIPTION);
savestr[GL_MAX_DESCRIPTION-1] = '\0';
for (i=0; i < GL_MAX_DESCRIPTION; i++) {
if (savestr[i] == '\n') savestr[i] = '\0';
if (savestr[i] == '\0') break;
}
if (savestr[0] == '\0') strcpy (savestr, "No Description");
}
int getLODData (char *name, lodPtr **lod)
{
CFileIO myfile;
char infile[GL_NAMESIZE];
glConcatFileExtension ((GLbyte *) infile, (GLbyte *) name, (GLbyte *) "FLT");
if (!myfile.openread (infile)) {
printf ("Can not open input file %s\n", infile);
exit (1);
}
*lod = 0;
lodPtr *newlod = 0;
lodPtr *curlod = 0;
int totallod = 0;
while (!myfile.eof()) {
char *record = getRecord (myfile);
if (!record) exit (1);
swapRecord (record);
short *srec = (short *) record;
short rectype = *srec++;
short reclen = *srec++;
if (rectype == OPCODE_LEVEL_OF_DETAIL) {
newlod = (lodPtr *) glAllocateMemory (sizeof(lodPtr));
if (!newlod) {
printf ("Can not allocate lod memory!\n");
exit (1);
}
flt_LODRecord *lodrec = (flt_LODRecord *) record;
newlod -> next = 0;
newlod -> flag = 0;
newlod -> distance = (GLint) lodrec -> switchin;
if (*lod) {
curlod -> next = newlod;
curlod = newlod;
}
else {
*lod = curlod = newlod;
}
totallod++;
}
else if (rectype == OPCODE_EXTERNAL_REFERENCE) {
if (newlod) {
flt_ExternalReferenceRecord *extrec =
(flt_ExternalReferenceRecord *) record;
int i = getUnixFilename (extrec -> filename);
strncpy (newlod -> name, &(extrec -> filename[i]), GL_NAMESIZE);
newlod -> name[GL_NAMESIZE-1] = '\0';
}
}
glReleaseMemory ((char *) record);
}
myfile.closefile();
printf ("Processing file %s\n", infile);
if (!totallod) {
totallod = 1;
*lod = (lodPtr *) glAllocateMemory (sizeof (lodPtr));
if (!*lod) {
printf ("Can not allocate lod memory!\n");
exit (1);
}
(*lod) -> next = 0;
(*lod) -> distance = 0x7fffffff;
(*lod) -> flag = 0;
strcpy ((*lod) -> name, name);
(*lod) -> name[GL_NAMESIZE-1] = '\0';
}
return totallod;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -