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 @@

// 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 Expand Up @@ -408,7 +392,7 @@
const d = Math.sin(y);
const f = Math.sin(z);
switch (this[3]) {
case Euler.XYZ: {

Check warning on line 395 in modules/core/src/classes/euler.ts

View workflow job for this annotation

GitHub Actions / test

The case statement does not have a shared enum type with the switch predicate
const ae = a * e,
af = a * f,
be = b * e,
Expand All @@ -424,7 +408,7 @@
te[10] = a * c;
break;
}
case Euler.YXZ: {

Check warning on line 411 in modules/core/src/classes/euler.ts

View workflow job for this annotation

GitHub Actions / test

The case statement does not have a shared enum type with the switch predicate
const ce = c * e,
cf = c * f,
de = d * e,
Expand All @@ -440,7 +424,7 @@
te[10] = a * c;
break;
}
case Euler.ZXY: {

Check warning on line 427 in modules/core/src/classes/euler.ts

View workflow job for this annotation

GitHub Actions / test

The case statement does not have a shared enum type with the switch predicate
const ce = c * e,
cf = c * f,
de = d * e,
Expand All @@ -456,7 +440,7 @@
te[10] = a * c;
break;
}
case Euler.ZYX: {

Check warning on line 443 in modules/core/src/classes/euler.ts

View workflow job for this annotation

GitHub Actions / test

The case statement does not have a shared enum type with the switch predicate
const ae = a * e,
af = a * f,
be = b * e,
Expand All @@ -472,7 +456,7 @@
te[10] = a * c;
break;
}
case Euler.YZX: {

Check warning on line 459 in modules/core/src/classes/euler.ts

View workflow job for this annotation

GitHub Actions / test

The case statement does not have a shared enum type with the switch predicate
const ac = a * c,
ad = a * d,
bc = b * c,
Expand All @@ -488,7 +472,7 @@
te[10] = ac - bd * f;
break;
}
case Euler.XZY: {

Check warning on line 475 in modules/core/src/classes/euler.ts

View workflow job for this annotation

GitHub Actions / test

The case statement does not have a shared enum type with the switch predicate
const ac = a * c,
ad = a * d,
bc = b * c,
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 @@ -226,7 +226,7 @@
* @returns self
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fromObject(object: {[key: string]: any}): this {

Check warning on line 229 in modules/core/src/classes/matrix4.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
return this.check();
}

Expand All @@ -240,6 +240,34 @@
return this.check();
}

/**
* Calculates a 4x4 matrix from the given matrix3
* @param matrix3
* @returns self
*/
fromMatrix3(matrix3: Readonly<NumericArray>): this {
Copy link
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
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
Loading