Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. public class MyGLSurfaceView extends GLSurfaceView {
  2.  
  3. private final MyGLRenderer mRenderer;
  4.  
  5. public MyGLSurfaceView(Context context) {
  6. super(context);
  7.  
  8. // Set the Renderer for drawing on the GLSurfaceView
  9. mRenderer = new MyGLRenderer();
  10. setRenderer(mRenderer);
  11.  
  12. // Render the view only when there is a change in the drawing data
  13. setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
  14. }
  15.  
  16.  
  17. @Override
  18. public boolean onTouchEvent(MotionEvent e)
  19. {
  20. float x =e.getX();
  21. float y =e.getY();
  22.  
  23. if(e.getAction()==MotionEvent.ACTION_MOVE)
  24. {
  25. mRenderer.setLoc(x,y);
  26. requestRender();
  27. }
  28. return true;
  29. }
  30.  
  31. public class MyGLRenderer implements GLSurfaceView.Renderer {
  32.  
  33. private float mAngle;
  34.  
  35. public PVector pos;
  36. public Rectangle r;
  37. public Square sq;
  38.  
  39. @Override
  40. public void onSurfaceCreated(GL10 gl, EGLConfig config) {
  41. // Set the background frame color
  42. gl.glClearColor(1f, 1f, 1f, 1.0f);
  43.  
  44. pos=new PVector();
  45. r=new Rectangle(0.5f,0.4f);
  46. sq=new Square(0.3f);
  47. }
  48.  
  49. @Override
  50. public void onDrawFrame(GL10 gl) {
  51.  
  52. // Draw background color
  53. gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  54.  
  55. // Set GL_MODELVIEW transformation mode
  56. gl.glMatrixMode(GL10.GL_MODELVIEW);
  57. gl.glLoadIdentity(); // reset the matrix to its default state
  58.  
  59. // When using GL_MODELVIEW, you must set the view point
  60. GLU.gluLookAt(gl, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
  61.  
  62. gl.glTranslatef(pos.x,pos.y,0f);
  63.  
  64. //r.draw(gl);
  65. sq.draw(gl);
  66.  
  67. }//rend
  68.  
  69. @Override
  70. public void onSurfaceChanged(GL10 gl, int width, int height) {
  71. // Adjust the viewport based on geometry changes
  72. // such as screen rotations
  73. gl.glViewport(0, 0, width, height);
  74.  
  75. // make adjustments for screen ratio
  76. float ratio = (float) width / height;
  77. gl.glMatrixMode(GL10.GL_PROJECTION); // set matrix to projection mode
  78. gl.glLoadIdentity(); // reset the matrix to its default state
  79. gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7); // apply the projection matrix
  80. }
  81.  
  82. /**
  83. * Returns the rotation angle of the triangle shape (mTriangle).
  84. *
  85. * @return - A float representing the rotation angle.
  86. */
  87. public float getAngle() {
  88. return mAngle;
  89. }
  90.  
  91. /**
  92. * Sets the rotation angle of the triangle shape (mTriangle).
  93. */
  94. public void setAngle(float angle) {
  95. mAngle = angle;
  96. }
  97.  
  98. public void setLoc(float x,float y)
  99. {
  100. pos.x=x; pos.y=y;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement