コード例 #1
0
ファイル: Vistroller.cpp プロジェクト: ronhuang/vistroller
JNIEXPORT jobject JNICALL
Java_org_ronhuang_vistroller_Vistroller_getMarker(JNIEnv *env, jobject)
{
    //LOG("Java_org_ronhuang_vistroller_Vistroller_getMarker");

    jobject result = NULL;

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

    for (int i = 0; i < state.getNumActiveTrackables(); i++) {
        const QCAR::Trackable *trackable = state.getActiveTrackable(i);
        assert(trackable->getType() == QCAR::Trackable::MARKER);
        const QCAR::Marker *marker = static_cast<const QCAR::Marker*>(trackable);

        result = newMarker(env, marker->getMarkerId(), marker->getPose().data, marker->getSize().data);
        break; // FIXME: return only the first one for now.
    }

    if (NULL == result) {
        // Make sure always return an instance of Trackable.
        // Return invalid one.
        float pose[3 * 4] = {
            0, 0, 0, 0,
            0, 0, 0, 0,
            0, 0, 0, 0
        };
        float size[2] = {0, 0};
        result = newMarker(env, -1, pose, size);
    }

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

    return result;
}
コード例 #2
0
ファイル: ImageTargets.cpp プロジェクト: Alice-/CVL
// Just returns 1 for OpenGLEs 1.1 and 2 for other
JNIEXPORT bool JNICALL
Java_edu_ethz_s3d_S3D_hasTarget(JNIEnv *, jobject)
{
	// Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();

    return (state.getNumActiveTrackables() > 0);
}
コード例 #3
0
ファイル: Dominoes.cpp プロジェクト: Kajo0/pdi1-tests
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_Dominoes_DominoesRenderer_renderFrame(JNIEnv* , jobject)
{
    // Clear the color and depth buffers
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    
    // Explicitly render the Video Background
    QCAR::Renderer::getInstance().drawVideoBackground();
    
    // to no to hide
	std::vector<const char*> found;

    // Did we find any trackables this frame?
    if (state.getNumTrackableResults() > 0) {

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

			// Get the first trackable
			const QCAR::TrackableResult* trackableResult = state.getTrackableResult(tIdx);
			const QCAR::Trackable& trackable = trackableResult->getTrackable();

			found.push_back(trackable.getName());

			// The image target specific result:
			assert(trackableResult->getType() == QCAR::TrackableResult::IMAGE_TARGET_RESULT);
			const QCAR::ImageTargetResult* imageTargetResult =
				static_cast<const QCAR::ImageTargetResult*>(trackableResult);

			// If this is our first time seeing the target, display a tip
			if (!displayedMessage) {
				displayMessage("Find marker man!");
				displayedMessage = true;
			}


			//const QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
			//const QCAR::Tracker* tracker = trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER);
			const QCAR::CameraCalibration& cameraCalibration = QCAR::CameraDevice::getInstance().getCameraCalibration();

			QCAR::Vec2F cameraPoint = QCAR::Tool::projectPoint(cameraCalibration, trackableResult->getPose(), QCAR::Vec3F(0,0,0));
			QCAR::Vec2F xyPoint = cameraPointToScreenPoint(cameraPoint);

			showTrackerButton(xyPoint.data[0], xyPoint.data[1], trackable.getName());

		}

    } else {
    	hideTrackerButton(found);
    }
    
    QCAR::Renderer::getInstance().end();
}
コード例 #4
0
ファイル: EasyQCAR.cpp プロジェクト: Josiastech/EasyQCAR
JNIEXPORT int JNICALL
Java_com_robopeak_EasyQCAR_EasyQCAR_getNumActiveTrackables(JNIEnv *, jobject)
{
    if (qcar_begun)
        return g_state.getNumActiveTrackables();
    else
        return 0;
}
コード例 #5
0
ファイル: EasyQCAR.cpp プロジェクト: Josiastech/EasyQCAR
JNIEXPORT jstring JNICALL
Java_com_robopeak_EasyQCAR_EasyQCAR_getName(JNIEnv* env, jobject, jint tIdx)
{
    if (!qcar_begun)
        return NULL;
    const QCAR::Trackable* trackable = g_state.getActiveTrackable(tIdx);
    const char* name = trackable->getName();
    return env->NewStringUTF(name);
}
コード例 #6
0
ファイル: EasyQCAR.cpp プロジェクト: Josiastech/EasyQCAR
JNIEXPORT jfloatArray JNICALL
Java_com_robopeak_EasyQCAR_EasyQCAR_getModelViewMatrix(JNIEnv* env, jobject, jint tIdx)
{
    if (!qcar_begun)
        return NULL;
    const QCAR::Trackable* trackable = g_state.getActiveTrackable(tIdx);
    QCAR::Matrix44F modelViewMatrix =
        QCAR::Tool::convertPose2GLMatrix(trackable->getPose());
    jfloatArray array = env->NewFloatArray(MAT_SIZE);
    env->SetFloatArrayRegion(array, 0, MAT_SIZE, modelViewMatrix.data);
    return array;
}
コード例 #7
0
    virtual void QCAR_onUpdate(QCAR::State& state)
    {

    	//from
        //https://developer.vuforia.com/forum/faq/android-how-can-i-access-camera-image

    	QCAR::Image *imageRGB565 = NULL;
        QCAR::Frame frame = state.getFrame();

        for (int i = 0; i < frame.getNumImages(); ++i) {
              const QCAR::Image *image = frame.getImage(i);
              if (image->getFormat() == QCAR::RGB565) {
                  imageRGB565 = (QCAR::Image*)image;

                  break;
              }
        }

        if (imageRGB565) {
            JNIEnv* env = 0;

            if ((javaVM != 0) && (activityObj != 0) && (javaVM->GetEnv((void**)&env, JNI_VERSION_1_4) == JNI_OK)) {

                const short* pixels = (const short*) imageRGB565->getPixels();
                int width = imageRGB565->getWidth();
                int height = imageRGB565->getHeight();
                int numPixels = width * height;


               // LOG("Update video image...");

                jbyteArray pixelArray = env->NewByteArray(numPixels * 2);
                env->SetByteArrayRegion(pixelArray, 0, numPixels * 2, (const jbyte*) pixels);


                jclass javaClass = env->GetObjectClass(activityObj);
                jmethodID method = env-> GetMethodID(javaClass, "setRGB565CameraImage", "([BII)V");
                env->CallVoidMethod(activityObj, method, pixelArray, width, height);

                env->DeleteLocalRef(pixelArray);


            }
        }

    }
コード例 #8
0
ファイル: ImageTargets.cpp プロジェクト: UPS-CS240-F12/mobile
JNIEXPORT void JNICALL
Java_edu_pugetsound_vichar_ar_ARGameRenderer_renderFrame(JNIEnv * env, jobject obj, jboolean updated, jfloatArray test, jint objSize)
{
	bool update;
	update = (bool) updated; //so we know whether or not to update the drawlist.
	float testScale = 0.3f;

	// here is an example of how to pull the elements out of the jfloatArray. I think c++ will implicitly handle the type casting of jfloats as floats,
	// but if you are getting errors, you can always explicitly type cast them like so (assuming you have jfloats in the array):
	// float x;
	// x = (float) posData[i];
	
	if(update){
		int i = 0;
		int j = 0;
		jsize len = env->GetArrayLength(test);
		jfloat* posData = env->GetFloatArrayElements(test, 0);
		while(i<len && posData[(i/objSize)*objSize] != 0){
			LOG("JSON to JNI test. Pos. %d : %f", i, posData[i]); //print the elements of the array.
			interpList[i/objSize][i%objSize]= (float) posData[i] * testScale;
			i++;
		}
		interpLength=(i)/objSize;
		LOG("%i", interpLength);
		env->ReleaseFloatArrayElements(test, posData, 0); //release memory
	}

    //LOG("Java_edu_pugetsound_vichar_ar_GLRenderer_renderFrame");
    // Clear color and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();

    // Explicitly render the Video Background
    QCAR::Renderer::getInstance().drawVideoBackground();

#ifdef USE_OPENGL_ES_1_1
    // Set GL11 flags:
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);

#endif

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    // Did we find any trackables this frame?
    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());

//Begin additions by Erin================================================================================
        QCAR::Matrix34F test;   //gets inverse pos matrix
        QCAR::Matrix34F pos;   //Gets positional data
        pos = trackable->getPose();

        //Get inverse
        test = SampleMath::phoneCoorMatrix(trackable->getPose());

        //Print results
//        LOG("Poisiton:");
//        LOG("%f %f %f %f",pos.data[0], pos.data[1], pos.data[2], pos.data[3]);
//        LOG("%f %f %f %f",pos.data[4], pos.data[5], pos.data[6], pos.data[7]);
//        LOG("%f %f %f %f",pos.data[8], pos.data[9], pos.data[10],pos.data[11]);
//        LOG("Inverse:");
//        LOG("%f %f %f %f",test.data[0], test.data[1], test.data[2], test.data[3]);
//        LOG("%f %f %f %f",test.data[4], test.data[5], test.data[6], test.data[7]);
//        LOG("%f %f %f %f",test.data[8], test.data[9], test.data[10], test.data[11]);
//        LOG("=========================");
        phoneLoc[0] = 1.0f;
        phoneLoc[1] = test.data[3];
        phoneLoc[2] = test.data[7];
        phoneLoc[3] = test.data[11];
//End============================================================================================

        // Assign Textures according in the texture indices defined at the beginning of the file, and based
        // on the loadTextures() method in ARGameActivity.java.


        const Texture* const tower_shellTexture = textures[tower_shellIndex];
        const Texture* const tower_topTexture = textures[tower_topIndex];
        const Texture* const bananaTexture = textures[banana180Index];

#ifdef USE_OPENGL_ES_1_1
        // Load projection matrix:
        glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(projectionMatrix.data);

        // Load model view matrix:
        glMatrixMode(GL_MODELVIEW);
        glLoadMatrixf(modelViewMatrix.data);
        glTranslatef(0.f, 0.f, kObjectScale);
        glScalef(kObjectScale, kObjectScale, kObjectScale);

        // Draw object:
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &teapotTexCoords[0]);
        glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &teapotVertices[0]);
        glNormalPointer(GL_FLOAT, 0,  (const GLvoid*) &teapotNormals[0]);
        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &teapotIndices[0]);
