Package Hexel.math

Examples of Hexel.math.Vector3i


    Iterator<Map.Entry<Vector3i, GLChunk>> it = this.glChunkTable.entrySet().iterator();
    solidsShader.useProgram(gl, true);
    it = this.glChunkTable.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry<Vector3i, GLChunk> entry = it.next();
      Vector3i position = entry.getKey();
      GLChunk glChunk = entry.getValue();

      if (glChunk == null || glChunk.buffer == null)
        continue;

      gl.glPushMatrix();

      Vector2d hexPosition = new Vector2d();
      HexGeometry.hexToCartesian(position.x, position.y, hexPosition);

      gl.glTranslatef((float) (hexPosition.x * 16),
          (float) (hexPosition.y * 16), position.z * 16);

      gl.glBindBuffer(GL.GL_ARRAY_BUFFER, glChunk.buffer.id[0]);
      gl.glVertexAttribPointer(0, 3, GL.GL_FLOAT, false, 9*4, 0);
      gl.glVertexAttribPointer(1, 2, GL.GL_FLOAT, false, 9*4, 3*4);
      gl.glVertexAttribPointer(2, 4, GL.GL_FLOAT, false, 9*4, 5*4);
      gl.glEnableVertexAttribArray(0);
      gl.glEnableVertexAttribArray(1);
      gl.glEnableVertexAttribArray(2);
     
      float[] mv = new float[16];
      gl.glGetFloatv(GL2.GL_MODELVIEW_MATRIX, mv, 0);
      gl.glUniformMatrix4fv(ssUMVMatrix, 1, false, mv, 0);
      float[] p = new float[16];
      gl.glGetFloatv(GL2.GL_PROJECTION_MATRIX, p, 0);
      gl.glUniformMatrix4fv(ssUPMatrix, 1, false, p, 0);
     
      gl.glUniform1i(ssTex, 0);

      gl.glDrawArrays(GL.GL_TRIANGLES, 0, glChunk.buffer.size / (4 * 9));
     
      gl.glDisableVertexAttribArray(0);
      gl.glDisableVertexAttribArray(1);
      gl.glDisableVertexAttribArray(2);
      gl.glPopMatrix();
    }
    solidsShader.useProgram(gl, false);

    transparentsShader.useProgram(gl, true);
    it = this.glChunkTable.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry<Vector3i, GLChunk> entry = it.next();
      Vector3i position = entry.getKey();
      GLChunk glChunk = entry.getValue();

      if (glChunk == null || glChunk.buffer == null)
        continue;

View Full Code Here


    try {
      Chunk c = this.chunkCache.getIfPresent(cpos);
      if (c != null)
        return c;
      else
        return this.chunkCache.get(new Vector3i(cpos));
    } catch (Exception e) {
      System.out.println("Caught Exception retrieving chunk from cache!");
      e.printStackTrace();
      System.exit(1);
      return null;
View Full Code Here

    Vector2d a = new Vector2d();
    Vector2d b = new Vector2d();
    Vector2d c = new Vector2d();
    Vector2d d = new Vector2d();

    Vector3i tmp = new Vector3i();

    Rect r = new Rect();

    Color color = new Color();
View Full Code Here

  @Override
  public int freqRun(int bx, int by, final int bz, boolean fastMode, Block b, final Chunk c,
      HighestBlockChunk hbc, final Chunks chunks, int step, final BlockDeltaAdder blockDeltaAdder) {
    BlockWater bw = (BlockWater)b;
    final Vector3i start = new Vector3i(bx, by, bz);
    checkAgain = false;
    numSeen = 0;
    final int startWaterLevel = bz*8 + bw.getTop();
    lowestWaterLevel.contents = Integer.MAX_VALUE;
    lowestWaterPoint.contents = null;
View Full Code Here

      }
    });

    dirtRules.add(new SpawnBlockRule(engine, 100){

      private Vector3i tmp = new Vector3i();

      @Override
      public boolean blockMatches(int x, int y, int z, Block b, Chunk c, HighestBlockChunk hbc, Chunks chunks, int steps) {
        Block ab = chunks.getBlock(x, y, z+1, tmp, c);
        return ab instanceof BlockEmpty;
      }

      @Override
      public void spawn(double x, double y, double z, int bx, int by, int bz, int step, Chunk c, Chunks chunks) {
        if (engine.thingSimulator.getNumberOfThingsOfType(Deer.class) < 10){
          Deer deer = new Deer(x, y, z, engine.getThingBridge());
          engine.addThing(deer);
        }
      }
    });

    dirtRules.add(new SpawnBlockRule(engine, 100){

      private Vector3i tmp = new Vector3i();

      @Override
      public boolean blockMatches(int x, int y, int z, Block b, Chunk c, HighestBlockChunk hbc, Chunks chunks, int steps) {
        Block ab = chunks.getBlock(x, y, z+1, tmp, c);
        return ab instanceof BlockEmpty;
View Full Code Here

        @Override
        public boolean canApply(int bx, int by, int bz, boolean fastMode, Block b, Chunk c,
            HighestBlockChunk hbc, Chunks chunks, int step, BlockDeltaAdder blockDeltaAdder) {
          Vector3i[] neighbors = HexGeometry.getAllNeighbors(bx);
          Vector3i neighbor = neighbors[neighborIndex];
          BlockWood wb = (BlockWood) b;
          if (!wb.data.alive)
            return false;
          Block nb = chunks.getBlock(bx + neighbor.x, by + neighbor.y, bz + neighbor.z, tmp3i, c);
          if (!(nb instanceof BlockEmpty || nb instanceof BlockLeaf))
            return false;
         
          int nx = bx + neighbor.x;
          int ny = by + neighbor.y;
          int nz = bz + neighbor.z;
         
          boolean isBranch = nx != bx || ny != by;

          if (nz < bz)
            return false;
          if(wb.data.level < 4 && isBranch)
            return false;
 
          int h = 1;
          h = 31*h + nx;
          h = 31*h + ny;
          h = 31*h + nz;
         
          if (wb.data.level != 0){
            double chanceGrow = 0;
            if (isBranch){
              chanceGrow =   .5*((wb.data.level-wb.data.branchLevel)%2) +
                        .05*(wb.data.level-10)
                       )
                       *(1-wb.data.branchLevel*.25)
                       *(1-wb.data.branches*.25);
            }
            else {
              chanceGrow = 3.0 - .1*wb.data.level*(wb.data.branchLevel*10000+1);
            }
            if (Util.hashToDouble(h) > chanceGrow)
              return false;
          }
         
          return true;
        }

        @Override
        public int probabilisticRun(int bx, int by, int bz, boolean fastMode, Block b, Chunk c,
            HighestBlockChunk hbc, Chunks chunks, int step, BlockDeltaAdder blockDeltaAdder) {
          BlockWood wb = (BlockWood) b;
         
          Vector3i[] neighbors = HexGeometry.getAllNeighbors(bx);
          Vector3i neighbor = neighbors[neighborIndex];
         
          int nx = bx + neighbor.x;
          int ny = by + neighbor.y;
          int nz = bz + neighbor.z;
         
          boolean isBranch = nx != bx || ny != by;
         
          tmp3i.x = nx;
          tmp3i.y = ny;
          tmp3i.z = nz;
          if (blockDeltaAdder.hasBlockDelta(tmp3i)){
            return 1;
          }
          tmp3i.x = bx;
          tmp3i.y = by;
          tmp3i.z = bz;
          if (blockDeltaAdder.hasBlockDelta(tmp3i)){
            return 1;
          }

          BlockWood grownWB;
          BlockWood newWB;
          if (isBranch){
            grownWB = BlockWood.Make(new BlockWoodData(BlockWood.MAX_HEALTH, wb.data.level+1, wb.data.branchLevel+1, 0, true));
            newWB = BlockWood.Make(new BlockWoodData(BlockWood.MAX_HEALTH, wb.data.level, wb.data.branchLevel, wb.data.branches+1, true));
          }
          else {
            grownWB = BlockWood.Make(new BlockWoodData(BlockWood.MAX_HEALTH, wb.data.level+1, wb.data.branchLevel, 0, true));
            newWB = BlockWood.Make(new BlockWoodData(BlockWood.MAX_HEALTH, wb.data.level, wb.data.branchLevel, wb.data.branches, true));
          }
          blockDeltaAdder.addBlockDelta(BlockDelta.Aquire(nx, ny, nz, grownWB, chunks.getStepsToSim(bx, by, bz, tmp3i, c)));
          blockDeltaAdder.addBlockDelta(BlockDelta.Aquire(bx, by, bz, newWB, chunks.getStepsToSim(bx, by, bz, tmp3i, c)));
          return BlockSimulator.DONT_RUN;
        }
      });
//
      //==========LEAFS=========
      woodRules.add(new ProbabilisticFreqBlockRule(500, .5){
       
        @Override
        public boolean canApply(int bx, int by, int bz, boolean fastMode, Block b, Chunk c,
            HighestBlockChunk hbc, Chunks chunks, int step, BlockDeltaAdder blockDeltaAdder) {
          Vector3i[] neighbors = HexGeometry.getAllNeighbors(bx);
          Vector3i neighbor = neighbors[neighborIndex];
          BlockWood wb = (BlockWood) b;
          if (!wb.data.alive)
            return false;
          if(wb.data.level < 4)
            return false;
          if (!(chunks.getBlock(bx + neighbor.x, by + neighbor.y, bz + neighbor.z, tmp3i, c) instanceof BlockEmpty))
            return false;
         
          int nx = bx + neighbor.x;
          int ny = by + neighbor.y;
          int nz = bz + neighbor.z;
 
          int h = 1;
          h = 31*h + nx;
          h = 31*h + ny;
          h = 31*h + nz;
          if (wb.data.level != 0){
            double chanceGrow = 0;
            chanceGrow = Math.min(Math.max(.1*(wb.data.level-5), 0), .75) + Math.min(.5*wb.data.branchLevel, .75);
            if (Util.hashToDouble(h) > chanceGrow)
              return false;
          }
          return true;
        }

        @Override
        public int probabilisticRun(int bx, int by, int bz, boolean fastMode, Block b, Chunk c,
            HighestBlockChunk hbc, Chunks chunks, int step, BlockDeltaAdder blockDeltaAdder) {
          BlockWood wb = (BlockWood) b;
         
          Vector3i[] neighbors = HexGeometry.getAllNeighbors(bx);
          Vector3i neighbor = neighbors[neighborIndex];
         
          int nx = bx + neighbor.x;
          int ny = by + neighbor.y;
          int nz = bz + neighbor.z;
         
View Full Code Here

TOP

Related Classes of Hexel.math.Vector3i

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.