Log in or register to post comments

Videoplay , ImageTarget and Virtual Button

October 8, 2013 - 12:04am #1

Hey ,  

I'm working on a project that combines VideoPlay back , Image Target, and Virtual button 

I did the combination between the Video and Image target on mutli Targets with mutli markers , 

Now i want to combine the virtual button with of the Image Targets  i studied the example of virtual button very well 

and i move the code of the sample to my code  ,  

But the buttons don't appear ,  

 

Here is my code : 

if (strcmp(imageTarget.getName(), "pepsi") == 0){
				currentTarget=STONES;

				sodamodelViewMatrix[currentTarget] = QCAR::Tool::convertPose2GLMatrix(trackableResult->getPose());
                 QCAR::Matrix44F modelViewProjection;
                /*Draw Virtual Button*/
				 // The image target specific result:
				assert(trackableResult->getType() == QCAR::TrackableResult::IMAGE_TARGET_RESULT);
				const QCAR::ImageTargetResult* imageTargetResult = static_cast<const QCAR::ImageTargetResult*>(trackableResult);
				
			   // Set the texture used for the teapot model:
				int textureIndex = 0;

				GLfloat vbVertices[imageTargetResult->getNumVirtualButtons()*24];
				unsigned char vbCounter=0;

				// Iterate through this targets virtual buttons:
				for (int i = 0; i < imageTargetResult->getNumVirtualButtons(); ++i)
				{
					const QCAR::VirtualButtonResult* buttonResult = imageTargetResult->getVirtualButtonResult(i);
					const QCAR::VirtualButton& button = buttonResult->getVirtualButton();

					// If the button is pressed, than use this texture:
					if (buttonResult->isPressed())
					{
						// Run through button name array to find texture index
						for (int j = 0; j < NUM_BUTTONS; ++j)
						{
							if (strcmp(button.getName(), virtualButtonColors[j]) == 0)
							{
								textureIndex = j+1;
								break;
							}
						}
					}

					const QCAR::Area* vbArea = &button.getArea();
					assert(vbArea->getType() == QCAR::Area::RECTANGLE);
					const QCAR::Rectangle* vbRectangle = static_cast<const QCAR::Rectangle*>(vbArea);


					// We add the vertices to a common array in order to have one single
					// draw call. This is more efficient than having multiple glDrawArray calls
					vbVertices[vbCounter   ]=vbRectangle->getLeftTopX();
					vbVertices[vbCounter+ 1]=vbRectangle->getLeftTopY();
					vbVertices[vbCounter+ 2]=0.0f;
					vbVertices[vbCounter+ 3]=vbRectangle->getRightBottomX();
					vbVertices[vbCounter+ 4]=vbRectangle->getLeftTopY();
					vbVertices[vbCounter+ 5]=0.0f;
					vbVertices[vbCounter+ 6]=vbRectangle->getRightBottomX();
					vbVertices[vbCounter+ 7]=vbRectangle->getLeftTopY();
					vbVertices[vbCounter+ 8]=0.0f;
					vbVertices[vbCounter+ 9]=vbRectangle->getRightBottomX();
					vbVertices[vbCounter+10]=vbRectangle->getRightBottomY();
					vbVertices[vbCounter+11]=0.0f;
					vbVertices[vbCounter+12]=vbRectangle->getRightBottomX();
					vbVertices[vbCounter+13]=vbRectangle->getRightBottomY();
					vbVertices[vbCounter+14]=0.0f;
					vbVertices[vbCounter+15]=vbRectangle->getLeftTopX();
					vbVertices[vbCounter+16]=vbRectangle->getRightBottomY();
					vbVertices[vbCounter+17]=0.0f;
					vbVertices[vbCounter+18]=vbRectangle->getLeftTopX();
					vbVertices[vbCounter+19]=vbRectangle->getRightBottomY();
					vbVertices[vbCounter+20]=0.0f;
					vbVertices[vbCounter+21]=vbRectangle->getLeftTopX();
					vbVertices[vbCounter+22]=vbRectangle->getLeftTopY();
					vbVertices[vbCounter+23]=0.0f;
					vbCounter+=24;

				}

				// We only render if there is something on the array
				if (vbCounter>0)
				{
					// Render frame around button
					glUseProgram(vbShaderProgramID);

					glVertexAttribPointer(vbVertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
						(const GLvoid*) &vbVertices[0]);

					glEnableVertexAttribArray(vbVertexHandle);

					glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
						(GLfloat*)&modelViewProjection.data[0] );

					// We multiply by 8 because that's the number of vertices per button
					// The reason is that GL_LINES considers only pairs. So some vertices
					// must be repeated.
					glDrawArrays(GL_LINES, 0, imageTargetResult->getNumVirtualButtons()*8);

					SampleUtils::checkGlError("VirtualButtons drawButton");

					glDisableVertexAttribArray(vbVertexHandle);
				}

			   /* End of Draw Virtual Button*/
												 
		
			   SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale,
                                                 &sodamodelViewMatrix[currentTarget].data[0]);
				
			  
				 ////// Rotation Code /////////////								 
				const QCAR::TrackableResult* result = state.getTrackableResult(tIdx);
				const QCAR::Trackable& trackable = result->getTrackable();
		
				if (trackable.getId() != lastTrackableId)
				{
					// reset animation time
					animationTime = 0;

					// Update lastTrackableId
					lastTrackableId = trackable.getId();
				}

				float currentTime = 0.001f * getCurrentTimeMilliseconds();

				float elapsedTime = currentTime - lastTime;

				animationTime += elapsedTime;

				lastTime = currentTime;

				// clamp to total duration
						if (animationTime > TOTAL_ANIMATION_DURATION)
				{
					animationTime = 0;
				}			 
				
				float totalRotationAngle = 90.0f;// use your custom value here
				float currentRotationAngle = 360.0f * (animationTime / TOTAL_ANIMATION_DURATION);
				SampleUtils::rotatePoseMatrix(currentRotationAngle, 0.f, 1.f, 0.f,&sodamodelViewMatrix[currentTarget].data[0]);
					//////////////// END Rotation Code /////////////////////
												 
                SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                                             &sodamodelViewMatrix[currentTarget].data[0]);
                SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                            &sodamodelViewMatrix[currentTarget].data[0] ,
                                            &modelViewProjection.data[0]);

                glUseProgram(shaderProgramID);

				

                glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &soda_canVerts[0]);
                glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &soda_canNormals[0]);
                glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &soda_canTexCoords[0]);

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

                glActiveTexture(GL_TEXTURE0);
                glBindTexture(GL_TEXTURE_2D, Itextures[currentTarget]->ITextureID);
                glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
                glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                                   (GLfloat*)&modelViewProjection.data[0] );
               //Ram glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                //               (const GLvoid*) &teapotIndices[0]);
             /*   glDrawArrays(GL_TRIANGLES, 0, soda_canNumVerts);*/
                SampleUtils::checkGlError("ImageTargets renderFrame");
				
                }

Thanks , 

Log in or register to post comments