#else
		/* MATRIX GUIDE
		ModelViewMatrix = starting point matrix, with no mods is the center of the image target.
		Is only modified when not using Prefab transforms

		ObjectMatrix = ModelViewMatrix * transform matrix(in the case of prefab transforms)
		OR
		ObjectMatrix = ModelViewMatrix with all transforms performed.

		ProjectionMatrix = Is set utilizing a method in this class, when called by the Java. Is not modified by
		drawing process.

		ModelViewProjection = (w/ prefab transforms) ObjectMatrix * Projection
		ModelViewProjection = (w/o prefab transforms) Modified ModelViewMatrix * Projection
		*/


		drawCount=0;
		//Get List of Objects to Draw
		//obtain list of objects to draw -- fills drawList.
		updateDrawList();

		//Get modelViewMatrix
		modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

		//Initialize intermediate and final Matricies
		//Intermediate matrix used only in multiplying using the transform matrix
		QCAR::Matrix44F objectMatrix;

		//The final matrix that is used to draw
		QCAR::Matrix44F modelViewProjection;

        glUseProgram(shaderProgramID);

		
		// Render the models
		for (int i = 0; i < drawCount; i++) {

			//Need to figure out which textures/verticies/etc to use here, currently hardcoded to turrets
			
			//Reinitalize ModelViewMatrix to its initialstate, as at this point it gets modified.
			modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

			//Loads the current model from the drawList
			Model* model = &drawList[i];

			//LOG("%i%i",i,drawCount);


			//These Lines used only for prefab transforms
			//QCAR::Matrix44F transform;
			//float* transform=&model->transform.data[0];
			
			//Test Prints to ensure data was being stored correctly
			//LOG("OBJECT ID:");
			//LOG("%i",model->id);
			

			//Verts,norms,texcords assigned here -- Is currently hardcoded to turret coords
			glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
								 (const GLvoid*) &tower_topVerts[0]);
			glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
								  (const GLvoid*) &tower_topNormals[0]);
			glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
								  (const GLvoid*) &tower_topTexCoords[0]);


			//NON-HARDCODED VERSION
			/*
			glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
								 (const GLvoid*) &model->&vertPointer);
			glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
								  (const GLvoid*) &model->&normalPointer);
			glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
								  (const GLvoid*) &model->&texPointer);
			*/
		
			//Open GL initialization
			glEnableVertexAttribArray(vertexHandle);
			glEnableVertexAttribArray(normalHandle);
			glEnableVertexAttribArray(textureCoordHandle);


			//Prep Transforms
			float* position=&model->pos[0];
			float* angle=&model->ang[0];

			//LOG("%f%f%f",position[0],position[1],position[2]);

			//Begin Transforms
			//BE WARY OF GETTING RID OR ADDING KObject SCALE
			SampleUtils::translatePoseMatrix(position[0], position[1], kObjectScale + position[2],
										&modelViewMatrix.data[0]);
			// So the tower_top appears upright
			SampleUtils::rotatePoseMatrix(90.0f + angle[0], 1.0f, 0.0f, 0.0f,
                        				&modelViewMatrix.data[0]);
			SampleUtils::rotatePoseMatrix(angle[1], 0.0f, 1.0f, 0.0f,
                        				&modelViewMatrix.data[0]);
			SampleUtils::rotatePoseMatrix(angle[2], 0.0f, 0.0f, 1.0f,
										&modelViewMatrix.data[0]);
			SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
										&modelViewMatrix.data[0]);

			//Combine projectionMatrix and modelViewMatrix to create final modelViewProejctionMatrix
			SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
										&modelViewMatrix.data[0] ,
										&modelViewProjection.data[0]);

			
			//attempt to use stored transform matrix
			//SampleUtils::multiplyMatrix(&modelViewMatrix.data[0], transform, &objectMatrix.data[0]);
			//SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &objectMatrix.data[0], &modelViewProjection.data[0]);
			//glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjection.data[0]);

			//Assign and bind texture -- once again this is hard coded to turrets
			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, tower_topTexture->mTextureID);


			//un-hardcoding
			//glBindTexture(GL_TEXTURE_2D, model->&texturePointer->mTextureID);

			//apply modelViewProjectionMatrix
			glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
							   (GLfloat*)&modelViewProjection.data[0] );
			//Draw -- hardcoded to turret
			glDrawArrays(GL_TRIANGLES, 0, tower_topNumVerts);

			//Un-hardcoding
			//glDrawArrays(GL_TRIANGLES, 0, model->&NumVerts);
			
			//Unused method that previous attempted to draw.
			//renderModel(&model->transform.data[0]);
			}

		//Output given after every frame is fully rendered
//		LOG("Render Frame Complete");
		 
        SampleUtils::checkGlError("ImageTargets renderFrame");

#endif

    }

    glDisable(GL_DEPTH_TEST);

#ifdef USE_OPENGL_ES_1_1
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
	//Deinit Open GL
    glDisableVertexAttribArray(vertexHandle);
    glDisableVertexAttribArray(normalHandle);
    glDisableVertexAttribArray(textureCoordHandle);
#endif
	//END
    QCAR::Renderer::getInstance().end();
}
コード例 #9
0
ファイル: TextReco.cpp プロジェクト: varunkumar/aRed
JNIEXPORT void JNICALL
Java_com_codered_ared_TextRecoRenderer_renderFrame(JNIEnv * env, jobject obj)
{
    //LOG("JJava_com_codered_ared_TextRecoRenderer_renderFrame");

    // Clear color and depth buffer 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    
    // Explicitly render the Video Background
    QCAR::Renderer::getInstance().drawVideoBackground();

    glEnable(GL_DEPTH_TEST);

    // We need Front Face, CW for the back camera and Front Face CCW for the front camera...
    // or more accuratly, we need CW for 0 and 2 reflections and CCW for 1 reflection
    glEnable(GL_CULL_FACE);
    glCullFace(GL_FRONT);
    if(QCAR::Renderer::getInstance().getVideoBackgroundConfig().mReflection == QCAR::VIDEO_BACKGROUND_REFLECTION_ON)
    {
        glFrontFace(GL_CCW);  //Front camera
    }
    else
    {
        glFrontFace(GL_CW);   //Back camera
    }

    // Enable blending to support transparency
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    jclass rendererJavaClass = env->GetObjectClass(obj);

    env->CallVoidMethod(obj, env->GetMethodID(rendererJavaClass, "wordsStartLoop", "()V"));

    NbWordsFound = 0;

    // Did we find any trackables this frame?
    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::Vec2F wordBoxSize(0, 0);

        if (result->getType() == QCAR::TrackableResult::WORD_RESULT)
        {
            const QCAR::WordResult* wordResult = (const QCAR::WordResult*) result;
            // Get the word
            const QCAR::Word& word = wordResult->getTrackable();
            const QCAR::Obb2D& obb = wordResult->getObb();
            wordBoxSize = word.getSize();

            if (word.getStringU())
            {
                // in portrait, the obb coordinate is based on
                // a 0,0 position being in the upper right corner
                // with :
                // X growing from top to bottom and
                // Y growing from right to left
                //
                // we convert those coordinates to be more natural
                // with our application:
                // - 0,0 is the upper left corner
                // - X grows from left to right
                // - Y grows from top to bottom
                float wordx = - obb.getCenter().data[1];
                float wordy = obb.getCenter().data[0];

                // For debugging purposes convert the string to 7bit ASCII
                // (if possible) and log it.
                char* stringA = 0;
                if (unicodeToAscii(word, stringA))
                {
                    // we store the word
                    if (NbWordsFound < MAX_NB_WORDS)
                    {
                        struct WordDesc * word =  & WordsFound[NbWordsFound];
                        NbWordsFound++;
                        strncpy(word->text, stringA, MAX_WORD_LENGTH - 1);
                        word->text[MAX_WORD_LENGTH - 1] = '\0';
                        word->Ax = wordx - (int)(wordBoxSize.data[0] / 2);
                        word->Ay = wordy - (int)(wordBoxSize.data[1] / 2);
                        word->Bx = wordx + (int)(wordBoxSize.data[0] / 2);
                        word->By = wordy + (int)(wordBoxSize.data[1] / 2);
                    }

                    delete[] stringA;
                }
            }
        }
        else
        {
            LOG("Unexpected detection:%d", result->getType());
            continue;
        }

        QCAR::Matrix44F modelViewProjection;

        SampleUtils::translatePoseMatrix(0.0f, 0.0f, 0.0f,
                                         &modelViewMatrix.data[0]);
        SampleUtils::scalePoseMatrix(wordBoxSize.data[0] + TEXTBOX_PADDING, wordBoxSize.data[1] + TEXTBOX_PADDING, 1.0f,
                                     &modelViewMatrix.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewMatrix.data[0] ,
                                    &modelViewProjection.data[0]);

        glUseProgram(lineShaderProgramID);
        glLineWidth(3.0f);

        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &quadVertices[0]);
        
        glEnableVertexAttribArray(vertexHandle);
        
        glUniform1f(lineOpacityHandle, 1.0f);
        // FF7200
        glUniform3f(lineColorHandle, 1.0f, 0.447f, 0.0f);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );

        glDrawElements(GL_LINES, NUM_QUAD_OBJECT_INDICES, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &quadIndices[0]);

        // Disable the vertex array handle
        glDisableVertexAttribArray(vertexHandle);

        // Restore default line width
        glLineWidth(1.0f);

        // Unbind shader program
        glUseProgram(0);
    }

    if (NbWordsFound > 0)
    {
        jmethodID method = env->GetMethodID(rendererJavaClass, "addWord", "(Ljava/lang/String;)V");

        // we order the words per line and left to right
        qsort(& WordsFound[0], NbWordsFound, sizeof(struct WordDesc), wordDescCompare);
        for(int i = 0 ; i < NbWordsFound ; i++)
        {
            struct WordDesc * word =  & WordsFound[i];
            jstring js = env->NewStringUTF(word->text);
            env->CallVoidMethod(obj, method, js);
        }
    }

    env->CallVoidMethod(obj, env->GetMethodID(rendererJavaClass, "wordsEndLoop", "()V"));


    SampleUtils::checkGlError("TextReco renderFrame - words post-render");

    glDisable(GL_DEPTH_TEST);

    drawRegionOfInterest(ROICenterX, ROICenterY, ROIWidth, ROIHeight);

    // Disable blending (restore default state)
    glDisable(GL_BLEND);

    SampleUtils::checkGlError("TextReco renderFrame - post-drawROI");

    QCAR::Renderer::getInstance().end();
}
コード例 #10
0
ファイル: SupaStriker.cpp プロジェクト: oladipo/SupaStrika
JNIEXPORT void JNICALL
Java_com_tvc_supastriker_SupaStrikerRenderer_renderFrame(JNIEnv* env, jobject obj){

	LOG("Java_com_tvc_supastriker_SupaStrikerRenderer_renderFrame");

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

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

	QCAR::Renderer::getInstance().drawVideoBackground();

#ifdef USE_OPENGL_ES_1_1
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glEnable(GL_TEXTURE_2D);
	//glDisable(GL_LIGHTING);
	glEnable(GL_LIGHTING);
#endif

	glEnable(GL_DEPTH_TEST);
	//glEnable(GL_CULL_FACE);
	glDisable(GL_CULL_FACE);
	glCullFace(GL_BACK);

	if(QCAR::Renderer::getInstance().getVideoBackgroundConfig().mReflection == QCAR::VIDEO_BACKGROUND_REFLECTION_ON)
		glFrontFace(GL_CCW);
	else
		glFrontFace(GL_CCW);

	for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++){
		const QCAR::TrackableResult* result = state.getTrackableResult(tIdx);
		const QCAR::Trackable& trackable = result->getTrackable();
		QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());

		int textureIndex;
		if(strcmp(trackable.getName(), "SupaStrika") == 0){
			textureIndex = 0;
		}

		const Texture* const thisTexture = textures[textureIndex];

#ifdef USE_OPENGL_ES_1_1
		//load projection matrix
		glMatrixMode(GL_PROJECTION);
		glLoadMatrixf(projectionMatrix.data);

		//load model view matrix
		glMatrixMode(GL_MODELVIEW);

		glLoadMatrixf(modelViewMatrix.data);
		glTranslatef(0.f, 0.f, kObjectScale);
		glScalef(kObjectScale, kObjectScale, kObjectScale);

		//draw object
		glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
		glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &teapotTexCoords[0]);
		glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &teapotVertices[0]);
		glNormalPointer(GL_FLOAT, 0, (const GLvoid*) &teapotNormals[0]);
		//glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
		//		(const GLvoid*) &teapotIndices[0]);
		glDrawArrays(GL_TRIANGLES, 0, NUM_TEAPOT_OBJECT_VERTEX);
#else
		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);
		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, thisTexture->mTextureID);
		glUniform1i(texSampler2DHandle, 0);
		glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
				(GLfloat*) &modelViewProjection.data[0]);
		glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
				(const GLvoid*) &teapotIndices[0]);
		SampleUtils::checkGlError("SupaStriker renderFrame");
#endif
	}

	glDisable(GL_DEPTH_TEST);

#ifdef USE_OPENGL_ES_1_1
	glDisable(GL_TEXTURE_2D);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

#else
    glDisableVertexAttribArray(vertexHandle);
    glDisableVertexAttribArray(normalHandle);
    glDisableVertexAttribArray(textureCoordHandle);
#endif
    QCAR::Renderer::getInstance().end();
}
コード例 #11
0
ファイル: ImageTargets.cpp プロジェクト: Josiastech/EasyQCAR
JNIEXPORT jboolean JNICALL
Java_com_snda_sdar_ImageTargetsRenderer_renderFrame(JNIEnv *env, jobject obj)
{
	//LOG("Java_com_snda_sdar_ImageTargets_GLRenderer_renderFrame");

	// Clear color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	jboolean isDetected = false;

	// Render video background:
	QCAR::State state = QCAR::Renderer::getInstance().begin();

	// Explicitly render the Video Background
	QCAR::Renderer::getInstance().drawVideoBackground();

#ifdef USE_OPENGL_ES_1_1
	// Set GL11 flags:
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glEnable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);

