Point3DCollectionAnimation中的collection.Clear问题
来源:互联网 发布:中文域名管理办法 编辑:程序博客网 时间:2024/06/13 01:53
模仿Charles Petzold的PointCollectionAnimation写了一个Point3DCollectionAnimation,自己按照理解的写了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
using Petzold.AnimationExtensions;
class Point3DCollectionAnimation:Point3DCollectionAnimationBase
{
Point3DCollection p3dcDst = new Point3DCollection();
public static DependencyProperty FromProperty = DependencyProperty.Register("From", typeof(Point3DCollection), typeof(Point3DCollectionAnimation));
public static DependencyProperty ToProperty = DependencyProperty.Register("To", typeof(Point3DCollection), typeof(Point3DCollectionAnimation));
public Point3DCollection From
{
set { SetValue(FromProperty, value); }
get { return (Point3DCollection)GetValue(FromProperty); }
}
public Point3DCollection To
{
set { SetValue(ToProperty, value); }
get { return (Point3DCollection)GetValue(ToProperty); }
}
protected override Point3DCollection GetCurrentValueCore(Point3DCollection defaultOriginValue, Point3DCollection defaultDestinationValue, AnimationClock animationClock)
{
if (animationClock.CurrentProgress == null)
return null;
double progress = animationClock.CurrentProgress.Value;
Point3DCollection p3dcFrom = From ?? defaultOriginValue;
Point3DCollection p3dcTo = To ?? defaultDestinationValue;
p3dcDst.Clear();
int count = defaultOriginValue.Count;
for (int i = 0; i < count; i++)
{
p3dcDst.Add(new Point3D((1 - progress) * p3dcFrom[i].X + progress * p3dcTo[i].X,
(1 - progress) * p3dcFrom[i].Y + progress * p3dcTo[i].Y,
(1 - progress) * p3dcFrom[i].Z + progress * p3dcTo[i].Z));
}
return p3dcDst;
}
protected override System.Windows.Freezable CreateInstanceCore()
{
return new Point3DCollectionAnimation();
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
using Petzold.AnimationExtensions;
class Point3DCollectionAnimation:Point3DCollectionAnimationBase
{
Point3DCollection p3dcDst = new Point3DCollection();
public static DependencyProperty FromProperty = DependencyProperty.Register("From", typeof(Point3DCollection), typeof(Point3DCollectionAnimation));
public static DependencyProperty ToProperty = DependencyProperty.Register("To", typeof(Point3DCollection), typeof(Point3DCollectionAnimation));
public Point3DCollection From
{
set { SetValue(FromProperty, value); }
get { return (Point3DCollection)GetValue(FromProperty); }
}
public Point3DCollection To
{
set { SetValue(ToProperty, value); }
get { return (Point3DCollection)GetValue(ToProperty); }
}
protected override Point3DCollection GetCurrentValueCore(Point3DCollection defaultOriginValue, Point3DCollection defaultDestinationValue, AnimationClock animationClock)
{
if (animationClock.CurrentProgress == null)
return null;
double progress = animationClock.CurrentProgress.Value;
Point3DCollection p3dcFrom = From ?? defaultOriginValue;
Point3DCollection p3dcTo = To ?? defaultDestinationValue;
p3dcDst.Clear();
int count = defaultOriginValue.Count;
for (int i = 0; i < count; i++)
{
p3dcDst.Add(new Point3D((1 - progress) * p3dcFrom[i].X + progress * p3dcTo[i].X,
(1 - progress) * p3dcFrom[i].Y + progress * p3dcTo[i].Y,
(1 - progress) * p3dcFrom[i].Z + progress * p3dcTo[i].Z));
}
return p3dcDst;
}
protected override System.Windows.Freezable CreateInstanceCore()
{
return new Point3DCollectionAnimation();
}
}
但实际的效果却总出不来,我设想的曲面动画总是不出现,弄了很久,把这些语句一个个调试过之后发现,似乎是p3dcDst.Clear出的问题,Clear之后再Add一批新点后,这些值在debug时看着是好的,但返回给WPF绘图时它就是没反应,而如果用p3dcDst = new Point3DCollection()替代效果才能出来。翻查原来Charles Petzold写的PointCollectionAnimation,才发现他用了一个flip的变量,同时定义了两个PointCollection实例,在操作时不停地flip。原来人家是知道这个问题的,奇怪怎么没有看到这方面的资料。。
于是给我的类加入了同样的机制:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
using Petzold.AnimationExtensions;
class Point3DCollectionAnimation:Point3DCollectionAnimationBase
{
Point3DCollection p3dcDst1 = new Point3DCollection();
Point3DCollection p3dcDst2 = new Point3DCollection();
bool flip = true;
public static DependencyProperty FromProperty = DependencyProperty.Register("From", typeof(Point3DCollection), typeof(Point3DCollectionAnimation));
public static DependencyProperty ToProperty = DependencyProperty.Register("To", typeof(Point3DCollection), typeof(Point3DCollectionAnimation));
public Point3DCollection From
{
set { SetValue(FromProperty, value); }
get { return (Point3DCollection)GetValue(FromProperty); }
}
public Point3DCollection To
{
set { SetValue(ToProperty, value); }
get { return (Point3DCollection)GetValue(ToProperty); }
}
protected override Point3DCollection GetCurrentValueCore(Point3DCollection defaultOriginValue, Point3DCollection defaultDestinationValue, AnimationClock animationClock)
{
if (animationClock.CurrentProgress == null)
return null;
double progress = animationClock.CurrentProgress.Value;
Point3DCollection p3dcFrom = From ?? defaultOriginValue;
Point3DCollection p3dcTo = To ?? defaultDestinationValue;
Point3DCollection p3dcDst=flip ? p3dcDst1 : p3dcDst2 ;
flip = !flip;
p3dcDst.Clear();
int count = defaultOriginValue.Count;
for (int i = 0; i < count; i++)
{
p3dcDst.Add(new Point3D((1 - progress) * p3dcFrom[i].X + progress * p3dcTo[i].X,
(1 - progress) * p3dcFrom[i].Y + progress * p3dcTo[i].Y,
(1 - progress) * p3dcFrom[i].Z + progress * p3dcTo[i].Z));
}
return p3dcDst;
}
protected override System.Windows.Freezable CreateInstanceCore()
{
return new Point3DCollectionAnimation();
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
using Petzold.AnimationExtensions;
class Point3DCollectionAnimation:Point3DCollectionAnimationBase
{
Point3DCollection p3dcDst1 = new Point3DCollection();
Point3DCollection p3dcDst2 = new Point3DCollection();
bool flip = true;
public static DependencyProperty FromProperty = DependencyProperty.Register("From", typeof(Point3DCollection), typeof(Point3DCollectionAnimation));
public static DependencyProperty ToProperty = DependencyProperty.Register("To", typeof(Point3DCollection), typeof(Point3DCollectionAnimation));
public Point3DCollection From
{
set { SetValue(FromProperty, value); }
get { return (Point3DCollection)GetValue(FromProperty); }
}
public Point3DCollection To
{
set { SetValue(ToProperty, value); }
get { return (Point3DCollection)GetValue(ToProperty); }
}
protected override Point3DCollection GetCurrentValueCore(Point3DCollection defaultOriginValue, Point3DCollection defaultDestinationValue, AnimationClock animationClock)
{
if (animationClock.CurrentProgress == null)
return null;
double progress = animationClock.CurrentProgress.Value;
Point3DCollection p3dcFrom = From ?? defaultOriginValue;
Point3DCollection p3dcTo = To ?? defaultDestinationValue;
Point3DCollection p3dcDst=flip ? p3dcDst1 : p3dcDst2 ;
flip = !flip;
p3dcDst.Clear();
int count = defaultOriginValue.Count;
for (int i = 0; i < count; i++)
{
p3dcDst.Add(new Point3D((1 - progress) * p3dcFrom[i].X + progress * p3dcTo[i].X,
(1 - progress) * p3dcFrom[i].Y + progress * p3dcTo[i].Y,
(1 - progress) * p3dcFrom[i].Z + progress * p3dcTo[i].Z));
}
return p3dcDst;
}
protected override System.Windows.Freezable CreateInstanceCore()
{
return new Point3DCollectionAnimation();
}
}
效果就出来了。
- Point3DCollectionAnimation中的collection.Clear问题
- JDK源码-Collection-clear()
- Collection中的一个小问题
- Collection中的一个小问题
- Eclipse中的clear
- Clear Case中的-mkbranch
- css中的clear属性
- CSS中的clear属性
- style中的clear:both
- CSS中的clear属性
- style中的clear:both
- div问题之clear
- IE6的clear问题
- Clear:both问题
- java中的集合框架Collection 接口 Map接口的问题
- Collection(Collections.sort)中的Values排序问题-java
- div中的float与clear
- python中的字典clear方法
- 转:对Sql Server 2000 系统表的常用操作
- 你真的了解.NET中的String吗?
- javascript Date对象详解来源:IT传媒网(www.cniter.com)
- PDM进化论
- CSS滑门技术:仿淘宝导航条布局效果
- Point3DCollectionAnimation中的collection.Clear问题
- 超酷循环出现的新闻特效代码
- asp 二进制字符串转换为普通字符串
- 字符串格式化,不足位数的补0
- ApplicationContext.xml的分析
- flex系列文章
- 数据库 随机取记录
- XML数据岛
- istream_iterator常见的错误说明