Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: KaiHH (posted 2015-08-19 15:01:05, viewed 252 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99   100   101   102   103   104   105   106   107   108   109   110   111   112   113   114   115   116   117   118   119   120   121   122   123   124   125   126   127   128   129   130   131   132   133   134   135   136   137   138   139   140   141   142   143   144   145   146   147   148   149   150   151   152   153   154  
public Matrix4d lerpTRS(Matrix4d other, double alpha, double dotThreshold, Matrix4d dest) {
        // extract scaling factors for 'this'
        double s0x = Math.sqrt(m00 * m00 + m01 * m01 + m02 * m02);
        double s0y = Math.sqrt(m10 * m10 + m11 * m11 + m12 * m12);
        double s0z = Math.sqrt(m20 * m20 + m21 * m21 + m22 * m22);
        // extract scaling factors for 'other'
        double s1x = Math.sqrt(other.m00 * other.m00 + other.m01 * other.m01 + other.m02 * other.m02);
        double s1y = Math.sqrt(other.m10 * other.m10 + other.m11 * other.m11 + other.m12 * other.m12);
        double s1z = Math.sqrt(other.m20 * other.m20 + other.m21 * other.m21 + other.m22 * other.m22);
        // extract translation for 'this'
        double t0x = m30, t0y = m31, t0z = m32;
        // extract translation for 'other'
        double t1x = other.m30, t1y = other.m31, t1z = other.m32;
        // convert rotation of 'this' to quaternion for nlerpIterative interpolation
        double t;
        double tr = m00 + m11 + m22;
        double x, y, z, w;
        if (tr >= 0.0) {
            t = Math.sqrt(tr + 1.0);
            w = t * 0.5;
            t = 0.5 / t;
            x = (m12 - m21) * t;
            y = (m20 - m02) * t;
            z = (m01 - m10) * t;
        } else {
            if (m00 >= m11 && m00 >= m22) {
                t = Math.sqrt(m00 - (m11 + m22) + 1.0);
                x = t * 0.5;
                t = 0.5 / t;
                y = (m10 + m01) * t;
                z = (m02 + m20) * t;
                w = (m12 - m21) * t;
            } else if (m11 > m22) {
                t = Math.sqrt(m11 - (m22 + m00) + 1.0);
                y = t * 0.5;
                t = 0.5 / t;
                z = (m21 + m12) * t;
                x = (m10 + m01) * t;
                w = (m20 - m02) * t;
            } else {
                t = Math.sqrt(m22 - (m00 + m11) + 1.0);
                z = t * 0.5;
                t = 0.5 / t;
                x = (m02 + m20) * t;
                y = (m21 + m12) * t;
                w = (m01 - m10) * t;
            }
        }
        double invNorm = (1.0 / Math.sqrt(x * x + y * y + z * z + w * w));
        double q1x = x * invNorm;
        double q1y = y * invNorm;
        double q1z = z * invNorm;
        double q1w = w * invNorm;
        // convert rotation of 'other' to quaternion for nlerpIterative interpolation
        tr = other.m00 + other.m11 + other.m22;
        if (tr >= 0.0) {
            t = Math.sqrt(tr + 1.0);
            w = t * 0.5;
            t = 0.5 / t;
            x = (other.m12 - other.m21) * t;
            y = (other.m20 - other.m02) * t;
            z = (other.m01 - other.m10) * t;
        } else {
            if (other.m00 >= other.m11 && other.m00 >= other.m22) {
                t = Math.sqrt(other.m00 - (other.m11 + other.m22) + 1.0);
                x = t * 0.5;
                t = 0.5 / t;
                y = (other.m10 + other.m01) * t;
                z = (other.m02 + other.m20) * t;
                w = (other.m12 - other.m21) * t;
            } else if (other.m11 > other.m22) {
                t = Math.sqrt(other.m11 - (other.m22 + other.m00) + 1.0);
                y = t * 0.5;
                t = 0.5 / t;
                z = (other.m21 + other.m12) * t;
                x = (other.m10 + other.m01) * t;
                w = (other.m20 - other.m02) * t;
            } else {
                t = Math.sqrt(other.m22 - (other.m00 + other.m11) + 1.0);
                z = t * 0.5;
                t = 0.5 / t;
                x = (other.m02 + other.m20) * t;
                y = (other.m21 + other.m12) * t;
                w = (other.m01 - other.m10) * t;
            }
        }
        invNorm = (1.0 / Math.sqrt(x * x + y * y + z * z + w * w));
        double q2x = x * invNorm;
        double q2y = y * invNorm;
        double q2z = z * invNorm;
        double q2w = w * invNorm;
        // interpolate quaternion via Quaternion.nlerpIterative with given dotThreshold parameter
        double dot = q1x * q2x + q1y * q2y + q1z * q2z + q1w * q2w;
        double absDot = Math.abs(dot);
        double resX, resY, resZ, resW;
        if (1.0 - 1E-6f < absDot) {
            resX = q1x;
            resY = q1y;
            resZ = q1z;
            resW = q1w;
        } else {
            double alphaN = alpha;
            while (absDot < dotThreshold) {
                double scale0 = 0.5;
                double scale1 = dot >= 0.0 ? 0.5 : -0.5;
                if (alphaN < 0.5) {
                    q2x = scale0 * q2x + scale1 * q1x;
                    q2y = scale0 * q2y + scale1 * q1y;
                    q2z = scale0 * q2z + scale1 * q1z;
                    q2w = scale0 * q2w + scale1 * q1w;
                    double s = (1.0 / Math.sqrt(q2x * q2x + q2y * q2y + q2z * q2z + q2w * q2w));
                    q2x *= s;
                    q2y *= s;
                    q2z *= s;
                    q2w *= s;
                    alphaN = alphaN * 2.0;
                } else {
                    q1x = scale0 * q1x + scale1 * q2x;
                    q1y = scale0 * q1y + scale1 * q2y;
                    q1z = scale0 * q1z + scale1 * q2z;
                    q1w = scale0 * q1w + scale1 * q2w;
                    double s = (1.0 / Math.sqrt(q1x * q1x + q1y * q1y + q1z * q1z + q1w * q1w));
                    q1x *= s;
                    q1y *= s;
                    q1z *= s;
                    q1w *= s;
                    alphaN = alphaN * 2.0 - 1.0;
                }
                dot = q1x * q2x + q1y * q2y + q1z * q2z + q1w * q2w;
                absDot = Math.abs(dot);
            }
            double scale0 = 1.0 - alphaN;
            double scale1 = dot >= 0.0 ? alphaN : -alphaN;
            resX = scale0 * q1x + scale1 * q2x;
            resY = scale0 * q1y + scale1 * q2y;
            resZ = scale0 * q1z + scale1 * q2z;
            resW = scale0 * q1w + scale1 * q2w;
            double s = (1.0 / Math.sqrt(resX * resX + resY * resY + resZ * resZ + resW * resW));
            resX *= s;
            resY *= s;
            resZ *= s;
            resW *= s;
        }
        // interpolate scaling
        double sx = s0x * (1.0 - alpha) + s1x * alpha;
        double sy = s0y * (1.0 - alpha) + s1y * alpha;
        double sz = s0z * (1.0 - alpha) + s1z * alpha;
        // interpolate translation
        double tx = t0x * (1.0 - alpha) + t1x * alpha;
        double ty = t0y * (1.0 - alpha) + t1y * alpha;
        double tz = t0z * (1.0 - alpha) + t1z * alpha;
        // create final transformation matrix
        return dest.translationRotateScale(tx, ty, tz, resX, resY, resZ, resW, sx, sy, sz);
    }





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 
Riven (521 views)
2019-09-04 15:33:17

hadezbladez (5494 views)
2018-11-16 13:46:03

hadezbladez (2397 views)
2018-11-16 13:41:33

hadezbladez (5754 views)
2018-11-16 13:35:35

hadezbladez (1217 views)
2018-11-16 13:32:03

EgonOlsen (4658 views)
2018-06-10 19:43:48

EgonOlsen (5667 views)
2018-06-10 19:43:44

EgonOlsen (3193 views)
2018-06-10 19:43:20

DesertCoockie (4093 views)
2018-05-13 18:23:11

nelsongames (5048 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!