简体   繁体   中英

Intersection Simulation in C#

I am making project for school "simulation of intersection" and i need few advices.

Canvas is a parent. For now i have created class "Car" which contains some properties like Rectangle(body), Speed, Enums (Car type, Direction of moving etc.). So:

  1. What is a best way to move objects in wpf? (I think about DispatcherTimer, but here is a question - each for one object or just one and just in one tick move all objects?)

  2. I have some problem with some math i mean how to create a animation of turn. Tried to find this, but all i found was some spirals. I know there will be some use of Math Class + angle. (Some code, ideas or keywords for search would be nice.)

Sry for english if someone will have troubles to understand what i wrote.

The usual way it is done in games is by having one main loop. You can do this in WPF just the way you mentioned - make a DispatcherTimer, and update their position all during one call. Creating more timers is needlessly consuming resources for hardly any benefit.

Real car physics are relatively complex, but for your use case, you can go with something really simple. This is a great (and short) article on simple but good looking car physics: http://engineeringdotnet.blogspot.com/2010/04/simple-2d-car-physics-in-games.html

You can use XAML or Code behind to make animation. Here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM