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

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

问题描述

我想旋转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);
}

在我们的渲染器类中,我们做了图纸,旋转和平移用下面的方法

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

但我不能,因为setRenderer是专门为GlSurfaceView。我现在在浏览GlSurfaceView.java源$ C ​​$ C,以使其适应我的设计。我发现GlSurfaceVİew.java的联系是<一个href="http://$c$c.google.com/p/apps-for-android/source/browse/trunk/SpriteMethodTest/src/com/android/spritemethodtest/GLSurfaceView.java?r=150" rel="nofollow">http://$c$c.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(以及任何扩展视图)被设计在2D canvas元素上绘制。它是不可能得出这些用openGL。如果你想绘制3D / GL图形用户界面,那么你将不得不code表示从头开始或找到一个库,它已经做到了这一点。我敢肯定,有几个在那里,但我还没有需要一个呢。

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"
/>

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

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