Update asset to add shear to matrix
This commit is contained in:
parent
b5c30a115d
commit
6f7a8cc3d2
|
|
@ -29,7 +29,7 @@ export default class Asset
|
||||||
#index: number;
|
#index: number;
|
||||||
#quad?: number;
|
#quad?: number;
|
||||||
|
|
||||||
static instance: Three.InstancedMesh = new Three.InstancedMesh(CONST.QUAD, new Three.MeshBasicMaterial({ color: new Three.Color(0xffffff) }), 1000000);
|
static instance: Three.InstancedMesh = new Three.InstancedMesh(CONST.QUAD, new Three.MeshBasicMaterial({ color: new Three.Color(0xffffff), side: Three.DoubleSide }), 1000000);
|
||||||
static quadtree: Quadtree = new Quadtree({ x1: -CONST.RESOLUTION_X / 2, x2: CONST.RESOLUTION_X / 2, y1: -CONST.RESOLUTION_Y / 2, y2: CONST.RESOLUTION_Y / 2 }, 6, 10);
|
static quadtree: Quadtree = new Quadtree({ x1: -CONST.RESOLUTION_X / 2, x2: CONST.RESOLUTION_X / 2, y1: -CONST.RESOLUTION_Y / 2, y2: CONST.RESOLUTION_Y / 2 }, 6, 10);
|
||||||
static assets: FreeList<Asset> = new FreeList<Asset>();
|
static assets: FreeList<Asset> = new FreeList<Asset>();
|
||||||
|
|
||||||
|
|
@ -45,8 +45,8 @@ export default class Asset
|
||||||
this.#scaleX = _scale.x;
|
this.#scaleX = _scale.x;
|
||||||
this.#scaleY = _scale.y;
|
this.#scaleY = _scale.y;
|
||||||
|
|
||||||
this.#shearX = 1;
|
this.#shearX = 0;
|
||||||
this.#shearY = 1;
|
this.#shearY = 0;
|
||||||
|
|
||||||
this.#updateAABB();
|
this.#updateAABB();
|
||||||
this.layer = layer ?? 0;
|
this.layer = layer ?? 0;
|
||||||
|
|
@ -137,10 +137,10 @@ export default class Asset
|
||||||
const e = this.mat.elements;
|
const e = this.mat.elements;
|
||||||
const cos = Math.cos(rad), sin = Math.sin(rad), tanX = Math.tan(this.#shearX), tanY = Math.tan(this.#shearY);
|
const cos = Math.cos(rad), sin = Math.sin(rad), tanX = Math.tan(this.#shearX), tanY = Math.tan(this.#shearY);
|
||||||
|
|
||||||
e[0] = cos * this.#scaleX;
|
e[0] = cos * this.#scaleX + -sin * this.#shearY;
|
||||||
e[1] = -sin * this.#scaleX;
|
e[1] = sin * this.#scaleX + cos * this.#shearX;
|
||||||
e[4] = sin * this.#scaleY;
|
e[4] = cos * this.#shearX + -sin * this.#scaleY;
|
||||||
e[5] = cos * this.#scaleY;
|
e[5] = sin * this.#shearX + cos * this.#scaleY;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -155,10 +155,28 @@ export default class Asset
|
||||||
const e = this.mat.elements;
|
const e = this.mat.elements;
|
||||||
const cos = Math.cos(this.#rot), sin = Math.sin(this.#rot);
|
const cos = Math.cos(this.#rot), sin = Math.sin(this.#rot);
|
||||||
|
|
||||||
e[0] = cos * this.#scaleX;
|
e[0] = cos * this.#scaleX + -sin * this.#shearY;
|
||||||
e[1] = -sin * this.#shearX;
|
e[1] = sin * this.#scaleX + cos * this.#shearX;
|
||||||
e[4] = sin * this.#shearY;
|
e[4] = cos * this.#shearX + -sin * this.#scaleY;
|
||||||
e[5] = cos * this.#scaleY;
|
e[5] = sin * this.#shearX + cos * this.#scaleY;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
shearTo(x: number, y: number): Asset
|
||||||
|
{
|
||||||
|
x = clamp(x, 0.1, CONST.RESOLUTION_X);
|
||||||
|
y = clamp(y, 0.1, CONST.RESOLUTION_Y);
|
||||||
|
|
||||||
|
this.#shearX = x;
|
||||||
|
this.#shearY = y;
|
||||||
|
|
||||||
|
const e = this.mat.elements;
|
||||||
|
const cos = Math.cos(this.#rot), sin = Math.sin(this.#rot);
|
||||||
|
|
||||||
|
e[0] = cos * this.#scaleX + -sin * this.#shearY;
|
||||||
|
e[1] = sin * this.#scaleX + cos * this.#shearX;
|
||||||
|
e[4] = cos * this.#shearX + -sin * this.#scaleY;
|
||||||
|
e[5] = sin * this.#shearX + cos * this.#scaleY;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -175,10 +193,10 @@ export default class Asset
|
||||||
const e = this.mat.elements;
|
const e = this.mat.elements;
|
||||||
const cos = Math.cos(this.#rot), sin = Math.sin(this.#rot);
|
const cos = Math.cos(this.#rot), sin = Math.sin(this.#rot);
|
||||||
|
|
||||||
e[0] = cos * this.#scaleX;
|
e[0] = cos * this.#scaleX + -sin * this.#shearY;
|
||||||
e[1] = -sin * this.#shearX;
|
e[1] = sin * this.#scaleX + cos * this.#shearX;
|
||||||
e[4] = sin * this.#shearY;
|
e[4] = cos * this.#shearX + -sin * this.#scaleY;
|
||||||
e[5] = cos * this.#scaleY;
|
e[5] = sin * this.#shearX + cos * this.#scaleY;
|
||||||
|
|
||||||
e[12] = this.#posX;
|
e[12] = this.#posX;
|
||||||
e[13] = this.#posY;
|
e[13] = this.#posY;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue