Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (690)
Games in Android Showcase (201)
games submitted by our members
Games in WIP (764)
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: Slyth2727 (posted 2014-06-15 10:54:21, viewed 199 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  
public Matrix4f invert(Matrix4f store) {
        if (store == null) {
            store = new Matrix4f();
        }

        float fA0 = m[0][0] * m[1][1] - m[0][1] * m[1][0];
        float fA1 = m[0][0] * m[1][2] - m[0][2] * m[1][0];
        float fA2 = m[0][0] * m[1][3] - m[0][3] * m[1][0];
        float fA3 = m[0][1] * m[1][2] - m[0][2] * m[1][1];
        float fA4 = m[0][1] * m[1][3] - m[0][3] * m[1][1];
        float fA5 = m[0][2] * m[1][3] - m[0][3] * m[1][2];
        float fB0 = m[2][0] * m[3][1] - m[2][1] * m[3][0];
        float fB1 = m[2][0] * m[3][2] - m[2][2] * m[3][0];
        float fB2 = m[2][0] * m[3][3] - m[2][3] * m[3][0];
        float fB3 = m[2][1] * m[3][2] - m[2][2] * m[3][1];
        float fB4 = m[2][1] * m[3][3] - m[2][3] * m[3][1];
        float fB5 = m[2][2] * m[3][3] - m[2][3] * m[3][2];
        float fDet = fA0 * fB5 - fA1 * fB4 + fA2 * fB3 + fA3 * fB2 - fA4 * fB1 + fA5 * fB0;

        if (Math.abs(fDet) <= 0f) {
            throw new ArithmeticException("This matrix cannot be inverted");
        }

        store.m[0][0] = +m[1][1] * fB5 - m[1][2] * fB4 + m[1][3] * fB3;
        store.m[1][0] = -m[1][0] * fB5 + m[1][2] * fB2 - m[1][3] * fB1;
        store.m[2][0] = +m[1][0] * fB4 - m[1][1] * fB2 + m[1][3] * fB0;
        store.m[3][0] = -m[1][0] * fB3 + m[1][1] * fB1 - m[1][2] * fB0;
        store.m[0][1] = -m[0][1] * fB5 + m[0][2] * fB4 - m[0][3] * fB3;
        store.m[1][1] = +m[0][0] * fB5 - m[0][2] * fB2 + m[0][3] * fB1;
        store.m[2][1] = -m[0][0] * fB4 + m[0][1] * fB2 - m[0][3] * fB0;
        store.m[3][1] = +m[0][0] * fB3 - m[0][1] * fB1 + m[0][2] * fB0;
        store.m[0][2] = +m[3][1] * fA5 - m[3][2] * fA4 + m[3][3] * fA3;
        store.m[1][2] = -m[3][0] * fA5 + m[3][2] * fA2 - m[3][3] * fA1;
        store.m[2][2] = +m[3][0] * fA4 - m[3][1] * fA2 + m[3][3] * fA0;
        store.m[3][2] = -m[3][0] * fA3 + m[3][1] * fA1 - m[3][2] * fA0;
        store.m[0][3] = -m[2][1] * fA5 + m[2][2] * fA4 - m[2][3] * fA3;
        store.m[1][3] = +m[2][0] * fA5 - m[2][2] * fA2 + m[2][3] * fA1;
        store.m[2][3] = -m[2][0] * fA4 + m[2][1] * fA2 - m[2][3] * fA0;
        store.m[3][3] = +m[2][0] * fA3 - m[2][1] * fA1 + m[2][2] * fA0;

        float fInvDet = 1.0f / fDet;
        store.mul(fInvDet);

        return store;
    }





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
 
xTheGamerPlayz (117 views)
2016-09-26 21:26:27

Wave Propagation (314 views)
2016-09-20 13:29:55

steveyg90 (424 views)
2016-09-15 20:41:23

steveyg90 (425 views)
2016-09-15 20:13:52

steveyg90 (466 views)
2016-09-14 14:44:42

steveyg90 (489 views)
2016-09-14 14:42:13

theagentd (485 views)
2016-09-12 16:57:14

theagentd (418 views)
2016-09-12 14:18:31

theagentd (304 views)
2016-09-12 14:14:46

Nihilhis (738 views)
2016-09-01 13:36:54
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21
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!