Java Code Examples for android.opengl.Matrix#translateM()

The following examples show how to use android.opengl.Matrix#translateM() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SkeletonLoader2.java    From react-native-3d-model-view with MIT License 6 votes vote down vote up
private JointData extractMainJointData(XmlNode jointNode, boolean isRoot){
	XmlNode instance_geometry = jointNode.getChild("instance_geometry");
	String meshId = instance_geometry != null? instance_geometry.getAttribute("url").substring(1) : null;
	String nameId = jointNode.getAttribute("id");
	int index = boneOrder.indexOf(nameId);
	if (index == -1){
		Log.e("SkeletonLoader2","Joint not found in order: "+nameId);
		boneOrder.add(nameId);
		index = boneOrder.indexOf(nameId);
	}
	String[] matrixData = jointNode.getChild("translate").getData().split(" ");
	float[] matrix = new float[16];
	Matrix.setIdentityM(matrix,0);
	Matrix.translateM(matrix,0,matrix,0,Float.valueOf(matrixData[0]),Float.valueOf(matrixData[1]),Float.valueOf(matrixData[2]));
	// Matrix.transposeM(matrix,0,matrix,0);
	if(isRoot){
		//because in Blender z is up, but in our game y is up.
		// Matrix.multiplyMM(matrix,0,CORRECTION,0,matrix,0);
	}
	jointCount++;
	return new JointData(index, nameId, matrix).setMeshId(meshId);
}
 
Example 2
Source File: MainActivity.java    From Cardboard with Apache License 2.0 6 votes vote down vote up
/**
 * Find a new random position for the object.
 * We'll rotate it around the Y-axis so it's out of sight, and then up or down by a little bit.
 */
private void hideObject() {
    float[] rotationMatrix = new float[16];
    float[] posVec = new float[4];

    // First rotate in XZ plane, between 90 and 270 deg away, and scale so that we vary
    // the object's distance from the user.
    float angleXZ = (float) Math.random() * 180 + 90;
    Matrix.setRotateM(rotationMatrix, 0, angleXZ, 0f, 1f, 0f);
    float oldObjectDistance = mObjectDistance;
    mObjectDistance = (float) Math.random() * 15 + 5;
    float objectScalingFactor = mObjectDistance / oldObjectDistance;
    Matrix.scaleM(rotationMatrix, 0, objectScalingFactor, objectScalingFactor, objectScalingFactor);
    Matrix.multiplyMV(posVec, 0, rotationMatrix, 0, mModelCube, 12);

    // Now get the up or down angle, between -20 and 20 degrees
    float angleY = (float) Math.random() * 80 - 40; // angle in Y plane, between -40 and 40
    angleY = (float) Math.toRadians(angleY);
    float newY = (float)Math.tan(angleY) * mObjectDistance;

    Matrix.setIdentityM(mModelCube, 0);
    Matrix.translateM(mModelCube, 0, posVec[0], newY, posVec[2]);
}
 
Example 3
Source File: GLES20Canvas.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setSize(int width, int height) {
    mWidth = width;
    mHeight = height;
    GLES20.glViewport(0, 0, mWidth, mHeight);
    checkError();
    Matrix.setIdentityM(mMatrices, mCurrentMatrixIndex);
    Matrix.orthoM(mProjectionMatrix, 0, 0, width, 0, height, -1, 1);
    if (getTargetTexture() == null) {
        mScreenWidth = width;
        mScreenHeight = height;
        Matrix.translateM(mMatrices, mCurrentMatrixIndex, 0, height, 0);
        Matrix.scaleM(mMatrices, mCurrentMatrixIndex, 1, -1, 1);
    }
}
 
Example 4
Source File: Sprite2d.java    From mobile-ar-sensor-logger with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Re-computes mModelViewMatrix, based on the current values for rotation, scale, and
 * translation.
 */
private void recomputeMatrix() {
    float[] modelView = mModelViewMatrix;

    Matrix.setIdentityM(modelView, 0);
    Matrix.translateM(modelView, 0, mPosX, mPosY, 0.0f);
    if (mAngle != 0.0f) {
        Matrix.rotateM(modelView, 0, mAngle, 0.0f, 0.0f, 1.0f);
    }
    Matrix.scaleM(modelView, 0, mScaleX, mScaleY, 1.0f);
    mMatrixReady = true;
}
 
