Example usage for android.opengl Matrix frustumM

List of usage examples for android.opengl Matrix frustumM

Introduction

In this page you can find the example usage for android.opengl Matrix frustumM.

Prototype

public static void frustumM(float[] m, int offset, float left, float right, float bottom, float top, float near,
        float far) 

Source Link

Document

Defines a projection matrix in terms of six clip planes.

Usage

From source file:Main.java

private static void setPerspectiveM(float[] m, int offset, double fovy, double aspect, double zNear,
        double zFar) {
    Matrix.setIdentityM(m, offset);// w w  w.j  a  v  a2s  . co m
    double ymax = zNear * Math.tan(fovy * Math.PI / 360.0);
    double ymin = -ymax;
    double xmin = ymin * aspect;
    double xmax = ymax * aspect;
    Matrix.frustumM(m, offset, (float) xmin, (float) xmax, (float) ymin, (float) ymax, (float) zNear,
            (float) zFar);
}

From source file:Main.java

public static void setPerspectiveM(float[] m, int offset, double fovy, double aspect, double zNear,
        double zFar) {
    Matrix.setIdentityM(m, offset);//from  w  ww.  j  a v  a  2s . c om
    double ymax = zNear * Math.tan(fovy * Math.PI / 360.0);
    double ymin = -ymax;
    double xmin = ymin * aspect;
    double xmax = ymax * aspect;
    Matrix.frustumM(m, offset, (float) xmin, (float) xmax, (float) ymin, (float) ymax, (float) zNear,
            (float) zFar);
}

From source file:com.projecttango.examples.java.planefitting.PlaneFittingActivity.java

/**
 * Use Tango camera intrinsics to calculate the projection Matrix for the Rajawali scene.
 *//*from   ww w. ja  v a 2s . c  om*/
private 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;
}

From source file:com.projecttango.examples.java.augmentedreality.AugmentedRealityActivity.java

/**
 * Use Tango camera intrinsics to calculate the projection matrix for the Rajawali scene.
 *
 * @param intrinsics camera instrinsics for computing the project matrix.
 *//*www  . ja v a  2s  .  com*/
private static float[] projectionMatrixFromCameraIntrinsics(TangoCameraIntrinsics intrinsics) {
    float cx = (float) intrinsics.cx;
    float cy = (float) intrinsics.cy;
    float width = (float) intrinsics.width;
    float height = (float) intrinsics.height;
    float fx = (float) intrinsics.fx;
    float fy = (float) intrinsics.fy;

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

    float xScale = near / fx;
    float yScale = near / fy;
    float xOffset = (cx - (width / 2.0f)) * xScale;
    // Color camera's coordinates has y pointing downwards so we negate this term.
    float yOffset = -(cy - (height / 2.0f)) * yScale;

    float m[] = new float[16];
    Matrix.frustumM(m, 0, xScale * (float) -width / 2.0f - xOffset, xScale * (float) width / 2.0f - xOffset,
            yScale * (float) -height / 2.0f - yOffset, yScale * (float) height / 2.0f - yOffset, near, far);
    return m;
}

From source file:com.projecttango.examples.java.modelcorrespondence.ModelCorrespondenceActivity.java

/**
 * Use Tango camera intrinsics to calculate the projection Matrix for the Rajawali scene.
 *///  ww w.ja  va  2 s .co m
private 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;

    // Adjust camera intrinsics according to rotation from color camera to display.
    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;
}

From source file:com.projecttango.examples.java.greenscreen.GreenScreenActivity.java

/**
 * Use Tango camera intrinsics to calculate the projection Matrix for the OpenGL scene.
 *//*from  w w  w.j a v  a2  s .c  o m*/
private 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;

    float xScale = near / (float) intrinsics.fx;
    float yScale = near / (float) intrinsics.fy;
    float xOffset = (float) (intrinsics.cx - (intrinsics.width / 2.0)) * xScale;
    // Color camera's coordinates has y pointing downwards so we negate this term.
    float yOffset = (float) -(intrinsics.cy - (intrinsics.height / 2.0)) * yScale;

    float m[] = new float[16];
    Matrix.frustumM(m, 0, xScale * (float) -intrinsics.width / 2.0f - xOffset,
            xScale * (float) intrinsics.width / 2.0f - xOffset,
            yScale * (float) -intrinsics.height / 2.0f - yOffset,
            yScale * (float) intrinsics.height / 2.0f - yOffset, near, far);
    return m;
}

From source file:com.projecttango.examples.java.openglar.OpenGlAugmentedRealityActivity.java

/**
 * Use Tango camera intrinsics to calculate the projection Matrix for the OpenGL scene.
 *
 * @param intrinsics camera instrinsics for computing the project matrix.
 *//*from  ww w.  j a va2 s.  c  o  m*/
private static float[] projectionMatrixFromCameraIntrinsics(TangoCameraIntrinsics intrinsics) {
    float cx = (float) intrinsics.cx;
    float cy = (float) intrinsics.cy;
    float width = (float) intrinsics.width;
    float height = (float) intrinsics.height;
    float fx = (float) intrinsics.fx;
    float fy = (float) intrinsics.fy;

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

    float xScale = near / fx;
    float yScale = near / fy;
    float xOffset = (cx - (width / 2.0f)) * xScale;
    // Color camera's coordinates has y pointing downwards so we negate this term.
    float yOffset = -(cy - (height / 2.0f)) * yScale;

    float m[] = new float[16];
    Matrix.frustumM(m, 0, xScale * (float) -width / 2.0f - xOffset, xScale * (float) width / 2.0f - xOffset,
            yScale * (float) -height / 2.0f - yOffset, yScale * (float) height / 2.0f - yOffset, near, far);
    return m;
}