Function to normalizing an angle

A simple function to normalize angles.

1
2
3
4
5
public static function normalizeAngle(angle:Number):Number
{
    if(angle < 0 || angle > Math.PI * 2) return Math.abs((Math.PI * 2) - Math.abs(angle));
    else return angle;
}

Diferents approaches to get next highest power of 2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
////////////////////////////
var powerOf2:int=1;
var val:int=456;
while ( powerOf2 <val )
{
    trace(powerOf2 <<= 1);
}

////////////////////////////
function nextPowerOfTwo( value_ : int ):int
{
    value_--;
    value_ = (value_>> 1) | value_;
    value_ = (value_>> 2) | value_;
    value_ = (value_>> 4) | value_;
    value_ = (value_>> 8) | value_;
    value_ = (value_>> 16) | value_;
    value_++;
    return value_;
}

////////////////////////////
function nextPowerOfTwo( value_ : int ):int
{
    return int(Math.pow(2,Math.ceil(Math.log(value_) / Math.log(2))));
}

From: http://www.blog.lessrain.com/flash-more-efficient-blur-filter-values/

How to get Pixel Precision in PV3D

Surfing the web I found an interesting post in Everyday Flash , it explains how to get Pixel Precision in PV3D ( Getting a textured object show his texture with a 1:1 aspect relation )

To position the object we use this formula:

1
3dobj.z = (camera.zoom * camera.focus) - Math.abs(camera.z)

And to get x,y 2D coordinates of the 3D object this one:

1
2
screenPosX = 3dobj.screen.x + viewport.viewportWidth / 2;
screenPosY = 3dobj.screen.y + viewport.viewportHeight / 2;