Browse Source

added initFromScene

ncannasse 8 years ago
parent
commit
b2948125f3
1 changed files with 17 additions and 0 deletions
  1. 17 0
      h3d/scene/CameraController.hx

+ 17 - 0
h3d/scene/CameraController.hx

@@ -74,6 +74,23 @@ class CameraController extends h3d.scene.Object {
 		if( !animate ) toTarget();
 		if( !animate ) toTarget();
 	}
 	}
 
 
+	/**
+		Initialize to look at the whole scene, based on reported scene bounds.
+	**/
+	public function initFromScene() {
+		var scene = getScene();
+		if( scene == null ) throw "Not in scene";
+		var bounds = scene.getBounds();
+		var center = bounds.getCenter();
+		scene.camera.target.load(center.toVector());
+		var d = bounds.getMax().sub(center);
+		d.scale(5);
+		d.z *= 0.5;
+		d = d.add(center);
+		scene.camera.pos.load(d.toVector());
+		loadFromCamera();
+	}
+
 	/**
 	/**
 		Stop animation by directly moving to end position.
 		Stop animation by directly moving to end position.
 		Call after set() if you don't want to animate the change
 		Call after set() if you don't want to animate the change