2013-02-25 65 views
1

我正在開發使用Vuforia的iOS SDK(不團結插件)的iOS應用。Vuforia iOS版SDK:聯合ImageTargets&VideoPlayback例如

我想將VideoPlaybackImageTargets樣品混合在一起。從論壇建議我開始videoplayback示例,並集成imageTarget。在編輯EAGLView文件後,該應用程序會同時獲得視頻和3D模型,但不會顯示3D模型。當圖像被跟蹤時,它將獲得renderFrameQCAR中的3D對象並打印日誌。

我能不明白的地方去看看。有沒有人嘗試過,沒有Unity的支持?任何幫助表示讚賞。

+0

您是否找到了解決辦法?我面臨同樣的問題.. – TKumar 2013-03-07 11:35:16

+0

燁我張貼的答案 – EarlySun 2013-03-14 10:16:10

+0

我正在尋找可申請樣品版本2.6.6 – Raptor 2013-11-27 06:07:46

回答

0

開始對VideoPlayback項目的工作,只有在EAGLView文件Teapot.h文件中EAGLview.m

附加部分代碼從ImageTargets空間聲明中頂部更改導入示例:

const float kObjectScale = 3.0f; 
const char* textureFilenames[] = { 
    "icon_play.png", 
    "icon_loading.png", 
    "icon_error.png", 
    "VuforiaSizzleReel_1.png", 
    "VuforiaSizzleReel_2.png", 

    // added for 3d model 
    "TextureTeapotBrass.png", 
    "TextureTeapotBlue.png", 
    "TextureTeapotRed.png" 
}; 

添加此功能(從ImageTargets

- (void)setup3dObjects 
{ 
for (int i=0; i < [textures count]; ++i) { 
    Object3D* obj3D = [[Object3D alloc] init]; 
    if (i >= 5) 
    { 
     obj3D.numVertices = NUM_TEAPOT_OBJECT_VERTEX; 
     obj3D.vertices = teapotVertices; 
     obj3D.normals = teapotNormals; 
     obj3D.texCoords = teapotTexCoords; 
     obj3D.numIndices = NUM_TEAPOT_OBJECT_INDEX; 
     obj3D.indices = teapotIndices; 
    } 
    obj3D.texture = [textures objectAtIndex:i]; 
    [objects3D addObject:obj3D]; 
    [obj3D release]; 
} 
} 

然後,在RenderFrameQCAR後:

int numActiveTrackables = state.getNumTrackableResults(); 

添加代碼3D模型,來自ImageTargets樣品

for (int i = 0; i < state.getNumTrackableResults(); ++i) { 
    // Get the trackable 
    const QCAR::TrackableResult* result = state.getTrackableResult(i); 
    const QCAR::Trackable& trackable = result->getTrackable(); 
    QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose()); 

    // Choose the texture based on the target name 
    int targetIndex = 0; // "stones" 
    if (!strcmp(trackable.getName(), "chips")) 
     targetIndex = 1; 
    else if (!strcmp(trackable.getName(), "tarmac")) 
     targetIndex = 2; 
    Object3D *obj3D = [objects3D objectAtIndex:targetIndex+5]; 

    // OpenGL 2 
    QCAR::Matrix44F modelViewProjection; 
    ShaderUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]); 
    ShaderUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &modelViewMatrix.data[0]); 
    ShaderUtils::multiplyMatrix(&qUtils.projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjection.data[0]); 
    glUseProgram(shaderProgramID); 
    glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.vertices); 
    glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.normals); 
    glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.texCoords); 
    glEnableVertexAttribArray(vertexHandle); 
    glEnableVertexAttribArray(normalHandle); 
    glEnableVertexAttribArray(textureCoordHandle); 
    glActiveTexture(GL_TEXTURE0); 
    glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]); 
    glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]); 
    glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/); 
    glDrawElements(GL_TRIANGLES, obj3D.numIndices, GL_UNSIGNED_SHORT, (const GLvoid*)obj3D.indices); 
    ShaderUtils::checkGlError("EAGLView renderFrameQCAR"); 
} 

只是確保你所有的東西正確加載,應該只是罰款。

+0

**注:**這不適用於樣本版本2.6.6 – Raptor 2013-11-27 06:06:02

0

此答案是根據實際經驗。

我呼籲在videoplayback調用3D模型,我的意思是這樣

if (strcmp(imageTarget.getName(), "affogato") == 0) 
{ 
const int kObjectScale = 500; 
[self secondSetup3dObjects]; 
playerIndex = 99; 
const QCAR::TrackableResult* result = state.getTrackableResult(i); 
QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose()); 
int targetIndex = 9; 
Object3D *obj3D = [objects3D objectAtIndex:targetIndex]; 
QCAR::Matrix44F modelViewProjection; 
ShaderUtils::translatePoseMatrix(0.0f, 0.0f, 50.0f, &modelViewMatrix.data[0]); 
ShaderUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &modelViewMatrix.data[0]); 
ShaderUtils::multiplyMatrix(&qUtils.projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjection.data[0]); 
glUseProgram(shaderProgramID); 
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.vertices); 
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.normals); 
      glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.texCoords); 

glEnableVertexAttribArray(vertexHandle); 
      glEnableVertexAttribArray(normalHandle); 
      glEnableVertexAttribArray(textureCoordHandle); 

      glActiveTexture(GL_TEXTURE0); 
      glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]); 
      glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]); 
      glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/); 
      glDrawArrays(GL_TRIANGLES, 0, obj3D.numVertices); 

      ShaderUtils::checkGlError("EAGLView renderFrameQCAR"); 

我希望這可以幫助任何人......

哦,順便說一句,你需要把在的appdelegate視頻這個目標和透明背景紋理,使這項工作就像一個魅力 問候