WPF实现3D粒子波浪效果
本文实例为大家分享了WPF实现3D粒子波浪效果的具体代码,供大家参考,具体内容如下
实现效果如下:
步骤:
1、3D粒子类Particle.cs
publicclassParticle
{
publicPoint3DPosition;//位置
publicdoubleSize;//尺寸
publicintXIndex;//X位置标识
publicintYIndex;//Y位置标识
}
2、粒子系统ParticleSystem类
publicclassParticleSystem
{
privatereadonlyList_particleList;
privatereadonlyGeometryModel3D_particleModel;
privatereadonlyintSEPARATION=100;
publicParticleSystem(intamountX,intamountY,Colorcolor,intSize)
{
XParticleCount=amountX;
YParticleCount=amountY;
_particleList=newList();
_particleModel=newGeometryModel3D{Geometry=newMeshGeometry3D()};
vare=newEllipse
{
Width=Size,
Height=Size
};
varb=newRadialGradientBrush();
b.GradientStops.Add(newGradientStop(Color.FromArgb(0xFF,color.R,color.G,color.B),0.25));
b.GradientStops.Add(newGradientStop(Color.FromArgb(0x00,color.R,color.G,color.B),1.0));
e.Fill=b;
e.Measure(newSize(Size,Size));
e.Arrange(newRect(0,0,Size,Size));
Brushbrush=null;
varrenderTarget=newRenderTargetBitmap(Size,Size,96,96,PixelFormats.Pbgra32);
renderTarget.Render(e);
renderTarget.Freeze();
brush=newImageBrush(renderTarget);
varmaterial=newDiffuseMaterial(brush);
_particleModel.Material=material;
}
publicintXParticleCount{get;set;}
publicintYParticleCount{get;set;}
publicModel3DParticleModel=>_particleModel;
privatedouble_count=0;
publicvoidUpdate()
{
//计算粒子位置及大小
for(intix=0;ix
3、Viewport布局
4、交互逻辑
privatereadonlyParticleSystem_ps;
privateDispatcherTimer_frameTimer;
publicMainWindow()
{
InitializeComponent();
_frameTimer=newDispatcherTimer();
_frameTimer.Tick+=OnFrame;
_frameTimer.Interval=TimeSpan.FromSeconds(1.0/60.0);
_frameTimer.Start();
_ps=newParticleSystem(50,50,Colors.White,30);
WorldModels.Children.Add(_ps.ParticleModel);
_ps.SpawnParticle(30);
KeyDown+=Window_KeyDown;
Cursor=Cursors.None;
}
privatevoidWindow_KeyDown(objectsender,KeyEventArgse)
{
if(e.Key==Key.Escape)
Close();
}
privatevoidOnFrame(objectsender,EventArgse)
{
_ps.Update();
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。