Skip to content

Commit

Permalink
Created enum for lens coordinate system options
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-bateman committed Jan 24, 2014
1 parent 320c1cf commit 3858115
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
20 changes: 20 additions & 0 deletions src/away3d/cameras/lenses/CoordinateSystem.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package away3d.cameras.lenses
{
/**
* Provides constant values for camera lens projection options use the the <code>coordinateSystem</code> property
*
* @see away3d.cameras.lenses.PerspectiveLens#coordinateSystem
*/
public class CoordinateSystem
{
/**
* Default option, projects to a left-handed coordinate system
*/
public static const LEFT_HANDED:uint = 0;

/**
* Projects to a right-handed coordinate system
*/
public static const RIGHT_HANDED:uint = 1;
}
}
34 changes: 16 additions & 18 deletions src/away3d/cameras/lenses/PerspectiveLens.as
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package away3d.cameras.lenses
{
import away3d.core.math.Matrix3DUtils;
import away3d.core.math.*;

import flash.geom.Vector3D;
import flash.geom.*;

/**
* The PerspectiveLens object provides a projection matrix that projects 3D geometry with perspective distortion.
Expand All @@ -14,21 +14,19 @@ package away3d.cameras.lenses
private var _focalLengthInv:Number;
private var _yMax:Number;
private var _xMax:Number;
private var _coordinateSystem:int;

public static const COORDINATE_SYSTEM_LEFT_HANDED:int = 1;
public static const COORDINATE_SYSTEM_RIGHT_HANDED:int = -1;
private var _coordinateSystem:uint;

/**
* Creates a new PerspectiveLens object.
*
* @param fieldOfView The vertical field of view of the projection.
*/
public function PerspectiveLens(fieldOfView:Number = 60)
public function PerspectiveLens(fieldOfView:Number = 60, coordinateSystem = CoordinateSystem.LEFT_HANDED)
{
super();
this.coordinateSystem = COORDINATE_SYSTEM_LEFT_HANDED;

this.fieldOfView = fieldOfView;
this.coordinateSystem = coordinateSystem;
}

/**
Expand Down Expand Up @@ -112,18 +110,20 @@ package away3d.cameras.lenses
}

/**
* The handedness of the coordinate system projection.
* The default is COORDINATE_SYSTEM_LEFT_HANDED.
* The handedness of the coordinate system projection. The default is LEFT_HANDED.
*/
public function get coordinateSystem():int
public function get coordinateSystem():uint
{
return _coordinateSystem;
}

public function set coordinateSystem(value:int):void
public function set coordinateSystem(value:uint):void
{
if (value == _coordinateSystem) return;
if (value == _coordinateSystem)
return;

_coordinateSystem = value;

invalidateMatrix();
}

Expand Down Expand Up @@ -176,12 +176,10 @@ package away3d.cameras.lenses
raw[uint(6)] = raw[uint(7)] = raw[uint(12)] = raw[uint(13)] = raw[uint(15)] = 0;
raw[uint(14)] = -2*_far*_near/(_far - _near);
}

if (_coordinateSystem == COORDINATE_SYSTEM_RIGHT_HANDED)
{
// Switch projection transform from left to right handed.

// Switch projection transform from left to right handed.
if (_coordinateSystem == CoordinateSystem.RIGHT_HANDED)
raw[uint(5)] = -raw[uint(5)];
}

_matrix.copyRawDataFrom(raw);

Expand Down

0 comments on commit 3858115

Please sign in to comment.