WPF implements the physical effect to pull a small ball, while wpf implements the physical ball.

Source: Internet
Author: User

WPF implements the physical effect to pull a small ball, while wpf implements the physical ball.

I have been mysterious to the physical effect, do not know how to achieve. Until I saw a blog written by Zhou yinhui earlier: http://www.cnblogs.com/zhouyinhui/archive/2007/06/23/793724.html finally know how to achieve it.

The Rendering event of the CompositionTarget class is triggered when each frame is successfully rendered. This allows you to perform more detailed operations on the object in a very short time to achieve the expected results.

However, the blog does not introduce the results formula, which makes me confused. So I decided to write it again and share it with interested people.

First:

In this scenario, a rubber band pulls a ball and moves in a space filled with media. The longer the rubber band, the larger the tension. The medium can be air or water, any liquid or gas, such as oil, depends on their viscosity coefficient.

To achieve this, we need to learn about Newton's motion theorem, sphere mass formula, and the Newton formula of a stochastic formula. Everyone is familiar with it: (maybe, I am not familiar with it anyway, this is what I checked by Baidu)

A = (v2-v1)/t

F = F-F resistance = ma

S = vt + 1/2at ^ 2

Where a is the acceleration, v is the speed, t is the time, F is the force, and s is the moving distance.

Sphere quality formula:

M = 4/3 * π * r ^ 3 * P

M indicates the quality, r indicates the ball radius, and P indicates the density.

Sticky resistance (I have never learned this kind of advanced physics, but I don't know it at all. It's also found in Baidu)

In theoretical mechanics, the "resistance proportional to the First-party velocity of an object" refers to the resistance caused by the viscosity resistance of an object that is not very fast in the air. It is mainly the viscosity resistance.

The stochastic formula is used for spherical objects F = 6 π x vr = 3 π x vd. The viscosity coefficient of the fluid r is the radius of the spherical object d is the diameter of the spherical object

 

All formulas are available. What we need to do is to find the moving distance between the last frame rendering and the frame rendering time under the action of tension and resistance.

Both the force and speed are regarded as the X-axis and Y-axis directions.

Here we take the distance of a unit in wpf as 1 Newton's force. the viscosity coefficient and ball density are set as parameters. with this, you can export the moving distance according to the formula. (process omitted... is a set of formulas... there are comments in the source code... the source code will be appended)

 

Then, it was hard to launch the program, and the running program found that the ball was not moving. I found out that I made a big mistake, that is, the difference in strength and quality is too great. For example, a person who took the rubber band to the Dubai tower must not be able to pull it.

So I added a cubic power of the diameter of a small ball. For example, I can understand how much I pulled, and how much I got, it has nothing to do with the size of the pulled item. when I went to Dubai, I was as tall as Dubai.

 

Attached source code: small ball physics efficiency. Zip

 

We recommend a good Blend, Wpf, and sl Communication Group.

Group number: 152049269

Thank you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.