Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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: CJLetsGame (posted 2014-04-01 02:15:22, viewed 274 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  
public void calculateFrustum(Camera cam)
    {    
            float[] proj = new float[16];           // This will hold our projection matrix
            float[] modl = new float[16];           // This will hold our modelview matrix
            float[] clip = new float[16];           // This will hold the clipping planes


            // glGetFloat() is used to extract information about our OpenGL world.
            // Below, we pass in GL_PROJECTION_MATRIX to abstract our projection matrix.
            // It then stores the matrix into an array of [16].
            proj_b.rewind();
            cam.getProjectionMatrix().store(proj_b);
            //GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, proj_b);
            proj_b.rewind();
            proj_b.get(proj);

            // By passing in GL_MODELVIEW_MATRIX, we can abstract our model view matrix.
            // This also stores it in an array of [16].
            modl_b.rewind();
            //new Matrix4f().store(modl_b);
            cam.getViewMatrix().store(modl_b);
            //GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modl_b);
            modl_b.rewind(); 
            modl_b.get(modl);

            // Now that we have our modelview and projection matrix, if we combine these 2 matrices,
            // it will give us our clipping planes.  To combine 2 matrices, we multiply them.
            
            clip[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12];
            clip[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13];
            clip[ 2] = modl[ 0] * proj[ 2] + modl[ 1] * proj[ 6] + modl[ 2] * proj[10] + modl[ 3] * proj[14];
            clip[ 3] = modl[ 0] * proj[ 3] + modl[ 1] * proj[ 7] + modl[ 2] * proj[11] + modl[ 3] * proj[15];

            clip[ 4] = modl[ 4] * proj[ 0] + modl[ 5] * proj[ 4] + modl[ 6] * proj[ 8] + modl[ 7] * proj[12];
            clip[ 5] = modl[ 4] * proj[ 1] + modl[ 5] * proj[ 5] + modl[ 6] * proj[ 9] + modl[ 7] * proj[13];
            clip[ 6] = modl[ 4] * proj[ 2] + modl[ 5] * proj[ 6] + modl[ 6] * proj[10] + modl[ 7] * proj[14];
            clip[ 7] = modl[ 4] * proj[ 3] + modl[ 5] * proj[ 7] + modl[ 6] * proj[11] + modl[ 7] * proj[15];

            clip[ 8] = modl[ 8] * proj[ 0] + modl[ 9] * proj[ 4] + modl[10] * proj[ 8] + modl[11] * proj[12];
            clip[ 9] = modl[ 8] * proj[ 1] + modl[ 9] * proj[ 5] + modl[10] * proj[ 9] + modl[11] * proj[13];
            clip[10] = modl[ 8] * proj[ 2] + modl[ 9] * proj[ 6] + modl[10] * proj[10] + modl[11] * proj[14];
            clip[11] = modl[ 8] * proj[ 3] + modl[ 9] * proj[ 7] + modl[10] * proj[11] + modl[11] * proj[15];

            clip[12] = modl[12] * proj[ 0] + modl[13] * proj[ 4] + modl[14] * proj[ 8] + modl[15] * proj[12];
            clip[13] = modl[12] * proj[ 1] + modl[13] * proj[ 5] + modl[14] * proj[ 9] + modl[15] * proj[13];
            clip[14] = modl[12] * proj[ 2] + modl[13] * proj[ 6] + modl[14] * proj[10] + modl[15] * proj[14];
            clip[15] = modl[12] * proj[ 3] + modl[13] * proj[ 7] + modl[14] * proj[11] + modl[15] * proj[15];
            
            // Now we actually want to get the sides of the frustum.  To do this we take
            // the clipping planes we received above and extract the sides from them.

            // This will extract the RIGHT side of the frustum
            m_Frustum[RIGHT][A] = clip[ 3] - clip[ 0];
            m_Frustum[RIGHT][B] = clip[ 7] - clip[ 4];
            m_Frustum[RIGHT][C] = clip[11] - clip[ 8];
            m_Frustum[RIGHT][D] = clip[15] - clip[12];

            // Now that we have a normal (A,B,C) and a distance (D) to the plane,
            // we want to normalize that normal and distance.

            // Normalize the RIGHT side
            normalizePlane(m_Frustum, RIGHT);

            // This will extract the LEFT side of the frustum
            m_Frustum[LEFT][A] = clip[ 3] + clip[ 0];
            m_Frustum[LEFT][B] = clip[ 7] + clip[ 4];
            m_Frustum[LEFT][C] = clip[11] + clip[ 8];
            m_Frustum[LEFT][D] = clip[15] + clip[12];

            // Normalize the LEFT side
            normalizePlane(m_Frustum, LEFT);

            // This will extract the BOTTOM side of the frustum
            m_Frustum[BOTTOM][A] = clip[ 3] + clip[ 1];
            m_Frustum[BOTTOM][B] = clip[ 7] + clip[ 5];
            m_Frustum[BOTTOM][C] = clip[11] + clip[ 9];
            m_Frustum[BOTTOM][D] = clip[15] + clip[13];

            // Normalize the BOTTOM side
            normalizePlane(m_Frustum, BOTTOM);

            // This will extract the TOP side of the frustum
            m_Frustum[TOP][A] = clip[ 3] - clip[ 1];
            m_Frustum[TOP][B] = clip[ 7] - clip[ 5];
            m_Frustum[TOP][C] = clip[11] - clip[ 9];
            m_Frustum[TOP][D] = clip[15] - clip[13];

            // Normalize the TOP side
            normalizePlane(m_Frustum, TOP);

            // This will extract the BACK side of the frustum
            m_Frustum[BACK][A] = clip[ 3] - clip[ 2];
            m_Frustum[BACK][B] = clip[ 7] - clip[ 6];
            m_Frustum[BACK][C] = clip[11] - clip[10];
            m_Frustum[BACK][D] = clip[15] - clip[14];

            // Normalize the BACK side
            normalizePlane(m_Frustum, BACK);

            // This will extract the FRONT side of the frustum
            m_Frustum[FRONT][A] = clip[ 3] + clip[ 2];
            m_Frustum[FRONT][B] = clip[ 7] + clip[ 6];
            m_Frustum[FRONT][C] = clip[11] + clip[10];
            m_Frustum[FRONT][D] = clip[15] + clip[14];

            // Normalize the FRONT side
            normalizePlane(m_Frustum, FRONT);
    }
}





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
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (33 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (51 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (60 views)
2014-11-29 21:32:03

toopeicgaming1999 (123 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!