Advertisement
ridjis

Zad3Template

May 21st, 2015
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.31 KB | None | 0 0
  1. package cg3d.e11scene3d;
  2.  
  3. import java.awt.Font;
  4. import javax.media.opengl.GL;
  5. import com.sun.opengl.util.j2d.TextRenderer;
  6. import cgex.jogl.base.Color4f;
  7. import cgex.jogl.base.JoglFrame;
  8. import cgex.jogl.base.Vector3f;
  9.  
  10. @SuppressWarnings({ "serial", "unused" })
  11. public class Zad3Template extends JoglFrame {
  12.     private TextRenderer tr;
  13.    
  14.     private Vector3f[] vertices = {
  15.             new Vector3f(-3f, -2f, 0f),
  16.             new Vector3f(3f, -2f, 0f),
  17.             new Vector3f(3f, -2f, -4f),
  18.             new Vector3f(-3f, -2f, -4f),
  19.            
  20.             new Vector3f(-2f, 2f, -1f),
  21.             new Vector3f(2f, 2f, -1f),
  22.             new Vector3f(2f, 2f, -3f),
  23.             new Vector3f(-2f, 2f, -3f)
  24.     };
  25.    
  26.     private int indices[] = { 0, 1, 2,  0, 2, 3,  0, 5, 1,  0, 5, 4,  1, 6, 2,  1, 6, 5,
  27.                               2, 6, 7,  2, 3, 7,  0, 4, 7,  0, 3, 7,  4, 5, 6,  4, 6, 7 };
  28.    
  29.     private static final Color4f[] colors = {
  30.         new Color4f(1.0f, 0.0f, 0.0f),
  31.         new Color4f(0.0f, 1.0f, 0.0f),
  32.         new Color4f(1.0f, 1.0f, 0.0f),
  33.         new Color4f(1.0f, 1.0f, 1.0f),
  34.         new Color4f(0.0f, 0.0f, 1.0f),
  35.         new Color4f(1.0f, 0.0f, 1.0f),
  36.         new Color4f(0.0f, 1.0f, 1.0f),
  37.         new Color4f(0.4f, 1.2f, 0.9f)
  38.     };
  39.    
  40.     @Override
  41.     protected void initialize(GL gl, Color4f backColor, Vector3f cameraPos,
  42.             Vector3f cameraDir) {
  43.         cameraPos.assign(6.32f, 8.56f, 13.27f);
  44.         cameraDir.assign(-0.35f, -0.53f, -0.77f);
  45.        
  46.         Font font = new Font("Tahoma", Font.BOLD, 12);
  47.         tr = new TextRenderer(font);
  48.        
  49.     }
  50.  
  51.     @Override
  52.     protected void render(GL gl, double elapsedTime) {
  53.        
  54.         gl.glBegin(GL.GL_TRIANGLES);
  55.        
  56.         for (int i = 0; i < indices.length; i++) {
  57.             int index = indices[i];
  58.             Vector3f vertex = vertices[index];
  59.             Color4f boje = colors[index];
  60.            
  61.             gl.glColor3f(boje.getRed(), boje.getGreen(), boje.getBlue());
  62.             gl.glVertex3f(vertex.getX(), vertex.getY(), vertex.getZ());
  63.         }
  64.        
  65.         gl.glEnd();
  66.        
  67.         int w = getWidth();
  68.         int h = getHeight();
  69.        
  70.         tr.beginRendering(w, h);
  71.         {
  72.  
  73.             tr.setColor(1.0f, 1.0f, 0.0f, 1.0f);
  74.             // trenutni FPS
  75.             tr.draw("FPS: " + getFps(), 8, h - 48);
  76.             // trenutna pozicija i orijentacija kamere
  77.             tr.draw("Position: " + camera.getPosition(), 8, h - 64);
  78.             tr.draw("Direction: " + camera.getLookDirection(), 8, h - 80);
  79.         }
  80.         tr.endRendering(); // kraj renderovanja
  81.     }
  82.  
  83.     public static void main(String[] args)
  84.     {
  85.         new Zad3Template().start("Zad3", 800, 600, false);
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement