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

The following examples show how to use android.opengl.Matrix#rotateM() . 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: Object3D.java    From smartGL with Apache License 2.0 6 votes vote down vote up
@Override
final public void computeMatrix(float[] matrix) {
	Matrix.setIdentityM(matrix, 0);
	Matrix.translateM(matrix, 0, mPosX, mPosY, mPosZ);

	if (mRotX != 0) {
		Matrix.rotateM(matrix, 0, mRotX, 1, 0, 0);
	}

	if (mRotY != 0) {
		Matrix.rotateM(matrix, 0, mRotY, 0, 1, 0);
	}

	if (mRotZ != 0) {
		Matrix.rotateM(matrix, 0, mRotZ, 0, 0, 1);
	}

	if ((mScaleX != 1) || (mScaleY != 1) || (mScaleZ != 1)) {
		Matrix.scaleM(matrix, 0, mScaleX, mScaleY, mScaleZ);
	}
}
 
Example 2
Source File: GraphicObject.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
public float [] applyDeltaRotation(float x, float y, float z) {
	computeMatrix();
	Matrix.rotateM(currentMatrix, 0, z, 0, 0, 1);
	Matrix.rotateM(currentMatrix, 0, x, 1, 0, 0);		
	Matrix.rotateM(currentMatrix, 0, y, 0, 1, 0);
	extractVectors();
	return currentMatrix;
}
 
Example 3
Source File: LessonOneRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 glUnused) 
{
	GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);			        
               
       // Do a complete rotation every 10 seconds.
       long time = SystemClock.uptimeMillis() % 10000L;
       float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
       
       // Draw the triangle facing straight on.
       Matrix.setIdentityM(mModelMatrix, 0);
       Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);        
       drawTriangle(mTriangle1Vertices);
       
       // Draw one translated a bit down and rotated to be flat on the ground.
       Matrix.setIdentityM(mModelMatrix, 0);
       Matrix.translateM(mModelMatrix, 0, 0.0f, -1.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, 90.0f, 1.0f, 0.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);        
       drawTriangle(mTriangle2Vertices);
       
       // Draw one translated a bit to the right and rotated to be facing to the left.
       Matrix.setIdentityM(mModelMatrix, 0);
       Matrix.translateM(mModelMatrix, 0, 1.0f, 0.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, 90.0f, 0.0f, 1.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
       drawTriangle(mTriangle3Vertices);
}
 
Example 4
Source File: Vector3.java    From Tanks with MIT License 5 votes vote down vote up
public void setFromAngles(Vector3 angles)
{
  float[] matrix = new float[16];
  Matrix.setIdentityM(matrix, 0);
  Matrix.rotateM(matrix, 0, angles.getX(), 1, 0, 0);
  Matrix.rotateM(matrix, 0, angles.getY(), 0, 1, 0);
  Matrix.rotateM(matrix, 0, angles.getZ(), 0, 0, 1);

  Matrix.multiplyMV(getRaw(), 0, matrix, 0, Vector3.xAxis.getRaw(), 0);
  normalize();
}
 
Example 5
Source File: GLUtils.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * モデルビュー変換行列にxy平面で指定した角度回転させた回転行列をセットする
 * @param mvp
 * @param degrees
 */
public static void setRotation(final float[] mvp, final int degrees) {
	Matrix.setIdentityM(mvp, 0);
	if ((degrees % 180) != 0) {
		Matrix.rotateM(mvp, 0, degrees, 0.0f, 0.0f, 1.0f);
	}
}
 
Example 6
Source File: AnimationLoader.java    From react-native-3d-model-view with MIT License 5 votes vote down vote up
private void processRotationZTransforms(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.rotateM(matrixData,0,matrixData,0, Float.parseFloat(rawData[i]), 0,1,0);
		keyFrames[keyTimes.indexOf(keyTime)].addJointTransform(new JointTransformData(jointName, matrixData));
	}
}
 
