Advertisement
FoxyCorndog

Untitled

Mar 12th, 2012
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.67 KB | None | 0 0
  1. package net.foxycorndog.presto3d.graphics;
  2.  
  3. import static org.lwjgl.opengl.GL11.*;
  4.  
  5. public class PrestoGL
  6. {
  7.    
  8.     public static void drawCube(float x, float y, float z, int size)
  9.     {
  10.        
  11.         glBegin(GL_QUADS);
  12.        
  13.             // Front face
  14.             glNormal3f(0       , 0       , 1       );
  15.             glVertex3f(x       , y       , z       );
  16.             glVertex3f(x + size, y       , z       );
  17.             glVertex3f(x + size, y + size, z       );
  18.             glVertex3f(x       , y + size, z       );
  19.            
  20.             // Back face
  21.             glNormal3f(0       , 0       , -1      );
  22.             glVertex3f(x       , y       , z - size);
  23.             glVertex3f(x       , y + size, z - size);
  24.             glVertex3f(x + size, y + size, z - size);
  25.             glVertex3f(x + size, y       , z - size);
  26.            
  27.             // Bottom face
  28.             glNormal3f(0       , 1       , 0      );
  29.             glVertex3f(x       , y       , z - size);
  30.             glVertex3f(x + size, y       , z - size);
  31.             glVertex3f(x + size, y       , z       );
  32.             glVertex3f(x       , y       , z       );
  33.            
  34.             // Top face
  35.             glNormal3f(0       , -1       , 0       );
  36.             glVertex3f(x       , y + size, z - size);
  37.             glVertex3f(x       , y + size, z       );
  38.             glVertex3f(x + size, y + size, z       );
  39.             glVertex3f(x + size, y + size, z - size);
  40.            
  41.             // Left face
  42.             glNormal3f(-1       , 0       , 0       );
  43.             glVertex3f(x       , y       , z       );
  44.             glVertex3f(x       , y + size, z       );
  45.             glVertex3f(x       , y + size, z - size);
  46.             glVertex3f(x       , y       , z - size);
  47.            
  48.             // Right face
  49.             glNormal3f(1       , 0       , 0       );
  50.             glVertex3f(x + size, y       , z       );
  51.             glVertex3f(x + size, y       , z - size);
  52.             glVertex3f(x + size, y + size, z - size);
  53.             glVertex3f(x + size, y + size, z       );
  54.            
  55.         glEnd();
  56.     }
  57.    
  58.     public static float[] getCubeArray(float x, float y, float z, int size)
  59.     {
  60.         float array[] = null;
  61.         array = new float[6 * 4];
  62.        
  63.         array = new float[]
  64.         {
  65.             // Front side
  66.             x       , y       , z,        
  67.             x + size, y       , z,      
  68.             x + size, y + size, z,      
  69.             x       , y + size, z,      
  70.            
  71.             // Back side
  72.             x       , y       , z - size,
  73.             x       , y + size, z - size,
  74.             x + size, y + size, z - size,
  75.             x + size, y       , z - size,
  76.            
  77.             // Bottom face
  78.             x       , y       , z - size,
  79.             x + size, y       , z - size,
  80.             x + size, y       , z,      
  81.             x       , y       , z,      
  82.            
  83.             // Top face
  84.             x       , y + size, z - size,
  85.             x       , y + size, z,      
  86.             x + size, y + size, z,      
  87.             x + size, y + size, z - size,
  88.            
  89.             // Left face
  90.             x       , y       , z,      
  91.             x       , y + size, z,      
  92.             x       , y + size, z - size,
  93.             x       , y       , z - size
  94.         };
  95.        
  96.         return array;
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement