📄 getcoord.cpp
字号:
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 + -