Example 5
Source File: Sprite2d.java    From VideoRecorder with Apache License 2.0 5 votes vote down vote up
/**
 * Re-computes mModelViewMatrix, based on the current values for rotation, scale, and
 * translation.
 */
private void recomputeMatrix() {
    float[] modelView = mModelViewMatrix;

    Matrix.setIdentityM(modelView, 0);
    Matrix.translateM(modelView, 0, mPosX, mPosY, 0.0f);
    if (mAngle != 0.0f) {
        Matrix.rotateM(modelView, 0, mAngle, 0.0f, 0.0f, 1.0f);
    }
    Matrix.scaleM(modelView, 0, mScaleX, mScaleY, 1.0f);
    mMatrixReady = true;
}
 
Example 6
Source File: Sprite2d.java    From RtmpPublisher with Apache License 2.0 5 votes vote down vote up
/**
 * Re-computes mModelViewMatrix, based on the current values for rotation, scale, and
 * translation.
 */
private void recomputeMatrix() {
    float[] modelView = mModelViewMatrix;

    Matrix.setIdentityM(modelView, 0);
    Matrix.translateM(modelView, 0, mPosX, mPosY, 0.0f);
    if (mAngle != 0.0f) {
        Matrix.rotateM(modelView, 0, mAngle, 0.0f, 0.0f, 1.0f);
    }
    Matrix.scaleM(modelView, 0, mScaleX, mScaleY, 1.0f);
    mMatrixReady = true;
}
 
Example 7
Source File: GLES20Canvas.java    From PhotoMovie with Apache License 2.0 5 votes vote down vote up
private void setMatrix(ShaderParameter[] params, float x, float y, float width, float height) {
    Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
    Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
    Matrix.multiplyMM(mTempMatrix, MATRIX_SIZE, mProjectionMatrix, 0, mTempMatrix, 0);
    GLES20.glUniformMatrix4fv(params[INDEX_MATRIX].handle, 1, false, mTempMatrix, MATRIX_SIZE);
    checkError();
}
 
Example 8
Source File: UiLayer.java    From myMediaCodecPlayer-for-FPV with MIT License 5 votes vote down vote up
@Override
void updateViewport(final Viewport viewport) {
    Matrix.setIdentityM(this.mMvp, 0);
    final float yScale = this.mButtonWidthPx / viewport.height;
    final float xScale = yScale * viewport.height / viewport.width;
    Matrix.translateM(this.mMvp, 0, 0.0f, yScale - 1.0f, 0.0f);
    Matrix.scaleM(this.mMvp, 0, xScale, yScale, 1.0f);
}
 
Example 9
Source File: AnimationLoader.java    From react-native-3d-model-view with MIT License 5 votes vote down vote up
private void processXYTransforms(String jointName, String[] rawTimes, String[] rawData, List<Float> keyTimes, KeyFrameData[] keyFrames, boolean root){
	for(int i=0;i<rawTimes.length;i++){
		Float keyTime = Float.parseFloat(rawTimes[i]);
		float[] matrixData = new float[16];
		Matrix.setIdentityM(matrixData,0);
		Matrix.translateM(matrixData,0,matrixData,0, Float.parseFloat(rawData[i*2 + 0]),Float.parseFloat(rawData[i*2 + 1]),0);
		if(root){
			//because up axis in Blender is different to up axis in game
			Matrix.multiplyMM(matrixData,0,CORRECTION,0,matrixData,0);
		}
		keyFrames[keyTimes.indexOf(keyTime)].addJointTransform(new JointTransformData(jointName, matrixData));
	}
}
 
