X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fmath%2FMathTools.java;h=63ac1ccc402b3a844e09bec7ec99417242fab272;hb=d624e3dc123c3730a438b7468c7ce5d49dbeb62f;hp=73d5e6067fdb255cd288d40cd2ad3e7c9e606fcb;hpb=9c5be9fa9ff5fece5710b9f21bcafca58388899d;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/math/MathTools.java b/org.simantics.g3d/src/org/simantics/g3d/math/MathTools.java index 73d5e606..63ac1ccc 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/math/MathTools.java +++ b/org.simantics.g3d/src/org/simantics/g3d/math/MathTools.java @@ -328,6 +328,19 @@ public class MathTools { } + public static void getMatrix(Quat4d quat, Matrix4d m) { + m.setZero(); + m.m00 = 1.0f - 2.0 * (quat.y * quat.y + quat.z * quat.z); + m.m01 = 2.0 * (quat.x * quat.y + quat.w * quat.z); + m.m02 = 2.0 * (quat.x * quat.z - quat.w * quat.y); + m.m10 = 2.0 * (quat.x * quat.y - quat.w * quat.z); + m.m11 = 1.0 - 2.0f * (quat.x * quat.x + quat.z * quat.z); + m.m12 = 2.0 * (quat.y * quat.z + quat.w * quat.x); + m.m20 = 2.0 * (quat.x * quat.z + quat.w * quat.y); + m.m21 = 2.0 * (quat.y * quat.z - quat.w * quat.x); + m.m22 = 1.0 - 2.0f * (quat.x * quat.x + quat.y * quat.y); + m.m33 = 1.0; + } private static double q[] = new double[3]; private static int nxt[] = { 1, 2, 0 }; @@ -917,4 +930,28 @@ public class MathTools { } return t; } + + public static Matrix4d glFrustum(double l, double r, double b, double t, double n, double f) { + Matrix4d mat = new Matrix4d(); + mat.m00 = 2.0 * n / (r - l); + mat.m11 = 2.0 * n / (t - b); + mat.m02 = (r+l) / (r-l); + mat.m12 = (t+b) / (t-b); + mat.m22 = -(f+n) / (f-n); + mat.m23 = -(2.0 *f * n) / (f-n); + mat.m32 = -1.0; + return mat; + } + + public static Matrix4d glOrtho(double l, double r, double b, double t, double n, double f) { + Matrix4d mat = new Matrix4d(); + mat.m00 = 2.0 / (r - l); + mat.m11 = 2.0 / (t - b); + mat.m22 = -2.0 / (f-n); + mat.m33 = 1.0; + mat.m03 = -(r+l)/(r-l); + mat.m13 = -(t+b)/(t-b); + mat.m23 = -(f+n)/(f-n); + return mat; + } }