@predy-js/math 0.3.0-beta.39 → 0.3.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +42 -0
- package/dist/index.mjs +41 -1
- package/dist/quat.d.ts +8 -1
- package/dist/vec4.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1086,6 +1086,19 @@ function quatFromRotation(out, x, y, z) {
|
|
|
1086
1086
|
out[3] = c1 * c2 * c3 + s1 * s2 * s3;
|
|
1087
1087
|
return out;
|
|
1088
1088
|
}
|
|
1089
|
+
function quatFromRotationXYZ(out, x, y, z) {
|
|
1090
|
+
const c1 = Math.cos((x * d2r) / 2);
|
|
1091
|
+
const c2 = Math.cos((y * d2r) / 2);
|
|
1092
|
+
const c3 = Math.cos((z * d2r) / 2);
|
|
1093
|
+
const s1 = Math.sin((x * d2r) / 2);
|
|
1094
|
+
const s2 = Math.sin((y * d2r) / 2);
|
|
1095
|
+
const s3 = Math.sin((z * d2r) / 2);
|
|
1096
|
+
out[0] = s1 * c2 * c3 + c1 * s2 * s3;
|
|
1097
|
+
out[1] = c1 * s2 * c3 - s1 * c2 * s3;
|
|
1098
|
+
out[2] = c1 * c2 * s3 + s1 * s2 * c3;
|
|
1099
|
+
out[3] = c1 * c2 * c3 - s1 * s2 * s3;
|
|
1100
|
+
return out;
|
|
1101
|
+
}
|
|
1089
1102
|
function quatStar(out, quat) {
|
|
1090
1103
|
const x = quat[0], y = quat[1], z = quat[2], w = quat[3];
|
|
1091
1104
|
out[0] = -x;
|
|
@@ -1094,6 +1107,33 @@ function quatStar(out, quat) {
|
|
|
1094
1107
|
out[3] = w;
|
|
1095
1108
|
return out;
|
|
1096
1109
|
}
|
|
1110
|
+
/**
|
|
1111
|
+
* @param {vec3} vstart
|
|
1112
|
+
* @param {vec3} vend
|
|
1113
|
+
* @returns {vec4}
|
|
1114
|
+
*/
|
|
1115
|
+
function quatFromVec3s(v1, v2) {
|
|
1116
|
+
const cross = [
|
|
1117
|
+
v1[1] * v2[2] - v1[2] * v2[1],
|
|
1118
|
+
v1[2] * v2[0] - v1[0] * v2[2],
|
|
1119
|
+
v1[0] * v2[1] - v1[1] * v2[0],
|
|
1120
|
+
];
|
|
1121
|
+
const dot = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
|
|
1122
|
+
if (dot < -0.999999) {
|
|
1123
|
+
let orthogonalAxis = [1, 0, 0];
|
|
1124
|
+
if (Math.abs(v1[0]) > Math.abs(v1[2])) {
|
|
1125
|
+
orthogonalAxis = [0, 0, 1];
|
|
1126
|
+
}
|
|
1127
|
+
const orthogonalCross = [
|
|
1128
|
+
v1[1] * orthogonalAxis[2] - v1[2] * orthogonalAxis[1],
|
|
1129
|
+
v1[2] * orthogonalAxis[0] - v1[0] * orthogonalAxis[2],
|
|
1130
|
+
v1[0] * orthogonalAxis[1] - v1[1] * orthogonalAxis[0],
|
|
1131
|
+
];
|
|
1132
|
+
return vecNormalize([orthogonalCross[0], orthogonalCross[1], orthogonalCross[2], 0]);
|
|
1133
|
+
}
|
|
1134
|
+
const w = Math.sqrt((Math.pow(v1[0], 2) + Math.pow(v1[1], 2) + Math.pow(v1[2], 2)) * (Math.pow(v2[0], 2) + Math.pow(v2[1], 2) + Math.pow(v2[2], 2))) + dot;
|
|
1135
|
+
return vecNormalize([cross[0], cross[1], cross[2], w]);
|
|
1136
|
+
}
|
|
1097
1137
|
|
|
1098
1138
|
exports.NumberEpsilon = NumberEpsilon;
|
|
1099
1139
|
exports.clamp = clamp;
|
|
@@ -1126,6 +1166,8 @@ exports.mat4translate = mat4translate;
|
|
|
1126
1166
|
exports.quatCreate = quatCreate;
|
|
1127
1167
|
exports.quatEquals = quatEquals;
|
|
1128
1168
|
exports.quatFromRotation = quatFromRotation;
|
|
1169
|
+
exports.quatFromRotationXYZ = quatFromRotationXYZ;
|
|
1170
|
+
exports.quatFromVec3s = quatFromVec3s;
|
|
1129
1171
|
exports.quatMultiply = quatMultiply;
|
|
1130
1172
|
exports.quatStar = quatStar;
|
|
1131
1173
|
exports.rotateVec2 = rotateVec2;
|
package/dist/index.mjs
CHANGED
|
@@ -1082,6 +1082,19 @@ function quatFromRotation(out, x, y, z) {
|
|
|
1082
1082
|
out[3] = c1 * c2 * c3 + s1 * s2 * s3;
|
|
1083
1083
|
return out;
|
|
1084
1084
|
}
|
|
1085
|
+
function quatFromRotationXYZ(out, x, y, z) {
|
|
1086
|
+
const c1 = Math.cos((x * d2r) / 2);
|
|
1087
|
+
const c2 = Math.cos((y * d2r) / 2);
|
|
1088
|
+
const c3 = Math.cos((z * d2r) / 2);
|
|
1089
|
+
const s1 = Math.sin((x * d2r) / 2);
|
|
1090
|
+
const s2 = Math.sin((y * d2r) / 2);
|
|
1091
|
+
const s3 = Math.sin((z * d2r) / 2);
|
|
1092
|
+
out[0] = s1 * c2 * c3 + c1 * s2 * s3;
|
|
1093
|
+
out[1] = c1 * s2 * c3 - s1 * c2 * s3;
|
|
1094
|
+
out[2] = c1 * c2 * s3 + s1 * s2 * c3;
|
|
1095
|
+
out[3] = c1 * c2 * c3 - s1 * s2 * s3;
|
|
1096
|
+
return out;
|
|
1097
|
+
}
|
|
1085
1098
|
function quatStar(out, quat) {
|
|
1086
1099
|
const x = quat[0], y = quat[1], z = quat[2], w = quat[3];
|
|
1087
1100
|
out[0] = -x;
|
|
@@ -1090,5 +1103,32 @@ function quatStar(out, quat) {
|
|
|
1090
1103
|
out[3] = w;
|
|
1091
1104
|
return out;
|
|
1092
1105
|
}
|
|
1106
|
+
/**
|
|
1107
|
+
* @param {vec3} vstart
|
|
1108
|
+
* @param {vec3} vend
|
|
1109
|
+
* @returns {vec4}
|
|
1110
|
+
*/
|
|
1111
|
+
function quatFromVec3s(v1, v2) {
|
|
1112
|
+
const cross = [
|
|
1113
|
+
v1[1] * v2[2] - v1[2] * v2[1],
|
|
1114
|
+
v1[2] * v2[0] - v1[0] * v2[2],
|
|
1115
|
+
v1[0] * v2[1] - v1[1] * v2[0],
|
|
1116
|
+
];
|
|
1117
|
+
const dot = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
|
|
1118
|
+
if (dot < -0.999999) {
|
|
1119
|
+
let orthogonalAxis = [1, 0, 0];
|
|
1120
|
+
if (Math.abs(v1[0]) > Math.abs(v1[2])) {
|
|
1121
|
+
orthogonalAxis = [0, 0, 1];
|
|
1122
|
+
}
|
|
1123
|
+
const orthogonalCross = [
|
|
1124
|
+
v1[1] * orthogonalAxis[2] - v1[2] * orthogonalAxis[1],
|
|
1125
|
+
v1[2] * orthogonalAxis[0] - v1[0] * orthogonalAxis[2],
|
|
1126
|
+
v1[0] * orthogonalAxis[1] - v1[1] * orthogonalAxis[0],
|
|
1127
|
+
];
|
|
1128
|
+
return vecNormalize([orthogonalCross[0], orthogonalCross[1], orthogonalCross[2], 0]);
|
|
1129
|
+
}
|
|
1130
|
+
const w = Math.sqrt((Math.pow(v1[0], 2) + Math.pow(v1[1], 2) + Math.pow(v1[2], 2)) * (Math.pow(v2[0], 2) + Math.pow(v2[1], 2) + Math.pow(v2[2], 2))) + dot;
|
|
1131
|
+
return vecNormalize([cross[0], cross[1], cross[2], w]);
|
|
1132
|
+
}
|
|
1093
1133
|
|
|
1094
|
-
export { NumberEpsilon, clamp, ensureVec3, getMat4TR, getMat4TRS, getMat4Transform, invertMat4, isZeroVec, mat3FromQuat, mat3FromRotation, mat3FromRotationZ, mat3MulMat3, mat3NormalFromMat4, mat3Rotate, mat3Scale, mat3Translate, mat3create, mat4Clone, mat4Determinate, mat4create, mat4fromRotationTranslationScale, mat4identity, mat4invert, mat4multiply, mat4perspective, mat4rotate, mat4scale, mat4translate, quatCreate, quatEquals, quatFromRotation, quatMultiply, quatStar, rotateVec2, rotationFromMat3, transposeMat3, transposeMat4, vec2AddVec2, vec2Create, vec2MulMat3, vec2MulVec2, vec2SubVec2, vec2TransformByMat3, vec3AddVec3, vec3Create, vec3Cross, vec3MulMat3, vec3MulMat4, vec3MulNum, vec3MulVec3, vec3RotateByMat4, vec3RotateByQuat, vec3TranslateByMat4, vec4Create, vecAdd, vecAddCombine, vecAssign, vecDot, vecFill, vecMinus, vecMulCombine, vecMulScalar, vecNormalize, vecSquareDistance, vecSub };
|
|
1134
|
+
export { NumberEpsilon, clamp, ensureVec3, getMat4TR, getMat4TRS, getMat4Transform, invertMat4, isZeroVec, mat3FromQuat, mat3FromRotation, mat3FromRotationZ, mat3MulMat3, mat3NormalFromMat4, mat3Rotate, mat3Scale, mat3Translate, mat3create, mat4Clone, mat4Determinate, mat4create, mat4fromRotationTranslationScale, mat4identity, mat4invert, mat4multiply, mat4perspective, mat4rotate, mat4scale, mat4translate, quatCreate, quatEquals, quatFromRotation, quatFromRotationXYZ, quatFromVec3s, quatMultiply, quatStar, rotateVec2, rotationFromMat3, transposeMat3, transposeMat4, vec2AddVec2, vec2Create, vec2MulMat3, vec2MulVec2, vec2SubVec2, vec2TransformByMat3, vec3AddVec3, vec3Create, vec3Cross, vec3MulMat3, vec3MulMat4, vec3MulNum, vec3MulVec3, vec3RotateByMat4, vec3RotateByQuat, vec3TranslateByMat4, vec4Create, vecAdd, vecAddCombine, vecAssign, vecDot, vecFill, vecMinus, vecMulCombine, vecMulScalar, vecNormalize, vecSquareDistance, vecSub };
|
package/dist/quat.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import type { mat3, vec4 } from '@predy-js/render-interface';
|
|
1
|
+
import type { mat3, vec3, vec4 } from '@predy-js/render-interface';
|
|
2
2
|
export declare function quatCreate(): vec4;
|
|
3
3
|
export declare function quatMultiply(out: vec4, a: vec4, b: vec4): vec4;
|
|
4
4
|
export declare function mat3FromQuat(out: mat3 | number[], quat: vec4): mat3;
|
|
5
5
|
export declare function quatEquals(q1: vec4, q2: vec4): boolean;
|
|
6
6
|
export declare function quatFromRotation(out: vec4, x: number, y: number, z: number): vec4;
|
|
7
|
+
export declare function quatFromRotationXYZ(out: vec4, x: number, y: number, z: number): vec4;
|
|
7
8
|
export declare function quatStar(out: vec4, quat: vec4): vec4;
|
|
9
|
+
/**
|
|
10
|
+
* @param {vec3} vstart
|
|
11
|
+
* @param {vec3} vend
|
|
12
|
+
* @returns {vec4}
|
|
13
|
+
*/
|
|
14
|
+
export declare function quatFromVec3s(v1: vec3, v2: vec3): vec4;
|
package/dist/vec4.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { vec4 } from '@predy-js/render-interface';
|
|
2
|
-
export declare function vec4Create(v
|
|
2
|
+
export declare function vec4Create(v?: vec4): vec4;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@predy-js/math",
|
|
3
|
-
"version": "0.3.0-beta.
|
|
3
|
+
"version": "0.3.0-beta.40",
|
|
4
4
|
"description": "Mars JSON Specification",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"prepublishOnly": "npm run build"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@predy-js/render-interface": "0.3.0-beta.
|
|
31
|
+
"@predy-js/render-interface": "0.3.0-beta.40",
|
|
32
32
|
"@commitlint/cli": "^13.2.1",
|
|
33
33
|
"@commitlint/config-conventional": "^13.2.0",
|
|
34
34
|
"@rollup/plugin-commonjs": "^21.0.3",
|