Example 10
Source File: MyOSDReceiverRenderer.java    From myMediaCodecPlayer-for-FPV with MIT License 5 votes vote down vote up
public void setupModelMatrices(){
    //Setup ModelMatrices(needs only be done one Time per Frame)
    if(countUp1){angle_z +=0.2;}else{angle_z -=0.2;}if(angle_z >=40){countUp1=false;}if(angle_z <=-40){countUp1=true;}
    //up_down
    if(countUp2){angle_x +=0.2;}else{angle_x -=0.2;}if(angle_x >=40){countUp2=false;}if(angle_x <=-40){countUp2=true;}
    //rotating vertically (only for Kopter)
    if(countUp3){angle_y +=0.2;}else{angle_y -=0.2;}if(angle_y >=40){countUp3=false;}if(angle_y <=-40){countUp3=true;}
    mHome_Arrow_angle_y+=0.4;if(mHome_Arrow_angle_y>=360){mHome_Arrow_angle_y=0;}
    mHeight_m+=0.1;if(mHeight_m>=100){mHeight_m=0;}
    //
    Matrix.setIdentityM(scratch,0);
    Matrix.rotateM(scratch, 0, angle_x, 1.0f, 0.0f, 0.0f);
    Matrix.rotateM(scratch, 0, angle_y, 0.0f, 1.0f, 0.0f);
    Matrix.rotateM(scratch, 0, angle_z, 0.0f, 0.0f, 1.0f);
    //Lines and their canvases
    float translate_height=(-50.0f+mHeight_m)/25.0f;
    float[] temp=new float[16];
    Matrix.setIdentityM(scratch2, 0);
    Matrix.translateM(scratch2, 0, 0.0f, -translate_height, 0);
    Matrix.multiplyMM(temp, 0, scratch, 0, scratch2, 0);
    Matrix.multiplyMM(mHeightModelM, 0,mWorldDistanceTranslationM, 0, temp, 0);
    //Kpter and side arrows
    Matrix.multiplyMM(mKopterModelM,0,mWorldDistanceTranslationM,0,scratch,0);
    //home arrow
    Matrix.setIdentityM(scratch2, 0);
    Matrix.rotateM(scratch2, 0, mHome_Arrow_angle_y, 0.0f, 1.0f, 0.0f);
    Matrix.multiplyMM(mHomeArrowModelM,0,mWorldDistanceTranslationM,0,scratch2,0);
    //OSD
    /*Matrix.setIdentityM(scratch2,0);
    Matrix.multiplyMM(mOSDModelM,0,mWorldDistanceTranslationM,0,scratch2,0);*/

}
 
Example 11
Source File: SurfaceTopology.java    From geoar-app with Apache License 2.0 5 votes vote down vote up
public SurfaceTopology(){
	
	Matrix.setIdentityM(modelToWorldMatrix, 0);
	Matrix.translateM(modelToWorldMatrix, 0, 0, cameraLandOffset, 0);
	
	this.topology = new TopologyFunction(){
		@Override
		float getHeightValue(float x, float z) {
			return 0;
		}
	};
}
 
Example 12
Source File: DecoderSurface.java    From Mp4Composer-android with MIT License 4 votes vote down vote up
/**
     * Draws the data from SurfaceTexture onto the current EGL surface.
     */
    void drawImage() {

        framebufferObject.enable();
        GLES20.glViewport(0, 0, framebufferObject.getWidth(), framebufferObject.getHeight());


        if (filter != null) {
            filterFramebufferObject.enable();
            GLES20.glViewport(0, 0, filterFramebufferObject.getWidth(), filterFramebufferObject.getHeight());
            GLES20.glClearColor(filter.getClearColor()[0], filter.getClearColor()[1], filter.getClearColor()[2], filter.getClearColor()[3]);
        }

        GLES20.glClear(GL_COLOR_BUFFER_BIT);

        Matrix.multiplyMM(MVPMatrix, 0, VMatrix, 0, MMatrix, 0);
        Matrix.multiplyMM(MVPMatrix, 0, ProjMatrix, 0, MVPMatrix, 0);

        float scaleDirectionX = flipHorizontal ? -1 : 1;
        float scaleDirectionY = flipVertical ? -1 : 1;

        float scale[];
        switch (fillMode) {
            case PRESERVE_ASPECT_FIT:
                scale = FillMode.getScaleAspectFit(rotation.getRotation(), inputResolution.getWidth(), inputResolution.getHeight(), outputResolution.getWidth(), outputResolution.getHeight());

                // Log.d(TAG, "scale[0] = " + scale[0] + " scale[1] = " + scale[1]);

                Matrix.scaleM(MVPMatrix, 0, scale[0] * scaleDirectionX, scale[1] * scaleDirectionY, 1);
                if (rotation != Rotation.NORMAL) {
                    Matrix.rotateM(MVPMatrix, 0, -rotation.getRotation(), 0.f, 0.f, 1.f);
                }
                break;
            case PRESERVE_ASPECT_CROP:
                scale = FillMode.getScaleAspectCrop(rotation.getRotation(), inputResolution.getWidth(), inputResolution.getHeight(), outputResolution.getWidth(), outputResolution.getHeight());
                Matrix.scaleM(MVPMatrix, 0, scale[0] * scaleDirectionX, scale[1] * scaleDirectionY, 1);
                if (rotation != Rotation.NORMAL) {
                    Matrix.rotateM(MVPMatrix, 0, -rotation.getRotation(), 0.f, 0.f, 1.f);
                }
                break;
            case CUSTOM:
                if (fillModeCustomItem != null) {
                    Matrix.translateM(MVPMatrix, 0, fillModeCustomItem.getTranslateX(), -fillModeCustomItem.getTranslateY(), 0f);
                    scale = FillMode.getScaleAspectCrop(rotation.getRotation(), inputResolution.getWidth(), inputResolution.getHeight(), outputResolution.getWidth(), outputResolution.getHeight());

                    if (fillModeCustomItem.getRotate() == 0 || fillModeCustomItem.getRotate() == 180) {
                        Matrix.scaleM(MVPMatrix,
                                0,
                                fillModeCustomItem.getScale() * scale[0] * scaleDirectionX,
                                fillModeCustomItem.getScale() * scale[1] * scaleDirectionY,
                                1);
                    } else {
                        Matrix.scaleM(MVPMatrix,
                                0,
                                fillModeCustomItem.getScale() * scale[0] * (1 / fillModeCustomItem.getVideoWidth() * fillModeCustomItem.getVideoHeight()) * scaleDirectionX,
                                fillModeCustomItem.getScale() * scale[1] * (fillModeCustomItem.getVideoWidth() / fillModeCustomItem.getVideoHeight()) * scaleDirectionY,
                                1);
                    }

                    Matrix.rotateM(MVPMatrix, 0, -(rotation.getRotation() + fillModeCustomItem.getRotate()), 0.f, 0.f, 1.f);

//                    Log.d(TAG, "inputResolution = " + inputResolution.getWidth() + " height = " + inputResolution.getHeight());
//                    Log.d(TAG, "out = " + outputResolution.getWidth() + " height = " + outputResolution.getHeight());
//                    Log.d(TAG, "rotation = " + rotation.getRotation());
//                    Log.d(TAG, "scale[0] = " + scale[0] + " scale[1] = " + scale[1]);


                }
            default:
                break;
        }


        previewShader.draw(texName, MVPMatrix, STMatrix, 1f);

        if (filter != null) {
            // 一度shaderに描画したものを、fboを利用して、drawする。drawには必要なさげだけど。
            framebufferObject.enable();
            GLES20.glClear(GL_COLOR_BUFFER_BIT);
            filter.draw(filterFramebufferObject.getTexName(), framebufferObject);
        }


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

        GLES20.glBindFramebuffer(GL_FRAMEBUFFER, 0);
        GLES20.glViewport(0, 0, framebufferObject.getWidth(), framebufferObject.getHeight());

        GLES20.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        normalShader.draw(framebufferObject.getTexName(), null);
    }
 
Example 13
Source File: GLES20Canvas.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void translate(float x, float y, float z) {
    Matrix.translateM(mMatrices, mCurrentMatrixIndex, x, y, z);
}
 
Example 14
Source File: GLES20Canvas.java    From android-openGL-canvas with Apache License 2.0 4 votes vote down vote up
@Override
public void translate(float x, float y, float z) {
    Matrix.translateM(mMatrices, mCurrentMatrixIndex, x, y, z);
}
 
