internal bool collides(World world, Vector3 position, Vector3 radii, int x, int y, int z) { return !( position.X + radii.X < x - .5 || position.Y + radii.Y < y - .5 || position.Z + radii.Z < y - .5 || position.X - radii.X > x + .5 || position.Y - radii.Y > y + .5 || position.Z - radii.Z > z + .5 ); }
public void resetVbo(World world) { vbo.begin(BeginMode.Quads, true, true); int x, y, z; for (int i = 0; i < chunkSize.x; i++) { for (int j = 0; j < chunkSize.y; j++) { for (int k = 0; k < chunkSize.z; k++) { x = i + (chunkPosition.x * chunkSize.x); y = j + (chunkPosition.y * chunkSize.y); z = k + (chunkPosition.z * chunkSize.z); int b = blockArray[i, j, k]; addCubeToVbo(Block.getBlock(b), x, y, z, world); } } } vbo.end(); Console.WriteLine("Chunk Vbo Reset "+chunkPosition.ToString()); }
public Chunk(Vector3i pos, World world, Game game) { this.chunkPosition = new Vector3i(pos.x, pos.y, pos.z); vbo = new VboGroup(game); fileName = world.directory + "\\chunk_" + chunkPosition.getSafeString()+".chunk"; bool loaded = false; if (File.Exists(fileName)) { loaded = load(); } if (!loaded) { generate(game, world); save(); Console.WriteLine("Generate Chunk"); } else { Console.WriteLine("Loaded Chunk"); } this.world = world; }
public void render(Game game, World world) { vbo.render(game); }
private void generate(Game game, World world) { setBlock(0, 0, 0, Block.stone); }
private void addCubeToVbo(Block block, int x, int y, int z, World world) { block.addToVbo(world, this, vbo, x, y, z); }
internal void update(Game game, World world) { if (needsVboReset) { needsVboReset = false; resetVbo(world); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); OpenTK.Input.Mouse.SetPosition(Bounds.X + Bounds.Width / 2, Bounds.Y + Bounds.Height / 2); System.IO.Directory.SetCurrentDirectory(System.IO.Directory.GetCurrentDirectory() + "\\..\\..\\"); Console.WriteLine(System.IO.Directory.GetCurrentDirectory() + ""); textureMapID = loadTexture("textureMap.png"); vertexShader = GL.CreateShader(ShaderType.VertexShader); GL.ShaderSource(vertexShader, vertexShaderSource); GL.CompileShader(vertexShader); fragmentShader = GL.CreateShader(ShaderType.FragmentShader); GL.ShaderSource(fragmentShader, fragmentShaderSource); GL.CompileShader(fragmentShader); glProgram = GL.CreateProgram(); GL.AttachShader(glProgram, vertexShader); GL.AttachShader(glProgram, fragmentShader); GL.LinkProgram(glProgram); GL.ValidateProgram(glProgram); GL.UseProgram(glProgram); Console.WriteLine(GL.GetError()); Console.WriteLine(GL.GetError()); GL.ClearColor(Color4.DarkGray); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Front); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp); world = new World(this); player = new Player(this); }
public void addToVbo(World world, Chunk chunk, VboGroup vbo, int x, int y, int z) { if (!flags.HasFlag(BlockFlags.invisible)) { vbo.addCube(new Vector3(x - .5f, y - .5f, z - .5f), new Vector3(x + .5f, y + .5f, z + .5f), sidesToRender(chunk, world, x, y, z), new Vector4[]{new Vector4(1, 1, 1, 1)}, textureCoords); } }
private Sides sidesToRender(Chunk chunk, World world, int x, int y, int z) { Sides sides = Sides.none; sides |= (world.getBlock(x - 1, y, z).flags.HasFlag(BlockFlags.abnormalRender) ? Sides.xLow : Sides.none); sides |= (world.getBlock(x + 1, y, z).flags.HasFlag(BlockFlags.abnormalRender) ? Sides.xHigh : Sides.none); sides |= (world.getBlock(x, y - 1, z).flags.HasFlag(BlockFlags.abnormalRender) ? Sides.yLow : Sides.none); sides |= (world.getBlock(x, y + 1, z).flags.HasFlag(BlockFlags.abnormalRender) ? Sides.yHigh : Sides.none); sides |= (world.getBlock(x, y, z - 1).flags.HasFlag(BlockFlags.abnormalRender) ? Sides.zLow : Sides.none); sides |= (world.getBlock(x, y, z + 1).flags.HasFlag(BlockFlags.abnormalRender) ? Sides.zHigh : Sides.none); //Console.WriteLine("Sides to render: "+sides.ToString()); return sides; }