Android 3D game tutorial – Part III

转载 2011年01月13日 22:19:00

Updated to be Android 2.0.1 compatible.

You are new to this series? Please start with the first part .

The third part of this series will show you how to stop the rotation of the triangle and that the rotation really just work on the triangle and not the “camera”.

We want to have more control over the rotation. To get that, we reset the matrix on every call of the onDrawFrame() method. This will reset the angle of our triangle so it always it stays rotated at the given angle on initialization.

In the VortexView class you should remove the division by 10 to be able to rotate it more than a bit.

If you try this, you will see the rotation will only goes the way our touch motion goes. If you don’t move the finger over the screen, it doesn’t change the rotation.

The next thing: Do we rotate the triangle or the view/camera?
To check that, the easiest way is to create a second triangle which will not rotate.
The fastest but also dirtiest way to do this is to copy & paste the initTriangle() method to initStaticTriangle(), copy & paste both buffers and finally copy & paste and modify the last 4 lines of the onDrawFrame() method.
Don’t forget to change the color of the second triangle and reduce the coordinates of the second triangle, so we can see both. I changed the every 0.5f coordinate to 0.4f.
Here the full class:

If you try this, you will see only one triangle rotate. If you want to rotate both, simply change the place where the rotation will be called to right above the comment “draw the static triangle”.

Compile and run the application and you will see the green triangle rotate while the red triangle stays at the same angle.
That should be prove enough for the answer, that we really only rotate the triangle and not the whole scene.

Source as Eclipse project: Vortex Part III

3d-part-three-triangle 3d-part-three-triangle

Go to Android 3D game tutorial – Part IV

Android 3D game tutorial – Part II

Updated to be Android 2.0.1 compatible.You are new to this series? Please start with the first part ...

Android 3D game tutorial – Part IV

Updated to be Android 2.0.1 compatible.You are new to this series? Please start with the first part ...

Android 3D game tutorial – Part I

The first part of this series will give you a short introduction to the OpenGL terminology and the...

Android 3D game tutorial – Part V

Updated to be Android 2.0.1 compatible.You are new to this series? Please start with the first part ...

OpenGL ES Tutorial for Android – Part III – Transformations

这篇文章里面介绍如何知道rotatef非常有用。在一个就是pushmatrix和popmatrix Last tutorial was about building your polygons. Th...

Android 3D 游戏开发教程– Part I-VI

开始 Android 3D 游戏开发教程– Part I-VI 本帖最后由 huzht 于 2010-4-25 07:58 编辑 这几篇Android 3D游戏开发的文章原文出自一位德国人...

How To Create A Breakout Game with Box2D and Cocos2D Tutorial: Part 2/2

How To Create A Breakout Game with Box2D and Cocos2D Tutorial: Part 2/2Like this post? Follow me on ...

Chromium Graphics: 3D上下文及其虚拟化(Virtualization) - Part III

Part I和Part II分别从实现原理的角度介绍了3D上下文和渲染表面等基本概念,阐述了Chromium需要创建多个上下文的内部逻辑,以及如何借助虚拟上下文解决GPU设备对多上下文支持方面的不足之...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Android 3D game tutorial – Part III
举报原因:
原因补充:

(最多只允许输入30个字)