Shader code beginnings
This commit is contained in:
@@ -127,6 +127,25 @@ export class Matrix4x4 {
|
||||
);
|
||||
}
|
||||
|
||||
static fromTRS(t: Vector3Object, r: QuaternionObject, s: Vector3Object): Matrix4x4 {
|
||||
const xx = r.x * r.x;
|
||||
const xy = r.x * r.y;
|
||||
const xz = r.x * r.z;
|
||||
const xw = r.x * r.w;
|
||||
const yy = r.y * r.y;
|
||||
const yz = r.y * r.z;
|
||||
const yw = r.y * r.w;
|
||||
const zz = r.z * r.z;
|
||||
const zw = r.z * r.w;
|
||||
|
||||
return new Matrix4x4(
|
||||
s.x * (1 - 2 * (yy + zz)), s.x * 2 * (xy + zw), s.x * 2 * (xz - yw), 0,
|
||||
s.y * 2 * (xy - zw), s.y * (1 - 2 * (xx + zz)), s.y * 2 * (yz + xw), 0,
|
||||
s.z * 2 * (xz + yw), s.z * 2 * (yz - xw), s.z * (1 - 2 * (xx + yy)), 0,
|
||||
t.x, t.y, t.z, 1,
|
||||
);
|
||||
}
|
||||
|
||||
setObject(object: Matrix4x4Object): Matrix4x4 {
|
||||
this.ix = object.ix;
|
||||
this.iy = object.iy;
|
||||
@@ -236,6 +255,61 @@ export class Matrix4x4 {
|
||||
this.tw = 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
setTRS(t: Vector3Object, r: QuaternionObject, s: Vector3Object): Matrix4x4 {
|
||||
const xx = r.x * r.x;
|
||||
const xy = r.x * r.y;
|
||||
const xz = r.x * r.z;
|
||||
const xw = r.x * r.w;
|
||||
const yy = r.y * r.y;
|
||||
const yz = r.y * r.z;
|
||||
const yw = r.y * r.w;
|
||||
const zz = r.z * r.z;
|
||||
const zw = r.z * r.w;
|
||||
|
||||
this.ix = s.x * (1 - 2 * (yy + zz));
|
||||
this.iy = s.x * 2 * (xy + zw);
|
||||
this.iz = s.x * 2 * (xz - yw);
|
||||
this.iw = 0;
|
||||
this.jx = s.y * 2 * (xy - zw);
|
||||
this.jy = s.y * (1 - 2 * (xx + zz));
|
||||
this.jz = s.y * 2 * (yz + xw);
|
||||
this.jw = 0;
|
||||
this.kx = s.z * 2 * (xz + yw);
|
||||
this.ky = s.z * 2 * (yz - xw);
|
||||
this.kz = s.z * (1 - 2 * (xx + yy));
|
||||
this.kw = 0;
|
||||
this.tx = t.x;
|
||||
this.ty = t.y;
|
||||
this.tz = t.z;
|
||||
this.tw = 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
add(m: Matrix4x4): Matrix4x4 {
|
||||
throw new Error("TODO");
|
||||
return this;
|
||||
}
|
||||
|
||||
sub(m: Matrix4x4): Matrix4x4 {
|
||||
throw new Error("TODO");
|
||||
return this;
|
||||
}
|
||||
|
||||
mulScalar(k: number): Matrix4x4 {
|
||||
throw new Error("TODO");
|
||||
return this;
|
||||
}
|
||||
|
||||
mulMatrix(m: Matrix4x4): Matrix4x4 {
|
||||
throw new Error("TODO");
|
||||
return this;
|
||||
}
|
||||
|
||||
premulMatrix(m: Matrix4x4): Matrix4x4 {
|
||||
throw new Error("TODO");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(Matrix4x4.prototype, "type", { value: "Matrix4x4" });
|
||||
|
@@ -4,7 +4,7 @@
|
||||
* obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { Camera, Mesh, Quaternion, QuaternionObject, Vector3, Vector3Object } from ".";
|
||||
import { Camera, Matrix4x4, Mesh, Quaternion, QuaternionObject, Vector3, Vector3Object } from ".";
|
||||
import { Material } from "../resources";
|
||||
|
||||
export interface NodeProps {
|
||||
@@ -44,6 +44,9 @@ export class Node {
|
||||
/** backreference */
|
||||
_parent: Node | null;
|
||||
|
||||
_localMatrix: Matrix4x4;
|
||||
_worldMatrix: Matrix4x4;
|
||||
|
||||
constructor({
|
||||
name = "",
|
||||
translation,
|
||||
@@ -68,6 +71,9 @@ export class Node {
|
||||
|
||||
this._parent = null;
|
||||
|
||||
this._localMatrix = Matrix4x4.fromTRS(this._translation, this._rotation, this._scale);
|
||||
this._worldMatrix = Matrix4x4.fromObject(this._localMatrix);
|
||||
|
||||
if (this._camera !== null) {
|
||||
this._camera._node = this;
|
||||
}
|
||||
|
Reference in New Issue
Block a user