Example 7
Source File: GLSpriteProvider.java    From Tanks with MIT License 5 votes vote down vote up
private void tryRebuildMatrix()
{
  if (!needRebuildMatrix)
    return;

  Matrix.setIdentityM(modelMatrix, 0);
  Matrix.translateM(modelMatrix, 0, position.getX(), position.getY(), position.getZ());
  Matrix.rotateM(modelMatrix, 0, angle, 0, 0, 1);
  Matrix.scaleM(modelMatrix, 0, width, height, 1);

  needRebuildMatrix = false;
}
 
Example 8
Source File: Vector.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * ベクトルを回転(スレッドセーフではない)
 * x軸:(1,0,0), y軸(0,1,0), z軸(0,0,1)
 * @param angle [度]
 * @param axisX
 * @param axisY
 * @param axisZ
 * @return
 */
public Vector rotate(final float angle, final float axisX, final float axisY, final float axisZ) {
	inVec[0] = x;
	inVec[1] = y;
	inVec[2] = z;
	inVec[3] = 1;
	Matrix.setIdentityM(matrix, 0);
	Matrix.rotateM(matrix, 0, angle, axisX, axisY, axisZ);
	Matrix.multiplyMV(outVec, 0, matrix, 0, inVec, 0);
	x = outVec[0];
	y = outVec[1];
	z = outVec[2];
	return this;
}
 
Example 9
Source File: Sprite2d.java    From grafika 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 10
Source File: GLRenderable.java    From Tanks with MIT License 5 votes vote down vote up
private void setModelMatrix(TData data)
{
  if (prevData != null && prevData.equals(data))
    return;
  else
  {
    prevData = new Data();
    prevData.setFrom(data);
  }

  // reset matrix
  Matrix.setIdentityM(modelMatrix, 0);

  Vector3 localPosition = data.localPosition.getSum(getLocalPosition());
  Vector3 localAngles = data.localAngles.getSum(getLocalAngles());

  // set global
  Matrix.translateM(modelMatrix, 0, data.position.getX(), data.position.getY(), data.position.getZ());
  Matrix.rotateM(modelMatrix, 0, data.angles.getX(), 1, 0, 0);
  Matrix.rotateM(modelMatrix, 0, data.angles.getY(), 0, 1, 0);
  Matrix.rotateM(modelMatrix, 0, data.angles.getZ(), 0, 0, 1);

  // set local
  Matrix.translateM(modelMatrix, 0, localPosition.getX(), localPosition.getY(), localPosition.getZ());
  Matrix.rotateM(modelMatrix, 0, localAngles.getX(), 1, 0, 0);
  Matrix.rotateM(modelMatrix, 0, localAngles.getY(), 0, 1, 0);
  Matrix.rotateM(modelMatrix, 0, localAngles.getZ(), 0, 0, 1);

  // set scale
  Matrix.scaleM(modelMatrix, 0, data.scale, data.scale, data.scale);

  Vector3.release(localPosition);
  Vector3.release(localAngles);
}
 
Example 11
Source File: OpenGLRenderer.java    From smartGL with Apache License 2.0 5 votes vote down vote up
private void computeProjMatrix3D(float[] matrix3D) {
//		float ratio = (float) mWidth / (float) mHeight;
//		float near = 0.1f;
//		Matrix.frustumM(matrix3D, 0, -near, near, -near / ratio, near / ratio, near, 100);

        if (mCamera == null) {
            return;
        }

        float FOV = mCamera.getFOV();
        final float near = mCamera.getNear();
        final float far = mCamera.getFar();
        float ratio = (float) getWidth() / (float) getHeight();
        Matrix.perspectiveM(matrix3D, 0, FOV, ratio, near, far);

        // Rotation
        float ox = -mCamera.getRotX();
        float oy = -mCamera.getRotY();
        float oz = -mCamera.getRotZ();
        if (ox != 0)
            Matrix.rotateM(matrix3D, 0, ox, 1, 0, 0);
        if (oy != 0)
            Matrix.rotateM(matrix3D, 0, oy, 0, 1, 0);
        if (oz != 0)
            Matrix.rotateM(matrix3D, 0, oz, 0, 0, 1);

        // Translation
        float x = -mCamera.getPosX();
        float y = -mCamera.getPosY();
        float z = -mCamera.getPosZ();
        Matrix.translateM(matrix3D, 0, x, y, z);

        mCamera.setDirty(false);
    }
 
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: SimpleCameraRender.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 4 votes vote down vote up
public void setRotation(int rotation) {
  Matrix.setIdentityM(rotationMatrix, 0);
  Matrix.rotateM(rotationMatrix, 0, rotation, 0f, 0f, -1f);
  update();
}
 
