/** Invoked when an entity is selected */
  private void entitySelected(Entity entity) {
    ArrayList<Reference> references = entity.getReferences();
    // TODO This code is used to display dangling references in the current file only.
    // 		Remember to remove this code later.
    // BEGIN OF CODE TO BE REMOVED
    if (entity instanceof UndeclaredEntity) {
      for (Reference reference : entity.getReferences()) {
        if (!filePathLabel.getText().endsWith(reference.getFilePath())) {
          references.remove(reference);
        }
      }
    }
    // END OF CODE TO BE REMOVED
    Collections.sort(
        references,
        new Reference.ReferenceComparator(
            new Reference.ReferenceComparatorByName(),
            new Reference.ReferenceComparatorByFile(),
            new Reference.ReferenceComparatorByPosition()));

    referenceListLabel.setText("Reference List: (" + references.size() + " references found)");
    referenceTableViewer.setInput(references);

    for (Reference reference : references) {
      if (filePathLabel.getText().endsWith(reference.getFilePath())) {
        referenceSelected(reference);
        break;
      }
    }
    entityTableViewer.getControl().setFocus();
  }
示例#2
0
  private void calculateCameraPosition(float horizontalDistance, float verticalDistance) {

    float theta = player.getRotY() + angleAroundPlayer;
    float offsetX = (float) (horizontalDistance * Math.sin(Math.toRadians(theta)));
    float offsetZ = (float) (horizontalDistance * Math.cos(Math.toRadians(theta)));
    position.x = player.getPosition().x - offsetX;
    position.z = player.getPosition().z - offsetZ;
    position.y = player.getPosition().y + 1 + verticalDistance;

    yaw = 180.0f - theta;
  }
  @Override
  public void update(long elapsedTime) {
    super.update(elapsedTime);

    if (currentAnimation.getId().contains("sword")
        || currentAnimation.getId().contains("test")
        ||
        //				currentAnimation.getId().contains("crouching") ||
        !firstTime) {

      if (framesDebug == 0) {
        System.out.println(
            currentAnimation.getId()
                + ": "
                + currentAnimation.getCurrentFrame()
                + " -> ("
                + getX()
                + ", "
                + getY()
                + ")");
      }

      if (framesDebug == 4) {
        framesDebug = -1;
      }

      framesDebug++;
      firstTime = false;
    }

    /* Updates the position of the bounding box */
    enableBoundingBox();
  }
 @Override
 public void drawSelf(Graphics g) {
   if (sword != null) {
     sword.drawSelf(g);
   }
   super.drawSelf(g);
   splash.drawSelf(g);
 }
示例#5
0
 public void move(Terrain terrain) {
   checkInputs();
   super.increaseRotation(0, currentTurnSpeed * DisplayManager.getFrameTimeSeconds(), 0);
   float distance = currentSpeed * DisplayManager.getFrameTimeSeconds();
   float dx = (float) (distance * Math.sin(Math.toRadians(super.getRotY())));
   float dz = (float) (distance * Math.cos(Math.toRadians(super.getRotY())));
   super.increasePosition(dx, 0, dz);
   upwardsSpeed += GRAVITY * DisplayManager.getFrameTimeSeconds();
   super.increasePosition(0, upwardsSpeed * DisplayManager.getFrameTimeSeconds(), 0);
   float terrainHeight = terrain.getHeightOfTerrain(getPosition().x, getPosition().z);
   // float terrainHeight = 0;
   if (super.getPosition().y < terrainHeight) {
     upwardsSpeed = 0;
     isInAir = false;
     super.getPosition().y = terrainHeight;
   }
 }
