不能用香蕉代替茶壶

时间:2013-10-11 07:48:28

标签: iphone opengl-es augmented-reality vuforia

我从http://heikobehrens.net/2009/08/27/obj2opengl/下载了banana.h文件。我在EAGLView.mm中包含.h文件。我在EAGLView.mm文件中替换。我按照指示用另一个3D模态替换茶壶。但我没有得到任何替换的输出。我不知道我错在哪里

namespace {    
    // Teapot texture filenames    
    const char* textureFilenames[] = {    
    "banana.jpg",    
    /*

    "TextureTeapotBrass.png",
    "TextureTeapotBlue.png",
    "TextureTeapotRed.png"
    */
    }

    // Model scale factor
    const float kObjectScale = 3.0f;
}

- (void) setup3dObjects    
{    
    // build the array of objects we want drawn and their texture    
    // in this example we have 3 targets and require 3 models
    // but using the same underlying 3D model of a teapot, differentiated
    // by using a different texture for each

    for (int i=0; i < [textures count]; i++)
    {
        Object3D *obj3D = [[Object3D alloc] init];
    //  obj3D.numVertices = NUM_TEAPOT_OBJECT_VERTEX;

        obj3D.numVertices =bananaNumVerts;
        obj3D.vertices = bananaVerts;
        obj3D.normals = bananaNormals;
        obj3D.texCoords = bananaTexCoords;
        obj3D.numIndices = 0;
        obj3D.indices = nil;
        obj3D.texture = [textures objectAtIndex:i];

        [objects3D addObject:obj3D];
        [obj3D release];
    }
}

在renderFrame中取代:

glVertexPointer(3, GL_FLOAT, 0, bananaVerts);    
glNormalPointer(GL_FLOAT, 0, bananaNormals);
glTexCoordPointer(2, GL_FLOAT, 0, bananaTexCoords);
glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);

我在哪里弄错了?

1 个答案:

答案 0 :(得分:1)

你的代码是对的。尝试增加比例尺,因为模型可能非常小。改变

const float kObjectScale = 50.0f; // Scale up

并且还使用.png格式的纹理。