Log in or register to post comments

See the Code a bit, I adapted to display the model 2.

April 1, 2013 - 9:11am #1

I've adapted this code Link on which code I adapted as follows:

for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
	{
	        // Get the trackable:
	        const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
	        QCAR::Matrix44F modelViewMatrix =  QCAR::Tool::convertPose2GLMatrix(trackable->getPose());
	        QCAR::Matrix44F modelViewProjection;
	        SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]);
	        SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,  &modelViewMatrix.data[0]);
	        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],   &modelViewMatrix.data[0] ,  &modelViewProjection.data[0]);
	        glUseProgram(shaderProgramID);

	        if (strcmp(trackable->getName(), "custom") == 0)
	        {// if target is "chips" then we use nyancat mesh

	        	//// Banana
	        			glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
	        					bananaVerts);
	        			glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
	        					bananaNormals);
	        			glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
	        					bananaTexCoords);
	        			glEnableVertexAttribArray(vertexHandle);
	        			glEnableVertexAttribArray(normalHandle);
	        			glEnableVertexAttribArray(textureCoordHandle);

	        			LOG("enabled arrays!");

	        			glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
	        					(GLfloat*)&modelViewProjection.data[0] );
	        			glActiveTexture(GL_TEXTURE0);
	        			glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
	        			glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);
	        			//////////////
	        }


	       // etc ...
	}

When I put code to compile this Error occurred.

Compile++ arm    : ImageTargets <= ImageTargets.cpp
jni/ImageTargets.cpp: In function 'void Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv*, jobject)':
jni/ImageTargets.cpp:330:33: error: 'class QCAR::State' has no member named 'getNumActiveTrackables'
jni/ImageTargets.cpp:333:51: error: 'class QCAR::State' has no member named 'getActiveTrackable'
jni/ImageTargets.cpp:334:89: error: 'const class QCAR::Trackable' has no member named 'getPose'
jni/ImageTargets.cpp:360:42: error: 'thisTexture' was not declared in this scope
/cygdrive/c/Development/Android/android-ndk-r8e-windows-x86/android-ndk-r8e/build/core/build-binary.mk:272: recipe for target `obj/local/armeabi/objs/ImageTargets/ImageTargets.o' failed
make: *** [obj/local/armeabi/objs/ImageTargets/ImageTargets.o] Error 1

 

Advice, please? Don't know if I'm wrong code section adapted.
Thank you very much

See the Code a bit, I adapted to display the model 2.

April 3, 2013 - 4:41am #8

Reading your code:

the problem is that you are rendering both models using the same modelview matrix, but you actually need to change the modelview for each model because the scaling is different;

in particular, the banana model requires a scaling of 100 or so (see kObjectScale), while the teapot requires a scaling of about 3.0f.

So, this code must also be "duplicted", each time using a different value for kObjectScale:

QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());

QCAR::Matrix44F modelViewProjection;

SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]);

SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &modelViewMatrix.data[0]);

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

See the Code a bit, I adapted to display the model 2.

April 3, 2013 - 4:39am #7

Hi, you simply need to duplicate the OpenGL code inside the "for loop", i.e. for each target, you first render one mesh (using the related vertices, normals and textrue coordinates) and then the other mesh.

 

See the Code a bit, I adapted to display the model 2.

April 3, 2013 - 3:15am #6

dorankseo wrote:

AlessandroB wrote:

When you say "I want to make it show 2 model at the same time", what do you mean exactly ?

do you want to augment two different targets with two different models (showing them at the same time), or do you want to see 2 models on top of the same marker ?

 

 

I want to see 2 models on top of the same marker 

 

thanks

 

helps me please

See the Code a bit, I adapted to display the model 2.

April 2, 2013 - 8:40am #5

AlessandroB wrote:

When you say "I want to make it show 2 model at the same time", what do you mean exactly ?

do you want to augment two different targets with two different models (showing them at the same time), or do you want to see 2 models on top of the same marker ?

 

 

I want to see 2 models on top of the same marker 

 

thanks

See the Code a bit, I adapted to display the model 2.

April 2, 2013 - 8:38am #4

When you say "I want to make it show 2 model at the same time", what do you mean exactly ?

do you want to augment two different targets with two different models (showing them at the same time), or do you want to see 2 models on top of the same marker ?

 

See the Code a bit, I adapted to display the model 2.

April 2, 2013 - 8:17am #3

AlessandroB wrote:

Hi,

that code still refers to the 1.5 API, so you need to adjust the first part of your code as follows:

 

for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
    {
        // Get the trackable:
        const QCAR::TrackableResult* result = state.getTrackableResult(tIdx);
        const QCAR::Trackable& trackable = result->getTrackable();
        QCAR::Matrix44F modelViewMatrix =
            QCAR::Tool::convertPose2GLMatrix(result->getPose());        
 
Also, you need to replace trackable->getName() with trackable.getName()
 
 

 

Thank you very much Now how do I make it show up and then the number 1

if I want to display model 1 model. I would like to adapt this code than I do?

for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
	{
		// Get the trackable:
		const QCAR::TrackableResult* result = state.getTrackableResult(tIdx);
		const QCAR::Trackable& trackable = result->getTrackable();
		QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());
		QCAR::Matrix44F modelViewProjection;
		SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]);
		SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &modelViewMatrix.data[0]);
		SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix.data[0] , &modelViewProjection.data[0]);
		glUseProgram(shaderProgramID);
		int textureIndex;
		int textureIndex2;
		if (strcmp(trackable.getName(), "custom") == 0)
		{	// if target is "chips" then we use nyancat mesh
			//// Banana
			textureIndex = 0;
			const Texture* const thisTexture = textures[textureIndex];
			glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
					bananaVerts);
			glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
					bananaNormals);
			glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
					bananaTexCoords);
			glEnableVertexAttribArray(vertexHandle);
			glEnableVertexAttribArray(normalHandle);
			glEnableVertexAttribArray(textureCoordHandle);

			LOG("enabled arrays!");

			glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
					(GLfloat*)&modelViewProjection.data[0] );
			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
			glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);
			//////////////

			glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
					(const GLvoid*) &teapotVertices[0]);
			glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
					(const GLvoid*) &teapotNormals[0]);
			glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
					(const GLvoid*) &teapotTexCoords[0]);

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

			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, 1);
			glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
			glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
					(GLfloat*)&modelViewProjection.data[0] );
			glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
					(const GLvoid*) &teapotIndices[0]);
			//////////////
		}

		// etc ...
	}

But I put this code, it will show only 1 model. I want to make it show 2 model at the same time. What should I do thank you!

See the Code a bit, I adapted to display the model 2.

April 2, 2013 - 4:54am #2

Hi,

that code still refers to the 1.5 API, so you need to adjust the first part of your code as follows:

 

for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
    {
        // Get the trackable:
        const QCAR::TrackableResult* result = state.getTrackableResult(tIdx);
        const QCAR::Trackable& trackable = result->getTrackable();
        QCAR::Matrix44F modelViewMatrix =
            QCAR::Tool::convertPose2GLMatrix(result->getPose());        
 
Also, you need to replace trackable->getName() with trackable.getName()
 
 
Log in or register to post comments