0

如何从不同的 3D 模型但名称和目录不同的 .h(3D 模型) 中获取值?

例如:

A1.h(香蕉模型)在/FrameMarkers/Model/A1.h

A1.h(老虎模型)在/FrameMarkers/Model1/A1.h

但是,我想从变量中获取值,这些变量是 A1NumVerts、A1Verts、A1Normal、A1TexCoords,以便用于我的条件。这是代码:

int Type=Animal;
 - (void) setup3dObjects
 {
     if(Type==Animal){
     [self add3DObjectWith:A1NumVerts ofVertices:A1Verts normals:A1Normals texcoords:A1TexCoords                        
                      with:NUM_R_OBJECT_INDEX ofIndices:RobjectIndices usingTextureIndex:0];                                     <<<<<<<<<<<< show Tiger
     }
     else
     {        
         [self add3DObjectWith:A1NumVerts ofVertices:A1Verts normals:A1Normals texcoords:A1TexCoords
                          with:NUM_R_OBJECT_INDEX ofIndices:RobjectIndices usingTextureIndex:0];                                    <<<<<<<<<<<< show Banana
     }
 }

如何更改我下划线的代码以便从中获取价值?

4

1 回答 1

0

如果您可以手动重命名这些文件中的变量,使它们不一样,那可能是最好的解决方案。

第二种解决方案是编写 2 个帮助函数,它们返回 2 个模型,它们位于不同的实现文件中。像这样的东西:

香蕉.h:

void getBananaData (int* numVerts, Vertex* verts, Normal* normals, TexCoords* texCoords); // Where Vertex* and Normal* are whatever types A1Verts and A1Normals are

香蕉.m:

#include "FrameMarkers/Model/A1.h"

void getBananaData (int* numVerts, Vertex* verts, Normal* normals, TexCoords* texCoords)
{
    // These will give you the data from the banana model
    // because we included the banana model's header and not the
    // tiger model's.
    *numVerts = A1NumVerts;
    *verts = A1Verts;
    *normals = A1Normals;
    *texCoords = A1TexCoords;
}

然后对 Tiger 模型做同样的事情:

老虎.h

void getTigerData (int* numVerts, Vertex* verts, Normal* normals, TexCoords* texCoords);

和 Tiger.m

#include "FrameMarkers/Model1/A1.h"

void getTigerData (int*numVerts, Vertex* verts, Normal* normals, TexCoords* texCoords)
{
    // These will give you the data from the tiger model
    // because we included the tiger model's header, and not the banana model's
    *numVerts = A1NumVerts;
    *verts = A1Verts; 
    *normals = A1Normals;
    *texCoords = A1TexCoords;
}

然后在你上面的方法中,你会有这样的东西:

 int numVerts = 0;
 Vertex verts;
 Normals normals;
 TexCoords texCoords;
 if(Type==Animal){
     getTigerData(&numVerts, &verts, &normals, &texCoords);
 }
 else
 {        
     getBananaData (&numVerts, &verts, &normals, &texCoords);
 }
 [self add3DObjectWith:numVerts ofVertices:verts normals:normals texcoords:A1TexCoords with:NUM_R_OBJECT_INDEX ofIndices:RobjectIndices usingTextureIndex:0];

第三种解决方案是#define在编译时使用 a 重命名其中一个文件中的变量。这不是我最喜欢的解决方案,因为它可能会导致其他问题。我可以解释它,但你可能不想这样做。

于 2012-12-22T06:46:02.677 回答