示例#6
0
 public void render(Map<TexturedModel, List<Entity>> entities, Matrix4f toShadowMap) {
   shader.loadToShadowSpaceMatrix(toShadowMap);
   for (TexturedModel model : entities.keySet()) {
     prepareTexturedModel(model);
     List<Entity> batch = entities.get(model);
     for (Entity entity : batch) {
       if (entity.isRenderable()) {
         prepareInstance(entity);
         if (SettingHolder.get("cg_debug_polygons").getValueB()) {
           GL11.glDrawElements(
               GL11.GL_LINE_STRIP, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
         } else {
           GL11.glDrawElements(
               GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
         }
       }
     }
     unbindTexturedModel();
   }
 }
示例#7
0
  @Override
  public void drawSelf(Graphics g) {
    super.drawSelf(g);

    //		g.setColor(Color.RED);
    //		g.drawRect((int) baseBoundingBox.getX() - currentAnimation.getImage().getWidth(),
    //				(int) baseBoundingBox.getY() - currentAnimation.getImage().getHeight(),
    //				(int) baseBoundingBox.getWidth(),
    //				(int) baseBoundingBox.getHeight());
    //		g.setColor(Color.BLACK);

  }
示例#8
0
 public void updateReal(long elapsedTime) {
   super.update(elapsedTime);
   if (this.getCurrentAnimation().getId().equals("opening")) {
     if (this.getCurrentAnimation().isOver(false)) {
       this.setCurrentAnimation("opened", FRAME_DURATION);
     }
   } else if (this.getCurrentAnimation().getId().equals("closing")) {
     if (this.getCurrentAnimation().isOver(false)) {
       this.setCurrentAnimation("closed", FRAME_DURATION);
     }
   }
 }
示例#9
0
 public void setSelectedEntity(Entity entity) {
   if (entity == null) {
     reset(true);
     return;
   }
   reset(false);
   for (Attribute<?> attr : entity.getAttributes()) {
     AttrComponent<?> ac = new AttrComponent(attr);
     attrComps.add(ac);
     getContentContainer().add(ac);
   }
 }
示例#10
0
 private void prepareInstance(Entity entity) {
   Matrix4f transformationMatrix =
       Maths.createTransformationMatrix(
           entity.getPosition(),
           entity.getRotX(),
           entity.getRotY(),
           entity.getRotZ(),
           entity.getScale());
   shader.loadTransformationMatrix(transformationMatrix);
   shader.loadOffset(entity.getTextureXOffset(), entity.getTextureYOffset());
 }
示例#11
0
  public void move() {
    if (cameraMode == CameraMode.OVERHEAD) {
      if (KeyboardHelper.isKeyDown(Keyboard.KEY_LEFT)) {
        this.position.x -= OVERHEAD_CAMERA_MOVE_SPEED * DisplayManager.getFrameTimeSeconds();
      }
      if (KeyboardHelper.isKeyDown(Keyboard.KEY_RIGHT)) {
        this.position.x += OVERHEAD_CAMERA_MOVE_SPEED * DisplayManager.getFrameTimeSeconds();
      }
      if (KeyboardHelper.isKeyDown(Keyboard.KEY_UP)) {
        this.position.z -= OVERHEAD_CAMERA_MOVE_SPEED * DisplayManager.getFrameTimeSeconds();
      }
      if (KeyboardHelper.isKeyDown(Keyboard.KEY_DOWN)) {
        this.position.z += OVERHEAD_CAMERA_MOVE_SPEED * DisplayManager.getFrameTimeSeconds();
      }

      this.yaw = 0;
      this.pitch = 70;
      this.position.y = world.getTerrain().getTerrainHeight(position.x, position.z) + cameraHeight;

    } else if (cameraMode == CameraMode.FIRST_PERSON) {
      Vector3f viewPos = player.getHardpointWorldPos("HP_VIEW");
      if (viewPos == null) viewPos = player.getPosition();

      this.position.x = viewPos.x;
      this.position.y = viewPos.y;
      this.position.z = viewPos.z;
      this.pitch = player.rotX;
      this.yaw = 180.0f - player.rotY;
    } else if (cameraMode == CameraMode.THIRD_PERSON) {
      calculateZoom();
      calculatePitch();
      calculateAngleAroundPlayer();

      float horizontalDistance = calculateHorizontalDistance();
      float verticalDistance = calculateVerticalDistance();
      calculateCameraPosition(horizontalDistance, verticalDistance);
    }
  }
示例#12
0
  private void drawGhost(EntityStatus ghost) {
    // TODO: Don't draw if off-screen!
    boolean facingRight = ghost.getFacingRight();
    double xPos = ghost.getXPos();
    double yPos = ghost.getYPos();
    double textureHalfWidth = ghost.getTextureHalfWidth();
    double textureHeight = ghost.getTextureHeight();
    double left = xPos - textureHalfWidth;
    double right = xPos + textureHalfWidth;
    GLDrawer.useTexture(ghost.getCurrentTexture());
    GLDrawer.drawQuad(
        (facingRight ? left : right), (facingRight ? right : left), yPos, yPos + textureHeight);

    Entity.drawMiniHealthBar(xPos, yPos + textureHeight, ghost.getAmtHealth());
  }
示例#13
0
  public static boolean collisionDetected(Entity e1, Entity e2) {

    /*
     * Two rectangles do not overlap when one is above/below, or to the
     * left/right of the other rectangle.
     */

    int e1x1 = e1.getX();
    int e1x2 = e1.getX() + e1.getWidth();
    int e1y1 = e1.getY();
    int e1y2 = e1.getY() + e1.getHeight();
    int e2x1 = e2.getX();
    int e2x2 = e2.getX() + e2.getWidth();
    int e2y1 = e2.getY();
    int e2y2 = e2.getY() + e2.getHeight();

    return ((e1x2 >= e2x1) && (e1y2 >= e2y1) && (e1x1 <= e2x2) && (e1y1 <= e2y2));
  }
 public BlockAnimation(Entity en, int type) {
   super(en);
   if (type == 1) getImages().add(en.getParser().getImage("Grass"));
   else if (type == 2) getImages().add(en.getParser().getImage("Block"));
 }
示例#15
0
 @Override
 public void setCurrentAnimation(String newAnimation, int frameDuration) {
   super.setCurrentAnimation(newAnimation, frameDuration);
 }
示例#16
0
  public CornellBoxScene(int seed) {
    cameraPos = new DVector(0, 0, -1);

    ents = new Vector<Entity>();

    Random rand = new Random(1337 + seed);

    ambientlight = 1;

    // overhead light
    Entity object = new Sphere(new DVector(0, -102, 2), 100.003);
    object.lightlevel = 20;
    object.diffuse = 1;
    object.absorb_wavelength1 = 400;
    object.absorb_amount1 = 0;
    object.absorb_width1 = 200;
    ents.add(object);

    // planes

    // floor
    object = new Plane(new DVector(0, 2, 0), new DVector(0, -1, 0));
    object.lightlevel = 0;
    object.diffuse = 0.9;
    object.focus = 1;
    ents.add(object);

    // backwall
    object = new Plane(new DVector(0, 0, 6), new DVector(0, 0, -1));
    object.lightlevel = 0;
    object.diffuse = 0.9;
    object.focus = 0.1;
    ents.add(object);

    // ceiling
    object = new Plane(new DVector(0, -2, 0), new DVector(0, 1, 0));
    object.lightlevel = 0;
    object.diffuse = 0.9;
    object.focus = 0.1;
    ents.add(object);

    // leftwall
    object = new Plane(new DVector(-2, 0, 0), new DVector(1, 0, 0));
    object.lightlevel = 0;
    object.diffuse = 0.9;
    object.focus = 0.1;
    object.absorb_wavelength1 = 540;
    object.absorb_amount1 = 1;
    object.absorb_width1 = 50;
    ents.add(object);

    // rightwall
    object = new Plane(new DVector(2, 0, 0), new DVector(-1, 0, 0));
    object.lightlevel = 0;
    object.diffuse = 0.9;
    object.focus = 0.1;
    object.absorb_wavelength1 = 610;
    object.absorb_amount1 = 1;
    object.absorb_width1 = 50;
    ents.add(object);

    // props

    object = new Sphere(new DVector(1.0, 1.2, 5.0), 0.8);
    object.lightlevel = 0; // Math.round(rand.nextDouble()*0.8f)*5;
    object.diffuse = 0.9;
    object.focus = 5;
    object.absorb_wavelength1 = 0;
    object.absorb_amount1 = 0;
    object.absorb_width1 = 0;
    ents.add(object);

    object = new Sphere(new DVector(-0.5, 1.0, 4), 1);
    object.lightlevel = 0; // Math.round(rand.nextDouble()*0.8f)*5;
    object.diffuse = 0.9;
    object.focus = 1;
    object.absorb_wavelength1 = 0;
    object.absorb_amount1 = 0;
    object.absorb_width1 = 0;
    ents.add(object);
  }