Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions modules/core/src/classes/euler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,7 @@ export class Euler extends MathArray {

// TODO - move to Quaternion
getQuaternion(): Quaternion {
const q = new Quaternion();
switch (this[3]) {
case RotationOrder.XYZ:
return q.rotateX(this[0]).rotateY(this[1]).rotateZ(this[2]);
case RotationOrder.YXZ:
return q.rotateY(this[0]).rotateX(this[1]).rotateZ(this[2]);
case RotationOrder.ZXY:
return q.rotateZ(this[0]).rotateX(this[1]).rotateY(this[2]);
case RotationOrder.ZYX:
return q.rotateZ(this[0]).rotateY(this[1]).rotateX(this[2]);
case RotationOrder.YZX:
return q.rotateY(this[0]).rotateZ(this[1]).rotateX(this[2]);
case RotationOrder.XZY:
return q.rotateX(this[0]).rotateZ(this[1]).rotateY(this[2]);
default:
throw new Error(ERR_UNKNOWN_ORDER);
}
return new Quaternion().fromEuler(this);
}

// INTERNAL METHODS
Expand Down
28 changes: 28 additions & 0 deletions modules/core/src/classes/matrix4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,34 @@ export class Matrix4 extends Matrix {
return this.check();
}

/**
* Calculates a 4x4 matrix from the given matrix3
* @param matrix3
* @returns self
*/
fromMatrix3(matrix3: Readonly<NumericArray>): this {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, though it does add a little to the size of the Matrix4 class for every user.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see in the CI log, you need to run yarn lint fix

You are welcome to join our OpenJS slack channel, see https://openvisualization.org for the link

this[0] = matrix3[0];
this[1] = matrix3[1];
this[2] = matrix3[2];
this[3] = 0;

this[4] = matrix3[3];
this[5] = matrix3[4];
this[6] = matrix3[5];
this[7] = 0;

this[8] = matrix3[6];
this[9] = matrix3[7];
this[10] = matrix3[8];
this[11] = 0;

this[12] = 0;
this[13] = 0;
this[14] = 0;
this[15] = 1;
return this.check();
}

/**
* Generates a frustum matrix with the given bounds
* @param view.left - Left bound of the frustum
Expand Down
34 changes: 30 additions & 4 deletions modules/core/src/classes/quaternion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
} from '../gl-matrix/quat';
// @ts-ignore gl-matrix types...
import {transformQuat as vec4_transformQuat} from '../gl-matrix/vec4';
import { Euler } from './euler';

const IDENTITY_QUATERNION = [0, 0, 0, 1] as const;

Expand Down Expand Up @@ -82,6 +83,31 @@ export class Quaternion extends MathArray {
return this.check();
}

/**
* Creates a quaternion from the given Euler.
* @param euler
* @returns
*/
fromEuler(euler: Euler): this {
this.identity();
switch (euler.order) {
case Euler.XYZ:
return this.rotateX(euler[0]).rotateY(euler[1]).rotateZ(euler[2]);
case Euler.YXZ:
return this.rotateY(euler[0]).rotateX(euler[1]).rotateZ(euler[2]);
case Euler.ZXY:
return this.rotateZ(euler[0]).rotateX(euler[1]).rotateY(euler[2]);
case Euler.ZYX:
return this.rotateZ(euler[0]).rotateY(euler[1]).rotateX(euler[2]);
case Euler.YZX:
return this.rotateY(euler[0]).rotateZ(euler[1]).rotateX(euler[2]);
case Euler.XZY:
return this.rotateX(euler[0]).rotateZ(euler[1]).rotateY(euler[2]);
default:
throw new Error('Unknown Euler angle order');
}
}

fromAxisRotation(axis: Readonly<NumericArray>, rad: number): this {
quat_setAxisAngle(this, axis, rad);
return this.check();
Expand Down Expand Up @@ -283,10 +309,10 @@ export class Quaternion extends MathArray {
arg0:
| Readonly<NumericArray>
| {
start: Readonly<NumericArray>;
target: Readonly<NumericArray>;
ratio: number;
},
start: Readonly<NumericArray>;
target: Readonly<NumericArray>;
ratio: number;
},
arg1?: Readonly<NumericArray> | number,
arg2?: number
): this {
Expand Down