Hello guys, I’m working on one IOS application. I have loaded one 3D Frame and one 2D image on that frame while camera is running. I have used Vuforia SDK for image targeting and augment 3D content and 2D image. 2D image is also augmented as a model on surface view. When first time I tired to implement zoom in and zoom out, image was displayed outside of frame, So I add another model and applied occlusion effect as per mentioned in vuforia sample for occlusion (https://developer.vuforia.com/resources/sample-apps/occlusion-management). Now output of my application is shown in below images.
1) First Image is normal image size (without zoom):- https://developer.vuforia.com/sites/default/files/1_0.PNG
2) Second image after zoom:- https://developer.vuforia.com/sites/default/files/2_0.PNG
3) Image drag after zoom :- https://developer.vuforia.com/sites/default/files/3_0.PNG
So now I’m facing these problems :
1) After zooming image when I drag image, it should be limited to frame edges.
2) Pinch Gesture listener should be applied only on Images.
3) Image should be zoom by Mid-point of pinch listener.
I have applied zoom effect by using pinch gesture for full screen and for moving I have used Pan Gesture.
my code:-
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 Mask_modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());
QCAR::Matrix44F Mask_modelViewProjection;
SampleApplicationUtils::translatePoseMatrix(170.0f, -150.0f, -18.0f,&Mask_modelViewMatrix.data[0]);
SampleApplicationUtils::rotatePoseMatrix(90,0, 90, 0, &Mask_modelViewMatrix.data[0]);
SampleApplicationUtils::scalePoseMatrix(9000, 9000, 9000,&Mask_modelViewMatrix.data[0]);
SampleApplicationUtils::multiplyMatrix(&vapp.projectionMatrix.data[0], &Mask_modelViewMatrix.data[0] , &Mask_modelViewProjection.data[0]);
glUseProgram(MaskShaderProgramID);
glVertexAttribPointer(MaskVertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)Mask_ObjVerts);
glVertexAttribPointer(MaskNormalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)Mask_ObjNormals);
glVertexAttribPointer(MaskTextureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)Mask_ObjTexCoords);
glEnableVertexAttribArray(MaskVertexHandle);
glEnableVertexAttribArray(MaskNormalHandle);
glEnableVertexAttribArray(MaskTextureCoordHandle);
glBindTexture(GL_TEXTURE_2D, 0);
glUniformMatrix4fv(Mask_mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&Mask_modelViewProjection.data[0]);
glDrawArrays(GL_TRIANGLES, 0, Mask_ObjNumVerts);
//mask end
//Display 3D frame:-
QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());
QCAR::Matrix44F modelViewProjection;
SampleApplicationUtils::translatePoseMatrix(0.0f, 0.0f, 0.0f, &modelViewMatrix.data[0]);
SampleApplicationUtils::rotatePoseMatrix(90,0, 90, 0, &modelViewMatrix.data[0]);
SampleApplicationUtils::scalePoseMatrix(kObjectScaleNormal, kObjectScaleNormal, kObjectScaleNormal, &modelViewMatrix.data[0]);
SampleApplicationUtils::multiplyMatrix(&vapp.projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjection.data[0]);
glUseProgram(shaderProgramID);
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)FramesOBJVerts);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)FramesOBJNormals);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)FramesOBJTexCoords);
glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, augmentationTexture[0].textureID);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
glDrawArrays(GL_TRIANGLES, 0, FramesOBJNumVerts);
//For Image Display
QCAR::Matrix44F modelViewMatrix_new = QCAR::Tool::convertPose2GLMatrix(result->getPose());
QCAR::Matrix44F modelViewProjection_new;
SampleApplicationUtils::translatePoseMatrix(-imageTranslate_y, -imageTranslate_x, -20.0f, &modelViewMatrix_new.data[0]);
SampleApplicationUtils::scalePoseMatrix(imageObjectScaleNormal, imageObjectScaleNormal, imageObjectScaleNormal, &modelViewMatrix_new.data[0]);
SampleApplicationUtils::multiplyMatrix(&vapp.projectionMatrix.data[0], &modelViewMatrix_new.data[0] , &modelViewProjection_new.data[0]);
glUseProgram(shaderProgramID_1);
glVertexAttribPointer(vertexHandle_1, 3, GL_FLOAT, GL_FALSE, 0,(const GLvoid*)planeVertices);
glVertexAttribPointer(normalHandle_1, 3, GL_FLOAT, GL_FALSE, 0,(const GLvoid*)planeNormals);
glVertexAttribPointer(textureCoordHandle_1, 2, GL_FLOAT, GL_FALSE, 0,(const GLvoid*)planeTexcoords);
glEnableVertexAttribArray(vertexHandle_1);
glEnableVertexAttribArray(normalHandle_1);
glEnableVertexAttribArray(textureCoordHandle_1);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, Image_augmentaionTexture[0].textureID);
glUniformMatrix4fv(mvpMatrixHandle_1, 1, GL_FALSE,
(GLfloat*)&modelViewProjection_new.data[0]);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,(const GLvoid*)planeIndices);
SampleApplicationUtils::checkGlError("EAGLView renderFrameQCAR");
// Finally, we render the top layer based on the video image
// this is the layer that actually gives the "transparent look"
// notice that we use the mask.png (textures[2]->mTextureID)
// to define how the transparency looks
glDepthFunc(GL_LEQUAL);
glActiveTexture(GL_TEXTURE0);
QCAR::Renderer::getInstance().bindVideoBackground(vbVideoTextureUnit);
glActiveTexture(GL_TEXTURE0 + vbMaskTextureUnit);
// glBindTexture(GL_TEXTURE_2D, [Mask_augmentedTexture[0] textureID]);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glViewport(theViewPort.posX, theViewPort.posY,
theViewPort.sizeX, theViewPort.sizeY);
glUseProgram(vbShaderProgramOcclusionID);
glVertexAttribPointer(vbVertexPositionOcclusionHandle, 3, GL_FLOAT,
GL_FALSE, 0, (const GLvoid*) &Mask_ObjVerts[0]);
glVertexAttribPointer(vbVertexTexCoordOcclusionHandle, 2, GL_FLOAT,
GL_FALSE, 0, (const GLvoid*) &Mask_ObjTexCoords[0]);
glEnableVertexAttribArray(vbVertexPositionOcclusionHandle);
glEnableVertexAttribArray(vbVertexTexCoordOcclusionHandle);
glUniform2f(vbViewportOriginHandle,
theViewPort.posX, theViewPort.posY);
glUniform2f(vbViewportSizeHandle, theViewPort.sizeX, theViewPort.sizeY);
glUniform2f(vbTextureRatioHandle, uRatio, vRatio);
glUniform1i(vbTexSamplerVideoOcclusionHandle, vbVideoTextureUnit);
glUniform1i(vbTexSamplerMaskOcclusionHandle, vbMaskTextureUnit);
glUniformMatrix4fv(vbProjectionMatrixOcclusionHandle, 1, GL_FALSE, (GLfloat*)&Mask_modelViewProjection.data[0] );
//glDrawElements(GL_TRIANGLES, NUM_CUBE_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &cubeIndices[0]);
glDrawArrays(GL_TRIANGLES, 0, Mask_ObjNumVerts);
glDisableVertexAttribArray(vbVertexPositionOcclusionHandle);
glDisableVertexAttribArray(vbVertexTexCoordOcclusionHandle);
glUseProgram(0);
glDepthFunc(GL_LESS);
SampleApplicationUtils::checkGlError("Transparency layer");
}