|
@@ -47,6 +47,7 @@ class Camera {
|
|
|
var mcamInv : Matrix;
|
|
|
var mprojInv : Matrix;
|
|
|
var needInv : Bool;
|
|
|
+ var directions : Matrix;
|
|
|
|
|
|
public function new( fovY = 25., zoom = 1., screenRatio = 1.333333, zNear = 0.02, zFar = 4000., rightHanded = false ) {
|
|
|
this.fovY = fovY;
|
|
@@ -130,6 +131,87 @@ class Camera {
|
|
|
return mcamInv;
|
|
|
}
|
|
|
|
|
|
+ function calcDirections() {
|
|
|
+ var cameraForward = ( target - pos ).normalized();
|
|
|
+ var cameraRight = up.cross(cameraForward).normalized();
|
|
|
+ var cameraUp = cameraForward.cross(cameraRight);
|
|
|
+
|
|
|
+ directions._11 = cameraForward.x;
|
|
|
+ directions._12 = cameraForward.y;
|
|
|
+ directions._13 = cameraForward.z;
|
|
|
+
|
|
|
+ directions._21 = cameraRight.x;
|
|
|
+ directions._22 = cameraRight.y;
|
|
|
+ directions._23 = cameraRight.z;
|
|
|
+
|
|
|
+ directions._31 = cameraUp.x;
|
|
|
+ directions._32 = cameraUp.y;
|
|
|
+ directions._33 = cameraUp.z;
|
|
|
+
|
|
|
+ directions._44 = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ Returns the forward of the camera. Cache the result until the next update().
|
|
|
+ **/
|
|
|
+ public function getForward( ?forward : h3d.Vector ) : h3d.Vector {
|
|
|
+ if ( forward == null)
|
|
|
+ forward = new h3d.Vector();
|
|
|
+
|
|
|
+ if ( directions == null ) {
|
|
|
+ directions = new h3d.Matrix();
|
|
|
+ directions._44 = 0;
|
|
|
+ }
|
|
|
+ if ( directions._44 == 0 )
|
|
|
+ calcDirections();
|
|
|
+
|
|
|
+ forward.x = directions._11;
|
|
|
+ forward.y = directions._12;
|
|
|
+ forward.z = directions._13;
|
|
|
+
|
|
|
+ return forward;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ Returns the right of the camera. Cache the result until the next update().
|
|
|
+ **/
|
|
|
+ public function getRight( ?right : h3d.Vector ) : h3d.Vector {
|
|
|
+ if ( right == null)
|
|
|
+ right = new h3d.Vector();
|
|
|
+ if ( directions == null ) {
|
|
|
+ directions = new h3d.Matrix();
|
|
|
+ directions._44 = 0;
|
|
|
+ }
|
|
|
+ if ( directions._44 == 0 )
|
|
|
+ calcDirections();
|
|
|
+
|
|
|
+ right.x = directions._21;
|
|
|
+ right.y = directions._22;
|
|
|
+ right.z = directions._23;
|
|
|
+
|
|
|
+ return right;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ Returns the up of the camera. Cache the result until the next update().
|
|
|
+ **/
|
|
|
+ public function getUp( ?up : h3d.Vector ) : h3d.Vector {
|
|
|
+ if ( up == null)
|
|
|
+ up = new h3d.Vector();
|
|
|
+ if ( directions == null ) {
|
|
|
+ directions = new h3d.Matrix();
|
|
|
+ directions._44 = 0;
|
|
|
+ }
|
|
|
+ if ( directions._44 == 0 )
|
|
|
+ calcDirections();
|
|
|
+
|
|
|
+ up.x = directions._31;
|
|
|
+ up.y = directions._32;
|
|
|
+ up.z = directions._33;
|
|
|
+
|
|
|
+ return up;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
Setup camera for cubemap rendering on the given face.
|
|
|
**/
|
|
@@ -199,6 +281,7 @@ class Camera {
|
|
|
needInv = true;
|
|
|
if( mcamInv != null ) mcamInv._44 = 0;
|
|
|
if( mprojInv != null ) mprojInv._44 = 0;
|
|
|
+ if( directions != null ) directions._44 = 0;
|
|
|
|
|
|
frustum.loadMatrix(m);
|
|
|
}
|