Package Hexel.math

Examples of Hexel.math.Vector3d


    this.thingBridge = thingBridge;
  }

  @Override
  public Vector3d getReqMoveVector(double fps) {
    Vector3d v = new Vector3d();
    double dragZ = 1;
    double dragXY = 1;
    if (this.thingBridge.inWater(this)) {
      dragZ = .5;
      dragXY = .75;
View Full Code Here


    double x = Math.cos(Math.toRadians(90 + this.headZRot))
        * Math.cos(Math.toRadians(this.headXRot));
    double y = Math.sin(Math.toRadians(90 + this.headZRot))
        * Math.cos(Math.toRadians(this.headXRot));
    double z = Math.sin(Math.toRadians(this.headXRot));
    return new Vector3d(x, y, z);
  }
View Full Code Here

  }

  @Override
  public void render(GL2 gl) {

    Vector3d dir = getDirectionLooking();
    dir.times(10);

    Vector3i closestBlock = this.thingBridge
        .getClosestNonEmptyBlockOnVector(
            new Vector3d(getCameraX(), getCameraY(), getCameraZ()), dir);

    Vector3i closestEmptyBlock = this.thingBridge
        .getClosestEmptyBlockOnVector(new Vector3d(getCameraX(),
            getCameraY(), getCameraZ()), dir);

    if (closestBlock != null) {
      Face f = HighlightBlockFace.getBetweenFace(closestBlock,
          closestEmptyBlock);
View Full Code Here

    return this.inventory.numBlock(c);
  }

  @Override
  public BlockAction getBlockAction() {
    Vector3d dir = getDirectionLooking();
    dir.times(10);

    if (this.createBlock) {
      lastDeleteBlock = this.deleteBlock;
      this.createBlock = false;
      if (!this.inventory.hasBlock(this.blockToPlace))
        return null;
      Vector3i closestBlock = this.thingBridge
          .getClosestEmptyBlockOnVector(
              new Vector3d(getCameraX(), getCameraY(),
                  getCameraZ()), dir);
      if (closestBlock != null) {
        AddBlock ab = new AddBlock();
        ab.x = closestBlock.x;
        ab.y = closestBlock.y;
        ab.z = closestBlock.z;
        ab.block = getBlockToPlace();
        return ab;
      } else {
        return null;
      }
    } else if (this.deleteBlock) {
      boolean justClickedDelete = this.deleteBlock != lastDeleteBlock;
      lastDeleteBlock = this.deleteBlock;
      this.deleteBlock = false;
      ArrayList<Vector3i> blocksAttacking = this.thingBridge.getNonEmptyBlocksOnVector(
          new Vector3d(getCameraX(), getCameraY(), getCameraZ()), dir);
      Set<Thing> things = this.thingBridge.getIntersectingThings(blocksAttacking);
      things.remove(this);
      if (things.size() > 0){
        if (justClickedDelete){
          for (Thing thing : things){
View Full Code Here

  public ArrayList<Vector3i> getNonEmptyBlocksOnVector(Vector3d offset, Vector3d t){
    ArrayList<Vector3i> blocks = new ArrayList<Vector3i>();
    double STEP_SIZE = .01;

    Vector3d v = new Vector3d();
    Vector3d step = Vector3d.Sub(t, v);
    step.unit();
    step.times(STEP_SIZE);

    Vector2d tmp2d = new Vector2d();
    Vector3i tmp3i = new Vector3i();

    Vector3i blockPos = new Vector3i();
View Full Code Here

  }

  public Vector3i getClosestNonEmptyBlockOnVector(Vector3d offset, Vector3d t) {
    double STEP_SIZE = .01;

    Vector3d v = new Vector3d();
    Vector3d step = Vector3d.Sub(t, v);
    step.unit();
    step.times(STEP_SIZE);

    Vector2d tmp2d = new Vector2d();
    Vector3i tmp3i = new Vector3i();

    Vector3i blockPos = new Vector3i();
View Full Code Here

  }

  public Vector3i getClosestEmptyBlockOnVector(Vector3d offset, Vector3d t) {
    double STEP_SIZE = .01;

    Vector3d v = new Vector3d();
    Vector3d step = Vector3d.Sub(t, v);
    step.unit();
    step.times(STEP_SIZE);

    Vector3i farthestEmpty = new Vector3i();
    Vector3i blockPos = new Vector3i();

    Vector2d tmp2d = new Vector2d();
View Full Code Here

    this.thingsToAdd.add(thing);
  }

  public void step(double fps) {
    Vector3i tmp = Resources.vector3iResourcePool.aquire();
    Vector3d tmp3d = Resources.vector3dResourcePool.aquire();
    Vector2i tmp2 = Resources.vector2iResourcePool.aquire();
    synchronized (this.things){
      thingsToRemove.clear();
      for (Thing t : this.thingsToAdd){
        this.things.add(t);
        if (t instanceof Player)
          this.thingBridge.player = (Player)t;
      }
      this.thingsToAdd.clear();
      Iterator<Thing> iter = this.things.iterator();
      LogData.set("numberZombies", getNumberOfThingsOfType(Zombie.class));
      while (iter.hasNext()) {
        Thing thing = iter.next();
        thing.step();

        if (thing instanceof Volumetric){
          if (this.thingTools.isOutOfRangeOfCamera((Volumetric)thing)){
            thingsToRemove.add(thing);
            continue;
          }
        }
       
        if (thing instanceof Player){
          Player player = (Player)thing;
          player.hunger -= 1.0/(60*60*10);
          if (player.isDead() && engine.camera == player){
            LinearCamera fc = new LinearCamera(player.getCameraX(), player.getCameraY(), player.getCameraZ(), 0, 0,
                              0, 0, .01, 0, 0);
            engine.addThing(fc);
            engine.setCamera(fc);
          }
        }
        else if (thing instanceof Zombie){
          Zombie zombie = (Zombie)thing;
          if (zombie.health <= 0){
            thingsToRemove.add(zombie);
          }
        }
        else if (thing instanceof Deer){
          Deer deer = (Deer)thing;
          if (deer.health <= 0){
            thingsToRemove.add(deer);
          }
        }

        if (thing instanceof Movable) {
          Movable movable = (Movable) thing;
          movable.accelerate(fps, 0, 0, -9.8);
          Vector3d reqMoveVector = movable.getReqMoveVector(fps);
          moveMovable(movable, reqMoveVector, tmp);
        }
        if (thing instanceof BlockManipulator) {
          BlockAction action = ((BlockManipulator) thing)
              .getBlockAction();
          if (action instanceof AddBlock) {
            AddBlock addBlockAction = (AddBlock) action;
            Block original = this.chunks.getBlock(addBlockAction.x, addBlockAction.y, addBlockAction.z, tmp, (Chunk)null);
            this.chunks.setBlock(addBlockAction.x, addBlockAction.y, addBlockAction.z, addBlockAction.block, tmp, tmp2, null);
            if (thing instanceof Volumetric) {
              if (thing instanceof Cuboid) {
                Vector3d offset = Resources.vector3dResourcePool.aquire();
                offset.x = 0;
                offset.y = 0;
                offset.z = 0;
                if (this.thingTools.fixOffset((Cuboid) thing,
                    offset, false, this.fixOffsetTmps) != null)
View Full Code Here

    return Math.abs(a - b) < epsilon;
  }

  public void moveMovable(Movable movable, Vector3d reqMoveVector, Vector3i tmp){

    Vector3d partialMove = new Vector3d(reqMoveVector);

    partialMove.unit();
    partialMove.times(.2);
    Vector3d leftToMove = new Vector3d(reqMoveVector);
    while (leftToMove.mag() > 0){
      if (leftToMove.mag() > partialMove.mag()){
        Movement movement = getMovement((Volumetric) movable,
            partialMove, tmp);
        if (movement.stoppedZ) {
          movable.stopZ();
        }
        movable.applyMoveVector(movement);
        leftToMove.sub(partialMove);
      }
      else {
        Movement movement = getMovement((Volumetric) movable,
            leftToMove, tmp);
        if (movement.stoppedZ) {
          movable.stopZ();
        }
        movable.applyMoveVector(movement);
        leftToMove.sub(leftToMove);
      }
    }

  }
View Full Code Here

  public Movement getMovement(Volumetric v, Vector3d reqMoveVector,
      Vector3i tmp) {
    Movement m = new Movement(reqMoveVector);

    Vector3d toFix = null;
    if (v instanceof Cuboid) {
      toFix = this.thingTools.fixOffset(new PaddedCuboid((Cuboid)v, .1, .1, 0), reqMoveVector, true, this.fixOffsetTmps);
      if (toFix != null) {
        m.add(toFix);
        Vector3d afterFix = this.thingTools.fixOffset((Cuboid) v, new Vector3d(m.x, m.y, m.z-.1), true, this.fixOffsetTmps);
        m.stoppedZ = afterFix != null || toFix.mag() == Math.abs(toFix.z);
      }
    }

    return m;
View Full Code Here

TOP

Related Classes of Hexel.math.Vector3d

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.