#endif

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);

	// Did we find any trackables this frame?
	for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
	{
		isDetected = true;

		// Get the trackable:
		const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
		QCAR::Matrix44F modelViewMatrix =
		QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

		// Choose the texture based on the target name:
		//int textureIndex = (!strcmp(trackable->getName(), "stones")) ? 0 : 1;

		const Texture* const thisTexture = textures[textureIndex];
		const Texture* const tagTexture = textures[textureCount - 1];

#ifdef USE_OPENGL_ES_1_1
		// Load projection matrix:
		glMatrixMode(GL_PROJECTION);
		glLoadMatrixf(projectionMatrix.data);

		// Load model view matrix:
		glMatrixMode(GL_MODELVIEW);
		glLoadMatrixf(modelViewMatrix.data);
		glTranslatef(0.f, 0.f, kObjectScale);
		glScalef(kObjectScale, kObjectScale, kObjectScale);

		// Draw object:
		glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
		glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &planeTexCoords[0]);
		glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &planeVertices[0]);
		glNormalPointer(GL_FLOAT, 0, (const GLvoid*) &planeNormals[0]);
		glDrawElements(GL_TRIANGLES, NUM_PLANE_OBJECT_INDEX, GL_UNSIGNED_SHORT,
				(const GLvoid*) &planeIndices[0]);

		//		// Load model view matrix:
		//		glMatrixMode(GL_MODELVIEW);
		//		glLoadMatrixf(modelViewMatrix.data);
		//		glTranslatef(50.f, 50.f, kObjectScale);
		//		glScalef(1, 1, 1);
		//
		//		// Draw object:
		//		glBindTexture(GL_TEXTURE_2D, tagTexture->mTextureID);
		//		glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &planeTexCoords[0]);
		//		glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &planeVertices[0]);
		//		glNormalPointer(GL_FLOAT, 0, (const GLvoid*) &planeNormals[0]);
		//		glDrawElements(GL_TRIANGLES, NUM_PLANE_OBJECT_INDEX, GL_UNSIGNED_SHORT,
		//				(const GLvoid*) &planeIndices[0]);
#else

		QCAR::Matrix44F modelViewMatrix2;

		for (int i = 0; i < 16; i++)
		{
			modelViewMatrix2.data[i] = modelViewMatrix.data[i];
		}

		QCAR::Matrix44F modelViewProjection;
		QCAR::Matrix44F modelViewProjection2;

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

		SampleUtils::rotatePoseMatrix(angleX, 0, 1, 0,
				&modelViewMatrix.data[0]);
		SampleUtils::rotatePoseMatrix(angleY, 1, 0, 0,
				&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, NUM_PLANE_OBJECT_INDEX, GL_UNSIGNED_SHORT,
				(const GLvoid*) &planeIndices[0]);

		/////////////////////////////////////////////////////////////////////////////

		SampleUtils::translatePoseMatrix(50, 50, kObjectScale,
				&modelViewMatrix2.data[0]);
		SampleUtils::scalePoseMatrix(1, 1, 1,
				&modelViewMatrix2.data[0]);

		SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
				&modelViewMatrix2.data[0] ,
				&modelViewProjection2.data[0]);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, tagTexture->mTextureID);
		glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
				(GLfloat*)&modelViewProjection2.data[0] );
		glDrawElements(GL_TRIANGLES, NUM_PLANE_OBJECT_INDEX, GL_UNSIGNED_SHORT,
				(const GLvoid*) &planeIndices[0]);

		jclass renderClass = env->GetObjectClass(obj);

		jmethodID screenPointMethodId = env->GetMethodID(renderClass , "screenPoint", "(FF)V");
		if (!screenPointMethodId)
		{
			LOG("Function screenPoint(float, float) not found.");
			return 0;
		}

		const QCAR::CameraCalibration& cameraCalibration =
		QCAR::CameraDevice::getInstance().getCameraCalibration();
		QCAR::Vec2F cameraPoint = QCAR::Tool::projectPoint(cameraCalibration, trackable->getPose(), QCAR::Vec3F(0, 0, 0));

		QCAR::Vec2F screenPoint = cameraPointToScreenPoint(cameraPoint, true);

		env->CallObjectMethod(obj, screenPointMethodId, screenPoint.data[0], screenPoint.data[1]);

		SampleUtils::checkGlError("ImageTargets renderFrame");
#endif

	}

	glDisable(GL_DEPTH_TEST);

#ifdef USE_OPENGL_ES_1_1        
	glDisable(GL_TEXTURE_2D);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
	glDisableVertexAttribArray(vertexHandle);
	glDisableVertexAttribArray(normalHandle);
	glDisableVertexAttribArray(textureCoordHandle);
#endif

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

	return isDetected;
}
コード例 #12
0
JNIEXPORT void JNICALL
Java_name_nailgun_irrlichtvuforia_Renderer_renderFrame(JNIEnv *, jobject)
{
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    QCAR::Renderer::getInstance().drawVideoBackground();
       
#ifndef DONT_SAVE_STATE
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);

    glEnable(GL_DEPTH_TEST);
    //glEnable(GL_CULL_FACE);
#endif

    // Did we find any trackables this frame?
    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());        

        // Choose the texture based on the target name:
        int textureIndex;
        if (strcmp(trackable->getName(), "chips") == 0)
        {
            textureIndex = 0;
        }
        else if (strcmp(trackable->getName(), "stones") == 0)
        {
            textureIndex = 1;
        }
        else
        {
            textureIndex = 2;
        }

        if (!mDevice->run()) {
            // TODO: error
        }

        irr::core::matrix4& cameraMatrix = mTransformationNode->getRelativeTransformationMatrix();
        cameraMatrix.setM(modelViewMatrix.data);

        mDriver->beginScene(false, true);
        mSceneManager->drawAll();
        mDriver->endScene();
    }

#ifndef DONT_SAVE_STATE        
    glDisable(GL_DEPTH_TEST);

    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#endif

    QCAR::Renderer::getInstance().end();
}
コード例 #13
0
ファイル: ImageTargets.cpp プロジェクト: Alice-/CVL
// Does all the rendering stuff
JNIEXPORT void JNICALL
Java_edu_ethz_s3d_S3DRenderer_renderFrame(JNIEnv *, jobject)
{
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);

    // Clear color and depth buffer 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    
    // Explicitly render the Video Background
    QCAR::Renderer::getInstance().drawVideoBackground();
       
#ifdef USE_OPENGL_ES_1_1
    // Set GL11 flags:
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);
        
#endif

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    // TODO: Only work, when there is exactly one trackable
    // Did we find any trackables this frame?
    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());

        // Choose the texture based on the target name:
        int textureIndex;
        if (strcmp(trackable->getName(), "chips") == 0)
        {
            textureIndex = 0;
        }
        else if (strcmp(trackable->getName(), "stones") == 0)
        {
            textureIndex = 1;
        }
        else
        {
            textureIndex = 2;
        }

        const Texture* const thisTexture = textures[textureIndex];

#ifdef USE_OPENGL_ES_1_1
        // Load projection matrix:
        glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(projectionMatrix.data);

        // Load model view matrix:
        glMatrixMode(GL_MODELVIEW);
        glLoadMatrixf(modelViewMatrix.data);
        glTranslatef(0.f, 0.f, kObjectScale);
        glScalef(kObjectScale, kObjectScale, kObjectScale);

        // Draw object:
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &teapotTexCoords[0]);
        glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &teapotVertices[0]);
        glNormalPointer(GL_FLOAT, 0,  (const GLvoid*) &teapotNormals[0]);
        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &teapotIndices[0]);
#else

        // Calculate the projection matrix
        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]);

        // Calculate the camera position
        QCAR::Matrix44F inverseModelView = SampleMath::Matrix44FTranspose(SampleMath::Matrix44FInverse(modelViewMatrix));
        QCAR::Vec3F cameraPosition(inverseModelView.data[12], inverseModelView.data[13], inverseModelView.data[14]);

        // Select the shader program
        glUseProgram(shaderProgramID);

        // Load the vertex attributes
        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotVertices[0]);
        glVertexAttribPointer(vertexColorHandle,3,GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &color[0]);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotNormals[0]);

        // Enable the vertex attributes
        glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(vertexColorHandle);
        
        // Load the reconstruction data
        if (reconstructionHandler != NULL) {
        	// First delete the old texture
        	glDeleteTextures(1, &texId);
        	// Load the reconstruction texture and its corresponding data
        	texId = reconstructionHandler->getTexture();
            float slices[2] = { reconstructionHandler->getOverX(), reconstructionHandler->getOVerY() };
            glUniform2fv(glGetUniformLocation(shaderProgramID, "slicesOver"), 1, (const GLfloat*) slices);
            glUniform1f(glGetUniformLocation(shaderProgramID, "numberOfSlices"), reconstructionHandler->getNSlices());
        }
        else {
        	// Load the texture specifications for the white texture
            float slices[2] = { 2.f, 1.f };
            glUniform2fv(glGetUniformLocation(shaderProgramID, "slicesOver"), 1, (const GLfloat*) slices);
            glUniform1f(glGetUniformLocation(shaderProgramID, "numberOfSlices"), 2);
        }

        // Load the eye position into the shader program
        glUniform3fv(glGetUniformLocation(shaderProgramID, "eyePos"), 1, (const GLfloat*) &cameraPosition.data[0]);

        // Load the texture into texture0 and set uVolData to 0 to load it
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, texId);
        glUniform1i(glGetUniformLocation(shaderProgramID, "uVolData"), 0);

        // Load the projection matrix into its uniform
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );

        // Draw the cube
        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &teapotIndices[0]);

        SampleUtils::checkGlError("ImageTargets renderFrame");
#endif

    }

    glDisable(GL_DEPTH_TEST);

#ifdef USE_OPENGL_ES_1_1        
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
#else
    glDisableVertexAttribArray(vertexHandle);
    glDisableVertexAttribArray(normalHandle);
    glDisableVertexAttribArray(vertexColorHandle);
#endif

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

    glDisable(GL_BLEND);
}
コード例 #14
0
JNIEXPORT void JNICALL
Java_com_mx_ipn_escom_ars_recorrido_ArsRenderer_renderFrame2(JNIEnv *env, jobject obj)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    QCAR::Renderer::getInstance().drawVideoBackground();

#ifdef USE_OPENGL_ES_1_1
    // Set GL11 flags:
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
//    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_LIGHTING);
//    glDisable(GL_LIGHTING);

#endif

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    // Did we find any trackables this frame?
    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());

#ifdef USE_OPENGL_ES_1_1
        // Load projection matrix:
        glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(projectionMatrix2.data);

        // Load model view matrix:
        glMatrixMode(GL_MODELVIEW);
        glLoadMatrixf(modelViewMatrix.data);
        glTranslatef(0.f, 0.f, kObjectScale);
        glScalef(kObjectScale, kObjectScale, kObjectScale);

        jclass javaClass = env->GetObjectClass(obj);

        char *buf = (char*)malloc(10);
        strcpy(buf, trackable->getName());
   	    jstring jstrBuf = env->NewStringUTF(buf);

	    jmethodID method1 = env->GetMethodID(javaClass, "prueba2", "(Ljava/lang/String;)V");

	    env->CallVoidMethod(obj, method1,jstrBuf);
	    env->DeleteLocalRef(jstrBuf);

#endif

    }

    glDisable(GL_DEPTH_TEST);

#ifdef USE_OPENGL_ES_1_1
//    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
#endif

    QCAR::Renderer::getInstance().end();
}
コード例 #15
0
JNIEXPORT void JNICALL
Java_com_siu_android_arapp_vuforia_ImageTargetsRenderer_renderFrame(JNIEnv* env, jobject object)
{
    //LOG("Java_com_siu_android_arapp_vuforia_GLRenderer_renderFrame");

    // Clear color and depth buffer 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    
    // Explicitly render the Video Background
    QCAR::Renderer::getInstance().drawVideoBackground();
       
#ifdef USE_OPENGL_ES_1_1
    // Set GL11 flags:
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);
        
#endif

