Skip to content

Commit 4436ba2

Browse files
committed
Add coordinateSystem property to PerspectiveLens.as
Away3D appears to default to a left-handed coordinate system, but other systems (e.g. Alternativa3D, OpenSceneGraph, etc) defaults to a right-handed projection. For compatibility with such systems I have added an option to PerspectiveLens which allows the handedness of the coordinate system to be switched. The default state of the projection will not be affected by this change.
1 parent 21e90e5 commit 4436ba2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/away3d/cameras/lenses/PerspectiveLens.as

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ package away3d.cameras.lenses
1414
private var _focalLengthInv:Number;
1515
private var _yMax:Number;
1616
private var _xMax:Number;
17+
private var _coordinateSystem:int;
1718

19+
public static const COORDINATE_SYSTEM_LEFT_HANDED:int = 1;
20+
public static const COORDINATE_SYSTEM_RIGHT_HANDED:int = -1;
21+
1822
/**
1923
* Creates a new PerspectiveLens object.
2024
*
@@ -23,6 +27,7 @@ package away3d.cameras.lenses
2327
public function PerspectiveLens(fieldOfView:Number = 60)
2428
{
2529
super();
30+
this.coordinateSystem = COORDINATE_SYSTEM_LEFT_HANDED;
2631
this.fieldOfView = fieldOfView;
2732
}
2833

@@ -97,9 +102,26 @@ package away3d.cameras.lenses
97102
clone._near = _near;
98103
clone._far = _far;
99104
clone._aspectRatio = _aspectRatio;
105+
clone._coordinateSystem = _coordinateSystem;
100106
return clone;
101107
}
102108

109+
/**
110+
* The handedness of the coordinate system projection.
111+
* The default is COORDINATE_SYSTEM_LEFT_HANDED.
112+
*/
113+
public function get coordinateSystem():int
114+
{
115+
return _coordinateSystem;
116+
}
117+
118+
public function set coordinateSystem(value:int):void
119+
{
120+
if (value == _coordinateSystem) return;
121+
_coordinateSystem = value;
122+
invalidateMatrix();
123+
}
124+
103125
/**
104126
* @inheritDoc
105127
*/
@@ -150,6 +172,12 @@ package away3d.cameras.lenses
150172
raw[uint(14)] = -2*_far*_near/(_far - _near);
151173
}
152174

175+
if (_coordinateSystem == COORDINATE_SYSTEM_RIGHT_HANDED)
176+
{
177+
// Switch projection transform from left to right handed.
178+
raw[uint(5)] = -raw[uint(5)];
179+
}
180+
153181
_matrix.copyRawDataFrom(raw);
154182

155183
var yMaxFar:Number = _far*_focalLengthInv;

0 commit comments

Comments
 (0)