1、动态模拟粒子溃堤效果动态模拟粒子溃堤效果收藏新一篇: Arcglobe 中平行于 opengl 的方法 | 旧一篇: Arcglobe 中平行于 opengl 的方法using System; using System.Collections.Generic; using System.Text; using ESRI.ArcGIS.Geometry; using CsGL.Basecode; using CsGL.OpenGL; using System.Drawing.Imaging; using CsGL; using System.Drawing; using ESRI.ArcGIS.
2、Analyst3D; namespace USTC / / 使用如下: / Particles pt = new Particles(); / pt.initParticles(“D:rr.bmp“,this.m_sceneViwer); / pt.DrawParticles(pp.glX,pp.glY,pp.glZ); / class Particles #region Private Fields private const int MAX_PARTICLES = 300; / Number Of Particles To Create private static bool rainbo
3、w = true; / Rainbow Mode? private static bool sbp; / Space Bar Pressed? private static bool rp; / R Pressed? private static float slowdown = 2.0f; / Slow Down Particles private static float xspeed = 0.0f; / Base X Speed (To Allow Keyboard Direction Of Tail) private static float yspeed = 0.0f; / Base
4、 Y Speed (To Allow Keyboard Direction Of Tail) private static float zoom = -40.0f; / Used To Zoom Out private static uint loop; / Misc Loop Variable private static uint col; / Current Color Selection private static uint delay; / Rainbow Effect Delay private static uint texture = new uint1; / Our Par
5、ticle Texture private struct Particle / Create A Structure For Particle public bool active; / Active True / False public float life; / Particle Life public float fade; / Fade Speed public float r; / Red Value public float g; / Green Value public float b; / Blue Value public float x; / X Position pub
6、lic float y; / Y Position public float z; / Z Position public float xi; / X Direction public float yi; / Y Direction public float zi; / Z Direction public float xg; / X Gravity public float yg; / Y Gravity public float zg; / Z Gravity private static Particle particle = new ParticleMAX_PARTICLES; / P
7、article Array private static float colors = new float12 / Rainbow Of Colors new float 1.0f, 0.5f, 0.5f, new float 1.0f, 0.75f, 0.5f, new float 1.0f, 1.0f, 0.5f, new float 0.75f, 1.0f, 0.5f, new float 0.5f, 1.0f, 0.5f, new float 0.5f, 1.0f, 0.75f, new float 0.5f, 1.0f, 1.0f, new float 0.5f, 0.75f, 1.
8、0f, new float 0.5f, 0.5f, 1.0f, new float 0.75f, 0.5f, 1.0f, new float 1.0f, 0.5f, 1.0f, new float 1.0f, 0.5f, 0.75f ; private static Random rand = new Random(); / Random Number Generator #endregion Private Fields private double m_modelViewMatrix = null; private double m_billboardMatrix = null; priv
9、ate ISceneViewer m_sceneViwer = null; #region 粒子系统计算 public void initParticles(string filename, ISceneViewer sceneViwer) this.m_sceneViwer = sceneViwer; texture0 = OpenGLTool.CreateTexture(filename); / Jump To Texture Loading Routine m_modelViewMatrix = new double16; m_billboardMatrix = new double16
10、; for (loop = 0; loop 25) / If rainbow Is On And delay Is Too High delay = 0; / Reset The Rainbow Color Cycling Delay col+; / Change The Particle Color if (col 11) / If col Is Too High col = 0; / Reset It GL.glDisable(GL.GL_BLEND); private void LoadTextures(string filename) /string filename = “D:Ope
11、nGL 专题 3DCsGLExamplesdataNeHeLesson19Particle.bmp“; / The File To Load Bitmap bitmap = null; / The Bitmap Image For Our Texture Rectangle rectangle; / The Rectangle For Locking The Bitmap In Memory BitmapData bitmapData = null; / The Bitmaps Pixel Data / Load The Bitmap try bitmap = new Bitmap(filen
12、ame); / Load The File As A Bitmap bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); / Flip The Bitmap Along The Y-Axis rectangle = new Rectangle(0, 0, bitmap.Width, bitmap.Height); / Select The Whole Bitmap / Get The Pixel Data From The Locked Bitmap bitmapData = bitmap.LockBits(rectangle, ImageLoc
13、kMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.glGenTextures(1, texture); / Create 1 Texture / Create Linear Filtered Texture GL.glBindTexture(GL.GL_TEXTURE_2D, texture0); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); GL.glTexParameteri(GL.GL_T
14、EXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, bitmap.Width, bitmap.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_BYTE, bitmapData.Scan0); catch (Exception e) / Handle Any Exceptions While Loading Textures, Exit App string errorMsg = “An Error Oc
15、curred While Loading Texture:nt“ + filename + “n“ + “nnStack Trace:nt“ + e.StackTrace + “n“; /MessageBox.Show(errorMsg, “Error“, MessageBoxButtons.OK, MessageBoxIcon.Stop); finally if (bitmap != null) bitmap.UnlockBits(bitmapData); / Unlock The Pixel Data From Memory bitmap.Dispose(); / Clean Up The Bitmap / / orient the icons so that itll face the camera / private void OrientBillboard() GL.glMultMatrixd(m_billboardMatrix);