Log in or register to post comments

Replace teapot sample with banana

April 9, 2016 - 2:57am #1

Hello.
As describe here:
http://heikobehrens.net/2009/08/27/obj2opengl/
I want to replace teapot with banana model in android studio,
everything is right but the IDE errors like this:
code too large
too many constant
I tryed with other 3d models but almost all of them are as large as banana model that seems to be large for android studio to edit.
Anyone has any suggustion?did you faced this problem when replacing teapot?

Thanks

Replace teapot sample with banana

March 7, 2018 - 7:12pm #5

Hi monkeyhanny, does this work with the Android SDK?

I don't think my project has ImageTargets.cpp, just ImageTargets.java. Is there somewhere I can add ImageTargets.cpp, or do I need to create a java version?

Replace teapot sample with banana

October 31, 2017 - 10:10am #4

Thank you for sharing your solution monkeyhanny!

Replace teapot sample with banana

October 31, 2017 - 9:02am #3

Hi both,

I've successfully replaced the teapot with banana, after you imported the banana.h file generated by obj2opengl.pl (http://heikobehrens.net/2009/08/27/obj2opengl/), add the following code to the ImageTargets.cpp:

#include "banana.h"

#include "SampleMath.h"

JNIEXPORT void JNICALL

Java_com_vuforia_samples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject){

    // Clear color and depth buffer

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // Render video background:

        Vuforia::State state = Vuforia::Renderer::getInstance().begin();

        glDisable(GL_TEXTURE_2D);

        glEnable(GL_DEPTH_TEST);

        glEnable(GL_CULL_FACE);

        Vuforia::Matrix44F mainModelViewMatrix;

        Vuforia::Vec3F targetCenters[2]; // make this big enough to hold all your targets



        int textureId;

        // Did we find any trackables this frame?

        for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)

        {

        // Get the trackable:

        const Vuforia::TrackableResult* result = state.getTrackableResult(tIdx);

        Vuforia::Matrix44F modelViewMatrix =

        Vuforia::Tool::convertPose2GLMatrix(result->getPose());

        if (tIdx == 0)

        {

            // Make the first visible target our world center (0, 0, 0)

            // Store its modelViewMatrix and continue looking for other targets

            mainModelViewMatrix = modelViewMatrix;

            targetCenters[0].data[0] = 0.0f;

            targetCenters[0].data[1] = 0.0f;

            targetCenters[0].data[2] = 0.0f;

        }

            else

            {

                // This is another visible target

                // Find its center point in relation to the first target

                // To do this we use the matrix inverse function (SampleMath.h from the

                //  Dominoes project)

                Vuforia::Matrix44F mainModelViewInverse = SampleMath::Matrix44FInverse

                (mainModelViewMatrix);

                Vuforia::Matrix44F modelViewTranspose = SampleMath::Matrix44FTranspose

                (modelViewMatrix); // let's work with row-major matrices

                Vuforia::Matrix44F offsetMatrix = Vuforia::Tool::multiply(mainModelViewInverse,

                modelViewTranspose);

                // Transform a point on the second target by this offset matrix

                // (0, 0, 0) is the local center of the target

                Vuforia::Vec4F position(0.0f, 0.0f, 0.0f, 1.0f);

                position = SampleMath::Vec4FTransform(position, offsetMatrix);

                // Add this position to our array

                targetCenters[1].data[0] = position.data[0];

                targetCenters[1].data[1] = position.data[1];

                targetCenters[1].data[2] = position.data[2];

            }

        }

        if (state.getNumTrackableResults() > 1)

        {



            Vuforia::Matrix44F modelViewProjection;

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

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

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

            glUseProgram(shaderProgramID);

            glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &noteVerts[0]);

           // glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &noteNormals[0]);

            glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &noteTexCoords[0]);

            glEnableVertexAttribArray (vertexHandle);

            //glEnableVertexAttribArray (normalHandle);

            glEnableVertexAttribArray (textureCoordHandle);

            glActiveTexture (GL_TEXTURE0);

            const Texture* const thisTexture = textures[0];

            glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);

            glDrawArrays(GL_TRIANGLES, 0, NUM_NOTE_OBJECT_VERTEX);

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



        }

        glDisable(GL_DEPTH_TEST);

        glEnable(GL_TEXTURE_2D);

        glDisableVertexAttribArray(vertexHandle);

        //glDisableVertexAttribArray(normalHandle);

        glDisableVertexAttribArray(textureCoordHandle);

        Vuforia::Renderer::getInstance().end();

sampleAppRenderer->renderFrame();

}

JNIEXPORT void JNICALL

Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_setProjectionMatrix(JNIEnv *, jobject)

{

    LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_setProjectionMatrix");

    // Cache the projection matrix:

    const Vuforia::CameraCalibration& cameraCalibration =

                                Vuforia::CameraDevice::getInstance().getCameraCalibration();

    projectionMatrix = Vuforia::Tool::getProjectionGL(cameraCalibration, 2.0f, 2000.0f);

}

 

 

Replace teapot sample with banana

October 23, 2017 - 8:28am #2

I have the same problem, did you find a solution for this problem?

 

Thanks

Log in or register to post comments