//    glEnable(GL_DEPTH_TEST);
//
//    // We must detect if background reflection is active and adjust the culling direction.
//    // If the reflection is active, this means the post matrix has been reflected as well,
//    // therefore standard counter clockwise face culling will result in "inside out" models.
//    glEnable(GL_CULL_FACE);
//    glCullFace(GL_BACK);
//    if(QCAR::Renderer::getInstance().getVideoBackgroundConfig().mReflection == QCAR::VIDEO_BACKGROUND_REFLECTION_ON)
//        glFrontFace(GL_CW);  //Front camera
//    else
//        glFrontFace(GL_CCW);   //Back camera


    // Did we find any trackables this frame?
    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::Matrix34F pose = result->getPose();
        QCAR::Vec3F position(pose.data[3], pose.data[7], pose.data[11]);
        float distance = sqrt(position.data[0] * position.data[0] +
                              position.data[1] * position.data[1] +
                              position.data[2] * position.data[2]);
        //LOG("DISTANCE: %f", distance);

        jclass clazz = env->FindClass("com/siu/android/arapp/vuforia/ImageTargetsRenderer");
        if (clazz == 0) {
            LOG("FindClass error");
            return;
        }

        jmethodID jmethod = env->GetMethodID(clazz, "objectDetected", "(Ljava/lang/String;F)V");
        if (jmethod == 0) {
            LOG("GetMethodID error");
            return;
        }

        jstring s = env->NewStringUTF(trackable.getName());

        env->CallVoidMethod(object, jmethod, s, distance);

//        QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());
//
//        // Choose the texture based on the target name:
//        int textureIndex;
//        if (strcmp(trackable.getName(), "chips") == 0)
//        {
//            textureIndex = 0;
//        }
//        else if (strcmp(trackable.getName(), "stones") == 0)
//        {
//            textureIndex = 1;
//        }
//        else
//        {
//            textureIndex = 2;
//        }
//
//        const Texture* const thisTexture = textures[textureIndex];
//
//#ifdef USE_OPENGL_ES_1_1
//        // Load projection matrix:
//        glMatrixMode(GL_PROJECTION);
//        glLoadMatrixf(projectionMatrix.data);
//
//        // Load model view matrix:
//        glMatrixMode(GL_MODELVIEW);
//        glLoadMatrixf(modelViewMatrix.data);
//        glTranslatef(0.f, 0.f, kObjectScale);
//        glScalef(kObjectScale, kObjectScale, kObjectScale);
//
//        // Draw object:
//        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
//        glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &teapotTexCoords[0]);
//        glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &teapotVertices[0]);
//        glNormalPointer(GL_FLOAT, 0,  (const GLvoid*) &teapotNormals[0]);
//        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
//                       (const GLvoid*) &teapotIndices[0]);
//#else
//
//        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);
//
//        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, thisTexture->mTextureID);
//        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]);
//
//        glDisableVertexAttribArray(vertexHandle);
//        glDisableVertexAttribArray(normalHandle);
//        glDisableVertexAttribArray(textureCoordHandle);
//
//        SampleUtils::checkGlError("ImageTargets renderFrame");
//#endif

    }
