Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyGLSurfaceView extends GLSurfaceView {
- private final MyGLRenderer mRenderer;
- public MyGLSurfaceView(Context context) {
- super(context);
- // Set the Renderer for drawing on the GLSurfaceView
- mRenderer = new MyGLRenderer();
- setRenderer(mRenderer);
- // Render the view only when there is a change in the drawing data
- setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
- }
- @Override
- public boolean onTouchEvent(MotionEvent e)
- {
- float x =e.getX();
- float y =e.getY();
- if(e.getAction()==MotionEvent.ACTION_MOVE)
- {
- mRenderer.setLoc(x,y);
- requestRender();
- }
- return true;
- }
- public class MyGLRenderer implements GLSurfaceView.Renderer {
- private float mAngle;
- public PVector pos;
- public Rectangle r;
- public Square sq;
- @Override
- public void onSurfaceCreated(GL10 gl, EGLConfig config) {
- // Set the background frame color
- gl.glClearColor(1f, 1f, 1f, 1.0f);
- pos=new PVector();
- r=new Rectangle(0.5f,0.4f);
- sq=new Square(0.3f);
- }
- @Override
- public void onDrawFrame(GL10 gl) {
- // Draw background color
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
- // Set GL_MODELVIEW transformation mode
- gl.glMatrixMode(GL10.GL_MODELVIEW);
- gl.glLoadIdentity(); // reset the matrix to its default state
- // When using GL_MODELVIEW, you must set the view point
- GLU.gluLookAt(gl, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
- gl.glTranslatef(pos.x,pos.y,0f);
- //r.draw(gl);
- sq.draw(gl);
- }//rend
- @Override
- public void onSurfaceChanged(GL10 gl, int width, int height) {
- // Adjust the viewport based on geometry changes
- // such as screen rotations
- gl.glViewport(0, 0, width, height);
- // make adjustments for screen ratio
- float ratio = (float) width / height;
- gl.glMatrixMode(GL10.GL_PROJECTION); // set matrix to projection mode
- gl.glLoadIdentity(); // reset the matrix to its default state
- gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7); // apply the projection matrix
- }
- /**
- * Returns the rotation angle of the triangle shape (mTriangle).
- *
- * @return - A float representing the rotation angle.
- */
- public float getAngle() {
- return mAngle;
- }
- /**
- * Sets the rotation angle of the triangle shape (mTriangle).
- */
- public void setAngle(float angle) {
- mAngle = angle;
- }
- public void setLoc(float x,float y)
- {
- pos.x=x; pos.y=y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement