/** * Convert the world location into a cell location (integer coordinates) */ public Vector3f toCellSpace(Vector3f worldLocation) { Vector3f tileCell = getTileCell(worldLocation); tileCell = new Vector3f(Math.round(tileCell.x), tileCell.y, Math.round(tileCell.z)); return tileCell; }
/** * Get the terrain tile at the specified world location, in XZ coordinates. */ public Terrain getTerrainAt(Vector3f worldLocation) { if (worldLocation == null) return null; Vector3f tileCell = getTileCell(worldLocation.setY(0)); tileCell = new Vector3f(Math.round(tileCell.x), tileCell.y, Math.round(tileCell.z)); return cache.get(tileCell); }
@Override public Material getMaterial(Vector3f worldLocation) { if (worldLocation == null) return null; Vector3f tileCell = getTileCell(worldLocation); Terrain terrain = cache.get(tileCell); if (terrain == null) return null; // terrain not loaded for that cell yet! return terrain.getMaterial(worldLocation); }
/** * Get the location in cell-coordinates of the specified location. * Cell coordinates are integer corrdinates, usually with y=0, each * representing a cell in the world. * For example, moving right in the +X direction: * (0,0,0) (1,0,0) (2,0,0), (3,0,0) * and then down the -Z direction: * (3,0,-1) (3,0,-2) (3,0,-3) */ public Vector3f getCamCell(Vector3f location) { Vector3f tile = getTileCell(location); Vector3f offsetHalf = new Vector3f(-0.5f, 0, -0.5f); Vector3f shifted = tile.subtract(offsetHalf); return new Vector3f(FastMath.floor(shifted.x), 0, FastMath.floor(shifted.z)); }
protected void removeQuad(TerrainQuad q) { if (q != null && ( (q.getQuadrant() > 0 && q.getQuadrant()<5) || q.getParent() != null) ) { for (TerrainGridListener l : listeners) { l.tileDetached(getTileCell(q.getWorldTranslation()), q); } q.setQuadrant((short)0); this.detachChild(q); cellsLoaded++; // For gridoffset calc., maybe the run() method is a better location for this. } }
/** * Convert the world location into a cell location (integer coordinates) */ public Vector3f toCellSpace(Vector3f worldLocation) { Vector3f tileCell = getTileCell(worldLocation); tileCell = new Vector3f(Math.round(tileCell.x), tileCell.y, Math.round(tileCell.z)); return tileCell; }
/** * Get the terrain tile at the specified world location, in XZ coordinates. */ public Terrain getTerrainAt(Vector3f worldLocation) { if (worldLocation == null) return null; Vector3f tileCell = getTileCell(worldLocation.setY(0)); tileCell = new Vector3f(Math.round(tileCell.x), tileCell.y, Math.round(tileCell.z)); return cache.get(tileCell); }
@Override public Material getMaterial(Vector3f worldLocation) { if (worldLocation == null) return null; Vector3f tileCell = getTileCell(worldLocation); Terrain terrain = cache.get(tileCell); if (terrain == null) return null; // terrain not loaded for that cell yet! return terrain.getMaterial(worldLocation); }
/** * Get the location in cell-coordinates of the specified location. * Cell coordinates are integer corrdinates, usually with y=0, each * representing a cell in the world. * For example, moving right in the +X direction: * (0,0,0) (1,0,0) (2,0,0), (3,0,0) * and then down the -Z direction: * (3,0,-1) (3,0,-2) (3,0,-3) */ public Vector3f getCamCell(Vector3f location) { Vector3f tile = getTileCell(location); Vector3f offsetHalf = new Vector3f(-0.5f, 0, -0.5f); Vector3f shifted = tile.subtract(offsetHalf); return new Vector3f(FastMath.floor(shifted.x), 0, FastMath.floor(shifted.z)); }
protected void removeQuad(TerrainQuad q) { if (q != null && ( (q.getQuadrant() > 0 && q.getQuadrant()<5) || q.getParent() != null) ) { for (TerrainGridListener l : listeners) { l.tileDetached(getTileCell(q.getWorldTranslation()), q); } q.setQuadrant((short)0); this.detachChild(q); cellsLoaded++; // For gridoffset calc., maybe the run() method is a better location for this. } }