//
//    glDisable(GL_DEPTH_TEST);
//
//#ifdef USE_OPENGL_ES_1_1
//    glDisable(GL_TEXTURE_2D);
//    glDisableClientState(GL_VERTEX_ARRAY);
//    glDisableClientState(GL_NORMAL_ARRAY);
//    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
//#endif
//
//    QCAR::Renderer::getInstance().end();
}
コード例 #16
0
ファイル: CloudReco.cpp プロジェクト: rxgranda/LumiV2
// ----------------------------------------------------------------------------
// renderFrame Method - Takes care of drawing in the different render states
// ----------------------------------------------------------------------------
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_CloudRecognition_CloudRecoRenderer_renderFrame(JNIEnv *, jobject)
{
    // Clear color and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();

    // Explicitly render the Video Background
    QCAR::Renderer::getInstance().drawVideoBackground();

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    if (deleteCurrentProductTexture)
    {
        // Deletes the product texture if necessary
        if (productTexture != 0)
        {
            glDeleteTextures(1, &(productTexture->mTextureID));
            delete productTexture;
            productTexture = 0;
        }

        deleteCurrentProductTexture = false;
    }

    // If the render state indicates that the texture is generated it generates
    // the OpenGL texture for start drawing the plane with the book data
    if (renderState == RS_TEXTURE_GENERATED)
    {
        generateProductTextureInOpenGL();
    }

    // Did we find any trackables this frame?
    if (state.getNumTrackableResults() > 0)
    {
        trackingStarted = true;

        // If we are already tracking something we don't need
        // to wait any frame before starting the 2D transition
        // when the target gets lost
        pthread_mutex_lock(&framesToSkipMutex);
        framesToSkipBeforeRenderingTransition = 0;
        pthread_mutex_unlock(&framesToSkipMutex);

        // Gets current trackable result
        const QCAR::TrackableResult* trackableResult = state.getTrackableResult(0);

        if (trackableResult == NULL)
        {
            return;
        }

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

        // Get the size of the ImageTarget
        QCAR::ImageTargetResult *imageResult = (QCAR::ImageTargetResult *)trackableResult;
        targetSize = imageResult->getTrackable().getSize();

        // Renders the Augmentation View with the 3D Book data Panel
        renderAugmentation(trackableResult);

    }
    else
    {
        // Manages the 3D to 2D Transition initialization
        if (!scanningMode && showAnimation3Dto2D && renderState == RS_NORMAL
                && framesToSkipBeforeRenderingTransition == 0)
        {
            startTransitionTo2D();
        }

        // Reduces the number of frames to wait before triggering
        // the transition by 1
        if( framesToSkipBeforeRenderingTransition > 0 && renderState == RS_NORMAL)
        {
            pthread_mutex_lock(&framesToSkipMutex);
            framesToSkipBeforeRenderingTransition -= 1;
            pthread_mutex_unlock(&framesToSkipMutex);
        }

    }

    // Logic for rendering Transition to 2D
    if (renderState == RS_TRANSITION_TO_2D && showAnimation3Dto2D)
    {
        renderTransitionTo2D();
    }

    // Logic for rendering Transition to 3D
    if (renderState == RS_TRANSITION_TO_3D )
    {
        renderTransitionTo3D();
    }

    // Get the tracker manager:
    QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();

    // Get the image tracker:
    QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(
            trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER));

    // Get the target finder:
    QCAR::TargetFinder* finder = imageTracker->getTargetFinder();

    // Renders the current state - User process Feedback
    if (finder->isRequesting())
    {
        // Requesting State - Show Requesting text in Status Bar
        setStatusBarText("Requesting");
        showStatusBar();
    }
    else
    {
        // Hiding Status Bar
        hideStatusBar();
    }

    glDisable(GL_DEPTH_TEST);

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

}
コード例 #17
0
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_VideoPlayback_VideoPlaybackRenderer_renderFrame(JNIEnv *, jobject)
{
    //LOG("Java_com_qualcomm_QCARSamples_VideoPlayback_GLRenderer_renderFrame");

    // Clear color and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();

    // Explicitly render the Video Background
    QCAR::Renderer::getInstance().drawVideoBackground();

    glEnable(GL_DEPTH_TEST);

    // We must detect if background reflection is active and adjust the culling direction.
    // If the reflection is active, this means the post matrix has been reflected as well,
    // therefore standard counter clockwise face culling will result in "inside out" models.
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    if(QCAR::Renderer::getInstance().getVideoBackgroundConfig().mReflection == QCAR::VIDEO_BACKGROUND_REFLECTION_ON)
        glFrontFace(GL_CW);  //Front camera
    else
        glFrontFace(GL_CCW);   //Back camera


    for (int i=0; i<NUM_TARGETS; i++)
    {
        isTracking[i] = false;
        targetPositiveDimensions[i].data[0] = 0.0;
        targetPositiveDimensions[i].data[1] = 0.0;
    }

    // Did we find any trackables this frame?
    for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
    {
        // Get the trackable:
        const QCAR::TrackableResult* trackableResult = state.getTrackableResult(tIdx);

        const QCAR::ImageTarget& imageTarget = (const QCAR::ImageTarget&) trackableResult->getTrackable();

        int currentTarget;

        // We store the modelview matrix to be used later by the tap calculation
        if (strcmp(imageTarget.getName(), "stones") == 0)
            currentTarget=STONES;
        else
            currentTarget=CHIPS;

        modelViewMatrix[currentTarget] = QCAR::Tool::convertPose2GLMatrix(trackableResult->getPose());

        isTracking[currentTarget] = true;

        targetPositiveDimensions[currentTarget] = imageTarget.getSize();

        // The pose delivers the center of the target, thus the dimensions
        // go from -width/2 to width/2, same for height
        targetPositiveDimensions[currentTarget].data[0] /= 2.0f;
        targetPositiveDimensions[currentTarget].data[1] /= 2.0f;


        // If the movie is ready to start playing or it has reached the end
        // of playback we render the keyframe
        if ((currentStatus[currentTarget] == READY) || (currentStatus[currentTarget] == REACHED_END) ||
                (currentStatus[currentTarget] == NOT_READY) || (currentStatus[currentTarget] == ERROR))
        {
            QCAR::Matrix44F modelViewMatrixKeyframe =
                QCAR::Tool::convertPose2GLMatrix(trackableResult->getPose());
            QCAR::Matrix44F modelViewProjectionKeyframe;
            SampleUtils::translatePoseMatrix(0.0f, 0.0f, targetPositiveDimensions[currentTarget].data[0],
                                             &modelViewMatrixKeyframe.data[0]);

            // Here we use the aspect ratio of the keyframe since it
            // is likely that it is not a perfect square

            float ratio=1.0;
            if (textures[currentTarget]->mSuccess)
                ratio = keyframeQuadAspectRatio[currentTarget];
            else
                ratio = targetPositiveDimensions[currentTarget].data[1] / targetPositiveDimensions[currentTarget].data[0];

            SampleUtils::scalePoseMatrix(targetPositiveDimensions[currentTarget].data[0],
                                         targetPositiveDimensions[currentTarget].data[0]*ratio,
                                         targetPositiveDimensions[currentTarget].data[0],
                                         &modelViewMatrixKeyframe.data[0]);
            SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                        &modelViewMatrixKeyframe.data[0] ,
                                        &modelViewProjectionKeyframe.data[0]);

            glUseProgram(keyframeShaderID);

            // Prepare for rendering the keyframe
            glVertexAttribPointer(keyframeVertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                  (const GLvoid*) &quadVertices[0]);
            glVertexAttribPointer(keyframeNormalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                  (const GLvoid*) &quadNormals[0]);
            glVertexAttribPointer(keyframeTexCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                  (const GLvoid*) &quadTexCoords[0]);

            glEnableVertexAttribArray(keyframeVertexHandle);
            glEnableVertexAttribArray(keyframeNormalHandle);
            glEnableVertexAttribArray(keyframeTexCoordHandle);

            glActiveTexture(GL_TEXTURE0);

            // The first loaded texture from the assets folder is the keyframe
            glBindTexture(GL_TEXTURE_2D, textures[currentTarget]->mTextureID);
            glUniformMatrix4fv(keyframeMVPMatrixHandle, 1, GL_FALSE,
                               (GLfloat*)&modelViewProjectionKeyframe.data[0] );
            glUniform1i(keyframeTexSampler2DHandle, 0 /*GL_TEXTURE0*/);

            // Render
            glDrawElements(GL_TRIANGLES, NUM_QUAD_INDEX, GL_UNSIGNED_SHORT,
                           (const GLvoid*) &quadIndices[0]);

            glDisableVertexAttribArray(keyframeVertexHandle);
            glDisableVertexAttribArray(keyframeNormalHandle);
            glDisableVertexAttribArray(keyframeTexCoordHandle);

            glUseProgram(0);
        }
        else // In any other case, such as playing or paused, we render the actual contents
        {
            QCAR::Matrix44F modelViewMatrixVideo =
                QCAR::Tool::convertPose2GLMatrix(trackableResult->getPose());
            QCAR::Matrix44F modelViewProjectionVideo;
            SampleUtils::translatePoseMatrix(0.0f, 0.0f, targetPositiveDimensions[currentTarget].data[0],
                                             &modelViewMatrixVideo.data[0]);

            // Here we use the aspect ratio of the video frame
            SampleUtils::scalePoseMatrix(targetPositiveDimensions[currentTarget].data[0],
                                         targetPositiveDimensions[currentTarget].data[0]*videoQuadAspectRatio[currentTarget],
                                         targetPositiveDimensions[currentTarget].data[0],
                                         &modelViewMatrixVideo.data[0]);
            SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                        &modelViewMatrixVideo.data[0] ,
                                        &modelViewProjectionVideo.data[0]);

            glUseProgram(videoPlaybackShaderID);

            // Prepare for rendering the keyframe
            glVertexAttribPointer(videoPlaybackVertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                  (const GLvoid*) &quadVertices[0]);
            glVertexAttribPointer(videoPlaybackNormalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                  (const GLvoid*) &quadNormals[0]);

            if (strcmp(imageTarget.getName(), "stones") == 0)
                glVertexAttribPointer(videoPlaybackTexCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &videoQuadTextureCoordsTransformedStones[0]);
            else
                glVertexAttribPointer(videoPlaybackTexCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &videoQuadTextureCoordsTransformedChips[0]);


            glEnableVertexAttribArray(videoPlaybackVertexHandle);
            glEnableVertexAttribArray(videoPlaybackNormalHandle);
            glEnableVertexAttribArray(videoPlaybackTexCoordHandle);

            glActiveTexture(GL_TEXTURE0);

            // IMPORTANT:
            // Notice here that the texture that we are binding is not the
            // typical GL_TEXTURE_2D but instead the GL_TEXTURE_EXTERNAL_OES
            glBindTexture(GL_TEXTURE_EXTERNAL_OES, videoPlaybackTextureID[currentTarget]);
            glUniformMatrix4fv(videoPlaybackMVPMatrixHandle, 1, GL_FALSE,
                               (GLfloat*)&modelViewProjectionVideo.data[0]);
            glUniform1i(videoPlaybackTexSamplerOESHandle, 0 /*GL_TEXTURE0*/);

            // Render
            glDrawElements(GL_TRIANGLES, NUM_QUAD_INDEX, GL_UNSIGNED_SHORT,
                           (const GLvoid*) &quadIndices[0]);

            glDisableVertexAttribArray(videoPlaybackVertexHandle);
            glDisableVertexAttribArray(videoPlaybackNormalHandle);
            glDisableVertexAttribArray(videoPlaybackTexCoordHandle);

            glUseProgram(0);

        }

        // The following section renders the icons. The actual textures used
        // are loaded from the assets folder

        if ((currentStatus[currentTarget] == READY)  || (currentStatus[currentTarget] == REACHED_END) ||
                (currentStatus[currentTarget] == PAUSED) || (currentStatus[currentTarget] == NOT_READY)   ||
                (currentStatus[currentTarget] == ERROR))
        {
            // If the movie is ready to be played, pause, has reached end or is not
            // ready then we display one of the icons
            QCAR::Matrix44F modelViewMatrixButton =
                QCAR::Tool::convertPose2GLMatrix(trackableResult->getPose());
            QCAR::Matrix44F modelViewProjectionButton;

            glDepthFunc(GL_LEQUAL);

            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


            // The inacuracy of the rendering process in some devices means that
            // even if we use the "Less or Equal" version of the depth function
            // it is likely that we will get ugly artifacts
            // That is the translation in the Z direction is slightly different
            // Another posibility would be to use a depth func "ALWAYS" but
            // that is typically not a good idea
            SampleUtils::translatePoseMatrix(0.0f, 0.0f, targetPositiveDimensions[currentTarget].data[1]/1.98f,
                                             &modelViewMatrixButton.data[0]);
            SampleUtils::scalePoseMatrix((targetPositiveDimensions[currentTarget].data[1]/2.0f),
                                         (targetPositiveDimensions[currentTarget].data[1]/2.0f),
                                         (targetPositiveDimensions[currentTarget].data[1]/2.0f),
                                         &modelViewMatrixButton.data[0]);
            SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                        &modelViewMatrixButton.data[0] ,
                                        &modelViewProjectionButton.data[0]);


            glUseProgram(keyframeShaderID);

            glVertexAttribPointer(keyframeVertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                  (const GLvoid*) &quadVertices[0]);
            glVertexAttribPointer(keyframeNormalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                  (const GLvoid*) &quadNormals[0]);
            glVertexAttribPointer(keyframeTexCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                  (const GLvoid*) &quadTexCoords[0]);

            glEnableVertexAttribArray(keyframeVertexHandle);
            glEnableVertexAttribArray(keyframeNormalHandle);
            glEnableVertexAttribArray(keyframeTexCoordHandle);

            glActiveTexture(GL_TEXTURE0);

            // Depending on the status in which we are we choose the appropriate
            // texture to display. Notice that unlike the video these are regular
            // GL_TEXTURE_2D textures
            switch (currentStatus[currentTarget])
            {
            case READY:
                glBindTexture(GL_TEXTURE_2D, textures[2]->mTextureID);
                break;
            case REACHED_END:
                glBindTexture(GL_TEXTURE_2D, textures[2]->mTextureID);
                break;
            case PAUSED:
                glBindTexture(GL_TEXTURE_2D, textures[2]->mTextureID);
                break;
            case NOT_READY:
                glBindTexture(GL_TEXTURE_2D, textures[3]->mTextureID);
                break;
            case ERROR:
                glBindTexture(GL_TEXTURE_2D, textures[4]->mTextureID);
                break;
            default:
                glBindTexture(GL_TEXTURE_2D, textures[3]->mTextureID);
                break;
            }
            glUniformMatrix4fv(keyframeMVPMatrixHandle, 1, GL_FALSE,
                               (GLfloat*)&modelViewProjectionButton.data[0] );
            glUniform1i(keyframeTexSampler2DHandle, 0 /*GL_TEXTURE0*/);

            // Render
            glDrawElements(GL_TRIANGLES, NUM_QUAD_INDEX, GL_UNSIGNED_SHORT,
                           (const GLvoid*) &quadIndices[0]);

            glDisableVertexAttribArray(keyframeVertexHandle);
            glDisableVertexAttribArray(keyframeNormalHandle);
            glDisableVertexAttribArray(keyframeTexCoordHandle);

            glUseProgram(0);

            // Finally we return the depth func to its original state
            glDepthFunc(GL_LESS);
            glDisable(GL_BLEND);
        }

        SampleUtils::checkGlError("VideoPlayback renderFrame");
    }

    glDisable(GL_DEPTH_TEST);

    QCAR::Renderer::getInstance().end();
}
コード例 #18
0
JNIEXPORT void JNICALL
Java_rajawali_vuforia_RajawaliVuforiaRenderer_renderFrame(JNIEnv* env,
		jobject object, jint frameBufferId, int frameBufferTextureId) {

	//LOG("Java_com_qualcomm_QCARSamples_FrameMarkers_GLRenderer_renderFrame");
	jclass ownerClass = env->GetObjectClass(object);

	// Clear color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Get the state from QCAR and mark the beginning of a rendering section
	QCAR::State state = QCAR::Renderer::getInstance().begin();

	glBindFramebuffer(GL_FRAMEBUFFER, frameBufferId);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
			frameBufferTextureId, 0);

	// Explicitly render the Video Background
	QCAR::Renderer::getInstance().drawVideoBackground();

	jfloatArray modelViewMatrixOut = env->NewFloatArray(16);

	// Did we find any trackables this frame?
	for (int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++) {
		// Get the trackable:
		const QCAR::TrackableResult* trackableResult = state.getTrackableResult(
				tIdx);
		const QCAR::Trackable& trackable = trackableResult->getTrackable();
		QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(
				trackableResult->getPose());
		if (isActivityInPortraitMode)
			Utils::rotatePoseMatrix(90.0f, 0, 1.0f, 0,
					&modelViewMatrix.data[0]);
		Utils::rotatePoseMatrix(-90.0f, 1.0f, 0, 0, &modelViewMatrix.data[0]);

		if (trackable.isOfType(QCAR::Marker::getClassType())) {
			jmethodID foundFrameMarkerMethod = env->GetMethodID(ownerClass,
					"foundFrameMarker", "(I[F)V");
			env->SetFloatArrayRegion(modelViewMatrixOut, 0, 16,
					modelViewMatrix.data);
			env->CallVoidMethod(object, foundFrameMarkerMethod,
					(jint) trackable.getId(), modelViewMatrixOut);
		} else if (trackable.isOfType(QCAR::CylinderTarget::getClassType())
				|| trackable.isOfType(QCAR::ImageTarget::getClassType())
				|| trackable.isOfType(QCAR::MultiTarget::getClassType())) {
			jmethodID foundImageMarkerMethod = env->GetMethodID(ownerClass,
					"foundImageMarker", "(Ljava/lang/String;[F)V");
			env->SetFloatArrayRegion(modelViewMatrixOut, 0, 16,
					modelViewMatrix.data);
			const char* trackableName = trackable.getName();
			jstring trackableNameJava = env->NewStringUTF(trackableName);
			env->CallVoidMethod(object, foundImageMarkerMethod,
					trackableNameJava, modelViewMatrixOut);
		}
	}
	env->DeleteLocalRef(modelViewMatrixOut);

	if (state.getNumTrackableResults() == 0) {
		jmethodID noFrameMarkersFoundMethod = env->GetMethodID(ownerClass,
				"noFrameMarkersFound", "()V");
		env->CallVoidMethod(object, noFrameMarkersFoundMethod);
	}

	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	QCAR::Renderer::getInstance().end();
}
コード例 #19
0
JNIEXPORT void JNICALL
Java_com_ar4android_rayPickingJME_RayPickingJME_updateTracking(JNIEnv *env, jobject obj)
{
    //LOG("Java_com_ar4android_rayPickingJME_RayPickingJMEActivity_GLRenderer_renderFrame");

    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    


    // Explicitly render the Video Background
  //  QCAR::Renderer::getInstance().drawVideoBackground();

  //  if(QCAR::Renderer::getInstance().getVideoBackgroundConfig().mReflection == QCAR::VIDEO_BACKGROUND_REFLECTION_ON)

    // Did we find any trackables this frame?
    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());

        //get the camera transformation
        QCAR::Matrix44F inverseMV = MathUtil::Matrix44FInverse(modelViewMatrix);
        //QCAR::Matrix44F invTranspMV = modelViewMatrix;
        QCAR::Matrix44F invTranspMV = MathUtil::Matrix44FTranspose(inverseMV);

        //get position
        float cam_x = invTranspMV.data[12];
        float cam_y = invTranspMV.data[13];
        float cam_z = invTranspMV.data[14];

        //get rotation
        float cam_right_x = invTranspMV.data[0];
        float cam_right_y = invTranspMV.data[1];
        float cam_right_z = invTranspMV.data[2];
        float cam_up_x = invTranspMV.data[4];
        float cam_up_y = invTranspMV.data[5];
        float cam_up_z = invTranspMV.data[6];
        float cam_dir_x = invTranspMV.data[8];
        float cam_dir_y = invTranspMV.data[9];
        float cam_dir_z = invTranspMV.data[10];

        //get perspective transformation
        float nearPlane = 1.0f;
        float farPlane = 1000.0f;
        const QCAR::CameraCalibration& cameraCalibration =
                                    QCAR::CameraDevice::getInstance().getCameraCalibration();

        QCAR::VideoBackgroundConfig config = QCAR::Renderer::getInstance().getVideoBackgroundConfig();

        float viewportWidth = config.mSize.data[0];
        float viewportHeight = config.mSize.data[1];

        QCAR::Vec2F size = cameraCalibration.getSize();
        QCAR::Vec2F focalLength = cameraCalibration.getFocalLength();
        float fovRadians = 2 * atan(0.5f * size.data[1] / focalLength.data[1]);
        float fovDegrees = fovRadians * 180.0f / M_PI;
        float aspectRatio=size.data[0]/size.data[1];

        //adjust for screen vs camera size distorsion
        float viewportDistort=1.0;

        if (viewportWidth != screenWidth)
        {
        	viewportDistort = viewportWidth / (float) screenWidth;
            fovDegrees=fovDegrees*viewportDistort;
            aspectRatio=aspectRatio/viewportDistort;
        }

        if (viewportHeight != screenHeight)
        {
        	viewportDistort = viewportHeight / (float) screenHeight;
            fovDegrees=fovDegrees/viewportDistort;
            aspectRatio=aspectRatio*viewportDistort;
        }

        //JNIEnv *env;
        //jvm->AttachCurrentThread((void **)&env, NULL);

        jclass activityClass = env->GetObjectClass(obj);
        jmethodID setCameraPerspectiveMethod = env->GetMethodID(activityClass,"setCameraPerspectiveNative", "(FF)V");
        env->CallVoidMethod(obj,setCameraPerspectiveMethod,fovDegrees,aspectRatio);

        // jclass activityClass = env->GetObjectClass(obj);
        jmethodID setCameraViewportMethod = env->GetMethodID(activityClass,"setCameraViewportNative", "(FFFF)V");
        env->CallVoidMethod(obj,setCameraViewportMethod,viewportWidth,viewportHeight,cameraCalibration.getSize().data[0],cameraCalibration.getSize().data[1]);

       // jclass activityClass = env->GetObjectClass(obj);
        jmethodID setCameraPoseMethod = env->GetMethodID(activityClass,"setCameraPoseNative", "(FFF)V");
        env->CallVoidMethod(obj,setCameraPoseMethod,cam_x,cam_y,cam_z);

        //jclass activityClass = env->GetObjectClass(obj);
        jmethodID setCameraOrientationMethod = env->GetMethodID(activityClass,"setCameraOrientationNative", "(FFFFFFFFF)V");
        env->CallVoidMethod(obj,setCameraOrientationMethod,cam_right_x,cam_right_y,cam_right_z,
        		cam_up_x,cam_up_y,cam_up_z,cam_dir_x,cam_dir_y,cam_dir_z);

       // jvm->DetachCurrentThread();

    }

    QCAR::Renderer::getInstance().end();
}
コード例 #20
0
	JNIEXPORT void JNICALL
	//Java_com_miosys_finder_ui_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject)
	Java_com_miosys_finder_ui_ImageTargetsRenderer_renderFrame(JNIEnv* env, jobject obj)
	{
	    LOG("Java_com_miosys_finder_ui_PfinderTargets_renderFrame");

	    // Clear color and depth buffer
	    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	    // Get the state from QCAR and mark the beginning of a rendering section
	    QCAR::State state = QCAR::Renderer::getInstance().begin();

	    // Explicitly render the Video Background
	    QCAR::Renderer::getInstance().drawVideoBackground();

	    glEnable(GL_DEPTH_TEST);

	    // We must detect if background reflection is active and adjust the culling direction.
	    // If the reflection is active, this means the post matrix has been reflected as well,
	    // therefore standard counter clockwise face culling will result in "inside out" models.
	    glEnable(GL_CULL_FACE);
	    glCullFace(GL_BACK);
	    if(QCAR::Renderer::getInstance().getVideoBackgroundConfig().mReflection == QCAR::VIDEO_BACKGROUND_REFLECTION_ON)
	        glFrontFace(GL_CW);  //Front camera
	    else
	        glFrontFace(GL_CCW);   //Back camera


	    // Did we find any trackables this frame?
	    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());

	        if(!isExtendedTrackingActivated)
	        {
	        	/*java method switch to listview activity after detected objects*/
	        	jstring jstrTargetName = env->NewStringUTF(trackable.getName());
	        	jclass renderClass = env->GetObjectClass(obj);
	        	jmethodID switchToListViewID = env->GetMethodID(renderClass,"switchToListView", "(Ljava/lang/String;)V");
	        	env->CallVoidMethod(obj, switchToListViewID, jstrTargetName);
	        	/*
				// Choose the texture based on the target name:
				int textureIndex;
				if (strcmp(trackable.getName(), "chips") == 0)
				{
					textureIndex = 0;
				}
				else if (strcmp(trackable.getName(), "stones") == 0)
				{
					textureIndex = 1;
				}
				else
				{
					textureIndex = 2;
				}
//				if(strcmp(trackable.getName(), "P1_01") == 0){
//					textureIndex = 0;
//				}
//				else if(strcmp(trackable.getName(),"P1_02") == 1){
//					textureIndex = 1;
//				}
//				else {
//					textureIndex = 2;
//				}

				const Texture* const thisTexture = textures[textureIndex];

				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);

				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, thisTexture->mTextureID);
				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]);

				glDisableVertexAttribArray(vertexHandle);
				glDisableVertexAttribArray(normalHandle);
				glDisableVertexAttribArray(textureCoordHandle);

				SampleUtils::checkGlError("ImageTargets renderFrame");
	        }
	        else
	        {
				const Texture* const thisTexture = textures[3];

				QCAR::Matrix44F modelViewProjection;

				SampleUtils::translatePoseMatrix(0.0f, 0.0f, kBuildingsObjectScale,
												 &modelViewMatrix.data[0]);
				SampleUtils::rotatePoseMatrix(90.0f, 1.0f, 0.0f, 0.0f,
				                                  &modelViewMatrix.data[0]);
				SampleUtils::scalePoseMatrix(kBuildingsObjectScale, kBuildingsObjectScale, kBuildingsObjectScale,
											 &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*) &buildingsVerts[0]);
				glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
									  (const GLvoid*) &buildingsNormals[0]);
				glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
									  (const GLvoid*) &buildingsTexCoords[0]);

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

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

				glDisableVertexAttribArray(vertexHandle);
				glDisableVertexAttribArray(normalHandle);
				glDisableVertexAttribArray(textureCoordHandle);

				SampleUtils::checkGlError("ImageTargets renderFrame");
				*/
	        }
	    }

	    glDisable(GL_DEPTH_TEST);

	    QCAR::Renderer::getInstance().end();
	}
