如何从.h(3D模型)获取不同3D模型但同名和不同目录的值?
例如:
A1.h
(香蕉模型)位于/FrameMarkers/Model/A1.h
A1.h
(Tiger模型)位于/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
}
}
如何更改我下划线的代码以便从中获取值?
答案 0 :(得分:0)
如果您可以手动重命名这些文件中的变量,那么它们可能是最佳解决方案。
第二种解决方案是编写2个辅助函数,它们返回2个模型,并且位于不同的实现文件中。像这样:
Banana.h:
void getBananaData (int* numVerts, Vertex* verts, Normal* normals, TexCoords* texCoords); // Where Vertex* and Normal* are whatever types A1Verts and A1Normals are
Banana.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模型做同样的事情:
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
重命名其中一个文件中的变量。这不是我最喜欢的解决方案,因为它可能会导致其他问题。我可以解释一下,但你可能不想这样做。