Example 15
Source File: ShapeRenderer.java    From ShapesInOpenGLES2.0 with MIT License 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 glUnused)
{
	GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

       // Do a complete rotation every 10 seconds.
       long time = SystemClock.uptimeMillis() % 10000L;
       float angleInDegrees = (360.0f / 10000.0f) * ((int) time);

	// Calculate position of the light. Push into the distance.
	Matrix.setIdentityM(aLightModelMatrix, 0);
	Matrix.translateM(aLightModelMatrix, 0, 0.0f, 0.0f, -5.0f);

	Matrix.multiplyMV(aLightPosInWorldSpace, 0, aLightModelMatrix, 0, aLightPosInModelSpace, 0);
	Matrix.multiplyMV(aLightPosInEyeSpace, 0, aViewMatrix, 0, aLightPosInWorldSpace, 0);

	// Translate the cube into the screen.
	Matrix.setIdentityM(aModelMatrix, 0);
	if(aHeightMap != null){
		Matrix.translateM(aModelMatrix, 0, 0, 0, -300.5f);
	}else {
		Matrix.translateM(aModelMatrix, 0, 0, 0, -3.5f);
	}
       if(aDeltaX != 0 || aDeltaY != 0) {
           aRotationStatus = false;
       }
       if(aRotationStatus) {
           Matrix.rotateM(aModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);
           Matrix.rotateM(aModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
           Matrix.rotateM(aModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
       }

	// Set a matrix that contains the current rotation.
	Matrix.setIdentityM(aCurrentRotation, 0);
       Matrix.rotateM(aCurrentRotation, 0, aDeltaX, 0.0f, 1.0f, 0.0f);
	Matrix.rotateM(aCurrentRotation, 0, aDeltaY, 1.0f, 0.0f, 0.0f);
	aDeltaX = 0.0f;
	aDeltaY = 0.0f;

	// Multiply the current rotation by the accumulated rotation, and then set the accumulated rotation to the result.
	Matrix.multiplyMM(aTemporaryMatrix, 0, aCurrentRotation, 0, aAccumulatedRotation, 0);
	System.arraycopy(aTemporaryMatrix, 0, aAccumulatedRotation, 0, 16);

	// Rotate the cube taking the overall rotation into account.
	Matrix.multiplyMM(aTemporaryMatrix, 0, aModelMatrix, 0, aAccumulatedRotation, 0);
	System.arraycopy(aTemporaryMatrix, 0, aModelMatrix, 0, 16);

	// This multiplies the view matrix by the model matrix, and stores
	// the result in the MVP matrix
	// (which currently contains model * view).
	Matrix.multiplyMM(aMVPMatrix, 0, aViewMatrix, 0, aModelMatrix, 0);

	// This multiplies the modelview matrix by the projection matrix,
	// and stores the result in the MVP matrix
	// (which now contains model * view * projection).
	Matrix.multiplyMM(aTemporaryMatrix, 0, aProjectionMatrix, 0, aMVPMatrix, 0);
	System.arraycopy(aTemporaryMatrix, 0, aMVPMatrix, 0, 16);

       if(aPoints != null){
           aPoints.render(aMVPMatrix);
       }else if(aLines != null){
           aLines.render(aMVPMatrix);
       }else if(aTriangles != null){
           aTriangles.render(aMVPMatrix);
       }else if(aQuad != null){
           aQuad.render(aMVPMatrix, aTexture);
       }else if(aCubes != null){
           aCubes.render(aMVPMatrix, aTexture);
       }else if(aSpheres != null){
           aSpheres.render(aMVPMatrix);
       }else if(aHeightMap != null){
		aHeightMap.render(aMVPMatrix);
	}

}
 
Example 16
Source File: StarWarsRenderer.java    From StarWars.Android with MIT License 4 votes vote down vote up
private void drawGl() {
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
    if (mAndroidDataHandle > 0) {

        GLES20.glUseProgram(programHandle);

        // Set program handles
        mvpMatrixHandle = GLES20.glGetUniformLocation(programHandle, "u_MVPMatrix");
        mvMatrixHandle = GLES20.glGetUniformLocation(programHandle, "u_MVMatrix");
        textureUniformHandle = GLES20.glGetUniformLocation(programHandle, "u_Texture");
        deltaPosHandle = GLES20.glGetUniformLocation(programHandle, "u_DeltaPos");

        positionHandle = GLES20.glGetAttribLocation(programHandle, "a_Position");
        normalHandle = GLES20.glGetAttribLocation(programHandle, "a_Normal");
        textureCoordinateHandle = GLES20.glGetAttribLocation(programHandle, "a_TexCoordinate");
        tileXyHandle = GLES20.glGetAttribLocation(programHandle, "a_TileXY");

        Matrix.setIdentityM(mModelMatrix, 0);
        Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, 5f);

        // Set a matrix that contains the current rotation.
        Matrix.setIdentityM(mCurrentRotation, 0);

        Matrix.multiplyMM(mTemporaryMatrix, 0, mCurrentRotation, 0, mAccumulatedRotation, 0);
        System.arraycopy(mTemporaryMatrix, 0, mAccumulatedRotation, 0, 16);

        Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);

        // Pass in the modelview matrix.
        GLES20.glUniformMatrix4fv(mvMatrixHandle, 1, false, mMVPMatrix, 0);

        Matrix.multiplyMM(mTemporaryMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
        System.arraycopy(mTemporaryMatrix, 0, mMVPMatrix, 0, 16);

        // Pass in the combined matrix.
        GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, mMVPMatrix, 0);

        // Pass in u_Gravity
        GLES20.glUniform1f(deltaPosHandle, deltaPosX);

        // Pass in the texture information
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

        // Bind the texture to this unit.
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mAndroidDataHandle);

        GLES20.glUniform1i(textureUniformHandle, 0);

        if (mPlane != null) {
            mPlane.render();
        }

        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
    }
}
 
