Drawing animated circle with OpenGL ES 2.0

陌路散爱 提交于 2019-12-11 20:00:36

问题


I have a circle object, created with OpenGL vertices.

When the circle is being touched, I want a scaling animation to be activated. The circle radius will grow bigger until it reaches a certain radius, and then the circle will transform back to its original radius.

What is the best way to implement this animation?


回答1:


You have a few possibilities. The simplest would be to just create a variable which would hold a scaling factor for your circle and multiply all vertices by it before rendering. Then using some timers and adjusting the scaling factor in time, you could create your animation. I should add that if you want to scale your circle by its center then you have to first translate the circle vertices so that circle's center will be at (0, 0) point, then scale by the factor and translate the circle back to its initial position.

If the circle animation you're trying to implement is some kind of your GUI element then another way which comes to my mind is to:

  1. create an ImageView in xml or dynamically in code

  2. draw the vertices on it

  3. create an XML android animation and apply it whenever you want

Here's a draft of the code for drawing a circle on the ImageView:

Bitmap tempBitmap = Bitmap.createBitmap(yourCircleWidth, yourCircleHeight, Bitmap.Config.ARGB_8888);
                Canvas tempCanvas = new Canvas(tempBitmap);

                //Draw the circle into the canvas               
                tempCanvas.drawColor(Color.WHITE);
                Paint paint = new Paint();
                paint.setStyle(Paint.Style.FILL);
                tempCanvas.drawCircle(circleCenterX, circleCenterY, yourCircleRadius, paint);

            //Attach the canvas to the ImageView
            yourImageView.setImageDrawable(new BitmapDrawable(yourImageView.getResources(), tempBitmap));

For XML animations, here's a good reference: http://www.androidhive.info/2013/06/android-working-with-xml-animations/



来源:https://stackoverflow.com/questions/25338156/drawing-animated-circle-with-opengl-es-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!