I've recently been doing some work on a physics engine sample for Microsoft Surface. The principal purpose of this work was to investigate how adding physical characteristics to virtual items adds to the realism of a Surface experience. The work had three main areas of focus:
- To add physical behaviour to virtual items in a Surface experience
- To combine physical behaviour with 3D WPF templates, textures and lighting sources
- To demonstrate how the object recognition capabilities of Microsoft Surface can be used to interact with these items
In addition to these points, I wanted to provide this functionality within a WPF layout control closely analagous to the Surface ScatterView control. In this way, it should be relatively easy to swap out a ScatterView implementation for a physics-based alternative.
Here's a video to illustrate the key features for this post.
The video is divided into the following sections:
Basic collision detection & response between circles, rectangles, and polygons. Notice that one can hold onto a given shape and flick other items into it. The held shape is affected by the collision but "springs" back to place. The items are all set to be the same density, so the size is proportional to the mass. The walls are "soft" and result in springy collision, rather than a hard collision between objects.
Illustration of directional forces (basic acceleration) and point forces (a gravity algorithm). Notice that point forces with low drag result in a chaotic rotational motion - heavier items accrete towards the gravity source, and lighter items rotate futher away. Multiple point forces can be added. Combinations of directional and point forces is also possible, e.g. "hanging" an object of suitable mass below a point force. Note also that the physical tags (poker chips) have a virtual presence and result in collisions.
3D Objects and Materials
This section illustrates some lighting and textures, e.g. "wooden" and "marble" tiles. The lighting is consistent between objects, in this case pointing from lower left to upper right with respect to the camera position. Patterns tiles have image textures generated in code. In this example they simply use black and white brushes, but one of the great things about WPF is that I could as easily use different image brushes and, for example, "inlay" different wood textures to form the same pattern.
This section illustrates the use of "fixed" objects, with and without directional forces (actually the "fixed" objects are just non-selectable items of very large mass). It also illustrates some of the object recognition of Microsoft Surface. Ordinary business cards placed on the Surface become part of the "virtual" world. One can also use other physical objects (e.g. brochures, hands etc) to "sweep" items.
Configuration and Debugging
This screen allows configuration of just some of the properties of the physical environment, such as "bounciness" (restitution) of items and walls, directional and angular drag, directional forcees, maximum directional and angular velocities etc. It was also an invaluable tool in debugging the build as it shows positions and vectors graphically.
I've included some screenshots below.
In the next article I'll describe some more physics-related and Surface-specific features of this framework.