tentone 2 年之前
父節點
當前提交
2fe7cebdce
共有 3 個文件被更改,包括 25 次插入8 次删除
  1. 7 1
      source/Viewport.js
  2. 15 4
      source/math/Box2.js
  3. 3 3
      source/math/Matrix.js

+ 7 - 1
source/Viewport.js

@@ -118,7 +118,11 @@ Viewport.prototype.updateMatrix = function()
 		{
 			this.matrix.scale(this.scale, this.scale);
 		}
-
+		
+		if(this.center.x !== 0 && this.center.y !== 0) {
+			this.matrix.multiply(new Matrix([1, 0, 0, 1, this.center.x, this.center.y]));
+		}
+		
 		this.inverseMatrix = this.matrix.getInverse();
 		this.matrixNeedsUpdate = false;
 	}
@@ -129,6 +133,8 @@ Viewport.prototype.updateMatrix = function()
  *
  * The position of the object is used a central point, this method does not consider "box" attributes or other strucures in the object.
  *
+ * Uses the object's local transformation matrix and the canvas size to calculate the new position of the viewport.
+ * 
  * @param {Object2D} object Object to be centered on the viewport.
  * @param {Element} canvas Canvas element where the image is drawn.
  */

+ 15 - 4
source/math/Box2.js

@@ -6,20 +6,31 @@ import {Vector2} from "./Vector2.js";
  * Can be used for collision detection with points and other boxes.
  *
  * @class
- * @param {Vector2} min
- * @param {Vector2} max
+ * @param {Vector2} min Minimum point of the box.
+ * @param {Vector2} max Maximum point of the box.
  */
 function Box2(min, max)
 {
+	/**
+	 * Minimum point of the box.
+	 * 
+	 * @type {Vector2}
+	 */
 	this.min = (min !== undefined) ? min : new Vector2();
+
+	/**
+	 * Maximum point of the box.
+	 * 
+	 * @type {Vector2}
+	 */
 	this.max = (max !== undefined) ? max : new Vector2();
 }
 
 /**
  * Set the box values.
  *
- * @param {Vector2} min
- * @param {Vector2} max
+ * @param {Vector2} min Minimum point of the box.
+ * @param {Vector2} max Maximum point of the box.
  */
 Box2.prototype.set = function(min, max)
 {

+ 3 - 3
source/math/Matrix.js

@@ -6,7 +6,7 @@ import {Vector2} from "./Vector2.js";
  * The values of the matrix are stored as numeric array. The matrix can be applied to the canvas or DOM elements using CSS transforms.
  *
  * @class
- * @param {number[]} values Array of matrix values by row, needs to have exactly 6 values.
+ * @param {number[]} values Array of matrix values by row, needs to have exactly 6 values. Default is the identity matrix.
  */
 function Matrix(values)
 {
@@ -58,7 +58,7 @@ Matrix.prototype.identity = function()
 /**
  * Multiply another matrix by this one and store the result.
  *
- * @param {Matrix} mat
+ * @param {Matrix} mat Matrix to multiply by.
  */
 Matrix.prototype.multiply = function(mat)
 {
@@ -75,7 +75,7 @@ Matrix.prototype.multiply = function(mat)
 /**
  * Premultiply another matrix by this one and store the result.
  *
- * @param {Matrix} mat
+ * @param {Matrix} mat Matrix to premultiply by.
  */
 Matrix.prototype.premultiply = function(mat)
 {