コード例 #21
0
void
MSRenderer::renderFrame() {
  // Clear color and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // Get the state from QCAR and mark the beginning of a rendering section
  QCAR::State state = QCAR::Renderer::getInstance().begin();

  // Explicitly render the Video Background
  QCAR::Renderer::getInstance().drawVideoBackground();

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_CULL_FACE);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  // Did we find any trackables this frame?
  for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
  {
  // Get the trackable:
  const QCAR::TrackableResult* trackableResult = state.getTrackableResult(tIdx);
  QCAR::Matrix44F modelViewMatrix =
    QCAR::Tool::convertPose2GLMatrix(trackableResult->getPose());
  MSRenderer::scalePoseMatrix(MSController::getFrameRatio(),
                              1,
                              1,
                              &modelViewMatrix.data[0]);

  // get the target info
  void *userData = trackableResult->getTrackable().getUserData();
  MSTargetInfo *info = static_cast<MSTargetInfo *>(userData);
  MSTexture *tex = info->getTexture();
  MSModel *model = info->getModel();
  // Bind texture to OpenGL if not done yet
  if (!tex->mHasID) {
    glGenTextures(1, &(tex->mTextureID));
    glBindTexture(GL_TEXTURE_2D, tex->mTextureID);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->mWidth,
                 tex->mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                 (GLvoid*) tex->mData);
    tex->mHasID = true;
  }

  MSRenderer::multiplyMatrix(&modelViewMatrix.data[0],
                             info->getPose(),
                             &modelViewMatrix.data[0]);

  QCAR::Matrix44F modelViewProjection;

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

  glUseProgram(shaderProgramID);

  glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, model->vertices);
  glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, model->normals);
  glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, model->texCoords);

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

  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, tex->mTextureID);
  glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)modelViewProjection.data);
  glUniform1i(texSampler2DHandle, 0);
  glDrawElements(GL_TRIANGLES, 3*model->nFaces, GL_UNSIGNED_SHORT, model->faces);
  }

  glDisable(GL_DEPTH_TEST);

  glDisableVertexAttribArray(vertexHandle);
  glDisableVertexAttribArray(normalHandle);
  glDisableVertexAttribArray(textureCoordHandle);

  glDisable(GL_BLEND);

  QCAR::Renderer::getInstance().end();
}
コード例 #22
0
ファイル: VirtualButtons.cpp プロジェクト: yaoyaowd/demo
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_VirtualButtons_VirtualButtonsRenderer_renderFrame(JNIEnv *, jobject)
{
    //LOG("Java_com_qualcomm_QCARSamples_VirtualButtons_GLRenderer_renderFrame");
 
    // Clear color and depth buffer 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Render video background:
    QCAR::State state = QCAR::Renderer::getInstance().begin();    

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    // Did we find any trackables this frame?
    if (state.getNumActiveTrackables())
    {
        // Get the trackable:
        const QCAR::Trackable* trackable = state.getActiveTrackable(0);
        QCAR::Matrix44F modelViewMatrix =
            QCAR::Tool::convertPose2GLMatrix(trackable->getPose()); 

        // The image target:
        assert(trackable->getType() == QCAR::Trackable::IMAGE_TARGET);
        const QCAR::ImageTarget* target =
            static_cast<const QCAR::ImageTarget*>(trackable);

        // Set transformations:
        QCAR::Matrix44F modelViewProjection;
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewMatrix.data[0],
                                    &modelViewProjection.data[0]);
                                    
                                    
        // Set the texture used for the teapot model:
        int textureIndex = 0;

        GLfloat vbVertices[96];
        unsigned char vbCounter=0;

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

            // If the button is pressed, than use this texture:
            if (button->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, target->getNumVirtualButtons()*8); 

            SampleUtils::checkGlError("VirtualButtons drawButton");

            glDisableVertexAttribArray(vbVertexHandle);
        }

        // Assumptions:
        assert(textureIndex < textureCount);
        const Texture* const thisTexture = textures[textureIndex];                            

        
        // Scale 3D model
        QCAR::Matrix44F modelViewScaled = modelViewMatrix;
        SampleUtils::scalePoseMatrix(kTeapotScale, kTeapotScale, kTeapotScale,
                                     &modelViewScaled.data[0]);

        QCAR::Matrix44F modelViewProjectionScaled;
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewScaled.data[0],
                                    &modelViewProjectionScaled.data[0]);
                                    
        // Render 3D model
        glUseProgram(shaderProgramID);
 
        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, thisTexture->mTextureID);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjectionScaled.data[0] );
        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &teapotIndices[0]);

        SampleUtils::checkGlError("VirtualButtons renderFrame");

    }
    
    glDisable(GL_DEPTH_TEST);

    glDisableVertexAttribArray(vertexHandle);
    glDisableVertexAttribArray(normalHandle);
    glDisableVertexAttribArray(textureCoordHandle);

    QCAR::Renderer::getInstance().end();
}
コード例 #23
0
ファイル: CloudReco.cpp プロジェクト: rxgranda/LumiV2
    virtual void QCAR_onUpdate(QCAR::State& state)
    {
        // Get the tracker manager:
        QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();

        // Get the image tracker:
        QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(
                trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER));

        // Get the target finder:
        QCAR::TargetFinder* finder = imageTracker->getTargetFinder();

        // Check if there are new results available:
        const int statusCode = finder->updateSearchResults();

        // Show a message if we encountered an error:
        if (statusCode < 0)
        {
            showErrorMessage(statusCode, state.getFrame().getTimeStamp());
        }
        else if (statusCode == QCAR::TargetFinder::UPDATE_RESULTS_AVAILABLE)
        {
            // Process new search results
            if (finder->getResultCount() > 0)
            {
                const QCAR::TargetSearchResult* result = finder->getResult(0);

                // Check if this target is suitable for tracking:
                if (result->getTrackingRating() > 0)
                {
                    // Create a new Trackable from the result:
                    QCAR::Trackable* newTrackable = finder->enableTracking(*result);
                    if (newTrackable != 0)
                    {
                        LOG("Successfully created new trackable '%s' with rating '%d'.",
                                newTrackable->getName(), result->getTrackingRating());
                                                
                        // Checks if the targets has changed
                        LOG( "Comparing Strings. currentTargetId: %s  lastTargetId: %s",
                                result->getUniqueTargetId(), lastTargetId);

                        if (strcmp(result->getUniqueTargetId(), lastTargetId) != 0)
                        {
                            // If the target has changed then regenerate the texture
                            // Cleaning this value indicates that the product Texture needs to be generated
                            // again in Java with the new Book data for the new target
                            deleteCurrentProductTexture = true;

                            // Starts the loading state for the product
                            renderState = RS_LOADING;

                            // Copies the new target Metadata
                            snprintf(targetMetadata, CONTENT_MAX, "%s", result->getMetaData());

                            // Calls the Java method with the current product texture
                            createProductTexture(targetMetadata);

                        }
                        else
                            renderState = RS_NORMAL;

                        // Initialize the frames to skip variable, used for waiting
                        // a few frames for getting the chance to tracking before
                        // starting the transition to 2D when there is no target
                        pthread_mutex_lock(&framesToSkipMutex);
                        framesToSkipBeforeRenderingTransition = 10;
                        pthread_mutex_unlock(&framesToSkipMutex);

                        // Initialize state variables
                        showAnimation3Dto2D = true;
                        trackingStarted = false;

                        // Updates the value of the current Target Id with the new target found
                        pthread_mutex_lock(&lastTargetIdMutex);
                        strcpy(lastTargetId, result->getUniqueTargetId());
                        pthread_mutex_unlock(&lastTargetIdMutex);

                        enterContentMode();
                    }
                    else
                        LOG("Failed to create new trackable.");
                }
            }
        }
    }
