Am working on a pixel engine… thought i test it out by making a sphere.
I now have the sphere calculations correct and understood..wohoo!
This sphere is made with setPixel and Matrix3D.appendRotation.
And this following formula to put pixels randomly over a sphere mesh:
View CodeACTIONSCRIPT | |
1 2 3 4 5 6 7 | var radius:Number = 100; var theta:Number = Math.random() * Math.PI; var phi:Number = Math.random() * 2 * Math.PI; var px:Number = radius * Math.sin(theta) * Math.cos(phi); var pz:Number = radius * Math.sin(theta) * Math.sin(phi); var py:Number = radius * Math.cos(theta); |
To calculate x,y,z back to x,y for setpixel.. i use the following function:
View CodeACTIONSCRIPT | |
1 2 3 4 5 | public function setPerspective($mat:Matrix3D, $pp:PerspectiveProjection):void { _projection = $mat.transformVector(_position); _projection.w = $pp.focalLength / ($pp.focalLength + _projection.z); _projection.project(); } |
Then call the _projection.x, _projection.y to set your pixel!
Here is the result:
This movie requires Flash Player 9

The [Lab] Sphere study #07 by Script.it, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Netherlands License.
