Android ViewGroup 3d 旋转
我想在android中以3d方式旋转我自己的FrameLayout。我必须使用 GlSurfaceView 类吗?我是计算机图形学的新手,但了解旋转和平移背后的理论。为了进行 3d opengl 旋转,我们通常执行以下操作。
在活动类中,我们创建一个 GLSurfaceView 对象并设置其渲染器。渲染器对象是从实现 GlSurfaceView.Renderer 接口的类创建的。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GLSurfaceView view = new GLSurfaceView(this);
view.setRenderer(new OpenGLRenderer());
setContentView(view);
}
在我们的 Renderer 类中,我们使用以下方法进行绘图、旋转和平移
// Called when the surface is created or recreated.
public void onSurfaceCreated(GL10 gl, EGLConfig config)
// Called to draw the current frame.
public void onDrawFrame(GL10 gl)
// Called when the surface changed size.
public void onSurfaceChanged(GL10 gl, int width, int height)
但是我有一个自定义的框架布局,它是按照
public class RotatedMapView extends FrameLayout
我想要的方式声明的:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RotatedMapView view = new RotatedMapView (this);
view.setRenderer(new OpenGLRenderer());
setContentView(view);
}
但我不能,因为 setRenderer 对于 GlSurfaceView 来说是特殊的。我现在正在浏览 GlSurfaceView.java 源代码,以便使其适应我的设计。我找到的 GlSurfaceVïew.java 的链接是 http://code.google.com/p/apps-for-android/source/browse/trunk/SpriteMethodTest/src/com/android/spritemethodtest/GLSurfaceView.java? r=150 源码太长了。事实上我并不懒惰地阅读它,但我想确定我的方式是否正确。
I want to rotate my own FrameLayout in 3d in android. Do i have to use GlSurfaceView class. I am new in computer graphics but know the theory behind the rotations and translations. In order to make 3d opengl rotations we do the followings generally.
In activity class we create a GLSurfaceView object and set its renderer. Renderer object is created from a class which implements GlSurfaceView.Renderer interface.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GLSurfaceView view = new GLSurfaceView(this);
view.setRenderer(new OpenGLRenderer());
setContentView(view);
}
In our Renderer class we make the drawings, rotations and translations with following methods
// Called when the surface is created or recreated.
public void onSurfaceCreated(GL10 gl, EGLConfig config)
// Called to draw the current frame.
public void onDrawFrame(GL10 gl)
// Called when the surface changed size.
public void onSurfaceChanged(GL10 gl, int width, int height)
However i have a custom framelayout which is declared as
public class RotatedMapView extends FrameLayout
I want to make this :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RotatedMapView view = new RotatedMapView (this);
view.setRenderer(new OpenGLRenderer());
setContentView(view);
}
But i can't, because setRenderer is special for GlSurfaceView. I am now browsing the GlSurfaceView.java source code in order to adapt it to my design. The link i found for GlSurfaceVİew.java is http://code.google.com/p/apps-for-android/source/browse/trunk/SpriteMethodTest/src/com/android/spritemethodtest/GLSurfaceView.java?r=150
The source is too long. In fact I am not lazy to read it but i want to be sure whether or not i am in correct way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在我正在看我从未使用过的动画。在 api 演示中,有一个关于 y 轴的旋转示例。我想在 x 上进行旋转。它对于负角度是成功的,但在正方向它会消失视图。该函数如下。
}
Now i am looking at animations which i have never used. In api demos there is a rotation example over y axis. I want to make rotation over x. It is succesful for negative angles but in positive direction it disappears the view. The function is below.
}
框架布局(以及任何扩展视图)被设计为在 2D 画布元素上绘制。使用 openGL 无法绘制这些。如果你想在 3D/GL 中绘制 GUI,那么你必须从头开始编写代码,或者找到一个已经完成此操作的库。我确信那里有一些,但我还没有需要。
您可以通过使用缩放动画在视图上获得一些假的 3D 效果,尽管这些效果只有在动画完成得很快而用户不会注意到的情况下才会起作用。这可能不是您所追求的。
Framelayouts (and anything extending View) are designed to be drawn on a Canvas element in 2D. It is not possible to draw these using openGL. If you want to draw a GUI in 3D/GL then you will have to code that up from scratch or find a library which has already done this. I'm sure there are a few out there but I haven't had the need for one yet.
You can get some fake looking 3D effects on views by using scale animations, though these will only work if the animation is done fast so the user doesn't notice. This probably isn't what you are after.