WPF Cover Flow Tutorial : Part 2
来源:互联网 发布:软件总体技术方案 编辑:程序博客网 时间:2024/04/18 17:49
Since Part 1, we now know how to display a cover in 3D.
In order to display a reflection mirror, we add another GeometryModel3D to our Model3DGroup. This new element will be based on these points :We define the Point2D alias because of the conflict with System.Drawing.Point.
For the texture, we use a VisualBrush object and we apply a LinearGradientBrush to the image OpacityMask :
There are two possibilities to browse the covers :
There are two transformations : a rotation and a translation on X and Z axes. The rotation angle will be 90, 0 or -90 degrees. The Z translation will be 0 or 1 for the current cover. The X translation will be 0 for the current cover, or proportional to the distance from the origin. For each cover, we will save its position. We will compare the cover position with the current index to compute the transformation parameters. This gives us :Applying the transformations to our Model3DGroup is easy. We create the transformation in the constructor with a default index of 0 :Then, we will call the Animate method the transform the cover :If we create three covers, we realize that only one is visible :We need to replace our single light source with two different ones :Continue with Part 3. Download source.
In order to display a reflection mirror, we add another GeometryModel3D to our Model3DGroup. This new element will be based on these points :
- using Point2D = System.Windows.Point;
- private Geometry3D TessellateMirror()
- {
- var p0 = new Point3D(-1, -3, 0);
- var p1 = new Point3D(1, -3, 0);
- var p2 = new Point3D(1, -1, 0);
- var p3 = new Point3D(-1, -1, 0);
- var q0 = new Point2D(0, 1);
- var q1 = new Point2D(1, 1);
- var q2 = new Point2D(1, 0);
- var q3 = new Point2D(0, 0);
- return BuildMesh(p0, p1, p2, p3, q0, q1, q2, q3);
- }
For the texture, we use a VisualBrush object and we apply a LinearGradientBrush to the image OpacityMask :
- using MediaColor = System.Windows.Media.Color;
- private Material LoadImageMirror(ImageSource imSrc)
- {
- var image = new System.Windows.Controls.Image();
- image.Source = imSrc;
- MediaColor startColor = MediaColor.FromArgb(127, 255, 255, 255);
- MediaColor endColor = MediaColor.FromArgb(127, 255, 255, 255);
- image.OpacityMask = new LinearGradientBrush(startColor, endColor, 90.0);
- var brush = new VisualBrush(image);
- return new DiffuseMaterial(brush);
- }
There are two possibilities to browse the covers :
- Keep the camera at the very same place and translate/rotate all covers as we are browsing.
- Transform only a few covers (e.g. the one currently selected) and move the camera.
There are two transformations : a rotation and a translation on X and Z axes. The rotation angle will be 90, 0 or -90 degrees. The Z translation will be 0 or 1 for the current cover. The X translation will be 0 for the current cover, or proportional to the distance from the origin. For each cover, we will save its position. We will compare the cover position with the current index to compute the transformation parameters. This gives us :
- private readonly int pos;
- private double RotationAngle(int index)
- {
- return Math.Sign(pos - index) * -90;
- }
- private double TranslationX(int index)
- {
- return pos * .2 + Math.Sign(pos - index) * 1.6;
- }
- private double TranslationZ(int index)
- {
- return pos == index ? 1 : 0;
- }
- private readonly AxisAngleRotation3D rotation;
- private readonly TranslateTransform3D translation;
- public Cover(string imagePath, int pos)
- {
- this.imagePath = imagePath;
- this.pos = pos;
- ImageSource imSrc = LoadImageSource();
- modelGroup = new Model3DGroup();
- modelGroup.Children.Add(new GeometryModel3D(Tessellate(), LoadImage(imSrc)));
- modelGroup.Children.Add(new GeometryModel3D(TessellateMirror(), LoadImageMirror(imSrc)));
- rotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), RotationAngle(0));
- translation = new TranslateTransform3D(TranslationX(0), 0, TranslationZ(0));
- var transformGroup = new Transform3DGroup();
- transformGroup.Children.Add(new RotateTransform3D(rotation));
- transformGroup.Children.Add(translation);
- modelGroup.Transform = transformGroup;
- Content = modelGroup;
- }
- public void Animate(int index)
- {
- rotation.Angle = RotationAngle(index);
- translation.OffsetX = TranslationX(index);
- translation.OffsetZ = TranslationZ(index);
- }
- <ModelVisual3D>
- <ModelVisual3D.Content>
- <DirectionalLight Color="White" Direction="1,0,-3" />
- </ModelVisual3D.Content>
- </ModelVisual3D>
- <ModelVisual3D>
- <ModelVisual3D.Content>
- <DirectionalLight Color="White" Direction="-1,0,-3" />
- </ModelVisual3D.Content>
- </ModelVisual3D>
- WPF Cover Flow Tutorial : Part 2
- WPF Cover Flow Tutorial : Part 1
- WPF Cover Flow Tutorial : Part 3
- WPF Cover Flow Tutorial : Part 4
- WPF Cover Flow Tutorial : Part 5
- WPF Cover Flow Tutorial : Part 6
- WPF Cover Flow Tutorial : Part 6 (bis)
- WPF Cover Flow Tutorial : Part 7
- WPF Cover Flow Tutorial : Part 7 (source)
- Cover Flow特效实现(2)
- GObject Tutorial Part 2
- TheWavelet Tutorial Part 2
- TheWavelet Tutorial Part 2
- Cover Flow编程1118
- Cover Flow布局
- Unity的Cover flow的实现包(2个)
- Tutorial - Deferred Rendering (Part 2)
- PyQt5-Beginner-tutorial-part 2
- Android线程间通信机制(Handler Looper )
- 游戏二: 随处移动的Ball
- 紫薇花开的季节(二)
- hdu Minimum Inversion Number(线段树求逆序数有关问题的一个小归纳)
- Oracle 正则表达式函数的使用
- WPF Cover Flow Tutorial : Part 2
- JS文件中变量命名防止重复
- installshield中执行批处理
- HGE 系列教材(5) --- 输入、声音和渲染
- 餐桌上的“爱心菜”
- 视图中使用select a.* 更改了表a的结构 导致读取字段值时发生错位
- “ 设置>备份和重置>恢复出厂设置 “这个功能是做什么的?
- 易语言"发送消息()"_SendMessage详细说明
- C# StreamReader/StreamWriter与FileStream用法详解