Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zui.polsl.pl.lab5przyklad;
- import android.opengl.GLSurfaceView;
- import android.opengl.GLU;
- import java.nio.ByteBuffer;
- import java.nio.ByteOrder;
- import java.nio.FloatBuffer;
- import javax.microedition.khronos.egl.EGLConfig;
- import javax.microedition.khronos.opengles.GL10;
- import static java.lang.Math.*;
- public class MyRenderer implements GLSurfaceView.Renderer
- {
- private float kat = 0;
- private float aspect = 0;
- int vertexCount = 360;
- float radius = 0.1f;
- float v = 0.02f;
- float center_x = 0.0f;
- float center_y = 0.0f;
- boolean block = false;
- @Override
- public void onSurfaceCreated(GL10 gl, EGLConfig config)
- {
- }
- @Override
- public void onSurfaceChanged(GL10 gl, int width, int height)
- {
- aspect = width/height*1.8f;
- gl.glViewport(0, 0, width, height);
- gl.glMatrixMode(GL10.GL_PROJECTION);
- gl.glLoadIdentity();
- GLU.gluPerspective(gl,45.0f,(float)width/(float)height,-1.0f, -10.0f);
- gl.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
- }
- @Override
- public void onDrawFrame(GL10 gl)
- {
- //float wierzcholki[] = {
- // -1.0f, 0.0f, -1.0f,
- // 0.0f, 1.0f, -1.0f,
- // 1.0f, 0.0f, -1.0f
- //};
- if(center_x >= 0.9f){
- block = true;
- }
- if(center_x <= -0.9f){
- block = false;
- }
- if(block){
- center_x -= v;
- }else{
- center_x += v;
- }
- float buffer[] = new float[vertexCount*2];
- int index = 0;
- buffer[index++] = center_x;
- buffer[index++] = center_y;
- float percent, rad, outer_x, outer_y;
- int outerVertexCount = vertexCount - 1;
- for(int i = 0; i < outerVertexCount; i++){
- percent = (i / (float)(outerVertexCount - 1));
- rad = (float)(percent * 2 * Math.PI);
- outer_x = (float)(center_x + radius * cos(rad));
- outer_y = (float)((center_y + radius * sin(rad)) * aspect);
- buffer[index++] = outer_x;
- buffer[index++] = outer_y;
- }
- ByteBuffer bufor = ByteBuffer.allocateDirect(vertexCount*3*4);
- bufor.order(ByteOrder.nativeOrder());
- FloatBuffer bufor_wierzcholkow = bufor.asFloatBuffer();
- bufor_wierzcholkow.put(buffer);
- bufor_wierzcholkow.position(0);
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
- gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
- gl.glLoadIdentity();
- //gl.glRotatef(kat++, 0.0f, 0.0f, 1.0f);
- gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
- gl.glVertexPointer(2, GL10.GL_FLOAT, 0, bufor_wierzcholkow);
- //gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);
- gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, vertexCount);
- gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement