Sunday, September 24, 2017

Slow Motion Physics Video

I haven't done much work on the 3DWorld source code since my last post. I've been mostly experimenting with the physics system and trying to reduce instability. I took some videos of slow motion physics to help me analyze the quality and problems in my system, and I'll show two of these here.

3DWorld has an interactive timestep adjustment feature that allows the user to slow down the physics timestep by an arbitrary factor, which can be used to make objects move in slow motion. The timestep can also be reduced to 0 to disable physics and lock all objects in place. This doesn't affect the player movement or weapon firing, only dynamic object motion. I can use this feature for analysis and debugging of physics problems. For example, I can fire a rocket at an object, then freeze physics and walk up to the object for a closer view of the collision, then let the rocket continue to explode in slow motion.

The following video shows me breaking windows in 3DWorld with the physics timestep set slow enough that the individual triangular glass fragments can be seen spinning though the air and colliding with the scene. They don't collide with each other. The sharp glass fragments damage the player, which is why there is so much blood in the air and on the ground. Blood moves in slow motion as well. Bloody glass fragments will turn a reddish color.

Note that I'm recording video in realtime on 7 of 8 threads (3.5 of 4 cores) and only letting 3DWorld use one thread for physics + rendering + screen capture. Even with this setup, the video compression can't always keep up with the 60 FPS target framerate. This means that 3DWorld sometimes can't produce the results at the recording rate, which is why the video plays back somewhat faster than realtime. However, the physics is slowed down by ~10x, so you can see the fragments moving just fine. Sorry, I still haven't figured out how to capture and record 3DWorld's audio stream, which is why there's no sound.


That big gray sphere at the end is my skull, and the black sphere is one of my eyes. The camera follows the other eye as it bounces on the floor. I have no idea what happened to my red nose. Yes, I bled to death from cuts due to broken glass. It happens, especially when using the baseball bat on windows. I don't recommend trying this at home. Oh, and if you're curious, you can get hurt by wood fragments as well.

If you look closely, there's some instability in the glass fragments resting on the windowsill and on the ground. Some of them rotate in place even though they're no longer falling. Why is that? Fragments rotate about a random axis at a rate that's a function of object velocity. This means that angular velocity scales with linear velocity. Objects that have come to rest on a flat horizontal surface such as the ground are flagged as "stopped". This allows the physics system to skip some of the work when processing stopped objects, and it also disables object rotation. Objects that aren't moving but aren't in a stopped state have a small negative Z velocity impulse related to the effect of gravity that pulls them down. This velocity produces a small rotation that looks odd.

The problem is that the stopped state logic is approximate, and doesn't work well when an object collides with multiple scene faces at the same time. This is what happens near the outside corner of the windowsills and the inside corner between the wall and the floor. They're not put into a stopped state due to the possible collision with a vertical face that may push the object away at the next timestep. If they land far enough away from vertical surfaces, everything is fine. These fragments look like triangles, but the physics system uses bounding spheres for them. This means that a triangle that appears to be resting on the ground may actually have its bounding sphere touching the wall.

In addition, the wood fragments from the bench are 1D polygons. I hadn't implemented texturing of thick 3D triangle fragments yet. I've partially fixed the glass instability now - the fragments sometimes jitter a small amount, but they don't rotate. I've also added textured thick wood fragments. These look better than flat polygons, but still don't look much like real wood splinters. It's progress, but far from complete. The updated video is below.


I was careful not to die this time.

There are still some issues to fix, but it looks a bit better. Well, at least if you know what to look for. For example, real glass fragments don't land at odd angles, they land with the flat side down. Unfortunately, that's also a bit too simple and doesn't look right. Drawing triangle fragments that intersect each other on the ground looks even worse. No, they land with the flat side down, but only if they're not landing on top of each other. If fragments land on each other, they form a chaotic pile. This requires collision detection between thousands of fragments. It's something to possibly add later.

I'll post more screenshots or videos if I make progress later.

No comments:

Post a Comment