Monday, March 8, 2010

CrazyGLU is for the Boids


Hey you! Think WebGLU isn't up to snuff? Let me know why so I can improve it!

As I’ve done work on WebGLU I’ve implemented a variety of neat features, but in doing so a couple problems have arisen. The first is that I sometimes have something semi-working, but not entirely done. The second is that some features don’t really need to be loaded into every page. The solution, for now at least, is CrazyGLU, which is where I will put any experimental, incomplete, or niche features until such time it is appropriate to relocate them to WebGLU proper.


To load CrazyGLU just call $W.useCrazyGLU() and it will be loaded in place, adding the features to the existing $W object. I don’t know if my method for dynamically loading JS files [Synchronous XMLHttpRequest for the file, then eval() the contents] is the right way to go about doing it, so speak up if there’s a better way to do it. Another upside to all this is that necessary supporting libraries, like Sylvester, now get loaded automatically, so that’s one less line you need in your page.
Speaking of Sylvester I intend to eventually replace it with a more performant library such as Vladimir Vukićević’s mjs. As Vlad mentions on his blog, Sylvester provides flexibility that isn’t necessary for a majority of graphics programming, arbitrarily sized vectors and matrices. Graphics really only require three element vectors and 4x4 matrices, and optimizing for that case speeds things up greatly.
As of today CrazyGLU includes a partially working physics simulation that powers the billiards demo. It also contains the .obj model loading code I still haven’t gotten around to fixing. The newest addition to CrazyGLU is a partial port of the C++ OpenSteer library by Craig Reynolds. OpenSteer provides a framework for giving objects ‘steering behaviors’ such as ‘stay close to others near me’ and ‘try to move towards that point’. Individually, these behaviors aren’t that big of a deal, but when you combine several behaviors in each of a few dozen objects you can get complex emergent behaviors. I will probably split OpenSteer back off into its own project at some point. In the meantime, I’ve put together a ‘Boids’ demo. Boids are ‘bird-like objects’, also developed by Craig Reynolds, that exhibit flocking behavior, but this behavior isn’t explicitly programmed. Instead, the three more simple behaviors of separation, alignment, and cohesion together allow flocking to emerge. For more information about Boids and the Java demo this one is based on, check out Craig's page on Boids.  The demo below shows 40 boids doing their thing.

I will get a video of the demo up as soon as I can. If you cannot see the demo please check the WebGL wiki for how to get a web browser that supports WebGL

Using WebGLU allowed me to focus on implementing the behaviors rather than spend time on the graphics code. Some other improvements include Keyframed animation rotations are now quaternion based and a new Framebuffer class makes working with framebuffers very easy. More information about Framebuffers in WebGLU as well as a picking demo that uses them will be explored further in a future post.

2 comments:

  1. can you put the examples in GitHub on line ??

    Would be great to play around with them.

    Also with your code i can see that the GameGlu is great, but it woudl not be a huge thing to make a IDE. In otherwords a blender UI ??



    Ged

    ReplyDelete
  2. >can you put the examples in GitHub on line ??

    All examples are live at http://www.cs.rit.edu/~bpd9116/WebGLU/examples

    >In otherwords a blender UI

    I am working on a basic animation editor, but a full application of that type is a bit out of my league at the moment.

    ReplyDelete