Log in or register to post comments

Get position ARCamera

January 13, 2014 - 3:29am #1
Hi everyone! I have a problem with finding the position of the camera, I always outputs 0,0,0. I wanted to do that when you touch the screen to move away from the camera, so I wanted to calculate the direction of the motion vector by the position of the camera, if you tell me how to do it I will be grateful.
Cited below code:
if (state.getNumTrackableResults()>0) {
            TrackableResult result = state.getTrackableResult(0);
            Trackable trackable = result.getTrackable();
            Matrix34F pose = result.getPose();
            position = new Vec3F(pose.getData()[3],pose.getData()[7],pose.getData()[11]);
            distance = (float) Math.sqrt(position.getData()[0] * position.getData()[0] +position.getData()[1] * position.getData()[1]);
            float angle = (float) Math.asin(position.getData()[0]/distance);

            Matrix44F modelViewMatrix_Vuforia = Tool.convertPose2GLMatrix(pose);

            /*=====================================================================*/
            Matrix44F modelViewMatrix_ = Tool.convertPose2GLMatrix(result.getPose());
            Matrix44F inverseMV = SampleMath.Matrix44FInverse(modelViewMatrix_);
            Matrix44F invTranspMV = SampleMath.Matrix44FTranspose(inverseMV);


            float cam_x = invTranspMV.getData()[12];
            float cam_y = invTranspMV.getData()[13];
            float cam_z = invTranspMV.getData()[14];

            Log.i("VOLL","X : " + cam_x + " Y : " + cam_y + " Z : " + cam_z);
            /*=====================================================================*/







            float[] modelViewMatrix = modelViewMatrix_Vuforia.getData();
            float[] modelViewProjection = new float[16];

            Matrix.translateM(modelViewMatrix, 0, positionX, positionY, 0.1f);
            Matrix.scaleM(modelViewMatrix, 0, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);



            Matrix.multiplyMM(modelViewProjection, 0, vuforiaAppSession.getProjectionMatrix().getData(), 0, modelViewMatrix, 0);

            GLES20.glUseProgram(shaderProgramID);


            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,mTexture.mTextureID[0]);
            GLES20.glUniform1i(texSampler2DHandle, 0);

            GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false,modelViewProjection, 0);

            // finally draw the teapot
            GLES20.glDrawElements(GLES20.GL_TRIANGLES,mTeapot.getNumObjectIndex(), GLES20.GL_UNSIGNED_SHORT,mTeapot.getIndices());


        }

 

 

Log in or register to post comments