Example 14
Source File: Sphere2DPlugin.java    From Pano360 with MIT License 4 votes vote down vote up
@Override
public void onDrawFrame(int textureId) {
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    glSphereProgram.use();
    sphere.uploadTexCoordinateBuffer(glSphereProgram.getTextureCoordinateHandle());
    sphere.uploadVerticesBuffer(glSphereProgram.getPositionHandle());

    float currentDegree= (float) (Math.toDegrees(Math.atan(mScale))*2);
    if(statusHelper.getPanoDisPlayMode()== PanoMode.DUAL_SCREEN)
        Matrix.perspectiveM(projectionMatrix, 0, currentDegree, ratio/2, 1f, 500f);
    else Matrix.perspectiveM(projectionMatrix, 0, currentDegree, ratio, 1f, 500f);

    Matrix.setIdentityM(modelMatrix, 0);
    if (statusHelper.getPanoInteractiveMode()==PanoMode.MOTION){
        orientationHelper.recordRotation(rotationMatrix);
        System.arraycopy(rotationMatrix, 0, modelMatrix, 0, 16);
        orientationHelper.revertRotation(modelMatrix);
    }
    else{
        Matrix.rotateM(modelMatrix, 0, mDeltaY, 1.0f, 0.0f, 0.0f);
        Matrix.rotateM(modelMatrix, 0, mDeltaX, 0.0f, 1.0f, 0.0f);
    }
    Matrix.multiplyMM(modelViewMatrix, 0, viewMatrix, 0, modelMatrix, 0);
    Matrix.multiplyMM(mMVPMatrix, 0, projectionMatrix, 0, modelViewMatrix, 0);

    GLES20.glUniformMatrix4fv(glSphereProgram.getMVPMatrixHandle(), 1, false, mMVPMatrix, 0);

    TextureUtils.bindTexture2D(textureId,GLES20.GL_TEXTURE0,glSphereProgram.getTextureSamplerHandle(),0);

    onPreDrawElements();

    if (statusHelper.getPanoDisPlayMode()== PanoMode.DUAL_SCREEN){
        GLES20.glViewport(0,0,surfaceWidth/2,surfaceHeight);
        sphere.draw();
        GLES20.glViewport(surfaceWidth/2,0,surfaceWidth-surfaceWidth/2,surfaceHeight);
        sphere.draw();
        drawHotSpot();
        GLES20.glViewport(0,0,surfaceWidth/2,surfaceHeight);
        drawHotSpot();
    }else{
        GLES20.glViewport(0,0,surfaceWidth,surfaceHeight);
        sphere.draw();
        drawHotSpot();
    }
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
}
 
Example 15
Source File: TextureRenderer.java    From VideoCompressor with Apache License 2.0 4 votes vote down vote up
public void surfaceCreated() {
    mProgram = createProgram(VERTEX_SHADER, FRAGMENT_SHADER);
    if (mProgram == 0) {
        throw new RuntimeException("failed creating program");
    }
    maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
    checkGlError("glGetAttribLocation aPosition");
    if (maPositionHandle == -1) {
        throw new RuntimeException("Could not get attrib location for aPosition");
    }
    maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord");
    checkGlError("glGetAttribLocation aTextureCoord");
    if (maTextureHandle == -1) {
        throw new RuntimeException("Could not get attrib location for aTextureCoord");
    }
    muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    checkGlError("glGetUniformLocation uMVPMatrix");
    if (muMVPMatrixHandle == -1) {
        throw new RuntimeException("Could not get attrib location for uMVPMatrix");
    }
    muSTMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uSTMatrix");
    checkGlError("glGetUniformLocation uSTMatrix");
    if (muSTMatrixHandle == -1) {
        throw new RuntimeException("Could not get attrib location for uSTMatrix");
    }
    int[] textures = new int[1];
    GLES20.glGenTextures(1, textures, 0);
    mTextureID = textures[0];
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);
    checkGlError("glBindTexture mTextureID");
    GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
    checkGlError("glTexParameter");

    Matrix.setIdentityM(mMVPMatrix, 0);
    if (rotationAngle != 0) {
        Matrix.rotateM(mMVPMatrix, 0, rotationAngle, 0, 0, 1);
    }
}
 
