在Opengl中产生涟漪 [英] Generating Ripples in Opengl

查看:145
本文介绍了在Opengl中产生涟漪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,


我对openGl有点陌生,并且有一个我无法解决的疑问.


我正在实现一个带有随机彩色圆圈弹出随机位置的应用程序.可以在http://picturepush.com/public/7736883
找到该应用程序的图像
我的要求是我应该在单击的位置生成波浪或涟漪.

我已经在codeproject和其他站点中搜索了相同的内容,但是我并没有实现相同的想法.如果有人可以告诉我基本的逻辑或想法,这将很有帮助.

还有一个问题,我们什么时候需要在OpegGl中使用纹理?

谢谢
Abhishek

Hi friends,


I am bit new to openGl And have a doubt which I am not able to clear out.


I am implementing an application with random colored circles popping up the random locations. The image of the application can be found http://picturepush.com/public/7736883

My requirement is that I should generate waves or ripples the location I click.

I had searched the same in codeproject and other sites but I am not getting the idea of implementing the same It will helpful if any one could tell me the basic logic or idea.

And another question when do we need to use texture in OpegGl?

Thanking you,
Abhishek

推荐答案

答案1:

好吧,我要解决的方法是创建一个平面网格.我会把它弄得很密集,这样涟漪就会很漂亮而且很平滑.也许我可以将网格设为128 x 128顶点.

我要确保所有顶点都分配了纹理坐标,以使UV的范围从0,0(左上)到1,1(bot右).

我会复制您窗口中显示的任何图像,并使其成为我分配给网格的纹理.


此时,您应该具有一个平面(平面)128 x 128顶点网格,该网格已将客户端的屏幕截图应用到该网格上.在此阶段,它在屏幕上的呈现效果与当前屏幕快照的呈现效果没有什么不同.


从那里,我将创建几个变量,以跟踪(a)最近一次鼠标单击的时间和(b)最近一次鼠标单击的位置.

从那里开始,只需根据收到点击的时间和点击发生的位置,即可在Y平面(上下)上移动网格的顶点.我很可能会使用正弦函数的阻尼版本来移动顶点.自发生点击起,我会根据距点击位置的距离和时间进行衰减.

每当用户单击鼠标时,这两个变量的任何先前值都将重新分配为当前位置和时间.

不幸的是,由于我们在最后一次单击鼠标时仅维护一对变量,因此每次单击鼠标时,任何/所有当前运动都将丢失.通过维护click-pos/click-time列表可以轻松解决此问题.


我强烈建议您看一下此页面上的第一篇文章:
http://nehe.gamedev.net/tutorial/lessons_11__15/28001/ [
Answer 1:

Well, the way I''d go about it would be to create a flat grid. I''d make it fairly dense, so that the ripples would be nice and smooth. Perhaps I''d make the grid 128 x 128 vertices.

I would make sure that the verts all had texture co-ords assigned, such that the UVs ranged from 0,0(top-left) to 1,1(bot-right).

I would take a copy of whatever image is displayed in your window and make this the texture that I assigned to the grid.


At this point, you should have a flat (planar) 128 x 128 vertex grid, that had the client are of your screen-shot applied to it. At this stage, it would render no different on the screen than your screen-shot appears currently.


From there, I would create a couple of variables that would keep track of (a) the time of most recent-mouse-click and (b) the position of most recent mouse-click.

From there, it would be a simply matter of displacing the vertices of the grid in the Y plane (up-down), based on how long since the click was received and the position that it happened at. I''d most likely use a dampened version of the sine function to displace the verts. I''d dampen based on both distance from click position and time since it happened.

Whenever the user clicked the mouse, any previous values for these two variables would be re-assigned the current position and time.

Unfortunately, since we''re only maintaining a single pair of variables for the last mouse-click, each time we clicked the mouse any/all current movement would be lost. This could easily be solved by maintaining a list of click-pos/click-time.


I strongly suggest that you take a look at the first tute on this page:
http://nehe.gamedev.net/tutorial/lessons_11__15/28001/[^]
It''s a tute that deals with displacing such a texture-mapped grid with a simple sine wave. Just modify the displacement code to account for your time and position of last click.

Answer 2:
There''s two times I can think of to rely on texture mapping in GL (or any other lib for that matter)
1) Because you can use an image that gives the same appearance with a small number of vertices that you may need to use a much larger number of vertices for without the map.
2) Because a texture map looks much better than a single solid/shaded colour.

Texture mapping when done by the gpu is very fast and (most often) serves as a good way to keep high image quality while maintaining a low vertex count.


请参见 ^ ]

http://freespace.virgin.net/hugo.elias/graphics/x_water.htm [ ^ ]

希望对您有帮助
jkchan
http://cgmath.blogspot.com
see http://stackoverflow.com/questions/665076/how-to-implement-water-ripples[^]

http://freespace.virgin.net/hugo.elias/graphics/x_water.htm[^]

hopes this helps
jkchan
http://cgmath.blogspot.com


这篇关于在Opengl中产生涟漪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