浏览代码

added Matrix.getDirection and Camera.setTransform

Nicolas Cannasse 4 年之前
父节点
当前提交
4e6211ed05
共有 2 个文件被更改,包括 12 次插入0 次删除
  1. 5 0
      h3d/Camera.hx
  2. 7 0
      h3d/Matrix.hx

+ 5 - 0
h3d/Camera.hx

@@ -288,6 +288,11 @@ class Camera {
 		m._44 = 1;
 	}
 
+	public function setTransform( m : Matrix ) {
+		pos.set(m._41, m._42, m._43);
+		target.load(pos.add(m.getDirection()));
+	}
+
 	function makeFrustumMatrix( m : Matrix ) {
 		m.zero();
 

+ 7 - 0
h3d/Matrix.hx

@@ -549,6 +549,13 @@ class Matrix {
 		return [_11, _12, _13, _14, _21, _22, _23, _24, _31, _32, _33, _34, _41, _42, _43, _44];
 	}
 
+	public function getDirection() {
+		var q = new h3d.Quat();
+		q.initRotateMatrix(this);
+		q.normalize();
+		return q.getDirection();
+	}
+
 	/**
 		Extracts Euler rotation angles from rotation matrix
 	**/