Android 3D game tutorial – Part III
来源:互联网 发布:spss软件安卓版 编辑:程序博客网 时间:2024/04/29 07:31
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
Go to Android 3D game tutorial – Part IV
- Android 3D game tutorial – Part III
- Android 3D game tutorial – Part I
- Android 3D game tutorial – Part I
- Android 3D game tutorial – Part II
- Android 3D game tutorial – Part IV
- Android 3D game tutorial – Part V
- Android 3D game tutorial – Part VI
- OpenGL ES Tutorial for Android – Part III – Transformations
- OpenGL ES Tutorial for Android – Part III – Transformations
- OpenGL ES Tutorial for Android – Part III – Transformations
- TheWavelet Tutorial Part III
- Beginning Game Development: Part III - DirectX II
- iPhone JSON Flickr Tutorial – Part 3
- iPhone JSON Flickr Tutorial – Part 3
- Android Restful Webservice Tutorial – How to call RESTful webservice in Android – Part 3
- Android 3D 游戏开发教程– Part I-VI
- OpenGL ES Tutorial for Android – Part VI – Textures
- OpenGL ES Tutorial for Android – Part VI – Textures
- Android 3D game tutorial – Part II
- Ascii码对照表
- Effective C++ XMind读书笔记
- PHPExcel ------ PHP中操作Excel、PDF、CVS的工具
- 爬楼梯与坐电梯
- Android 3D game tutorial – Part III
- Android Property System | Android属性系统
- Android 3D game tutorial – Part IV
- 9寸触屏 电影中曝光诺基亚首款平板Z500
- linux 系统调用 -- 不用syscall table的方法来截获系统调用的方法的分析
- 明天----
- java源代码统计工具
- shell 使用技巧
- Android 3D game tutorial – Part V