コード例 #24
0
JNIEXPORT void JNICALL
Java_com_wheelphone_targetNavigation_WheelphoneTargetNavigation_getTrackInfo(JNIEnv *env, jobject obj)
{

    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    
	//QCAR::Vec2F markerSize;
   	jint jx[4] = {0};
	jint jy[4] = {0};            
	jfloat distance[4] = {0};
	jfloat cam_x[4] = {0}; 
	jfloat cam_y[4] = {0}; 
	jfloat cam_z[4] = {0}; 
	jfloat target_pose_x[4] = {0};	// x, y, z coordinates of the targets with respect to the camera frame
	jfloat target_pose_y[4] = {0};
	jfloat target_pose_z[4] = {0};
	
	jboolean detected[4] = {false};
	jclass javaClass = env->GetObjectClass(obj);	// obj is the java class object calling the "renderFrame" method, that is an FrameMarkersRenderer object
    //jclass javaClass = env->FindClass("Lcom/wheelphone/targetNavigation/WheelphoneTargetNavigation;"); // doesn't work!
	jmethodID method = env->GetMethodID(javaClass, "updateMarkersInfo", "(IZIIFFFF)V");
        
    // Did we find any trackables this frame?
    for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
    {
        // Get the trackable:
        const QCAR::TrackableResult* trackableResult = state.getTrackableResult(tIdx);
        if(trackableResult == NULL) {
        	continue;
        }
        QCAR::Matrix44F modelViewMatrix =
            QCAR::Tool::convertPose2GLMatrix(trackableResult->getPose());        
        //if(modelViewMatrix == NULL) {
        //	continue;
        //}

        // Choose the texture based on the target name:
        int textureIndex = 0;
        
        // Check the type of the trackable:
        assert(trackableResult->getType() == QCAR::TrackableResult::MARKER_RESULT);
        const QCAR::MarkerResult* markerResult = static_cast<
                                    const QCAR::MarkerResult*>(trackableResult);
        if(markerResult == NULL) {
        	continue;
        }

        const QCAR::Marker& marker = markerResult->getTrackable();
        //if(marker == NULL) {
        //	continue;
        //}

        textureIndex = marker.getMarkerId();
        
		//markerSize = marker.getSize();	// this is the size specified during marker creation! Not the current size!

        assert(textureIndex < textureCount);

        // Select which model to draw:
        const GLvoid* vertices = 0;
        const GLvoid* normals = 0;
        const GLvoid* indices = 0;
        const GLvoid* texCoords = 0;
        int numIndices = 0;

		QCAR::Vec2F result(0,0);		     
		const QCAR::CameraCalibration& cameraCalibration = QCAR::CameraDevice::getInstance().getCameraCalibration();      
	    QCAR::Vec2F cameraPoint = QCAR::Tool::projectPoint(cameraCalibration, trackableResult->getPose(), QCAR::Vec3F(0, 0, 0));
	    QCAR::VideoMode videoMode = QCAR::CameraDevice::getInstance().getVideoMode(QCAR::CameraDevice::MODE_OPTIMIZE_QUALITY); //MODE_DEFAULT);
	    QCAR::VideoBackgroundConfig config = QCAR::Renderer::getInstance().getVideoBackgroundConfig();		
	    //if(config == NULL) {
	    //	continue;
	    //}
	    int xOffset = ((int) screenWidth - config.mSize.data[0]) / 2.0f + config.mPosition.data[0];
	    int yOffset = ((int) screenHeight - config.mSize.data[1]) / 2.0f - config.mPosition.data[1];
	
	    if (isActivityInPortraitMode)
	    {
	        // camera image is rotated 90 degrees
	        int rotatedX = videoMode.mHeight - cameraPoint.data[1];
	        int rotatedY = cameraPoint.data[0];
	
	        result = QCAR::Vec2F(rotatedX * config.mSize.data[0] / (float) videoMode.mHeight + xOffset,
	                           rotatedY * config.mSize.data[1] / (float) videoMode.mWidth + yOffset);
	    }
	    else
	    {
	        result = QCAR::Vec2F(cameraPoint.data[0] * config.mSize.data[0] / (float) videoMode.mWidth + xOffset,
	                           cameraPoint.data[1] * config.mSize.data[1] / (float) videoMode.mHeight + yOffset);
	    }		           
        jx[textureIndex] = (int)result.data[0];
        jy[textureIndex] = (int)result.data[1];
        // get position and orientation of the target respect to the camera reference frame
       	QCAR::Matrix34F pose = trackableResult->getPose();        
       	target_pose_x[textureIndex] = pose.data[3];
       	target_pose_y[textureIndex] = pose.data[7];
       	target_pose_z[textureIndex] = pose.data[11];
		QCAR::Vec3F position(pose.data[3], pose.data[7], pose.data[11]);
		// dist = modulo del vettore traslazione = sqrt(x*x + y*y + z*z)
		distance[textureIndex] = sqrt(position.data[0] * position.data[0] + position.data[1] * position.data[1] + position.data[2] * position.data[2]);            
        QCAR::Matrix44F inverseMV = SampleMath::Matrix44FInverse(modelViewMatrix);
        QCAR::Matrix44F invTranspMV = SampleMath::Matrix44FTranspose(inverseMV);
        // position of the camera and orientation axis with coordinates represented in the reference frame of the trackable
        //cam_x[textureIndex] = invTranspMV.data[4];
        //cam_y[textureIndex] = invTranspMV.data[5];
        cam_z[textureIndex] = invTranspMV.data[6]; 
        detected[textureIndex] = true;           	              

        //jstring js = env->NewStringUTF(marker.getName());
        //jclass javaClass = env->GetObjectClass(obj);
       	//jmethodID method = env->GetMethodID(javaClass, "displayMessage", "(Ljava/lang/String;)V");
       	//env->CallVoidMethod(obj, method, js);
    }
    
    // put outside the previous loop because we want to warn the java object of the state of the detection in all cases (both when detected and when not detected)
    for(int i=0; i<4; i++) {
    	// obj, method, marker id, detected, x screen coord, y screen coord, distance, robot orientation component, robot to target angle component y, robot to target angle component z);
		env->CallVoidMethod(obj, method, i, detected[i], jx[i], jy[i], distance[i], cam_z[i], target_pose_y[i], target_pose_z[i]);
	}	

    QCAR::Renderer::getInstance().end();
    
}
コード例 #25
0
ファイル: ImageTargets.cpp プロジェクト: sdujq/ladydu
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *env, jobject obj)
{
	//LOG("Java_com_qualcomm_QCARSamples_ImageTargets_GLRenderer_renderFrame");

	// Clear color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Get the state from QCAR and mark the beginning of a rendering section
	QCAR::State state = QCAR::Renderer::getInstance().begin();

	// Explicitly render the Video Background
	QCAR::Renderer::getInstance().drawVideoBackground();

#ifdef USE_OPENGL_ES_1_1
	// Set GL11 flags:
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glEnable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);

#endif

	glEnable(GL_DEPTH_TEST);

	// We must detect if background reflection is active and adjust the culling direction.
	// If the reflection is active, this means the post matrix has been reflected as well,
	// therefore standard counter clockwise face culling will result in "inside out" models.
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	if(QCAR::Renderer::getInstance().getVideoBackgroundConfig().mReflection == QCAR::VIDEO_BACKGROUND_REFLECTION_ON)
	glFrontFace(GL_CW);//Front camera
	else
	glFrontFace(GL_CCW);//Back camera

	// Did we find any trackables this frame?
	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());

		// Choose the texture based on the target name:
		int textureIndex;
		if (strcmp(trackable.getName(), "chips") == 0)
		{
			textureIndex = 0;
		}
		else if (strcmp(trackable.getName(), "stones") == 0)
		{
			textureIndex = 1;
		}
		else
		{
			textureIndex = 2;
		}

		const Texture* const thisTexture = textures[textureIndex];

#ifdef USE_OPENGL_ES_1_1
		// Load projection matrix:
		glMatrixMode(GL_PROJECTION);
		glLoadMatrixf(projectionMatrix.data);

		// Load model view matrix:
		glMatrixMode(GL_MODELVIEW);
		glLoadMatrixf(modelViewMatrix.data);
		glTranslatef(0.f, 0.f, kObjectScale);
		glScalef(kObjectScale, kObjectScale, kObjectScale);

		// Draw object:
		glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
		//glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &teapotTexCoords[0]);
		glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &cubeVerts[0]);
		glNormalPointer(GL_FLOAT, 0, (const GLvoid*) &cubeNormals[0]);
		glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
				(const GLvoid*) &teapotIndices[0]);
#else

		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);
		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);
//        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, thisTexture->mTextureID);
		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]);
//		glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);
		//glDrawArrays(GL_TRIANGLES, 0, cubeNumVerts);
		glDisableVertexAttribArray(vertexHandle);
		glDisableVertexAttribArray(normalHandle);
		glDisableVertexAttribArray(textureCoordHandle);

		SampleUtils::checkGlError("ImageTargets renderFrame");
#endif
		//jq mark
		jclass javaClass = env->GetObjectClass(obj);
		jfloatArray modelviewArray = env->NewFloatArray(16);
		env->SetFloatArrayRegion(modelviewArray, 0, 16, modelViewMatrix.data);
		jmethodID method = env->GetMethodID(javaClass, "updateModelviewMatrix", "([F)V");
		env->CallVoidMethod(obj,method,modelviewArray);
		env->DeleteLocalRef(modelviewArray);
		//jq mark
		jclass javaClass2 = env->GetObjectClass(obj);
		jfloatArray modelviewArray2 = env->NewFloatArray(16);
		env->SetFloatArrayRegion(modelviewArray2, 0, 16, projectionMatrix.data);
		jmethodID method2 = env->GetMethodID(javaClass2, "projectionMatrix", "([F)V");
		env->CallVoidMethod(obj,method2,modelviewArray2);
		env->DeleteLocalRef(modelviewArray2);
	}

	glDisable(GL_DEPTH_TEST);

#ifdef USE_OPENGL_ES_1_1        
	glDisable(GL_TEXTURE_2D);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#endif

	QCAR::Renderer::getInstance().end();
}
コード例 #26
0
ファイル: ImageTargets.cpp プロジェクト: naveenlp/AR_Trials
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject)
{
    //LOG("Java_com_qualcomm_QCARSamples_ImageTargets_GLRenderer_renderFrame");

    // Clear color and depth buffer 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Render video background:
    QCAR::State state = QCAR::Renderer::getInstance().begin();
        
#ifdef USE_OPENGL_ES_1_1
    // Set GL11 flags:
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);
        
#endif

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    // Did we find any trackables this frame?
    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());        

        // Choose the texture based on the target name:
        int textureIndex = (!strcmp(trackable->getName(), "stones")) ? 0 : 1;
        const Texture* const thisTexture = textures[textureIndex];

#ifdef USE_OPENGL_ES_1_1
        // Load projection matrix:
        glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(projectionMatrix.data);

        // Load model view matrix:
        glMatrixMode(GL_MODELVIEW);
        glLoadMatrixf(modelViewMatrix.data);
        glTranslatef(0.f, 0.f, kObjectScale);
        glScalef(kObjectScale, kObjectScale, kObjectScale);

        // Draw object:
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &teapotTexCoords[0]);
        glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &teapotVertices[0]);
        glNormalPointer(GL_FLOAT, 0,  (const GLvoid*) &teapotNormals[0]);
        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &teapotIndices[0]);
