Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the collision of elastic objects in C# simulation test

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to achieve elastic object collision in the C# simulation test. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

When bored, I wrote an elastic object collision simulation with C #. This idea originated from the computer class a few days ago when someone wanted me to do a perspective projection program in the computer room, so I immediately wrote a projection and made a wireframe ball to jump. As a result, I thought, what if the object is elastic? Go back to the dorm and put your ideas into practice.

This program is 2D, using C # mainly because GDI+ is easier to write, at least easier to use than poor MFC, although C # things are slow and take up CPU usage. I swear that the Timer of .NET is not made with WM_TIMER messages, idling occupies such a high CPU, and it can't be reduced with Sleep. Excessive CPU occupancy for too long will lead to an increase in CPU temperature.

There's still something wrong with the program. For example, the classic problem of physics engine: floating point error and collision penetration. It hasn't been dealt with 100% yet, although in most cases it's fine. The second is because elasticity is beyond the scope of my physical knowledge, so the speed of collision is higher, temporarily scribbling, wait a few days to solve a system of ternary quadratic equations, and then change the code.

Put three screenshots first, and then get the code out after the program has been changed. This thing is fun. Hey, hey. Taking gravity into account.

C # simulation (1): two elastic 7 polygons are created

C # Simulation (2): the object on the left hits the wall

C # Simulation (3): the object on the right hits the ground

I used to make the elasticity very small and the number of sides very large, and as a result, there was something like a water-filled balloon.

About how to achieve elastic object collision in the C# simulation test is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report