package org.wheelmap.android.tango;
import android.opengl.Matrix;
import com.google.atap.tangoservice.Tango;
import com.google.atap.tangoservice.TangoCameraIntrinsics;
import org.wheelmap.android.app.WheelmapApp;
public class TangoUtils {
public static boolean isTangoSupported() {
return Tango.getVersion(WheelmapApp.get()) > 0;
}
/**
* Use Tango camera intrinsics to calculate the projection Matrix for the Rajawali scene.
*/
static float[] projectionMatrixFromCameraIntrinsics(TangoCameraIntrinsics intrinsics) {
// Uses frustumM to create a projection matrix taking into account calibrated camera
// intrinsic parameter.
// Reference: http://ksimek.github.io/2013/06/03/calibrated_cameras_in_opengl/
float near = 0.1f;
float far = 100;
double cx = intrinsics.cx;
double cy = intrinsics.cy;
double width = intrinsics.width;
double height = intrinsics.height;
double fx = intrinsics.fx;
double fy = intrinsics.fy;
double xscale = near / fx;
double yscale = near / fy;
double xoffset = (cx - (width / 2.0)) * xscale;
// Color camera's coordinates has y pointing downwards so we negate this term.
double yoffset = -(cy - (height / 2.0)) * yscale;
float m[] = new float[16];
Matrix.frustumM(m, 0,
(float) (xscale * -width / 2.0 - xoffset),
(float) (xscale * width / 2.0 - xoffset),
(float) (yscale * -height / 2.0 - yoffset),
(float) (yscale * height / 2.0 - yoffset), near, far);
return m;
}
}