📄 getloc.cpp
字号:
if (fltversion > 1500) {//== 1520) {
aflt_PolygonRecord *poly;
poly = (aflt_PolygonRecord *) rec;
sprintf (buffer, "%s", poly -> IDField);
int i = checkForLongID (tree);
if (!polynameList.InNameList (buffer)) {
if (polyname[0]) {
// if (strcmp (polyname, buffer)) break;
if (strncmp (polyname, buffer, polynamelen)) break;
}
else if (polyfilename[0]) break;
}
treePtr *curtree;
if (i) curtree = tree -> next -> child;
else curtree = tree -> child;
if (curtree) {
aflt_VertexList *vtx;
vtx = (aflt_VertexList *) curtree -> record;
if (vtx -> Opcode == OPCODE_VERTEX_LIST) {
vertexRecord *coord = findVertex (findVertexNo (vtx -> offset[0]));
sprintf (buffer1, "%s = %f, %f, %f\n",
buffer, coord -> x, coord -> y, coord -> z);
myfile.writedata (buffer1);
}
else {
puts ("Error! Can not find VertexList record");
}
}
}
else {
flt_PolygonRecord *poly;
poly = (flt_PolygonRecord *) rec;
sprintf (buffer, "%s", poly -> IDField);
int i = checkForLongID (tree);
if (!polynameList.InNameList (buffer)) {
if (polyname[0]) {
// if (strcmp (polyname, buffer)) break;
if (strncmp (polyname, buffer, polynamelen)) break;
}
else if (polyfilename[0]) break;
}
treePtr *curtree;
if (i) curtree = tree -> next -> child;
else curtree = tree -> child;
if (curtree) {
flt_VertexList *vtx;
vtx = (flt_VertexList *) curtree -> record;
if (vtx -> Opcode == OPCODE_VERTEX_LIST) {
vertexRecord *coord = findVertex (findVertexNo (vtx -> offset[0]));
sprintf (buffer1, "%s = %f, %f, %f\n",
buffer, coord -> x, coord -> y, coord -> z);
myfile.writedata (buffer1);
}
else {
puts ("Error! Can not find VertexList record");
}
}
}
}
break;
}
processBeadElement (myfile, tree -> child);
processBeadElement (myfile, tree -> next);
processBeadElement (myfile, tree -> subface);
}
}
int convertColor (int color, int intensity)
{
int r, g, b, a;
r = color & 0xff;
g = (color >> 8) & 0xff;
b = (color >> 16) & 0xff;
a = (color >> 24) & 0xff;
r = (r * intensity) / 127;
g = ((g * intensity) / 127) << 8;
b = ((b * intensity) / 127) << 16;
a = ((a * intensity) / 127) << 24;
a = 0xff000000; // ignored alpha blend value
return r+g+b+a;
}
int checkForLongID (treePtr *tree)
{
if (tree -> next) {
short *srec = (short *) tree -> next -> record;
short rectype = *srec;
if (rectype == OPCODE_LONG_IDENTIFIER) {
flt_LongIDRecord *longid;
longid = (flt_LongIDRecord *) tree -> next -> record;
sprintf (buffer, "%s", longid -> id);
return 1;
}
}
return 0;
}
int saveRecordHeader (CFileIO& myfile, char *rec)
{
unsigned int colindex, colintensity, vertexcolor;
short *srec = (short *) rec;
short rectype = *srec++;
short reclen = *srec++;
vertexRecord *vtxptr;
switch (rectype) {
case OPCODE_SHARED_VERTEX_TABLE:
{
flt_SharedVertex *vtx;
vtx = (flt_SharedVertex *) rec;
vertexOffset += vtx -> recordLen;
}
break;
case OPCODE_VERTEX_COORDINATE:
{
vtxptr = getVertex ();
if (fltversion > 1500) {//== 1520) {
aflt_VertexCoordinate *vtx;
vtx = (aflt_VertexCoordinate *) rec;
storeVertex (vertexOffset, vertexno);
vertexOffset += vtx -> recordLen;
vtxptr -> id = vertexno++;
vtxptr -> x = (float) vtx -> x;
vtxptr -> y = (float) -vtx -> z;
vtxptr -> z = (float) vtx -> y;
if (!(vtx -> Flags & 0x2000)) {
colindex = vtx -> vertexColor >> 7;
vertexcolor = getColorFromTable (colindex);
colintensity = vtx -> vertexColor & 0x7f;
vertexcolor = convertColor (vertexcolor, colintensity);
vtxptr -> r = (float) (vertexcolor & 0xff) / (GLfloat) 255.0;
vtxptr -> g = (float) ((vertexcolor >> 8) & 0xff) / (GLfloat) 255.0;
vtxptr -> b = (float) ((vertexcolor >> 16) & 0xff) / (GLfloat) 255.0;
vtxptr -> a = (float) ((vertexcolor >> 24) & 0xff) / (GLfloat) 255.0;
}
}
else {
flt_VertexCoordinate *vtx;
vtx = (flt_VertexCoordinate *) rec;
storeVertex (vertexOffset, vertexno);
vertexOffset += vtx -> recordLen;
vtxptr -> id = vertexno++;
vtxptr -> x = (float) vtx -> x;
vtxptr -> y = (float) -vtx -> z;
vtxptr -> z = (float) vtx -> y;
if (!(vtx -> Flags & 0x2000)) {
colindex = vtx -> vertexColor >> 7;
vertexcolor = getColorFromTable (colindex);
colintensity = vtx -> vertexColor & 0x7f;
vertexcolor = convertColor (vertexcolor, colintensity);
vtxptr -> r = (float) (vertexcolor & 0xff) / (GLfloat) 255.0;
vtxptr -> g = (float) ((vertexcolor >> 8) & 0xff) / (GLfloat) 255.0;
vtxptr -> b = (float) ((vertexcolor >> 16) & 0xff) / (GLfloat) 255.0;
vtxptr -> a = (float) ((vertexcolor >> 24) & 0xff) / (GLfloat) 255.0;
}
}
}
break;
case OPCODE_VERTEX_WITH_NORMAL:
{
vtxptr = getVertex ();
if (fltversion > 1500) {//== 1520) {
aflt_VertexCoordinateNormal *vtx;
vtx = (aflt_VertexCoordinateNormal *) rec;
storeVertex (vertexOffset, vertexno);
vertexOffset += vtx -> recordLen;
vtxptr -> id = vertexno++;
vtxptr -> x = (float) vtx -> x;
vtxptr -> y = (float) -vtx -> z;
vtxptr -> z = (float) vtx -> y;
vtxptr -> nx = (float) vtx -> nx;
vtxptr -> ny = (float) -vtx -> nz;
vtxptr -> nz = (float) vtx -> ny;
if (!(vtx -> Flags & 0x2000)) {
colindex = vtx -> vertexColor >> 7;
vertexcolor = getColorFromTable (colindex);
colintensity = vtx -> vertexColor & 0x7f;
vertexcolor = convertColor (vertexcolor, colintensity);
vtxptr -> r = (float) (vertexcolor & 0xff) / (GLfloat) 255.0;
vtxptr -> g = (float) ((vertexcolor >> 8) & 0xff) / (GLfloat) 255.0;
vtxptr -> b = (float) ((vertexcolor >> 16) & 0xff) / (GLfloat) 255.0;
vtxptr -> a = (float) ((vertexcolor >> 24) & 0xff) / (GLfloat) 255.0;
}
}
else {
flt_VertexCoordinateNormal *vtx;
vtx = (flt_VertexCoordinateNormal *) rec;
storeVertex (vertexOffset, vertexno);
vertexOffset += vtx -> recordLen;
vtxptr -> id = vertexno++;
vtxptr -> x = (float) vtx -> x;
vtxptr -> y = (float) -vtx -> z;
vtxptr -> z = (float) vtx -> y;
vtxptr -> nx = (float) vtx -> nx;
vtxptr -> ny = (float) -vtx -> nz;
vtxptr -> nz = (float) vtx -> ny;
if (!(vtx -> Flags & 0x2000)) {
colindex = vtx -> vertexColor >> 7;
vertexcolor = getColorFromTable (colindex);
colintensity = vtx -> vertexColor & 0x7f;
vertexcolor = convertColor (vertexcolor, colintensity);
vtxptr -> r = (float) (vertexcolor & 0xff) / (GLfloat) 255.0;
vtxptr -> g = (float) ((vertexcolor >> 8) & 0xff) / (GLfloat) 255.0;
vtxptr -> b = (float) ((vertexcolor >> 16) & 0xff) / (GLfloat) 255.0;
vtxptr -> a = (float) ((vertexcolor >> 24) & 0xff) / (GLfloat) 255.0;
}
}
}
break;
case OPCODE_VERTEX_WITH_UV:
{
vtxptr = getVertex ();
if (fltversion > 1500) {//== 1520) {
aflt_VertexCoordinateTexture *vtx;
vtx = (aflt_VertexCoordinateTexture *) rec;
storeVertex (vertexOffset, vertexno);
vertexOffset += vtx -> recordLen;
vtxptr -> id = vertexno++;
vtxptr -> x = (float) vtx -> x;
vtxptr -> y = (float) -vtx -> z;
vtxptr -> z = (float) vtx -> y;
vtxptr -> u = (float) vtx -> u;
vtxptr -> v = 1.0f - (float) vtx -> v;
if (!(vtx -> Flags & 0x2000)) {
colindex = vtx -> vertexColor >> 7;
vertexcolor = getColorFromTable (colindex);
colintensity = vtx -> vertexColor & 0x7f;
vertexcolor = convertColor (vertexcolor, colintensity);
vtxptr -> r = (float) (vertexcolor & 0xff) / (GLfloat) 255.0;
vtxptr -> g = (float) ((vertexcolor >> 8) & 0xff) / (GLfloat) 255.0;
vtxptr -> b = (float) ((vertexcolor >> 16) & 0xff) / (GLfloat) 255.0;
vtxptr -> a = (float) ((vertexcolor >> 24) & 0xff) / (GLfloat) 255.0;
}
}
else {
flt_VertexCoordinateTexture *vtx;
vtx = (flt_VertexCoordinateTexture *) rec;
storeVertex (vertexOffset, vertexno);
vertexOffset += vtx -> recordLen;
vtxptr -> id = vertexno++;
vtxptr -> x = (float) vtx -> x;
vtxptr -> y = (float) -vtx -> z;
vtxptr -> z = (float) vtx -> y;
vtxptr -> u = (float) vtx -> u;
vtxptr -> v = 1.0f - (float) vtx -> v;
if (!(vtx -> Flags & 0x2000)) {
colindex = vtx -> vertexColor >> 7;
vertexcolor = getColorFromTable (colindex);
colintensity = vtx -> vertexColor & 0x7f;
vertexcolor = convertColor (vertexcolor, colintensity);
vtxptr -> r = (float) (vertexcolor & 0xff) / (GLfloat) 255.0;
vtxptr -> g = (float) ((vertexcolor >> 8) & 0xff) / (GLfloat) 255.0;
vtxptr -> b = (float) ((vertexcolor >> 16) & 0xff) / (GLfloat) 255.0;
vtxptr -> a = (float) ((vertexcolor >> 24) & 0xff) / (GLfloat) 255.0;
}
}
}
break;
case OPCODE_VERTEX_WITH_NORMAL_AND_UV:
{
vtxptr = getVertex ();
if (fltversion > 1500) {//== 1520) {
aflt_VertexCoordinateTextureNormal *vtx;
vtx = (aflt_VertexCoordinateTextureNormal *) rec;
storeVertex (vertexOffset, vertexno);
vertexOffset += vtx -> recordLen;
vtxptr -> id = vertexno++;
vtxptr -> x = (float) vtx -> x;
vtxptr -> y = (float) -vtx -> z;
vtxptr -> z = (float) vtx -> y;
vtxptr -> nx = (float) vtx -> nx;
vtxptr -> ny = (float) -vtx -> nz;
vtxptr -> nz = (float) vtx -> ny;
vtxptr -> u = (float) vtx -> u;
vtxptr -> v = 1.0f - (float) vtx -> v;
if (!(vtx -> Flags & 0x2000)) {
colindex = vtx -> vertexColor >> 7;
vertexcolor = getColorFromTable (colindex);
colintensity = vtx -> vertexColor & 0x7f;
vertexcolor = convertColor (vertexcolor, colintensity);
vtxptr -> r = (float) (vertexcolor & 0xff) / (GLfloat) 255.0;
vtxptr -> g = (float) ((vertexcolor >> 8) & 0xff) / (GLfloat) 255.0;
vtxptr -> b = (float) ((vertexcolor >> 16) & 0xff) / (GLfloat) 255.0;
vtxptr -> a = (float) ((vertexcolor >> 24) & 0xff) / (GLfloat) 255.0;
}
}
else {
flt_VertexCoordinateTextureNormal *vtx;
vtx = (flt_VertexCoordinateTextureNormal *) rec;
storeVertex (vertexOffset, vertexno);
vertexOffset += vtx -> recordLen;
vtxptr -> id = vertexno++;
vtxptr -> x = (float) vtx -> x;
vtxptr -> y = (float) -vtx -> z;
vtxptr -> z = (float) vtx -> y;
vtxptr -> nx = (float) vtx -> nx;
vtxptr -> ny = (float) -vtx -> nz;
vtxptr -> nz = (float) vtx -> ny;
vtxptr -> u = (float) vtx -> u;
vtxptr -> v = 1.0f - (float) vtx -> v;
if (!(vtx -> Flags & 0x2000)) {
colindex = vtx -> vertexColor >> 7;
vertexcolor = getColorFromTable (colindex);
colintensity = vtx -> vertexColor & 0x7f;
vertexcolor = convertColor (vertexcolor, colintensity);
vtxptr -> r = (float) (vertexcolor & 0xff) / (GLfloat) 255.0;
vtxptr -> g = (float) ((vertexcolor >> 8) & 0xff) / (GLfloat) 255.0;
vtxptr -> b = (float) ((vertexcolor >> 16) & 0xff) / (GLfloat) 255.0;
vtxptr -> a = (float) ((vertexcolor >> 24) & 0xff) / (GLfloat) 255.0;
}
}
}
break;
case OPCODE_BINARY_SEPARATING_PLANE:
case OPCODE_TRANSFORMATION_MATRIX:
case OPCODE_PUSH_SUBFACE:
case OPCODE_POP_SUBFACE:
case OPCODE_PUSH_LEVEL:
case OPCODE_POP_LEVEL:
case OPCODE_DEGREE_OF_FREEDOM:
case OPCODE_GROUP:
case OPCODE_OBJECT:
case OPCODE_LONG_IDENTIFIER:
case OPCODE_POLYGON:
case OPCODE_VERTEX_LIST:
case OPCODE_SWITCH_BEAD:
case OPCODE_BOUNDING_BOX:
case OPCODE_BOUNDING_SPHERE:
return 1;
}
return 0;
}
void buildTreeRecord (char *rec)
{
short rectype, reclen;
short *srec = (short *) rec;
rectype = *srec++;
reclen = *srec++;
switch (rectype) {
case OPCODE_PUSH_SUBFACE:
subfacecounter++;
subfaceList[insubfacemode++] = subfaceRoot;
if (insubfacemode >= 1000) {
insubfacemode = 999;
puts ("Only 1000 subfaces are allowed!");
}
glReleaseMemory (rec);
break;
case OPCODE_POP_SUBFACE:
insubfacemode--;
glReleaseMemory (rec);
break;
case OPCODE_PUSH_LEVEL:
glReleaseMemory (rec);
if (insubfacemode) {
if (currentsubfacetree) inpushsubfacemode = 1;
}
else if (treeRoot) inpushmode = 1;
break;
case OPCODE_POP_LEVEL:
glReleaseMemory (rec);
if (insubfacemode) {
inpushsubfacemode = 0;
if (currentsubface)
currentsubface = currentsubface -> parent;
else {
puts ("Warning! subface parent can not be found");
}
break;
}
if (treeRoot) {
inpushmode = 0;
if (currentTree)
currentTree = currentTree -> parent;
else {
puts ("Warning! Parent can not be found");
}
}
break;
case OPCODE_TRANSFORMATION_MATRIX:
case OPCODE_DEGREE_OF_FREEDOM:
case OPCODE_GROUP:
case OPCODE_OBJECT:
case OPCODE_LONG_IDENTIFIER:
case OPCODE_BINARY_SEPARATING_PLANE:
case OPCODE_POLYGON:
case OPCODE_VERTEX_LIST:
case OPCODE_SWITCH_BEAD:
case OPCODE_BOUNDING_BOX:
case OPCODE_BOUNDING_SPHERE:
newTree = (treePtr *) glAllocateMemory (sizeof(treePtr));
newTree -> record = rec;
newTree -> objectid = -1;
newTree -> child = newTree -> next =
newTree -> parent = newTree -> prev =
newTree -> subface = 0;
newTree -> beadcounter = 0;
if (insubfacemode) {
if (rectype == OPCODE_POLYGON) {
subfaceRoot = subfaceList[insubfacemode-1];
if (subfaceRoot -> subface) {
subfaceRoot = subfaceRoot -> subface;
while (subfaceRoot -> next) {
subfaceRoot = subfaceRoot -> next;
}
subfaceRoot -> next = newTree;
}
else subfaceRoot -> subface = newTree;
newTree -> beadcounter = subfacecounter;
subfaceRoot = newTree;
currentsubfacetree = currentsubface = newTree;
}
else {
if (currentsubfacetree) {
if (inpushsubfacemode) {
currentsubface -> child = newTree;
newTree -> parent = currentsubface;
}
else {
currentsubface -> next = newTree;
newTree -> prev = currentsubface;
newTree -> parent = currentsubface -> parent;
}
currentsubface = newTree;
}
inpushsubfacemode = 0;
}
break;
}
if (rectype == OPCODE_POLYGON) {
subfaceRoot = newTree;
currentsubfacetree = 0;
currentsubface = 0;
inpushsubfacemode = 0;
}
if (treeRoot) {
if (inpushmode) {
currentTree -> child = newTree;
newTree -> parent = currentTree;
}
else {
currentTree -> next = newTree;
newTree -> prev = currentTree;
newTree -> parent = currentTree -> parent;
}
currentTree = newTree;
}
else {
treeRoot = currentTree = newTree;
}
inpushmode = 0;
break;
default:
glReleaseMemory ((char *) rec);
break;
}
// DisplaySupportedType (rectype);
}
int getColorFromTable (int index)
{
if (fltversion > 1500) {//== 1520) {
aflt_ColorRecord *color = (aflt_ColorRecord *) colorTableRecord;
return color -> rgb[index];
}
else {
flt_ColorRecord *color = (flt_ColorRecord *) colorTableRecord;
return color -> rgb[index];
}
}
void getMaterialFromTable (rgbaRecord *col, int matindex)
{
if (fltversion > 1500) {//== 1520) {
newmaterialPalette = headmaterialPalette;
while (newmaterialPalette) {
aflt_MaterialRecord *mat = newmaterialPalette -> materialPalette;
if (mat -> materialIndex == matindex) {
col -> r = (int) (mat -> diffuseRed * (float) 255.0);
col -> g = (int) (mat -> diffuseGreen * (float) 255.0);
col -> b = (int) (mat -> diffuseBlue * (float) 255.0);
col -> a = (int) (((float) 1.0 - mat -> alpha) * (float) 65536.0);
return;
}
newmaterialPalette = newmaterialPalette -> next;
}
}
else {
flt_MaterialTable *mat = &(materialTableRecord -> mat[matindex]);
col -> r = (int) (mat -> diffuseRed * (float) 255.0);
col -> g = (int) (mat -> diffuseGreen * (float) 255.0);
col -> b = (int) (mat -> diffuseBlue * (float) 255.0);
col -> a = (int) (((float) 1.0 - mat -> alpha) * (float) 65536.0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -