翻书动画实现

最近一周忙着做一个东西,本来没有我什么事,有一个浏览图片的项目想使用书本翻页的效果。动画效果参考一个flash,2D效果。出于对算法的强烈兴趣,我蹦将出来,大吼一声我能做,随之就陷入了一周的悲惨世界。

十多张A4演算和草图,一对平面几何点线关系的公式,一天时间就弄明白了算法,其实简单的不值一提,就是对效能十分怀疑。作为科学家的我很快完成了工作,接着就是作为工程师的工作,这个时候真羡慕那些有小弟的同事了。

一捋袖子,我就操练起刚刚学的C#,一边是VS,一边是MSDN,一篇GDI+的文档,两天不吃不喝外加睡觉上厕所的时间,基本完成,C#和GDI+确实比传统的C++和GDI方便太多。兴奋之余,拿出一个演示版交给老大。

主管显然不以为然,因为他有自己的一套框架和打算。一番讨价还价之后,我明白他已经交待的解决方案是MFC+DirectX,框架是MFC,创建子窗口内嵌D3D。项目实现人员基于此方案的实现是在发现3D翻书的算法相当复杂之后,采用3DSMAX绘制动画,导出后用D3D实时渲染。可叹我CAD专业出身,又对游戏编程满腔热情,却没有机会凭此报效公司。回到我的方案,成了3D方案的后背方案,前提是把C#改成C++的。

有过上一次为他们做记分牌特效的经验,我在实现之初就定义了良好的类和接口(巴掌的程序,也体现不出什么类的良好定义),改成C++也不是什么难事。这时候又开始幻想有个小弟就好了。话说回来,万一改写者完全不考虑指针的回收问题,岂不坏了我的算法。一咬牙,又花了一天改了个C++版本。

3D版本很快陷入了困境,实现人员的小弟显然还不是很熟悉3DS导出X文件的使用。虽然这里面完全没有什么技术含量,但弄了很多天之后,他们终于明白算法为王。不过我们做软件的,都有一套发包应付实现不了的方案。主管很快英明决定删减功能。最后的方案是做成一个实时渲染的动画,动态改变纹理贴图,翻动动作是固定的,根据鼠标位置前后播放动画。

这个时候我的2 D C++版也新鲜出炉。不过最初的担心还是出现了,效能不很好,勉强达到flash的水平。一番测试,性能主要损耗在GDI+的函数,SetClip和DrawImage,一声叹息,这可是我没办法优化的,或者要优化就需要更大的精力。也许更好的方案是2D算法+D3D渲染,就这样吧,交差!

也许下周真正把我的成功交付其他项目组使用的时候,调试的任务还用很多。毕竟很多人喜欢问别人而不是仅仅参考别人的代码,而相比于不耻下问,还有很多人喜欢直接跟你说:“嗨,听说这是你写的,真不出,可我们不知道接口怎么用啊,帮我们整合一下吧。”我要连忙说:“客气客气,您谬赞了,您老先歇着哈。”哎,至少有个小妹帮我写文档也好呀。

 

最近看Silverlight,似乎有翻书的示例,可惜我无缘拜阅。总有更合适的技术和工具来做项目,现实却有很多阻力。总在科研和工程之间摇摆,挺郁闷。啥时候能有自己的研究所才好,工作室也成。不是说软件是艺术嘛。我很想在人类历史长河中找一个生产组织形式形容我现在工作的部门状况,却由于对早期原始社会的不了解而想不出来,大概形势就是主管是酋长或长老,拿着挂着骷髅头的木棒一吆喝,大家就拿着顺手的家伙一起呼啸着朝一只小松鼠冲过去了。恐怕能看到的最高级的家伙也不过是两头绑着石块的草绳吧。

The "Unity3D Book Page Curl" is a unity package that is used to create a book with page flip effect using unity3D native UI tools. Getting Started Create your first book:  Import the unity package  Create a canvas and EventSystem objects if you don't have one (the easiest way to create them is by adding any UI object -like a button- then you can delete it).  Drag a book prefab under the Canvas element  Resize the book on your scene and reposition the anchors as required.  Select the book from hierarchy to show it in inspector.  Assign the canvas to the canvas slot in inspector  Assign the background sprite with the sprite that you want to show on the right or left side when all pages flipped to the other side.  To edit the book pages, expand the Book Pages list in inspector, change the Size to your pages count, then start drag your pages in the Element boxes in order  Set the current page to the page that you want to be shown initially in the right side of the book.  If you want to call any function when any page flipped add it to the OnFlip Event List.  If you want to resize the area that the user can drag the page from it, open the Book node in inspector to show its children, you will find two objects "RightHotSpot" and "LeftHotSpot" resize them and set their anchors as required.  RUN and enjoy the page curl effect! Create Automatic Flipping Book:  After creating your book as mentioned above add an "Auto Flip" component on it.  Choose flipping direction( if you choose left to right make sure that the current page of the book component is equal to your page count "last page index + 1").  Uncheck the interactable check in the book component.  Specify the page flipping time parameters (Page Flip Time, Time Between Pages, Delay before Start flipping, Number of Animation frames for each page flip).  Check "Auto Start Flip" if you want the book to start flipping automatically, or uncheck it and call the StartFlipping() function in your code. Control Flipping Manually: This section will explore how to create a scene like the “Example_2_Controled Flipping” scene  To be able to let the user control page flipping using some buttons, create your book, add an "Auto Flip" component on it and configured them as mentioned above.  Uncheck the “interactable” of the book and "Auto Start Flip" of the “Auto Flip” components.  Add previous and next buttons to your scene (check Example_2_Controled Flipping scene if you have any issues setting them correctly).  Add a new slot on each button OnClick list by clicking the (+) sign, assign the Book as the game object then select the “AutoFlip->FlipRightPage” for the next button and “Auto Flip->Flip Left Page” to the previous button.  If you need to flip the page from code (based on custom action) you can call the FlipLeftPage() or FlipRightPage().
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值