#else

        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);
         
        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, thisTexture->mTextureID);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );
        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &teapotIndices[0]);

        SampleUtils::checkGlError("ImageTargets renderFrame");
#endif

    }

    glDisable(GL_DEPTH_TEST);

#ifdef USE_OPENGL_ES_1_1        
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
    glDisableVertexAttribArray(vertexHandle);
    glDisableVertexAttribArray(normalHandle);
    glDisableVertexAttribArray(textureCoordHandle);
#endif

    QCAR::Renderer::getInstance().end();
}
コード例 #27
0
ファイル: ImageTargets.cpp プロジェクト: vdarmadi/dishart
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject)
{
    //LOG("Java_com_qualcomm_QCARSamples_ImageTargets_GLRenderer_renderFrame");

    // Clear color and depth buffer 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    
    // Explicitly render the Video Background
    QCAR::Renderer::getInstance().drawVideoBackground();
       
#ifdef USE_OPENGL_ES_1_1
    // Set GL11 flags:
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);
        
#endif

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    // Did we find any trackables this frame?
    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());

        const QCAR::CameraCalibration& cameraCalibration = QCAR::CameraDevice::getInstance().getCameraCalibration();
        QCAR::Vec2F cameraPoint = QCAR::Tool::projectPoint(cameraCalibration, result->getPose(), QCAR::Vec3F(0,0,0));
        QCAR::Vec2F xyPoint = cameraPointToScreenPoint(cameraPoint);
        // LOG("xyPoint %f, %f ", xyPoint.data[0], xyPoint.data[1] );
        if (xyPoint.data[1] > (screenHeight / 2) + tolerancy || xyPoint.data[1] < (screenHeight / 2) - tolerancy) {
        	continue;
        }
        // Choose the texture based on the target name:
        int textureIndex = 0;
        // LOG("texture = %s", trackable->getName());
        // LOG("textureCount %d", textureCount);

        char trackJpg[strlen(trackable.getName()) + 4];
        strcpy(trackJpg, trackable.getName());
        strcat(trackJpg, ".jpg");
        // LOG("trackJpg %s", trackJpg);

        char trackPng[strlen(trackable.getName()) + 4];
        strcpy(trackPng, trackable.getName());
        strcat(trackPng, ".png");
        // LOG("trackPng %s", trackPng);

        for(int i = 0; i < textureCount; i++) {
            // LOG("textures[i]->mName %s", textures[i]->mName);
        	if (strcmp(textures[i]->mName, trackPng) == 0 ||
        			strcmp(textures[i]->mName, trackJpg) == 0) {
        		textureIndex = i;
        	}
        }
        const Texture* const thisTexture = textures[textureIndex];
        // LOG("thisTexture->mName %s", textures[textureIndex]->mName);

#ifdef USE_OPENGL_ES_1_1
        // Load projection matrix:
        glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(projectionMatrix.data);

        // Load model view matrix:
        glMatrixMode(GL_MODELVIEW);
        glLoadMatrixf(modelViewMatrix.data);
        glTranslatef(0.f, 0.f, kObjectScale);
        glScalef(kObjectScale, kObjectScale, kObjectScale);

        // Draw object:
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &teapotTexCoords[0]);
        glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &teapotVertices[0]);
        glNormalPointer(GL_FLOAT, 0,  (const GLvoid*) &teapotNormals[0]);
        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &teapotIndices[0]);
#else
        /*
        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);
         
        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, thisTexture->mTextureID);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );
        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &teapotIndices[0]);
		*/
        //QCAR::Vec2F targetSize = ((QCAR::ImageTarget *) trackable)->getSize();
        //QCAR::Vec2F targetSize = thisTexture->getSize();

        const QCAR::ImageTarget& imageTarget = (const QCAR::ImageTarget&) result->getTrackable();

        QCAR::Vec2F targetSize = imageTarget.getSize();

        QCAR::Matrix44F modelViewProjection;

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

        //SampleUtils::scalePoseMatrix(targetSize.data[0], targetSize.data[1], 1.0f, &modelViewMatrix.data[0]); SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix.data[0] , &modelViewProjection.data[0]);
        SampleUtils::scalePoseMatrix(256, 256, kObjectScale,  &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]);

        SampleUtils::checkGlError("ImageTargets renderFrame");
#endif

    }

    glDisable(GL_DEPTH_TEST);

#ifdef USE_OPENGL_ES_1_1        
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
    glDisableVertexAttribArray(vertexHandle);
    glDisableVertexAttribArray(normalHandle);
    glDisableVertexAttribArray(textureCoordHandle);
#endif

    QCAR::Renderer::getInstance().end();
}
コード例 #28
0
    JNIEXPORT void JNICALL
    Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject)
    {
        //LOG("Java_com_qualcomm_QCARSamples_ImageTargets_GLRenderer_renderFrame");

        // Clear color and depth buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // Get the state from QCAR and mark the beginning of a rendering section
        QCAR::State state = QCAR::Renderer::getInstance().begin();

        // Explicitly render the Video Background
        QCAR::Renderer::getInstance().drawVideoBackground();

        glEnable(GL_DEPTH_TEST);

        // We must detect if background reflection is active and adjust the culling direction.
        // If the reflection is active, this means the post matrix has been reflected as well,
        // therefore standard counter clockwise face culling will result in "inside out" models.
        glEnable(GL_CULL_FACE);
        glCullFace(GL_BACK);
        if (QCAR::Renderer::getInstance().getVideoBackgroundConfig().mReflection == QCAR::VIDEO_BACKGROUND_REFLECTION_ON)
            glFrontFace(GL_CW);  //Front camera
        else
            glFrontFace(GL_CCW);   //Back camera


        // Did we find any trackables this frame?
        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());

            // Choose the texture based on the target name:
            int textureIndex;
            modeltype = 11;
            if (strcmp(trackable.getName(), "huitailang") == 0||strcmp(trackable.getName(), "stones") == 0||strcmp(trackable.getName(), "chips") == 0)
            {
                modeltype = 2;
                textureIndex = 0;

                const Texture* const thisTexture = textures[textureIndex];

                QCAR::Matrix44F modelViewProjection;

                modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());
                animateteapot(modelViewMatrix);
                //1.35f*120.0f
                SampleUtils::translatePoseMatrix(0.0f,-0.50f*120.0f,1.35f*120.0f,
                                                 &modelViewMatrix.data[0]);
                //-90.0f
                SampleUtils::rotatePoseMatrix(objectx,  objecty,0.0f, 0,
                                              &modelViewMatrix.data[0]);
                SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                                             &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*) &teapotVerts[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, thisTexture->mTextureID);
                glUniform1i(texSampler2DHandle, 0 );
                glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                                   (GLfloat*)&modelViewProjection.data[0] );
                glDrawArrays(GL_TRIANGLES, 0,teapotNumVerts);

                glDisableVertexAttribArray(vertexHandle);
                glDisableVertexAttribArray(normalHandle);
                glDisableVertexAttribArray(textureCoordHandle);

                SampleUtils::checkGlError("ImageTargets renderFrame");
                glDisable(GL_DEPTH_TEST);

                QCAR::Renderer::getInstance().end();
            }
            else if (strcmp(trackable.getName(), "heroin") == 0)
            {
                textureIndex = 0;
                modeltype = 1;

                const Texture* const thisTexture = textures[textureIndex];

                QCAR::Matrix44F modelViewProjection;

                modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());
                animateteapot(modelViewMatrix);
                //1.35f*120.0f
                SampleUtils::translatePoseMatrix(0.0f,-0.50f*120.0f,1.35f*120.0f,
                                                 &modelViewMatrix.data[0]);
                //-90.0f
                SampleUtils::rotatePoseMatrix(objectx,  objecty,0.0f, 0,
                                              &modelViewMatrix.data[0]);
                SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                                             &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*) &HeroinVerts[0]);
                glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &HeroinNormals[0]);
                glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &HeroinTexCoords[0]);

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

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

                glDisableVertexAttribArray(vertexHandle);
                glDisableVertexAttribArray(normalHandle);
                glDisableVertexAttribArray(textureCoordHandle);

                SampleUtils::checkGlError("ImageTargets renderFrame");
                glDisable(GL_DEPTH_TEST);

                QCAR::Renderer::getInstance().end();
            }
            else if (strcmp(trackable.getName(), "stones") == 0)
            {
                textureIndex = 2;
            }
            else if (strcmp(trackable.getName(), "chips") == 0)
            {
                ;
            }
            else if (strcmp(trackable.getName(), "chhhh") == 0)
            {
                textureIndex = 0;
                modeltype = 3;

                const Texture* const thisTexture = textures[textureIndex];

                QCAR::Matrix44F modelViewProjection;

                modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());
                animateteapot(modelViewMatrix);
                //1.35f*120.0f
                SampleUtils::translatePoseMatrix(0.0f,-0.50f*120.0f,1.35f*120.0f,
                                                 &modelViewMatrix.data[0]);
                //-90.0f
                SampleUtils::rotatePoseMatrix(objectx,  objecty,0.0f, 0,
                                              &modelViewMatrix.data[0]);
                SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                                             &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*) &chhhhVerts[0]);
                glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &chhhhNormals[0]);
                glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &chhhhTexCoords[0]);

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

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

                glDisableVertexAttribArray(vertexHandle);
                glDisableVertexAttribArray(normalHandle);
                glDisableVertexAttribArray(textureCoordHandle);

                SampleUtils::checkGlError("ImageTargets renderFrame");
                glDisable(GL_DEPTH_TEST);

                QCAR::Renderer::getInstance().end();
            }
            else if (strcmp(trackable.getName(), "hh") == 0)
            {
                textureIndex = 0;
                modeltype = 4;

                const Texture* const thisTexture = textures[textureIndex];

                QCAR::Matrix44F modelViewProjection;

                modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());
                animateteapot(modelViewMatrix);
                //1.35f*120.0f
                SampleUtils::translatePoseMatrix(0.0f,-0.50f*120.0f,1.35f*120.0f,
                                                 &modelViewMatrix.data[0]);
                //-90.0f
                SampleUtils::rotatePoseMatrix(objectx,  objecty,0.0f, 0,
                                              &modelViewMatrix.data[0]);
                SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                                             &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*) &hhVerts[0]);
                glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &hhNormals[0]);
                glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &hhTexCoords[0]);

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

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

                glDisableVertexAttribArray(vertexHandle);
                glDisableVertexAttribArray(normalHandle);
                glDisableVertexAttribArray(textureCoordHandle);

                SampleUtils::checkGlError("ImageTargets renderFrame");
                glDisable(GL_DEPTH_TEST);

                QCAR::Renderer::getInstance().end();
            }
            else if (strcmp(trackable.getName(), "coo") == 0)
            {
                textureIndex = 0;
                modeltype = 5;

                const Texture* const thisTexture = textures[textureIndex];

                QCAR::Matrix44F modelViewProjection;

                modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());
                animateteapot(modelViewMatrix);
                //1.35f*120.0f
                SampleUtils::translatePoseMatrix(0.0f,-0.50f*120.0f,1.35f*120.0f,
                                                 &modelViewMatrix.data[0]);
                //-90.0f
                SampleUtils::rotatePoseMatrix(objectx,  objecty,0.0f, 0,
                                              &modelViewMatrix.data[0]);
                SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                                             &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*) &cooVerts[0]);
                glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &cooNormals[0]);
                glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &cooTexCoords[0]);

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

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

                glDisableVertexAttribArray(vertexHandle);
                glDisableVertexAttribArray(normalHandle);
                glDisableVertexAttribArray(textureCoordHandle);

                SampleUtils::checkGlError("ImageTargets renderFrame");
                glDisable(GL_DEPTH_TEST);

                QCAR::Renderer::getInstance().end();
            }
            else
            {
                textureIndex = 6;
            }

        }

        /*glDisable(GL_DEPTH_TEST);

        QCAR::Renderer::getInstance().end();*/
    }