Exemplo n.º 1
0
 private void endThisLoop() {
   // FPS meter
   if (time <= System.currentTimeMillis() - 1000) {
     Display.setTitle("Simulating gravity @ " + frameNumber + " FPS"); // Normal
     FPS = frameNumber;
     frameNumber = 0;
     time = System.currentTimeMillis();
   } else {
     frameNumber++;
   }
   Display.update();
   Display.sync(60);
 }
Exemplo n.º 2
0
  public void run() {
    init();
    engine = new Engine();

    long lastTime = System.nanoTime();
    double delta = 0.0;
    // Amout of nanoseconds in 1/60th of a second
    double ns = 1000000000.0 / 60.0;
    long timer = System.currentTimeMillis();
    int updates = 0;
    int frames = 0;
    while (running) {
      long now = System.nanoTime();
      delta += (now - lastTime) / ns;
      lastTime = now;
      // if delta >= than one then the amount of time >= 1/60th of a second
      if (delta >= 1.0) {
        update();
        updates++;
        delta--;
      }
      render();
      frames++;
      // If a second has passed, we print the stats
      if (System.currentTimeMillis() - timer > 1000) {
        timer += 1000;
        System.out.println(updates + " ups, " + frames + " fps");
        updates = 0;
        frames = 0;
      }
      if (glfwWindowShouldClose(window) == GL_TRUE) running = false;
    }
    engine.CleanUp();
    keyCallback.release();
    sizeCallback.release();
    mouseCallback.release();
    focusCallback.release();
    glfwDestroyWindow(window);
    glfwTerminate();
  }
 public void addPoint(
     System s,
     int x,
     int y,
     int oX,
     int oY,
     float r,
     float red,
     float green,
     float blue,
     double force) {
   Point p = new Point(x, y, oX, oY, r, red, green, blue, force);
   s.addPoint(p);
 }
Exemplo n.º 4
0
  private void checkInput() {
    if (Mouse.isButtonDown(0)) {
      leftHold(Mouse.getX(), Mouse.getY());
    }
    while (Mouse.next()) {
      if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) {
        leftClick(Mouse.getX(), Mouse.getY());
      }

      if (Mouse.getEventButtonState() && Mouse.getEventButton() == 1) {
        rightClick();
      }
    }
    while (Keyboard.next()) {
      if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
        System.exit(0);
      }

      if (Keyboard.getEventKey() == Keyboard.KEY_SPACE) {
        if (drawVector) {
          drawVector = false;
        } else {
          drawVector = true;
        }
      }
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
      if (vecSlider.y < 85) {
        vecSlider.y++;
      }
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
      if (vecSlider.x > -90) {
        vecSlider.x--;
      }
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
      if (vecSlider.y > -85) {
        vecSlider.y--;
      }
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
      if (vecSlider.x < 85) {
        vecSlider.x++;
      }
    }
  }
Exemplo n.º 5
0
  private void initGL(int width, int height) {

    try {
      // DisplayMode mode = new DisplayMode(width,height);
      // DisplayMode mode = Display.getDesktopDisplayMode(); Old code, for not-fullscreen stuff
      Display.setDisplayMode(Display.getDesktopDisplayMode());
      Display.setFullscreen(true);
      Display.create();
      Display.setVSyncEnabled(true);
    } catch (LWJGLException e) {
      System.out.println("Catched an error in intiGL");
      e.printStackTrace();
      System.exit(0);
    }

    // init OpenGL
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, width, 0, height, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  }
  public SimpleRenderer(int x, int y) {
    this.width = x;
    this.height = y;
    try {
      Display.setDisplayMode(new DisplayMode(x, y));
      Display.setTitle("Crowd Simulation");
      Display.create();
      Display.setVSyncEnabled(true);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    Random r = new Random();

    System s = new System(this.width, this.height - 2, 0.0f, 1.0f);
    for (int i = 0; i < 1200; i++) {

      int xX = r.nextInt(this.width);
      int yY = r.nextInt(this.height);
      int oldX = xX; // + r.nextInt(1) ;
      int oldY = yY; // + r.nextInt(2) + 1;

      double size = r.nextGaussian() * 1.2 + 16;
      addPoint(
          s,
          xX,
          yY,
          oldX,
          oldY,
          (float) size, // r.nextFloat() * 20 + 10,
          1,
          i > 600 ? 0 : 1,
          1,
          i > 600 ? -0.9 : 0.9); // r.nextFloat(), r.nextFloat(), r.nextFloat());

      // addPoint(s, xX, yY, oldX, oldY, (float)size,//r.nextFloat() * 20 + 10,
      //		r.nextFloat(), r.nextFloat(), r.nextFloat(),i>400 ?-r.nextFloat():r.nextFloat());

    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, x, y, 0, 1, -1);
    glMatrixMode(GL_MODELVIEW);

    boolean isPressed = false;
    while (!Display.isCloseRequested()) // rendering
    {

      glClear(GL_COLOR_BUFFER_BIT);
      // glClearColor(1.0f,1.0f,1.0f,1.0f);
      if (Mouse.isButtonDown(0)) {

        // isPressed = true;
        /*int xX = Mouse.getX();
        int yY = this.height - Mouse.getY();

        int oldX = xX;// + r.nextInt(4) - 2;
        int oldY = yY;
        double size = r.nextGaussian()*1.2 +14;
        addPoint(s, xX, yY, oldX, oldY,(float)size,// r.nextFloat() * 20 + 10,
        		r.nextFloat(), r.nextFloat(), r.nextFloat(),30);
        */
        s.setDestroying(true);
      }

      if (Mouse.isButtonDown(1)) {

        for (int i = -150; i < 150; i += 10) {

          int xX = Mouse.getX();
          int yY = this.height - Mouse.getY();
          s.applyDirerction(s.searchPoint(xX, yY + i), 10);
        }
      }

      // java.lang.System.out.println("Number of objects: " +s.getListOfPoints().size() +"
      // Destroying? "+ s.isDestroying());
      s.step(3);

      int xX = Mouse.getX();
      int yY = this.height - Mouse.getY();

      for (int i = -150; i < 150; i += 10) {
        Point k = s.searchPoint(xX, yY + i);
        if (k != null) {
          glColor3f(0.0f, 0.0f, 0.0f);
          Point.DrawCircle(k.getX(), k.getY(), k.getRadius() - 2, 20);
        }
      }

      Display.update();
      Display.sync(30);
    }

    Display.destroy();
  }
Exemplo n.º 7
0
 private void endProgram() {
   GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
   System.exit(0);
 }