The Famous F# DirectX Sample

Links: Up

This sample, written mostly by James Margetson, shows how to interactively visualize 3D surfaces and simulate motion on these surfaces using Managed DirectX. It is a compelling demonstration of F# Interactive and the potential of the F# Langauge in the arena of scientific visualization and simulation.

The sample shows how to draw surfaces that are a function over X/Y coordinates and also as a function of time. It also shows how to track mouse events to adjust view parameters, how to use top level 'refs' as locations to hold tweakable/adjustable parameters, and how to use numerical differentiation to compute the normal vector used ot simulate the motion of ice hockey puckS on a moving 3D surface. Finally it shows how to wrap up some of the functionality of the demo as a class.

For F# advocates: Get the code. Install DirectX. Learn how to go through the code. Learn how to interactively change the function being displayed, or the base mesh, or the parameters of the simulation (make gravity positive instead of negative!) Learn how to drag the mouse to change the view matrix. Learn how to explain to your friends why the simulation goes so fast, (because F# is fast, native code, not threaded-interpreted) Adapt the code to do something completely different. Turn it into a component, or use it to seed a funky library, or a community initiative to simplify and DirectX programming. Or use it to fix that niggling rattle you've had in your car for ages. It can do anything.

The script won't do anything until the point where you set up lights on the form. After that each fragment does something more interesting. Look particularly for the bits marked 'ff :=' and which change the active ball list.

Some more details are on the F# Community Site called The Hub.