Example 16
Source File: GLDrawer.java    From Building-Android-UIs-with-Custom-Views with MIT License 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 unused) {
    angle = ((float) SystemClock.elapsedRealtime() - startTime) * 0.02f;
    GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    Matrix.setLookAtM(mViewMatrix, 0,
            0, 0, -4,
            0f, 0f, 0f,
            0f, 1.0f, 0.0f);

    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);
    Matrix.rotateM(mMVPMatrix, 0, angle, 1.f, 1.f, 1.f);

    GLES20.glUseProgram(shaderProgram);

    int positionHandle = GLES20.glGetAttribLocation(shaderProgram, "vPosition");

    GLES20.glVertexAttribPointer(positionHandle, 3,
            GLES20.GL_FLOAT, false,
            3 * 4, vertexBuffer);

    int colorHandle = GLES20.glGetAttribLocation(shaderProgram, "aColor");
    GLES20.glVertexAttribPointer(colorHandle, 4,
            GLES20.GL_FLOAT, false,
            4 * 4, colorBuffer);

    int mMVPMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "uMVPMatrix");

    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);

    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glEnableVertexAttribArray(colorHandle);
    GLES20.glEnableVertexAttribArray(positionHandle);
    GLES20.glDrawElements(
            GLES20.GL_TRIANGLES, index.length,
            GLES20.GL_UNSIGNED_SHORT, indexBuffer);

    GLES20.glDisableVertexAttribArray(positionHandle);
    GLES20.glDisableVertexAttribArray(colorHandle);
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
}
 
Example 17
Source File: GLViewTransformer.java    From libcommon with Apache License 2.0 4 votes vote down vote up
/**
 * トランスフォームマトリックスを設定
 * @param transX
 * @param transY
 * @param scaleX
 * @param scaleY
 * @param degrees
 * @return
 */
protected GLViewTransformer setTransform(
	final float transX, final float transY,
	final float scaleX, final float scaleY,
	final float degrees) {

	if ((mCurrentTransX != transX) || (mCurrentTransY != transY)
		|| (mCurrentScaleX != scaleX) || (mCurrentScaleY != scaleY)
		|| (mCurrentRotate != degrees)) {

		mCurrentScaleX = scaleX;
		mCurrentScaleY = scaleY;
		mCurrentTransX = transX;
		mCurrentTransY = transY;
		mCurrentRotate = degrees;
		if (degrees != Float.MAX_VALUE) {
			while (mCurrentRotate > 360) {
				mCurrentRotate -= 360;
			}
			while (mCurrentRotate < -360) {
				mCurrentRotate += 360;
			}
		}

		final int w2 = mTargetView.getView().getWidth() >> 1;
		final int h2 = mTargetView.getView().getHeight() >> 1;
		Matrix.setIdentityM(mTransform, 0);
		// 回転 → 拡大縮小 → 平行移動 → デフォルト
		// デフォルトトランスフォームマトリックスを適用
		Matrix.multiplyMM(mTransform, 0, mTransform, 0, mDefaultTransform, 0);
		// 平行移動
		Matrix.translateM(mTransform, 0, transX, transY, 0.0f);
		// 拡大縮小(たぶんこれじゃだめ、画面中心を原点にして回転させてから元に戻す?)
		Matrix.scaleM(mTransform, 0, scaleX, scaleY, 1.0f);
		// 回転
		if (degrees != Float.MAX_VALUE) {
			Matrix.rotateM(mTransform, 0, mCurrentRotate, 0.0f, 0.0f, 1.0f);
		}
		// apply to target view
		internalSetTransform(mTransform);
	}
	return this;
}
 
Example 18
Source File: TextureRenderer.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
public void surfaceCreated() {
    mProgram = createProgram(VERTEX_SHADER, FRAGMENT_SHADER);
    if (mProgram == 0) {
        throw new RuntimeException("failed creating program");
    }
    maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
    checkGlError("glGetAttribLocation aPosition");
    if (maPositionHandle == -1) {
        throw new RuntimeException("Could not get attrib location for aPosition");
    }
    maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord");
    checkGlError("glGetAttribLocation aTextureCoord");
    if (maTextureHandle == -1) {
        throw new RuntimeException("Could not get attrib location for aTextureCoord");
    }
    muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    checkGlError("glGetUniformLocation uMVPMatrix");
    if (muMVPMatrixHandle == -1) {
        throw new RuntimeException("Could not get attrib location for uMVPMatrix");
    }
    muSTMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uSTMatrix");
    checkGlError("glGetUniformLocation uSTMatrix");
    if (muSTMatrixHandle == -1) {
        throw new RuntimeException("Could not get attrib location for uSTMatrix");
    }
    int[] textures = new int[1];
    GLES20.glGenTextures(1, textures, 0);
    mTextureID = textures[0];
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);
    checkGlError("glBindTexture mTextureID");
    GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
    checkGlError("glTexParameter");

    Matrix.setIdentityM(mMVPMatrix, 0);
    if (rotationAngle != 0) {
        Matrix.rotateM(mMVPMatrix, 0, rotationAngle, 0, 0, 1);
    }
}
 
Example 19
Source File: SpaceObjectAI.java    From Alite with GNU General Public License v3.0 4 votes vote down vote up
public float orient(Vector3f targetPosition, Vector3f targetUp, float deltaTime) {
	so.updateInternals();
	Quaternion.fromMatrix(so.getMatrix(), q1);
	q1.normalize();

	so.getPosition().sub(targetPosition, v0);
	v0.normalize();

	targetUp.cross(v0, v1);
	v1.normalize();
	v0.cross(v1, v2);
	v2.normalize();

	Quaternion.fromVectors(v1, v2, v0, q2);
	q2.normalize();
	q1.computeDifference(q2, q3);
	q3.normalize();

	q3.axisOfRotation(v0);
	float angle = (float) Math.toDegrees(q3.angleOfRotation());
	if (angle > 180) {
		angle = 360 - angle;
		v0.negate();
	}
	float result = 0.0f;
	if (deltaTime > 0) {
		float tempAngle = clamp(angle, -so.getMaxPitchSpeed() * 40, so.getMaxPitchSpeed() * 40) * deltaTime;
		result = Math.abs(tempAngle - angle);
		angle = tempAngle;
	}
	if (Math.abs(angle) > 0.0001f && !Float.isInfinite(angle) && !Float.isNaN(angle)) {
		Matrix.rotateM(so.getMatrix(), 0, angle, v0.x, v0.y, v0.z);
		if (so instanceof CobraMkIII && ((CobraMkIII) so).isPlayerCobra()) {
			v1.x = 1;
			v1.y = 0;
			v1.z = 0;
			v2.x = 0;
			v2.y = 0;
			v2.z = 1;
			so.getGame().getCobra().setRotation(v0.dot(v1), v0.dot(v2));
		}
		so.computeInternals();
	}
	return result;
}
 
Example 20
Source File: MatrixUtils.java    From ZGDanmaku with Apache License 2.0 2 votes vote down vote up
/**
 * 设置绕xyz轴转动
 *
 * @param angle
 * @param x
 * @param y
 * @param z
 */
public static void rotate(float angle, float x, float y, float z)/**/ {
    Matrix.rotateM(mTranslateMatrix, 0, angle, x, y, z);
}