Archive for February, 2008

Automatic Bending Joints in As3 (Simple Bones)

This was part of a Rock’em Sock’em Robot game& 8212;for an internal sales project no less! At any rate the budget was good, but the timeline was a little tight, and I was still getting my head around AS3 and the new Flash 9 features.

So I had this idea:

I’m working with a bunch of designer’s who are really good with illustrator, and keyframe animating, but don’t have the time to animate all the movements (each head, body, upper arm x2 lower arm x2, legs, hands, feet… well you get the idea). So I needed a way to reduce the number of animations that the designers would be needed for, but also not create too many Tweeners or other hard coded animation solutions. I really needed bones, but those don’t seem to be arriving for a while, so the next best thing was automatically animated elbows (and knees). Fortunately for me the illustrator I was working with designed the robot’s arms and legs with even length upper and lower lengths so I could do some trig and get this:

var theta:Number = Math.acos((distance/2)/limbL)*180/Math.PI;
this.limb.rotation =  baseRotation - theta;
this.omoLimb.rotation = theta * 2;

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)
Click and drag the hand or foot to see the automagic joint rotation

AS3 Joint class source file

Right now it’s limited to even length bones, but my little brother with the physics and math degrees, says he has a better equation, so as soon as I have time I’ll update the classes. A public SVN repository is in the works too, stay tuned.

Rsyslogd man pages have a great sense of humor

During a day of red5 programming, in the hopes to get a true streaming solution for my flash projects I stumbled upon this little gem. I’ll post about my experiences with red5 at a later time. However, for now I think you should check out this excerpt from the rsyslogd man pages. We are using rsyslog in the hopes that we can log all the red5 events to a centralized server for easier reporting. Check back for updates on that. As always if you like this article please digg it and or leave a comment so we don’t feel like we are talking to ourselves…. Enjoy

sucker rod and rsyslog

At least the suggest violence as a last ditch effort. Hilarious open source world keep it up…

Highlight selected navigation item in ruby on rails

For an example site where I used this technique please refer to you’ll notice that when you click on best / worst or most recent it is highlighted with a black underline. This type of highlighting seems trivial. However to do it in rails in a nice elegant way is not obvious. So without further a do, I present my method. This method dis-involves the controller which makes for a cleaner more centralized place for managing your highlighted navigation.

The primary thing required is a method for creating navigation items. I choose to put my method / helper. in the app/helpers/application_helper.rb that way it will be available to all all of my views. The method I chose to use is

def nav_selected_no_span(hash_name, selectedkey )
                result =""
                hash_name.each do |item|
                        if(item[0].to_s== selectedkey)
                                result +="<li class="selected"+item[0].to_s.gsub(" ", "_").downcase+" selected">"+link_to(item[0].to_s,item[1].to_s)+"</li>"
                                result +="<li class=""+item[0].to_s.gsub(" ","_").downcase+" ns">"+link_to(item[0].to_s,item[1].to_s)+"</li>"
                  return result

This function is fairly, simple what it allows you to do in your view is, make an unorded list of your navigation items. You would use this method most likely in your app/views/layout/application.rb. An example of the navigation from is:

     <%= nav_selected_no_span([["Vote On Pets",home_path],["Best / Worst",best_worst_path],["Most Recent",most_recent_path]], params[:location] ) %>

The important thing to notice is the params[:location] the function above says that if params[:location] matches one of the names like “Vote On Pets” then highlight that item. Pretty simple. Then in your css you can define the rules that make something selected. Now you may be wondering where params[:location] is set. And you would be correct to wonder that. That parameter is actually set in your routes file believe it or not. As an example i’ll show you the route for “Vote On Pets”. located in config/routes.rb your could do something like this.

map.home '', :controller => 'index', :action => 'index', :location=>'Vote On Pets'

if you wanted most recent you would do something like this

map.most_recent '/most_recent', :controller=>'index',:action=>'recent',:location=>'Most Recent'

The location parameter is sent to the helper and the correct items is selected. So I hope this helps you in your efforts to stay dry and much more organized.

Questions and comments are very welcome on this blog. We like to know we are not talking to ourselves, so if you would like further explanation please feel free to post a comment.