Monday, February 16, 2009

simulated 3D - 360 Rotation




The integration of 3D Graphics and Flash has come a long way over the past few months. With the advent of Papervision3D among other 3D engines, creating real-time 3D graphics in Flash is now a very tangible prospect. I intend to post more about Papervision3D and Collada file integration in the future.


However, the use of "simulated-3D" (for lack of a better term) is still very much in demand by clients. The process involves rendering an animated sequence (usually a 360 rotation of some sort) and then importing dozens (if not hundreds) of individual frames into a MovieClip in Flash.

Needless to say, it's not the most elegant means, but done sparingly and with efficiency in mind, it can produce stunning results.

I recently created a prototype for Licor Biosciences. I used a function that generated an integer based on the width of the stage - that integer was then used as the frame number of the corresponding MovieClip.

Here's the function I wrote

function giveDis(event:Event):void
{

var bX:Number = dragger.x
var bY:Number = dragger.y
var cX:Number = center.x
var cY:Number = center.y

distance = Math.round(Math.sqrt((bX) * (bX) + (cX) * (cX))/13.4);
trace(distance);
photon.gotoAndStop(distance);

}

In this case, the function is triggered by an ENTER_FRAME event. So it perpetually tracks the integer that the 'distance' variable produces.


[NOTE: 'dragger' here refers to the MovieClip used as the dragging mechanism
(i.e dragger.startDrag();) and 'center' is a second clip used at the edge of the stage.]


The distance formula shown is the Pythagorean Theorem rounded to the nearest integer and then devided by 13.4, which was a number I found by trial and error. It gave me a integer between 0 and 200 which was equal to the number of frames in my MovieClip.

(I'm sure a math genius out there could tell me why 13.4 it makes sense here.)

I'll be re-writing the code for this program shortly, and it'll be structured in the proper 'package' format.

The benefit of the code above is that it can be used for virtually any number of frames, on any stage, for any animation.

See the example here:http://www.mastertrackproductions.com/Licor/view360/Licor360.html



-Alchemist

No comments:

Post a Comment