Example 17
Source File: SurfaceTextureRender.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
/**
 * オフスクリーンに SurfaceTexture を描画します.
 *
 * @param st 描画を行う SurfaceTexture
 * @param displayRotation 画面の回転
 */
void drawFrame(SurfaceTexture st, int displayRotation) {
    st.getTransformMatrix(mSTMatrix);

    switch (displayRotation) {
        default:
        case Surface.ROTATION_0:
            break;
        case Surface.ROTATION_90:
            Matrix.rotateM(mSTMatrix, 0, 270, 0, 0, 1);
            Matrix.translateM(mSTMatrix, 0, -1, 0, 0);
            break;
        case Surface.ROTATION_180:
            Matrix.rotateM(mSTMatrix, 0, 180, 0, 0, 1);
            Matrix.translateM(mSTMatrix, 0, -1, -1, 0);
            break;
        case Surface.ROTATION_270:
            Matrix.rotateM(mSTMatrix, 0, 90, 0, 0, 1);
            Matrix.translateM(mSTMatrix, 0, 0, -1, 0);
            break;
    }

    // (optional) clear to green so we can see if we're failing to set pixels
    GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glUseProgram(mProgram);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);

    mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
    GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
    GLES20.glEnableVertexAttribArray(maPositionHandle);

    mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
    GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
    GLES20.glEnableVertexAttribArray(maTextureHandle);

    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
    GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

    // IMPORTANT: on some devices, if you are sharing the external texture between two
    // contexts, one context may not see updates to the texture unless you un-bind and
    // re-bind it.  If you're not using shared EGL contexts, you don't need to bind
    // texture 0 here.
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
}
 
Example 18
Source File: Left.java    From IjkVRPlayer with Apache License 2.0 4 votes vote down vote up
public Left(Texture2dProgram program) {
    super(program);
    Matrix.setIdentityM(mModelMatrix, 0);
    Matrix.scaleM(mModelMatrix, 0, 0.5f, 0.5f, 0.5f);
    Matrix.translateM(mModelMatrix, 0, -1f, 0, 0); // translation to the left
}
 
Example 19
Source File: GLCanvasImpl.java    From document-viewer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void translate(final float x, final float y, final float z) {
    Matrix.translateM(mMatrixValues, 0, x, y, z);
}
 
Example 20
Source File: myRenderer.java    From opengl with Apache License 2.0 3 votes vote down vote up
public void onDrawFrame(GL10 glUnused) {

        // Clear the color buffer  set above by glClearColor.
        GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT | GLES30.GL_DEPTH_BUFFER_BIT);

        //need this otherwise, it will over right stuff and the cube will look wrong!
        GLES30.glEnable(GLES30.GL_DEPTH_TEST);

        // Set the camera position (View matrix)  note Matrix is an include, not a declared method.
        Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

        // Create a rotation and translation for the cube
        Matrix.setIdentityM(mRotationMatrix, 0);

        //move the cube up/down and left/right
        Matrix.translateM(mRotationMatrix, 0, mTransX, mTransY, 0);

        //mangle is how fast, x,y,z which directions it rotates.
        Matrix.rotateM(mRotationMatrix, 0, mAngle, 1.0f, 1.0f, 1.0f);

        // combine the model with the view matrix
        Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mRotationMatrix, 0);

        // combine the model-view with the projection matrix
        Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);

        mCube.draw(mMVPMatrix);

        //change the angle, so the cube will spin.
        mAngle+=.4;

    }