在android上实现页面卷曲? [英] Implement page curl on android?
问题描述
我在网上冲浪,寻找在 Android 上翻页的不错效果,但似乎没有.由于我正在学习该平台,因此能够做到这一点似乎是一件好事.
I was surfing the net looking for a nice effect for turning pages on Android and there just doesn't seem to be one. Since I'm learning the platform it seemed like a nice thing to be able to do is this.
我在这里找到了一个页面:http://wdnuon.blogspot.com/2010/05/implementing-ibooks-page-curling-using.html
I managed to find a page here: http://wdnuon.blogspot.com/2010/05/implementing-ibooks-page-curling-using.html
- (void)deform
{
Vertex2f vi; // Current input vertex
Vertex3f v1; // First stage of the deformation
Vertex3f *vo; // Pointer to the finished vertex
CGFloat R, r, beta;
for (ushort ii = 0; ii < numVertices_; ii++)
{
// Get the current input vertex.
vi = inputMesh_[ii];
// Radius of the circle circumscribed by vertex (vi.x, vi.y) around A on the x-y plane
R = sqrt(vi.x * vi.x + pow(vi.y - A, 2));
// Now get the radius of the cone cross section intersected by our vertex in 3D space.
r = R * sin(theta);
// Angle subtended by arc |ST| on the cone cross section.
beta = asin(vi.x / R) / sin(theta);
// *** MAGIC!!! ***
v1.x = r * sin(beta);
v1.y = R + A - r * (1 - cos(beta)) * sin(theta);
v1.z = r * (1 - cos(beta)) * cos(theta);
// Apply a basic rotation transform around the y axis to rotate the curled page.
// These two steps could be combined through simple substitution, but are left
// separate to keep the math simple for debugging and illustrative purposes.
vo = &outputMesh_[ii];
vo->x = (v1.x * cos(rho) - v1.z * sin(rho));
vo->y = v1.y;
vo->z = (v1.x * sin(rho) + v1.z * cos(rho));
}
}
给出了 iPhone 的示例(以上)代码,但我不知道如何在 android 上实现它.有没有哪位数学大神能帮我看看我将如何在 Android Java 中实现它.
that gives an example (above) code for iPhone but I have no idea how I would go about implementing this on android. Could any of the Math gods out there please help me out with how I would go about implementing this in Android Java.
是否可以使用本机绘图 API,我是否必须使用 openGL?我可以以某种方式模仿这种行为吗?
Is it possible using the native draw APIs, would I have to use openGL? Could I mimik the behaviour somehow?
任何帮助将不胜感激.谢谢.
Any help would be appreciated. Thanks.
****************编辑****************************************************
****************EDIT**********************************************
我在 Android API 演示中找到了一个位图网格示例:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapMesh.html
I found a Bitmap Mesh example in the Android API demos: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapMesh.html
也许有人可以帮我解决一个等式,简单地在页面上对角向内折叠右上角以创建类似的效果,我以后可以应用阴影来增加深度?
Maybe someone could help me out on an equation to simply fold the top right corner inward diagnally across the page to create a similar effect that I can later apply shadows to to gie it more depth?
推荐答案
我刚刚创建了一个开源项目,该项目具有使用本机画布进行 2D 页面卷曲模拟的功能:https://github.com/moritz-wundke/android-page-curl我仍在努力添加适配器等以使其可用作独立视图.
I just created a open source project which features a page curl simulation in 2D using the native canvas: https://github.com/moritz-wundke/android-page-curl I'm still working on it to add adapters and such to make it usable as a standalone view.
- 链接已更新.
- 丢失的文件已推送到存储库.
这篇关于在android上实现页面卷曲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!