在android上实现页面卷曲?

发布于 2024-10-06 10:03:11 字数 2181 浏览 4 评论 0原文

我在网上寻找一种在 Android 上翻页的好效果,但似乎没有。因为我正在学习这个平台,所以能够做到这一点似乎是一件好事。

我设法在这里找到一个页面: 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 中实现这个功能吗?

是否可以使用本机绘图 API,我是否必须使用 openGL?我可以以某种方式模仿这种行为吗?

任何帮助将不胜感激。谢谢。

****************编辑********************************* *************

我在 Android API 演示中找到了一个位图网格示例:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapMesh.html< /a>

也许有人可以帮我算出一个方程式,简单地将右上角向内折叠穿过页面,以创建类似的效果,我稍后可以应用阴影以使其更具深度?

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.

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

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.

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**********************************************

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如果没有你 2024-10-13 10:03:11

我目前正在使用 OpenGL ES 在 Android 上进行一些卷页效果实验。实际上,这只是一个草图,但也许给出了一些如何根据您的需求实现页面卷曲的想法。如果您对 3D 翻页实现感兴趣的话。

至于你所指的公式 - 我尝试了一下,但不太喜欢结果。我想说它根本不适合小屏幕,因此开始破解一个更简单的解决方案。

代码可以在这里找到:
https://github.com/harism/android_page_curl/

在写这篇文章时,我正处于决定如何实现“假”软阴影 - 以及是否创建适当的应用程序来展示此页面卷曲效果。另外,这几乎是我做过的极少数 OpenGL 实现之一,不应该过多地作为一个适当的示例。

I'm doing some experimenting on page curl effect on Android using OpenGL ES at the moment. It's quite a sketch actually but maybe gives some idea how to implement page curl for your needs. If you're interested in 3D page flip implementation that is.

As for the formula you're referring to - I tried it out and didn't like the result too much. I'd say it simply doesn't fit small screen very well and started to hack a more simple solution.

Code can be found here:
https://github.com/harism/android_page_curl/

While writing this I'm in the midst of deciding how to implement 'fake' soft shadows - and whether to create a proper application to show off this page curl effect. Also this is pretty much one of the very few OpenGL implementations I've ever done and shouldn't be taken too much as a proper example.

筱果果 2024-10-13 10:03:11

我刚刚创建了一个开源项目,该项目使用本机画布进行 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.

  • EDIT: Links updated.
  • EDIT: Missing files has been pushed to repo.
¢好甜 2024-10-13 10:03:11

我很确定,您必须使用 OpenGL 才能获得良好的效果。基本的 UI 框架的功能非常有限,您只能使用动画对视图进行基本的转换(alpha、平移、旋转)。

不过,可以使用 FrameLayout 和其中的自定义视图来模仿 2D 中的类似内容。

I'm pretty sure, that you'd have to use OpenGL for a nice effect. The basic UI framework's capabilities are quite limited, you can only do basic transformations (alpha, translate, rotate) on Views using animations.

Tho it might be possible to mimic something like that in 2D using a FrameLayout, and a custom View in it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文