diff options
author | olamedia <[email protected]> | 2012-12-23 12:27:04 +0600 |
---|---|---|
committer | olamedia <[email protected]> | 2012-12-23 12:27:04 +0600 |
commit | 65b0b9afbaf8141e7b6fd807c7117e61b543d19b (patch) | |
tree | 470061ba1f00d335718fa7532fcc76b79c410d97 /src/ru/olamedia/olacraft/render/jogl | |
parent | fdd051d2b1abb6b96c1d1b58a5369a537d593a9c (diff) |
0.1.7.b
Diffstat (limited to 'src/ru/olamedia/olacraft/render/jogl')
-rw-r--r-- | src/ru/olamedia/olacraft/render/jogl/BlockRenderer.java | 87 | ||||
-rw-r--r-- | src/ru/olamedia/olacraft/render/jogl/ChunkRenderer.java | 168 |
2 files changed, 0 insertions, 255 deletions
diff --git a/src/ru/olamedia/olacraft/render/jogl/BlockRenderer.java b/src/ru/olamedia/olacraft/render/jogl/BlockRenderer.java deleted file mode 100644 index 6d96403..0000000 --- a/src/ru/olamedia/olacraft/render/jogl/BlockRenderer.java +++ /dev/null @@ -1,87 +0,0 @@ -package ru.olamedia.olacraft.render.jogl; - -import javax.media.opengl.GL; -import javax.media.opengl.GL2; -import javax.media.opengl.GLAutoDrawable; - -import com.jogamp.opengl.util.texture.Texture; -import com.jogamp.opengl.util.texture.TextureCoords; - -import ru.olamedia.geom.SimpleQuadMesh; -import ru.olamedia.olacraft.world.chunk.BlockSlice; -import ru.olamedia.texture.TextureManager; - -public class BlockRenderer { - private BlockSlice slice; - private SimpleQuadMesh mesh; - - public BlockRenderer(BlockSlice slice) { - this.slice = slice; - } - - public SimpleQuadMesh getMesh(GL glx) { - GL2 gl = glx.getGL2(); - // 14739 - SimpleQuadMesh mesh = new SimpleQuadMesh(999999); - mesh.useColor(); - mesh.useTexture(); - - gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, - GL.GL_NEAREST_MIPMAP_NEAREST); - gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, - GL.GL_NEAREST_MIPMAP_NEAREST); - gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_FASTEST); - gl.glHint(GL2.GL_LINE_SMOOTH_HINT, GL2.GL_NICEST); - Texture grass = TextureManager.get("texture/grass.png"); - int tex = grass.getTextureObject(gl); - - TextureCoords tc = grass.getImageTexCoords(); - // mesh.setTextureSize(tc.right(), tc.top()); - System.out.println(grass.getWidth() + " " + grass.getHeight() + " | " - + tc.left() + " " + tc.right() + " " + tc.top() + " " - + tc.bottom()); - mesh.setTextureSize(grass.getWidth(), grass.getHeight()); - for (int x = 0; x < slice.getWidth(); x++) { - for (int y = 0; y < slice.getHeight(); y++) { - for (int z = 0; z < slice.getDepth(); z++) { - mesh.setTranslation(x, y, z); - // mesh.setColor4f(0, 1, 0, 1); - mesh.setColor4f((float) Math.random(), - (float) Math.random(), (float) Math.random(), 1); - mesh.setGLTexture(tex); - if (y == 0) { - mesh.addBottomQuad(); - } - if (y == 3) { - // Math.random(); - mesh.addTopQuad(); - } - if (y < 4) { - if (x == 0) { - mesh.addLeftQuad(); - } - if (x == slice.getWidth() - 1) { - mesh.addRightQuad(); - } - if (z == 0) { - mesh.addBackQuad(); - } - if (z == slice.getDepth() - 1) { - mesh.addFrontQuad(); - } - } - } - } - } - mesh.endMesh(); - return mesh; - } - - public void render(GL glx) { - if (null == mesh) { - mesh = getMesh(glx); - } - mesh.joglRender(glx); - } - -} diff --git a/src/ru/olamedia/olacraft/render/jogl/ChunkRenderer.java b/src/ru/olamedia/olacraft/render/jogl/ChunkRenderer.java deleted file mode 100644 index 4aaf38c..0000000 --- a/src/ru/olamedia/olacraft/render/jogl/ChunkRenderer.java +++ /dev/null @@ -1,168 +0,0 @@ -package ru.olamedia.olacraft.render.jogl; - -import ru.olamedia.Options; -import ru.olamedia.geom.SimpleQuadMesh; -import ru.olamedia.math.Box; -import ru.olamedia.math.Classifier; -import ru.olamedia.olacraft.game.Game; -import ru.olamedia.olacraft.world.chunk.BlockSlice; -import ru.olamedia.olacraft.world.chunk.Chunk; -import ru.olamedia.olacraft.world.chunk.ChunkMeshBulder; -import ru.olamedia.olacraft.world.chunk.ChunkSlice; -import ru.olamedia.olacraft.world.location.BlockLocation; -import ru.olamedia.olacraft.world.location.ChunkLocation; - -public class ChunkRenderer { - private BlockSlice slice; - - public ChunkRenderer(BlockSlice slice) { - this.slice = slice; - } - - public int testedChunks = 0; - - public int visibleTop = 0; - public int visibleBottom = 0; - public int visibleLeft = 0; - public int visibleRight = 0; - public int visibleFront = 0; - public int visibleBack = 0; - - public int frustumCulledChunks = 0; - public int frustumIntersectChunks = 0; - - public boolean renderChunk(Chunk chunk, boolean skipnew) { - float d = (float) Math.sqrt(Math.pow(chunk.getOffset().x + 8 - cameraBlock.x, 2) - + Math.pow(chunk.getOffset().y + 8 - cameraBlock.y, 2) - + Math.pow(chunk.getOffset().z + 8 - cameraBlock.z, 2)); - if (d > Options.renderDistance) { - return skipnew; - } - testedChunks++; - if (!chunk.inWorldRange()) { - return skipnew; - } - Box box = new Box(chunk.getOffset().x, chunk.getOffset().y, chunk.getOffset().z, chunk.getOffset().x - + chunk.getWidth(), chunk.getOffset().y + chunk.getHeight(), chunk.getOffset().z + chunk.getDepth()); - if (Game.instance.camera.frustum.quickClassify(box) == Classifier.OUTSIDE) { - frustumCulledChunks++; - return skipnew; - } - - chunk.render(); - if (!chunk.isMeshCostructed) { - if (!chunk.isAvailable()) { - // System.out.println("not available " + chunk); - chunk.request(); - return skipnew; - } - - if (!chunk.isNeighborsAvailable()) { - // System.out.println("not available " + chunk); - chunk.requestNeighbors(); - return skipnew; - } - // compute visibility - - // System.out.println("available"); - - // // boolean inside = true; - // if (Game.camera.frustum != null) { - // if (Game.camera.frustum.quickClassify(box) == - // Classifier.Classification.OUTSIDE) { - // frustumCulledChunks++; - // return; - // } - // } - // } else if (Game.camera.frustum.test(box) == Classifier.INTERSECT) - // { - // inside = false; - // frustumIntersectChunks++; - // } else { - // frustumCulledChunks++; - // return; - // } - if (!chunk.isMeshCostructed) { - if (skipnew) { - return skipnew; - } - } - if (!chunk.isMeshCostructed) { - ChunkMeshBulder.instance.add(chunk); - if (ChunkMeshBulder.instance.isFull()) { - // System.out.println("queue is full, skipping"); - skipnew = true; - } - // System.out.println("not constructed"); - return skipnew; - } - - return skipnew; - } else { - return skipnew; - } - } - - BlockLocation cameraBlock; - ChunkLocation cameraChunk; - int distance; - public ChunkSlice chunkSlice; - - public void render() { - - if (!ChunkMeshBulder.instance.isAlive() && !ChunkMeshBulder.instance.isInterrupted()) { - ChunkMeshBulder.instance.start(); - } - if (null == chunkSlice) { - chunkSlice = slice.getChunkSlice(); - } - testedChunks = 0; - visibleTop = 0; - visibleBottom = 0; - visibleLeft = 0; - visibleRight = 0; - visibleFront = 0; - visibleBack = 0; - frustumCulledChunks = 0; - - cameraBlock = Game.client.getScene().getPlayer().getCameraBlockLocation(); - cameraChunk = cameraBlock.getChunkLocation(); - ChunkLocation renderLoc; - - boolean skipnew = false; - - for (distance = 0; distance <= Options.renderDistance / 16; distance++) { - if (distance > 0) { - int shortDistance = distance - 1; - renderLoc = new ChunkLocation(cameraChunk); - for (renderLoc.x = cameraChunk.x - distance; renderLoc.x <= cameraChunk.x + distance; renderLoc.x += distance * 2) { - // render ZY sides - for (renderLoc.y = cameraChunk.y - distance; renderLoc.y <= cameraChunk.y + distance; renderLoc.y++) { - for (renderLoc.z = cameraChunk.z - distance; renderLoc.z <= cameraChunk.z + distance; renderLoc.z++) { - skipnew = renderChunk(chunkSlice.getChunk(renderLoc), skipnew); - } - } - } - for (renderLoc.z = cameraChunk.z - distance; renderLoc.z <= cameraChunk.z + distance; renderLoc.z += distance * 2) { - // render XY sides - for (renderLoc.x = cameraChunk.x - shortDistance; renderLoc.x <= cameraChunk.x + shortDistance; renderLoc.x++) { - for (renderLoc.y = cameraChunk.y - distance; renderLoc.y <= cameraChunk.y + distance; renderLoc.y++) { - skipnew = renderChunk(chunkSlice.getChunk(renderLoc), skipnew); - } - } - } - for (renderLoc.y = cameraChunk.y - distance; renderLoc.y <= cameraChunk.y + distance; renderLoc.y += distance * 2) { - // render XZ sides - for (renderLoc.x = cameraChunk.x - shortDistance; renderLoc.x <= cameraChunk.x + shortDistance; renderLoc.x++) { - for (renderLoc.z = cameraChunk.z - shortDistance; renderLoc.z <= cameraChunk.z + shortDistance; renderLoc.z++) { - skipnew = renderChunk(chunkSlice.getChunk(renderLoc), skipnew); - } - } - } - } else { - renderLoc = new ChunkLocation(cameraChunk); - skipnew = renderChunk(chunkSlice.getChunk(renderLoc), skipnew); - } - } - } -} |