// @Override public void orbit(float horizAmount, float vertAmount) { xRotation += horizAmount; yRotation += vertAmount; Log.d("XROT", "X rotation: " + xRotation); Log.d("YROT", "Y rotation: " + yRotation); float[] newPos = Utilities.subtractVectors(position, target); float[] rotMatrix = new float[16]; float[] rotatedPos = new float[4]; if (newPos.length >= 4) newPos[3] = 1.0f; Matrix.setRotateM(rotMatrix, 0, horizAmount, 0.0f, 1.0f, 0.0f); Matrix.multiplyMV(rotatedPos, 0, rotMatrix, 0, newPos, 0); Matrix.multiplyMV(crossProd, 0, rotMatrix, 0, crossProd, 0); Matrix.multiplyMM(rotationMatrix, 0, rotMatrix, 0, rotationMatrix, 0); Matrix.setRotateM(rotMatrix, 0, vertAmount, crossProd[0], crossProd[1], crossProd[2]); Matrix.multiplyMV(rotatedPos, 0, rotMatrix, 0, rotatedPos, 0); Matrix.multiplyMM(rotationMatrix, 0, rotMatrix, 0, rotationMatrix, 0); position = Utilities.addVectors(rotatedPos, target); direction = Utilities.subtractVectors(target, position); }
@Override public void onDrawFrame(GL10 unused) { // Draw background color GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); // Set the camera position (View matrix) Matrix.setLookAtM(mVMatrix, 0, 0, 0, -5, 0f, 0f, 0f, 0f, 5.0f, 0.0f); // Calculate the projection and view transformation Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0); // Draw square // mSquare.draw(mMVPMatrix); // Create a rotation for the triangle // long time = SystemClock.uptimeMillis() % 4000L; // float angle = 0.090f * ((int) time); // Matrix.setRotateM(mRotationMatrix, 0, mAngle, 1, 0, -1.0f); Matrix.setRotateM(xRotationMatrix, 0, -mAngle2, 1, 0, 0f); Matrix.setRotateM(yRotationMatrix, 0, -mAngle, 0, 1, 0f); Matrix.multiplyMM(mRotationMatrix, 0, xRotationMatrix, 0, yRotationMatrix, 0); // Combine the rotation matrix with the projection and camera view Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0); // Draw triangle // mTriangle.draw(mMVPMatrix); if (mMesh != null) { mMesh.draw(mMVPMatrix); } }
@Override public void onDrawFrame(GL10 unused) { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); float[] parScratch = new float[16]; float[] bogieScratch = new float[16]; float[] birdieScratch = new float[16]; float[] shadowScratch1 = new float[16]; float[] shadowScratch2 = new float[16]; // Set the camera position (View matrix) Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); // Calculate the projection and view transformation Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0); float parAngle = -1 * (360 * parPercent); float birdieAngle = -1 * (360 * birdiePercent); float startingAngle = -90; // System.out.println("par angle = " + Float.toString(parAngle)); // System.out.println("birdie angle = " + Float.toString(birdieAngle)); // System.out.println("bogie angle = " + Float.toString(-1 * (360 * bogiePercent))); // Create a rotation transformation; if (angle > -450) { // rotates birdie sector to starting angle from angle 0 if (angle > startingAngle) { Matrix.setRotateM(mRotationMatrixBirdie, 0, angle, 0, 0, -1.0f); } if (angle > startingAngle + birdieAngle) { Matrix.setRotateM(mRotationMatrixPar, 0, angle, 0, 0, -1.0f); } if (angle > startingAngle + birdieAngle + parAngle) { Matrix.setRotateM(mRotationMatrixBogie, 0, angle, 0, 0, -1.0f); } angle -= 2; } // Combine the rotation matrix with the projection and camera view // Note that the mMVPMatrix factor *must be first* in order // for the matrix multiplication product to be correct. Matrix.multiplyMM(shadowScratch1, 0, mMVPMatrix, 0, mRotationMatrixShadow, 0); Matrix.multiplyMM(bogieScratch, 0, mMVPMatrix, 0, mRotationMatrixBogie, 0); Matrix.multiplyMM(parScratch, 0, mMVPMatrix, 0, mRotationMatrixPar, 0); Matrix.multiplyMM(birdieScratch, 0, mMVPMatrix, 0, mRotationMatrixBirdie, 0); shadowPieWheel.draw(mMVPMatrix); wheelBG.draw(mMVPMatrix); bogiePieWheel.draw(bogieScratch); parPieWheel.draw(parScratch); birdiePieWheel.draw(birdieScratch); wheelHole.draw(mMVPMatrix); }
public void rotate(float angle, float x, float y, float z) { if (angle == 0) return; float[] temp = mTempMatrix; Matrix.setRotateM(temp, 0, angle, x, y, z); Matrix.multiplyMM(temp, 16, mMatrixValues, 0, temp, 0); System.arraycopy(temp, 16, mMatrixValues, 0, 16); }
@Override public void onDrawFrame(GL10 unused) { GLES20.glClearColor(0f, 0f, 0f, 0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); if (mShaderCompilerSupport[0] == false) { return; } GLES20.glDisable(GLES20.GL_DEPTH_TEST); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); float angle = (SystemClock.uptimeMillis() % 5000) / 5000f * 360; Matrix.setRotateM(mMatrixModel, 0, angle, 1, 2, 0); Matrix.multiplyMM(mMatrixModelViewProjection, 0, mMatrixView, 0, mMatrixModel, 0); Matrix.multiplyMM( mMatrixModelViewProjection, 0, mMatrixProjection, 0, mMatrixModelViewProjection, 0); mShaderSpline.useProgram(); GLES20.glUniformMatrix4fv( mShaderSpline.getHandle("uModelViewProjectionM"), 1, false, mMatrixModelViewProjection, 0); GLES20.glVertexAttribPointer( mShaderSpline.getHandle("aPosition"), 2, GLES20.GL_FLOAT, false, 0, mBufferSpline); GLES20.glEnableVertexAttribArray(mShaderSpline.getHandle("aPosition")); for (float[] ctrl : mSplines) { GLES20.glUniform3fv(mShaderSpline.getHandle("uCtrl"), 4, ctrl, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, COUNT_VERTICES); } }
public void onDrawFrame(GL10 gl) { // Redraw background color GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); Log.i("MyGLRenderer", "MyGLRenderer : onDrawFrame() - Starting to set camera position"); float[] mViewMatrix = new float[16]; // Set the camera position (View matrix) Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); float[] mMVPMatrix = new float[16]; // Calculate the projection and view transformation Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0); Log.i("MyGLRenderer", "MyGLRenderer : onDrawFrame() - Drawing ClientSide"); float[] scratch = new float[16]; // Create a rotation transformation for the triangle long time = SystemClock.uptimeMillis() % 4000L; float angle = 0.090f * ((int) time); Matrix.setRotateM(mRotationMatrix, 0, angle, 0, 0, -1.0f); // Combine the rotation matrix with the projection and camera view // Note that the mMVPMatrix factor *must be first* in order // for the matrix multiplication product to be correct. Matrix.multiplyMM(scratch, 0, mMVPMatrix, 0, mRotationMatrix, 0); // Draw triangle mTriangle.draw_ClientSide(scratch); }
@Override public void onDrawFrame(GL10 gl) { // TODO Auto-generated method stub // Draw background color GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); // Draw triangle mTriangle.draw(); // 设置相机的位置(视口矩阵) // Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); // 计算投影和视口变换 // Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0); // 绘制形状 // mTriangle.draw(mMVPMatrix); // Create a rotation for the triangle // long time = SystemClock.uptimeMillis() % 4000L; // float angle = 0.090f * ((int) time); Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f); // 把旋转矩阵合并到投影和相机矩阵 Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0); // 画三角形 mTriangle.draw(mMVPMatrix); }
public BallForControl(MySurfaceView mv, float scale, float aHalf, int n) { this.mv = mv; ball = new Ball(mv, scale, aHalf, n); // 初始化自带旋转矩阵 selfRotateMatrix = new float[16]; // 初始时旋转一定的度数 Matrix.setRotateM(selfRotateMatrix, 0, 10, 0, 1, 0); }
/** Handles camera opening */ private void openCamera(int which) { if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } if (mCameraId >= 0) { Camera.getCameraInfo(mCameraId, mCameraInfo); if (which == FRONT) mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT); else mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK); params = mCamera.getParameters(); params.setRotation(0); /** set focus mode */ List<String> FocusModes = params.getSupportedFocusModes(); if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } mCamera.setParameters(params); try { if (mSurfaceTexture != null) { mCamera.setPreviewTexture(mSurfaceTexture); mCamera.startPreview(); } } catch (Exception ex) { } } if (mCamera == null || mSharedData == null) { return; } int orientation = mCameraInfo.orientation + rot_angle; Matrix.setRotateM(mSharedData.mOrientationM, 0, orientation, 0f, 0f, 1f); Camera.Size size = mCamera.getParameters().getPreviewSize(); if (orientation % 90 == 0) { int w = size.width; size.width = size.height; size.height = w; } mSharedData.mAspectRatioPreview[0] = (float) Math.min(size.width, size.height) / size.width; mSharedData.mAspectRatioPreview[1] = (float) Math.min(size.width, size.height) / size.height; }
public int performRaySelection(TouchRay tRay) { Matrix.setRotateM( this.modelMatrix, 0, -this.angle, 0.0f, 1.0f, 0.0f); // derotating to world coordinates tRay = tRay.multiplyByMatrix(this.modelMatrix); int sel = -1; for (int i = 0; i < nodes.length; i++) { Vector3f curPos = nodes[i].getPosV(); if (tRay.pointOnRay(curPos)) { if (sel == -1) sel = i; else if (!tRay.closestSelected(nodes[sel].getPosV(), curPos)) sel = i; } } return sel; }
// 球前进的方法 public void go() { tempSPANX = Constant.SPANX; // 球移动距离的临时变量赋值 tempSPANZ = Constant.SPANZ; tempX = Constant.XOFFSET + tempSPANX; // 根据传感器,变化当前球的位置 tempZ = Constant.ZOFFSET + tempSPANZ; // 如果与上下两条边发生碰撞 if ((tempZ < -ZBOUNDARY) || (tempZ > ZBOUNDARY)) { tempSPANZ = 0; } // 如果与左右两条边发生碰撞 if ((tempX < -XBOUNDARY) || (tempX > XBOUNDARY)) { tempSPANX = 0; } // 球当前的位置发生变化 Constant.XOFFSET += tempSPANX; Constant.ZOFFSET += tempSPANZ; // *****************旋转 begin************************ // 前进的方向向量为Constant.SPANX Constant.SPANZ, // 那么旋转轴为 rotateX = tempSPANZ; rotateY = 0; rotateZ = -tempSPANX; // 前进的距离 tempLength = (float) Math.sqrt(tempSPANX * tempSPANX + tempSPANZ * tempSPANZ); // 计算前进的角度值 tempAngle = (float) Math.toDegrees(tempLength / Constant.BALLR); // 改变球的旋转矩阵 // 旋转时要求角度不为0且轴不能全为0 if (Math.abs(tempAngle) != 0 && (Math.abs(rotateZ) != 0 || Math.abs(rotateX) != 0)) { float[] newMatrix = new float[16]; Matrix.setRotateM(newMatrix, 0, tempAngle, rotateX, rotateY, rotateZ); float[] resultMatrix = new float[16]; Matrix.multiplyMM(resultMatrix, 0, newMatrix, 0, selfRotateMatrix, 0); selfRotateMatrix = resultMatrix; } // ************************旋转 end************************ }
private void renderLines() { if (phenixLineProgram != null) { if (!phenixLineProgram.use()) { return; } float angle = 360.0f * getTimeDeltaByScale((long) (1 * 50000L / speedFactor / rotationSpeedFactor)); Matrix.setRotateM(M_matrix, 0, angle, 0, 0, 1.0f); Matrix.multiplyMM(MVP_matrix, 0, V_matrix, 0, M_matrix, 0); Matrix.multiplyMM(MVP_matrix, 0, P_matrix, 0, MVP_matrix, 0); float delta = getTimeDeltaByScale((long) (1 * 25000L / speedFactor)); lineVertices.bind(phenixLineProgram, "aPosition", null); GLES20.glUniformMatrix4fv( phenixLineProgram.getUniformLocation("uMVPMatrix"), 1, false, MVP_matrix, 0); GLES20.glUniform1f(phenixLineProgram.getUniformLocation("uDelta"), delta); GLES20.glUniform1f( phenixLineProgram.getUniformLocation("uBrightness"), brightness * brightnessFactor); GLES20.glUniform3f( phenixLineProgram.getUniformLocation("uColor"), linesColorRed, linesColorGreen, linesColorBlue); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE); GLES20.glLineWidth(lineWidth * lineWidthFactor); lineVertices.draw(GLES20.GL_LINES, 0, MOVING_LINE_COUNT); GLES20.glUniform1f(phenixLineProgram.getUniformLocation("uDelta"), 0.0f); lineVertices.draw(GLES20.GL_LINES, MOVING_LINE_COUNT, STALE_LINE_COUNT); GLES20.glDisable(GLES20.GL_BLEND); lineVertices.unbind(phenixLineProgram, "aPosition", null); } }
public void onDrawFrame(GL10 gl) { // TODO Auto-generated method stub loopStart = System.currentTimeMillis(); try { if (loopRunTime < ZxCEngine.GAME_THREAD_FPS_SLEEP) { Thread.sleep(ZxCEngine.GAME_THREAD_FPS_SLEEP - loopRunTime); } } catch (InterruptedException e) { e.printStackTrace(); } GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); // gl.glLoadIdentity(); loopEnd = System.currentTimeMillis(); loopRunTime = ((loopEnd - loopStart)); // Draw background color // GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); // Set the camera position (View matrix) Matrix.setLookAtM(mVMatrix, 0, 0, 0, -10, 0f, 0f, 0f, 0f, 10.0f, 10.0f); // Calculate the projection and view transformation Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0); // Draw square mSquare.draw(mMVPMatrix); // personaje.draw(mMVPMatrix); // Create a rotation for the triangle // long time = SystemClock.uptimeMillis() % 4000L; // float angle = 0.090f * ((int) time); Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f); // Combine the rotation matrix with the projection and camera view Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0); // Draw triangle // mTriangle.draw(mMVPMatrix); }
public void camMove(float ay, float az) { float[] matCamTemp = new float[16]; float[] matZ = new float[16]; Matrix.setRotateM(matZ, 0, az, 0.0f, 0.0f, 1.0f); Matrix.multiplyMM(matCamTemp, 0, matZ, 0, matCam, 0); matCopy(matCamTemp, matCam); Matrix.rotateM(matCam, 0, ay, 0.0f, 1.0f, 0.0f); if (Math.abs(Math.atan2(matCam[2], matCam[10])) > ANGLE_Y_LIMIT) { matCopy(matCamTemp, matCam); } Matrix.setLookAtM( mViewMatrix, 0, matCam[0] * len, matCam[1] * len, matCam[2] * len, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); }
public static void setInitStack() // 获取不变换初始矩阵 { currMatrix = new float[16]; Matrix.setRotateM(currMatrix, 0, 0, 1, 0, 0); }
public void glRotatef(float angle, float x, float y, float z) { Matrix.setRotateM(mTemp, 0, angle, x, y, z); System.arraycopy(mMatrix, mTop, mTemp, MATRIX_SIZE, MATRIX_SIZE); Matrix.multiplyMM(mMatrix, mTop, mTemp, MATRIX_SIZE, mTemp, 0); }