WPF中的3D网球动画 [英] 3D Tennis ball animation in wpf

查看:103
本文介绍了WPF中的3D网球动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,这只是我尝试使用WPF创建的另一个有趣的3D应用程序.

它是一种3D动画应用程序.经过艰苦的搜索,我终于找到了一种在wpf中创建3D网球的方法.我创建了一个将x,y,z position,size等作为参数的方法.

在我的代码中,我两次调用了该方法,因此屏幕上有两个网球.:D ..我将两个球的初始位置分别指定为(0,0,0)和(3,3, 3).现在,我想根据我给的位置为它们设置动画.基本上,我希望第二个球追逐第一个球,但它永远无法追赶第一个球.;)

我编写了一小段代码(如下所示),每次执行第一个for循环时,它们都可以为我提供两个球的新位置.我假设我将根据第一个for循环获得100个新职位?第二个for循环将执行两次,因为有两个网球,它们的位置存储在数组中?

每次执行第一个循环时,我都希望将新位置传递到两个球上,并且我想使球移动并使其成为连续的动画.我对如何执行此操作一无所知,而且我从未在WPF上进行过任何3D动画.

我是一个初学者,所以在解释技术概念时,请放轻松.我将不胜感激任何插图,示例和教程.

//位置生成器

for(int frame = 0; frame< 100; i ++)
{
for(int j = 0; j< 2; j ++)
{
xposition [j] = xposition [j] +2;
yposition [j] = yposition [j] +2;
zposition [j] = zposition [j] +2;
}
}


谢谢,

So, this is just another funny 3D application i am trying to create using WPF.

It is a 3D animation kind of an application. After an ardous search, i finally figured out a way to create a 3D tennis ball in wpf. I have created a method that takes the x,y,z positions , size, etc as parameters.

In my code, i have called that method twice, and thus have got two tennis balls on my screen.:D..I have given the initial positions for both the balls as (0,0,0) and (3,3,3). Now, I would like to animate them according to the positions I give. Basically, I want the second ball to chase the first ball, but it can never catch the first one.;)

I have written a small chunk of code(as given below) that can give me new positions for both the balls every time the first for loop is executed. I am assuming that I will get 100 new positions according to the first for loop ? and the second for loops will execute two times as there are two tennis balls and their positions are stored in an array ?

Everytime the first loop is executed i want the new position to be passed to both the balls and I want to make the balls move and make it a continuous animation. I don''t have any idea of how to do this and I have never done any 3D animations on WPF ever before.

I am a beginner and so Please go easy on me when explaining technical concepts. I would greatly appreciate any illustrations, examples and tutorials.

//Position generator

for(int frame=0;frame<100;i++)
{
for(int j=0;j<2;j++)
{
xposition[j] = xposition[j]+2;
yposition[j] = yposition[j]+2;
zposition[j] = zposition[j]+2;
}
}


Thanks

推荐答案

实际上,对于这种简单的动画,不需要预先计算接下来的100个位置.

创建一个每30毫秒触发一次的计时器(大约每秒30帧)并计算新位置.您将要保留当前向量的变量.每当您的计时器计时时更新这些内容.

将这些元素的位置绑定到类中的数据.您可以在CP上找到大量的数据绑定信息(当然在Google上也可以找到很多).

干杯.
Actually, for this simple of animation there is no need to pre-compute the next 100 positions.

Create a timer that fires every 30ms (that gives you about 30 frames/sec) and calculate the new position. You''ll want to keep variables for current vectors. Update these every time your timer ticks.

Bind your position of these elements to the data in your class. You can find a wealth of databinding information here on CP (and certainly a tonne more on Google).

Cheers.


我尝试使用wpf中的dispatchertimer类.我很高兴这个程序似乎无法达到我的目的.输出效果不佳,我也无法对其进行动画处理.我正在考虑通过使用translatetransform3D或其他方式使我的项目成为基于属性的动画.我目前没有预先计算任何东西. x,y和z坐标有3个数组. x [0]将具有x球1的位置,x [1]将具有x球2的位置,以及类似的y和z数组. X [0],X [1] ...等中的值.会使用一种简单的方法进行频繁更改,该方法在for循环中包含一些计算.我希望将这些值(位置)用作网球的新位置.动画应根据功能更新的位置运行. (这些新位置可以用作offsettransform3d的偏移量吗?)当方法中的循环终止时,动画应结束.我已经阅读了大量有关使用C#/WPF的基于计时器的动画,基于帧的动画和基于属性的动画的文章,但是到目前为止,我还没有发现任何有用的东西.有一些解决方案,但所有解决方案都是针对2D对象的.我已经在C#中完成了大部分工作,并没有那么多地使用xaml.请解决我的问题.
I Tried using dispatchertimer class in wpf. I am afriad that this procedure does not seem to work for my purpose. The output does not work very well, and I could not animate it either. I am thinking of making my project a property based animation by using translatetransform3D or something. I am not precomputing anything at the moment. There are 3 arrays for x,y and z co-ordinates. x[0] will have x position of ball-1 and x[1] will have x position of ball-2 and similarly the y and z arrays. The values in X[0], X[1]...etc. will be changed frequently using a simple method that contains some calculations within a for loop. I want these values(positions) to be used as new positions for the tennis balls. The animation should run accordingly to the positions updated by the function. (can these new positions be used as an offset to translatetransform3d ?) The animation should end when the loop within the method terminates. I have done quite a lot of reading about timer-based animation, frame-based animation and property based animation using C#/WPF, but so far I have not found anything useful. There are a few solutions but all of them are for 2D objects. I have done most of my work in C# and have not used xaml that much. Please resolve my problem.


这篇关于WPF中的3D网球动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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