コード例 #1
0
 public FloatCoord getPinLocation(PlacedItem i, Pin p) {
   Coord itemLoc = i.loc;
   Coord pinLoc = p.getLocation();
   ItemType type = i.i.getType();
   return new FloatCoord(
       spacing.getX(itemLoc.x) - type.getOffsetX() + pinLoc.x,
       spacing.getY(itemLoc.y) - type.getOffsetY() + pinLoc.y);
 }
コード例 #2
0
  public void act(int dt) {
    z = new float[(int) spacing.getTotalWidth()][(int) spacing.getTotalHeight()];
    List<RenderedWire> newWires = new ArrayList<>();
    List<RenderedWire> oldWires = new ArrayList<>();

    List<PlacedItem> itemSet = new ArrayList<>();
    for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {
        if (items[x][y] != null) {
          PlacedItem newItem = new PlacedItem(items[x][y], new Coord(x, y));
          if (!itemSet.contains(newItem)) {
            itemSet.add(newItem);
          }
        }
      }
    }
    List<PlacedPin> pinSet = new ArrayList<>();
    for (PlacedItem i : itemSet) {
      for (Pin p : i.i.getPins()) {
        if (p.getAttatched() != null) {
          pinSet.add(new PlacedPin(p, i));
        }
      }
    }
    while (pinSet.size() > 0) {
      PlacedPin p0 = pinSet.remove(0);
      if (p0.p.getAttatched() != null) {
        boolean flag = true;
        if (p0.p.getAttatched().isAttatchedOnBothSides()) {
          flag = false;
          Pin other = p0.p.getAttatched().getOtherEnd(p0.p);
          PlacedPin p1 =
              pinSet.stream().filter(placedPin -> placedPin.p == other).findAny().orElse(null);
          if (p1 != null) {
            pinSet.remove(p1);
            RenderedWire testWire = new RenderedWire(p0, p1);
            if (wires.contains(testWire)) {
              oldWires.add(testWire);
            } else {
              newWires.add(testWire);
            }
          } else {
            flag = true;
          }
        }
        if (flag) // p0.p is not attached on both sides, or it is attached to something not in the
        // grid.
        {
          RenderedWire testWire = new RenderedWire(p0, null);
          if (wires.contains(testWire)) {
            oldWires.add(testWire);
          } else {
            newWires.add(testWire);
          }
        }
      }
    }
    for (RenderedWire w : wires) {
      if (oldWires.contains(w)) {
        addDepthInfo(w.path);
      } else {
        removeWire(w.path);
      }
    }
    for (RenderedWire w : newWires) {
      if (w.end != null) {
        w.setWirePath(addWire(w.start, w.end));
      } else {
        w.setWirePath(addUnfinishedWire(w.start));
      }
    }

    wires.retainAll(oldWires);
    wires.addAll(newWires);

    super.act(dt);
  }
コード例 #3
0
ファイル: Main.java プロジェクト: bruckart/OpenCraft
  // ***************************************************************************
  // run
  // ***************************************************************************
  private void run() {
    // Main camera = new Main(0, 0, 0);

    float dx = 0.0f;
    float dy = 0.0f;
    float dt = 0.0f;

    float lastTime = 0.0f; // when the last frame was
    float time = 0.0f;

    float mouseSensitivity = 0.15f;
    float movementSpeed = 10.0f; // move 10 units per second

    // hide the mouse
    Mouse.setGrabbed(true);

    while ((gameRunning) && (!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))) {
      // update();

      // render();
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
      // GL11.glLoadIdentity();
      GL11.glTranslatef(0.0f, 0.0f, -5.0f);

      axis.draw();
      grid.render();
      // cube.render();

      /*
      {
         Color.white.bind();
         texture.bind(); // or GL11.glBind(texture.getTextureID());

         GL11.glBegin(GL11.GL_QUADS);
         GL11.glTexCoord2f(0,0);
         GL11.glVertex2f(100,100);
         GL11.glTexCoord2f(1,0);
         GL11.glVertex2f(100+texture.getTextureWidth(),100);
         GL11.glTexCoord2f(1,1);
         GL11.glVertex2f(100+texture.getTextureWidth(),100+texture.getTextureHeight());
         GL11.glTexCoord2f(0,1);
         GL11.glVertex2f(100,100+texture.getTextureHeight());
         GL11.glEnd();
      }
      */

      Display.update();

      // keep looping till the display window is closed the ESC key is down
      /*
      while (!Display.isCloseRequested() ||
      !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
      {
       */
      time = Sys.getTime();

      // here is your movement speed, which can be changed to anything
      dt = 0.0005f;

      lastTime = time;

      // distance in mouse movement from the last getDX() call.
      dx = Mouse.getDX();
      // distance in mouse movement from the last getDY() call.
      dy = Mouse.getDY();

      // control camera yaw from x movement from the mouse
      camera.yaw(dx * mouseSensitivity);
      // control camera pitch from y movement from the mouse
      camera.pitch(-dy * mouseSensitivity);

      // when passing in the distrance to move
      // we times the movementSpeed with dt this is a time scale
      // so if its a slow frame u move more then a fast frame
      // so on a slow computer you move just as fast as on a fast computer

      if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
        camera.moveForward(movementSpeed * dt);
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
        camera.moveBackwards(movementSpeed * dt);
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
        camera.moveLeft(movementSpeed * dt);
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
        camera.moveRight(movementSpeed * dt);
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
        camera.moveRight(movementSpeed * dt);
      }

      if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
        camera.moveUp(movementSpeed * dt);
      }

      if (Keyboard.isKeyDown(Keyboard.KEY_P)) {

        // camera.moveRight(movementSpeed * dt);
      }

      // set the modelview matrix back to the identity
      GL11.glLoadIdentity();
      // look through the camera before you draw anything
      camera.lookThrough();

      // you would draw your scene here.

      if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
        Sys.alert("Close", "To continue, press ESCAPE on your keyboard or OK on the screen.");
        System.exit(0);
      }
    }
  }