Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dd.ww;
- import javax.microedition.khronos.egl.EGLConfig;
- import javax.microedition.khronos.opengles.GL10;
- import android.content.Context;
- import android.opengl.GLES20;
- import android.opengl.GLSurfaceView.Renderer;
- import android.opengl.Matrix;
- public class Render implements Renderer {
- private Context context;
- private Cube cube;
- private float[] modelViewProjectionMatrix = new float[16];
- private float[] projectionMatrix = new float[16];
- private float[] viewMatrix = new float[16];
- private float[] rotationMatrix = new float[16];
- private float angle = 0f;
- public Render(Context context) {
- this.context = context;
- }
- @Override
- public void onSurfaceCreated(GL10 unused, EGLConfig config) {
- GLES20.glClearColor(1f, 1f, 1f, 1f);
- cube = new Cube(context);
- }
- @Override
- public void onSurfaceChanged(GL10 unused, int width, int height) {
- GLES20.glViewport(0, 0, width, height);
- float ratio = (float) width / (float) height;
- Matrix.frustumM(projectionMatrix, 0, -3f, 3f, -3f, 3f, 1f, 10f);
- }
- @Override
- public void onDrawFrame(GL10 unused) {
- GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
- //Camera position
- Matrix.setLookAtM(viewMatrix, 0, 0f, 0f, -4f, 0f, 0f, 0f, 0f, 1f, 0f);
- // projection x view = modelView
- Matrix.multiplyMM(modelViewProjectionMatrix, 0, projectionMatrix, 0, viewMatrix, 0);
- //Creating rotation matrix
- Matrix.setRotateM(rotationMatrix, 0, angle, 0f, 0f, -1f);
- //rotation x camera = modelView
- Matrix.multiplyMM(modelViewProjectionMatrix, 0, rotationMatrix, 0, modelViewProjectionMatrix, 0);
- Matrix.setRotateM(rotationMatrix, 0, angle, 0f, -1f, 0f);
- Matrix.multiplyMM(modelViewProjectionMatrix, 0, rotationMatrix, 0, modelViewProjectionMatrix, 0);
- Matrix.setRotateM(rotationMatrix, 0, angle, -1f, 0f, 0f);
- Matrix.multiplyMM(modelViewProjectionMatrix, 0, rotationMatrix, 0, modelViewProjectionMatrix, 0);
- cube.draw(modelViewProjectionMatrix);
- angle += 0.7f;
- if (angle > 360f)
- angle = 0f;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment