Tuesday, December 2, 2008

Flash 10 3d functions...

There is nothing better than playing around with a fresh set of functions in a nice API (that almost sounded like something entirely different).. the last couple of night I've been playing around with the new 3d functions in flash 10, trying to figure what's new, and what's good..

Conclusions so far..

Flash 10 does not provide Hardware accelerated 3d ...
Flash 10 does not provide Hardware pixel shaders (or vertex shaders)
Flash 10's drawtriangles work in a 2d NOT 3d coordinate space
Flash 10's not RotateX/RotateY/RotateZ functions ARE cool

As always i ended up playing around with a few things, the following code loads up a bitmap inside a sprite and spins it around in a 3d cordinate system. not exactly a "3d engine" but hey, it's moving right !

currently in working on a more "correct" apropoch to the 3d functions in flash 10, as well as a small 3d engine which will stresstest the 3d sprites ability of flash 10 to the limit ;)

code for spinning surface (download)
package 
{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;

/**
* ...
* @author Kenneth Christensen
*/
[SWF(width = '640', height = '480', backgroundColor = '#000000', framerate = '30')]
public class Main extends Sprite
{
[Embed(source = "..\\picture.png")]
private var pictureclass:Class;

private var surface:Sprite = null;
public function Main():void
{

surface = new Sprite();
this.addChild(surface);

var bitmap:Bitmap = new pictureclass();
surface.addChild(bitmap);

bitmap.x = (bitmap.width / 2) * -1;
bitmap.y = (bitmap.height / 2) * -1;

surface.x = 320;
surface.y = 240;

addEventListener(Event.ENTER_FRAME, renderframe);
}

private function renderframe(e:Event = null):void
{
surface.rotationX++;
surface.rotationZ++;
}
}
}