Log in or register to post comments

How to put multiple textures in one trackable image

July 24, 2013 - 3:25am #1
I am using this code to put a single texture in a trackable image. I have shrunk the texture and shifted it as i need it. i want to fit several more texture there. Can anyone help me with this.
 
<pre class="brush: Lang">const QCAR::TrackableResult* trackableResult = state.getTrackableResult(tIdx);
 
const QCAR::ImageTarget& imageTarget = (const QCAR::ImageTarget&) trackableResult->getTrackable();
 
QCAR::Vec2F targetSize = imageTarget.getSize();
QCAR::Matrix44F modelViewProjection;
SampleUtils::translatePoseMatrix(-40.0f, -35.0f, kObjectScale,
&modelViewMatrix.data[0]);
SampleUtils::scalePoseMatrix(targetSize.data[0]/4, targetSize.data[1]/6, 1.0f,
&modelViewMatrix.data[0]);
SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
&modelViewMatrix.data[0] ,
&modelViewProjection.data[0]);
glUseProgram(shaderProgramID);
 
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &planeVertices[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &planeNormals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &planeTexcoords[0]);
 
glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, thisTexture_1stFloor->mTextureID);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjection.data[0] );
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
(const GLvoid*) &planeIndices[0]);
 </pre>

How to put multiple textures in one trackable image

August 26, 2013 - 1:07am #5
//Position of textures
static const float texPosX[] =
{
    -250.0,-200.0, 0.0, 1.0, 0.0, 0.0,120.0,100.0, 20.0,
};
static const float texPosY[] =
{
    -20.0, 125.0, 225.0, 340.0, 420.0, 505.0,-350.0, -250.0, -150.0,
};
void
loadTexture( QCAR::Matrix44F modelViewProjection,QCAR::Vec2F targetSize, int floor_index, float translateX, float translateY, float scaleXx,float scaleYy)
{
	if(textures[floor_index]->mWidth!=1)
	{

		    	SampleUtils::translatePoseMatrix(translateX, translateY, kObjectScale,
		    	                                         &modelViewMatrix.data[0]);
		    	SampleUtils::scalePoseMatrix(targetSize.data[0]/scaleXx, targetSize.data[1]/scaleYy, 1.0f,
		    	                                     &modelViewMatrix.data[0]);

		    SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
		                                &modelViewMatrix.data[0] ,
		                                &modelViewProjection.data[0]);
		    glUseProgram(shaderProgramID);

		    glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
		                          (const GLvoid*) &planeVertices[0]);
		    glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
		                          (const GLvoid*) &planeNormals[0]);
		    glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
		                          (const GLvoid*) &planeTexcoords[0]);

		    glEnableVertexAttribArray(vertexHandle);
		    glEnableVertexAttribArray(normalHandle);
		    glEnableVertexAttribArray(textureCoordHandle);
		    glActiveTexture(GL_TEXTURE0);
		    glBindTexture(GL_TEXTURE_2D, textures[floor_index]->mTextureID);
		    glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
		                       (GLfloat*)&modelViewProjection.data[0] );
		    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
		                   (const GLvoid*) &planeIndices[0]);
		    modelViewMatrixForTextures[floor_index] = modelViewMatrix;
	}

}

 

