diff options
-rw-r--r-- | src/ru/olamedia/Options.java | 5 | ||||
-rw-r--r-- | src/ru/olamedia/math/Matrix4f.java | 191 | ||||
-rw-r--r-- | src/ru/olamedia/math/Matrix4fUtil.java | 36 | ||||
-rw-r--r-- | src/ru/olamedia/math/TransformMatrix.java | 15 | ||||
-rw-r--r-- | src/ru/olamedia/math/ViewMatrix.java | 111 | ||||
-rw-r--r-- | src/ru/olamedia/olacraft/inventory/Frame.java | 44 | ||||
-rw-r--r-- | src/ru/olamedia/olacraft/render/jogl/BlockRenderer.java | 87 | ||||
-rw-r--r-- | src/ru/olamedia/olacraft/render/jogl/ChunkRenderer.java | 168 | ||||
-rw-r--r-- | src/ru/olamedia/olacraft/world/World.java | 12 |
9 files changed, 0 insertions, 669 deletions
diff --git a/src/ru/olamedia/Options.java b/src/ru/olamedia/Options.java deleted file mode 100644 index 9adf252..0000000 --- a/src/ru/olamedia/Options.java +++ /dev/null @@ -1,5 +0,0 @@ -package ru.olamedia; - -public class Options { - public static int renderDistance = 128; -} diff --git a/src/ru/olamedia/math/Matrix4f.java b/src/ru/olamedia/math/Matrix4f.java deleted file mode 100644 index 1ce2eb6..0000000 --- a/src/ru/olamedia/math/Matrix4f.java +++ /dev/null @@ -1,191 +0,0 @@ -package ru.olamedia.math; - -import static org.openmali.FastMath.*; - -// 4x4 float matrix, column-major notation -public class Matrix4f { - protected float[] m; - - public Matrix4f() { - m = new float[16]; - } - - public Matrix4f(float[] m) { - this.m = m; - } - - public Matrix4f(javax.vecmath.Matrix4f m2) { - m = new float[16]; - m[0] = m2.m00; - m[1] = m2.m10; - m[2] = m2.m20; - m[3] = m2.m30; - m[4] = m2.m01; - m[5] = m2.m11; - m[6] = m2.m21; - m[7] = m2.m31; - m[8] = m2.m02; - m[9] = m2.m12; - m[10] = m2.m22; - m[11] = m2.m32; - m[12] = m2.m03; - m[13] = m2.m13; - m[14] = m2.m23; - m[15] = m2.m33; - } - - public float[] toFloatArray() { - return m; - } - - public void set(int i, float v) { - m[i] = v; - } - - public float get(int i) { - return m[i]; - } - - public void loadIdentity() { - setIdentity(); - } - - public void setIdentity() { - m[0] = m[5] = m[10] = m[15] = 1.0f; - m[1] = m[2] = m[3] = m[4] = 0.0f; - m[6] = m[7] = m[8] = m[9] = 0.0f; - m[11] = m[12] = m[13] = m[14] = 0.0f; - } - - public static Matrix4f translateMatrix(float x, float y, float z) { - Matrix4f m = new Matrix4f(); - m.setIdentity(); - // Translate slots. - m.set(12, x); - m.set(13, y); - m.set(14, z); - return m; - } - - public static Matrix4f scaleMatrix(float sx, float sy, float sz) { - Matrix4f m = new Matrix4f(); - m.setIdentity(); - // Scale slots. - m.set(0, sx); - m.set(5, sy); - m.set(10, sz); - return m; - } - - public static Matrix4f rotateXMatrix(float degrees) { - float radians = toRad(degrees); - float c = cos(radians); - float s = sin(radians); - Matrix4f m = new Matrix4f(); - m.setIdentity(); - // Rotate X formula. - m.set(5, c); - m.set(6, -s); - m.set(9, s); - m.set(10, c); - return m; - } - - public static Matrix4f rotateYMatrix(float degrees) { - float radians = toRad(degrees); - float c = cos(radians); - float s = sin(radians); - Matrix4f m = new Matrix4f(); - m.setIdentity(); - // Rotate Y formula. - m.set(0, c); - m.set(2, s); - m.set(8, -s); - m.set(10, c); - return m; - } - - public static Matrix4f rotateZMatrix(float degrees) { - float radians = toRad(degrees); - float c = cos(radians); - float s = sin(radians); - Matrix4f m = new Matrix4f(); - m.setIdentity(); - // Rotate Z formula. - m.set(0, c); - m.set(1, s); - m.set(4, -s); - m.set(5, c); - return m; - } - - public Vector3f getUpVector() { - return new Vector3f(m[1], m[5], m[9]); - } - - public Vector3f getLookVector() { // POSITIVE_Z - return new Vector3f(m[2], m[6], m[10]); - } - - public Vector3f getRightVector() { - return new Vector3f(m[0], m[4], m[8]); - } - - public Matrix4f multiply(Matrix4f m) { - return Matrix4fUtil.multiply(this, m); - } - - public void apply(Matrix4f m) { - this.m = multiply(m).toFloatArray(); - } - - public float[] getAngles() { - // TODO check majority - float ax, ay, az; - float cy; - ay = -asin(m[2]); /* Calculate Y-axis angle */ - cy = cos(ay); - ay = toDeg(ay); - float trX, trY; - - if (Math.abs(cy) > 0.005) /* Gimball lock? */ - { - trX = m[10] / cy; /* No, so get X-axis angle */ - trY = -m[6] / cy; - - ax = toDeg(atan2(trY, trX)); - - trX = m[0] / cy; /* Get Z-axis angle */ - trY = -m[1] / cy; - - az = toDeg(atan2(trY, trX)); - } else /* Gimball lock has occurred */ - { - ax = 0; /* Set X-axis angle to zero */ - - trX = m[5]; /* And calculate Z-axis angle */ - trY = m[4]; - - az = toDeg(atan2(trY, trX)); - } - - ax = clamp(ax, 0, 360); /* Clamp all angles to range */ - ay = clamp(ay, 0, 360); - az = clamp(az, 0, 360); - return new float[] { ax, ay, ax }; - } - - private float clamp(float a, float min, float max) { - a = a % max; - return a; - } - - public float c(int column, int row) { - // COLUMN-BASED - return m[column * 4 + row]; - } - - public void set(float[] m) { - this.m = m; - } -} diff --git a/src/ru/olamedia/math/Matrix4fUtil.java b/src/ru/olamedia/math/Matrix4fUtil.java deleted file mode 100644 index 46d153e..0000000 --- a/src/ru/olamedia/math/Matrix4fUtil.java +++ /dev/null @@ -1,36 +0,0 @@ -package ru.olamedia.math; - -public class Matrix4fUtil { - public static Matrix4f multiply(Matrix4f m1, Matrix4f m2) { - return new Matrix4f(multiply(m1.toFloatArray(), m2.toFloatArray())); - } - - // MATRIX MULTIPLICATION - public static float[] multiply(float[] m1, float[] m2) { - float[] result = new float[16]; - // First Column - result[0] = m1[0] * m2[0] + m1[4] * m2[1] + m1[8] * m2[2] + m1[12] * m2[3]; - result[1] = m1[1] * m2[0] + m1[5] * m2[1] + m1[9] * m2[2] + m1[13] * m2[3]; - result[2] = m1[2] * m2[0] + m1[6] * m2[1] + m1[10] * m2[2] + m1[14] * m2[3]; - result[3] = m1[3] * m2[0] + m1[7] * m2[1] + m1[11] * m2[2] + m1[15] * m2[3]; - - // Second Column - result[4] = m1[0] * m2[4] + m1[4] * m2[5] + m1[8] * m2[6] + m1[12] * m2[7]; - result[5] = m1[1] * m2[4] + m1[5] * m2[5] + m1[9] * m2[6] + m1[13] * m2[7]; - result[6] = m1[2] * m2[4] + m1[6] * m2[5] + m1[10] * m2[6] + m1[14] * m2[7]; - result[7] = m1[3] * m2[4] + m1[7] * m2[5] + m1[11] * m2[6] + m1[15] * m2[7]; - - // Third Column - result[8] = m1[0] * m2[8] + m1[4] * m2[9] + m1[8] * m2[10] + m1[12] * m2[11]; - result[9] = m1[1] * m2[8] + m1[5] * m2[9] + m1[9] * m2[10] + m1[13] * m2[11]; - result[10] = m1[2] * m2[8] + m1[6] * m2[9] + m1[10] * m2[10] + m1[14] * m2[11]; - result[11] = m1[3] * m2[8] + m1[7] * m2[9] + m1[11] * m2[10] + m1[15] * m2[11]; - - // Fourth Column - result[12] = m1[0] * m2[12] + m1[4] * m2[13] + m1[8] * m2[14] + m1[12] * m2[15]; - result[13] = m1[1] * m2[12] + m1[5] * m2[13] + m1[9] * m2[14] + m1[13] * m2[15]; - result[14] = m1[2] * m2[12] + m1[6] * m2[13] + m1[10] * m2[14] + m1[14] * m2[15]; - result[15] = m1[3] * m2[12] + m1[7] * m2[13] + m1[11] * m2[14] + m1[15] * m2[15]; - return result; - } -} diff --git a/src/ru/olamedia/math/TransformMatrix.java b/src/ru/olamedia/math/TransformMatrix.java deleted file mode 100644 index 6f2ea9d..0000000 --- a/src/ru/olamedia/math/TransformMatrix.java +++ /dev/null @@ -1,15 +0,0 @@ -package ru.olamedia.math; - -public class TransformMatrix extends Matrix4f { - public void applyTranslation(Matrix4f m) { - apply(m); - } - - public void applyRotation(Matrix4f m) { - apply(m); - } - - public void applyScale(Matrix4f m) { - apply(m); - } -} diff --git a/src/ru/olamedia/math/ViewMatrix.java b/src/ru/olamedia/math/ViewMatrix.java deleted file mode 100644 index dad4778..0000000 --- a/src/ru/olamedia/math/ViewMatrix.java +++ /dev/null @@ -1,111 +0,0 @@ -package ru.olamedia.math; - -public class ViewMatrix extends Matrix4f { - private Matrix4f translation = new Matrix4f(); - private Matrix4f scale = new Matrix4f(); - private Matrix4f rotation = new Matrix4f(); - private TransformMatrix transform = new TransformMatrix(); - - public ViewMatrix() { - translation.setIdentity(); - scale.setIdentity(); - rotation.setIdentity(); - transform.setIdentity(); - pack(); - } - - public void pack() { - loadIdentity(); - transform.loadIdentity(); - transform.applyScale(scale); - transform.applyRotation(rotation); - transform.applyTranslation(translation); - apply(transform); - @SuppressWarnings("unused") - float[] t = transform.toFloatArray(); - - // this.m[12] = 0; - // this.m[13] = 0; - // this.m[14] = 0; - // Fill translation: - // this.m[3] = -(t[0] * t[12] + t[1] * t[13] + t[2] * t[14]); - // this.m[7] = -(t[4] * t[12] + t[5] * t[13] + t[6] * t[14]); - // this.m[11] = (t[8] * t[12] + t[9] * t[13] + t[10] * t[14]); - // m[12] = -(t[0] * t[12] + t[1] * t[13] + t[2] * t[14]); - // m[13] = -(t[4] * t[12] + t[5] * t[13] + t[6] * t[14]); - // m[14] = (t[8] * t[12] + t[9] * t[13] + t[10] * t[14]); - } - - public float getX() { - return -translation.get(12); - } - - public float getY() { - return -translation.get(13); - } - - public float getZ() { - return -translation.get(14); - } - - /** - * @return the translation - */ - public Matrix4f getTranslation() { - return translation; - } - - /** - * @param translation - * the translation to set - */ - public void setTranslation(Matrix4f translation) { - this.translation = translation; - } - - /** - * @return the scale - */ - public Matrix4f getScale() { - return scale; - } - - /** - * @param scale - * the scale to set - */ - public void setScale(Matrix4f scale) { - this.scale = scale; - } - - /** - * @return the rotation - */ - public Matrix4f getRotation() { - return rotation; - } - - /** - * @param rotation - * the rotation to set - */ - public void setRotation(Matrix4f rotation) { - this.rotation = rotation; - } - - public void rotateX(float degrees) { - setRotation(getRotation().multiply(Matrix4f.rotateXMatrix(degrees))); - } - - public void rotateY(float degrees) { - setRotation(getRotation().multiply(Matrix4f.rotateYMatrix(degrees))); - } - - public void rotateZ(float degrees) { - setRotation(getRotation().multiply(Matrix4f.rotateZMatrix(degrees))); - } - - public Matrix4f getTransform() { - return transform; - } -} diff --git a/src/ru/olamedia/olacraft/inventory/Frame.java b/src/ru/olamedia/olacraft/inventory/Frame.java deleted file mode 100644 index a5cd979..0000000 --- a/src/ru/olamedia/olacraft/inventory/Frame.java +++ /dev/null @@ -1,44 +0,0 @@ -package ru.olamedia.olacraft.inventory; - -import org.olamedia.olacraft.draw.DrawInterface; -import org.olamedia.olacraft.entity.AbstractEntity; - -import static org.olamedia.olacraft.blocks.Block.BLOCK_SIZE; -import org.olamedia.olacraft.util.CommonApi; - -public class Frame extends AbstractEntity implements DrawInterface { - public Frame(double x, double y, double z, double width, double height, - double depth) { - super(x, y, z, width, height, depth); - } - - public CommonApi api = CommonApi.instance; - - @Override - public void update(double delta) { - - } - - @Override - public void draw() { - api.draw.texRecti("inventory_frame", x, y, BLOCK_SIZE, BLOCK_SIZE); - return; - // Texture t = api.texture.get("inventory_frame"); - // t.bind(); - // glColor3f(1, 1, 1); - // glLoadIdentity(); - // glTranslated(x, y, 0); - // glBegin(GL_QUADS); - // glTexCoord2f(0, 0); - // glVertex2f(0, 0); // Upper-left - // glTexCoord2f(1, 0); - // glVertex2f(BLOCK_SIZE, 0); // Upper-right - // glTexCoord2f(1, 1); - // glVertex2f(BLOCK_SIZE, BLOCK_SIZE); // Bottom-right - // glTexCoord2f(0, 1); - // glVertex2f(0, BLOCK_SIZE); // Bottom-left - // glEnd(); - // glLoadIdentity(); - } - -} 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); - } - } - } -} diff --git a/src/ru/olamedia/olacraft/world/World.java b/src/ru/olamedia/olacraft/world/World.java deleted file mode 100644 index e3d25f2..0000000 --- a/src/ru/olamedia/olacraft/world/World.java +++ /dev/null @@ -1,12 +0,0 @@ -package ru.olamedia.olacraft.world; - -import ru.olamedia.olacraft.world.block.BlockRegistry; -import ru.olamedia.olacraft.world.blockTypes.GrassBlockType; - -public class World { - private BlockRegistry blockRegistry; - public void setup() { - blockRegistry = new BlockRegistry(); - blockRegistry.registerBlockType(GrassBlockType.class); - } -} |