3d 中的 Android ViewGroup 旋转 [英] Android ViewGroup Rotation in 3d

查看:39
本文介绍了3d 中的 Android ViewGroup 旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 android 中以 3d 形式旋转我自己的 FrameLayout.我是否必须使用 GlSurfaceView 类.我是计算机图形学的新手,但知道旋转和平移背后的理论.为了进行 3d opengl 旋转,我们通常执行以下操作.

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.

在活动类中,我们创建一个 GLSurfaceView 对象并设置它的渲染器.Renderer 对象是从实现 GlSurfaceView.Renderer 接口的类创建的.

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);
}

在我们的 Renderer 类中,我们使用以下方法进行绘图、旋转和平移

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

我想做这个:

@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来源太长了.事实上,我并不懒惰阅读它,但我想确定我的方法是否正确.

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.

推荐答案

Framelayouts(以及任何扩展 View)被设计为在 2D 中绘制在 Canvas 元素上.无法使用 openGL 绘制这些.如果您想在 3D/GL 中绘制 GUI,那么您将不得不从头开始编写代码或找到已经完成此操作的库.我确定那里有一些,但我还没有需要.

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.

您可以通过使用缩放动画在视图上获得一些假的 3D 效果,但这些只有在动画快速完成以使用户不会注意到的情况下才有效.这可能不是你想要的.

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.

<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
    android:fromXScale="1.0" android:toXScale="0.0"
    android:fromYScale="1.0" android:toYScale="1.0"
    android:pivotX="50%" android:pivotY="0%"
    android:duration="@android:integer/config_shortAnimTime"
/>

这篇关于3d 中的 Android ViewGroup 旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