This is in the render frame method

 // Did we find any trackables this frame?
    for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
    {
        .
        .
        .
        if (tap)
		{
    		LOG("tap coordinates (screen space): %.2f, %.2f", tapX, tapY);
        	for(int i=0;i<9;i++)
			{
        		QCAR::Vec3F intersection, lineStart, lineEnd;
					projectScreenPointToPlane1(inverseProjMatrix, modelViewMatrixForTextures[i], screenWidth, screenHeight,
												  QCAR::Vec2F(tapX, tapY), QCAR::Vec3F(0, 0, 0), QCAR::Vec3F(0, 0, 1), intersection, lineStart, lineEnd);
				QCAR::Vec2F trackableSize = imageTarget.getSize();
				trackableSize.data[0]/=2.5;
				trackableSize.data[1]/=3.0;
				LOG("tap coordinates[%d] (target space): %.2f, %.2f", i,intersection.data[0], intersection.data[1]);

				if (fabs(intersection.data[0]) < (trackableSize.data[0] / 2) &&
					fabs(intersection.data[1]) < (trackableSize.data[1] / 2))
				{
					LOG("tapped inside the target!");
					tappedFloorID = i+1;
					tappedInsideTarget = true;// do something here
					trackableName = (char*) trackable.getName();
					LOG("Position : %s",trackableName);
				}
			}
        				tap = false;
		}
                .
                .
                .//loading textures
        for(int i=0;i<9;i++)
        {
        	modelViewMatrix =
        	                QCAR::Tool::convertPose2GLMatrix(result->getPose());
        	loadTexture(modelViewProjection,targetSize,i,texPosX[i],texPosY[i],2.5,3.0);
        }

 

This is the taponscreen method which wait until tapping processing is done on renderframe
JNIEXPORT bool JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_isTapOnScreenInsideTarget(JNIEnv *env, jobject, jint floor_id, jfloat x, jfloat y)
{

	LOG("TapOnScreenMethod");
	do
	{}
	while(tap!=false);
	LOG("Just Tapped");
	if(tappedInsideTarget==true)
	{
		LOG("Tapped inside Target");
		tappedInsideTarget=false;
		return true;
	}
	else
		return false;
}

On java i am using it like this

public boolean onSingleTapUp(MotionEvent e)
        {
            // Calls the Autofocus Native Method
            autofocus();

            // Triggering manual auto focus disables continuous
            // autofocus
            mContAutofocus = false;
			
            //Sets the boolean tap varaible in native c to true if tapped inside target
			nativeTapEvent(e.getX(), e.getY());
            //gets the variable modified above
			if(isTapOnScreenInsideTarget(1, e.getX(), e.getY()))
			{
				String position = getTrackableName();
				showToast("Tapped on floor"+ getFloorID() +"standing at position" + position);
			}
			
						
            return true;
        }

I already tested similar code with the trackable ie the image to track and it works.It shows the toast when i tap the trackable.
What i want is to know is to show the toast when it taps different textures and know which texture it tapped. In this case each texture is a Floor. Can you help me on this.

How to put multiple textures in one trackable image

August 20, 2013 - 1:35am #4

What i want is 8 textures to be displayed in different positions similarly. I could do that this way but i don't think it is the correct way. Is there an easier way to do it? 

Your code makes use of many hard-coded values for the position and scaling; you simply need to introduce some C++ variables to handle the different values more efficiently and avoid code bloat, but this is simply about C++ programming style, cannot really advise on this (and it is not relevant to Vuforia).

 

After this what i need to do it enlarge the texture to fullscreen when user taps it. I have successfully implemented the tap event by the help of this thread https://developer.vuforia.com/forum/android/how-get-tap-event-3d-model . Can you give me an idea how to do this

The texture can be enlarged by plaing with the scaling, pretty much as you are doing already in your code.

 

How to put multiple textures in one trackable image

August 19, 2013 - 8:51pm #3

I am new using vuforia here. Sorry for not formatting the code earlier. I have successfully displayed two textures when it detects one of the trackables by this code here.

This is the code in ImageTargets.cpp that does the trick in the 

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject)
 method

<pre class="brush: cpp">

        // This is the default code except the x and y axis has been changed
       SampleUtils::translatePoseMatrix(-40.0f, -35.0f, kObjectScale,
        	                                         &modelViewMatrix.data[0]);
        SampleUtils::scalePoseMatrix(targetSize.data[0]/8, targetSize.data[1]/12, 1.0f,
        	                                     &modelViewMatrix.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewMatrix.data[0] ,
                                    &modelViewProjection.data[0]);
        glUseProgram(shaderProgramID);

        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &planeVertices[0]);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &planeNormals[0]);
        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &planeTexcoords[0]);

        glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(textureCoordHandle);
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );
        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &planeIndices[0]);
///------------------------------Default code until here----------------------//

///---I copied the same thing resetting the modelView Matrix to draw another texture on top of the trackable---///
///--on a different position
        modelViewMatrix =
                    QCAR::Tool::convertPose2GLMatrix(result->getPose());

        SampleUtils::translatePoseMatrix(40, 0.0f, kObjectScale,
                                         &modelViewMatrix.data[0]);
        SampleUtils::scalePoseMatrix(targetSize.data[0]/8, targetSize.data[1]/12, 1.0f,
                                     &modelViewMatrix.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewMatrix.data[0] ,
                                    &modelViewProjection.data[0]);
        glUseProgram(shaderProgramID);

        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &planeVertices[0]);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &planeNormals[0]);
        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &planeTexcoords[0]);



        glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(textureCoordHandle);
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, thisTexture1->mTextureID);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );
        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &planeIndices[0]);

</pre>

What i want is 8 textures to be displayed in different positions similarly. I could do that this way but i don't think it is the correct way. Is there an easier way to do it? 

After this what i need to do it enlarge the texture to fullscreen when user taps it. I have successfully implemented the tap event by the help of this thread https://developer.vuforia.com/forum/android/how-get-tap-event-3d-model . Can you give me an idea how to do this

How to put multiple textures in one trackable image

August 1, 2013 - 8:22am #2

I am using this code to put a single texture in a trackable image. I have shrunk the texture and shifted it as i need it. i want to fit several more texture there

Slow down a bit and take a step back.

It is unclear to me what you are trying to do and why.  Please explain more clearly so that the code is actually meaningful.  Also please use the code formatting if at all possible.

 

thanks

N

Log in or register to post comments