Exemplo n.º 1
0
        public WorldRenderer(MainClass In, World For, float Aspect)
        {
            _for = For;
            _hmap = new HeightmapRenderer(this, _for.Terrain);
            FragmentShader fsimple = new FragmentShader("res/shader/simple.frag");
            FragmentShader fwater = new FragmentShader("res/shader/water.frag");
            FragmentShader fuwater = new FragmentShader("res/shader/underwater.frag");

            _simple = new ShaderProgram();
            _simple.AddFragShader(fsimple);
            GLUtil.PrintGLError("Simple");

            _underwater = new ShaderProgram();
            _underwater.AddFragShader(fuwater);
            GLUtil.PrintGLError("Underwater");

            _water = new ShaderProgram();
            _water.AddFragShader(fwater);
            GLUtil.PrintGLError("Water");

            _curr = _simple;

            _aspect = Aspect;
            _projectionMatrix = Matrix4.CreatePerspectiveFieldOfView((float)(FOV), _aspect, 0.01f, MAX_DEPTH);
            _modelview = Matrix4.CreateTranslation(-10f, -5f, -10f);
            _pos = new Vector3(10, 2, 10);
            _mviewstack = new Stack<Matrix4>();
            _in = In;
            _oldwidth = 0;
            _oldheight = 0;
        }
Exemplo n.º 2
0
 public void Init(MainClass Main)
 {
     //XXX:Make this better...
     _in = Main;
     //Game world setup.
     HeightMap map = new HeightMap("res/map.map");
     _pe = new PlayerEntity(new Vector3(0, map [0, 0] + 10, 0));
     _world = new World(map, _pe);
     //GFX setup
     _camOffset = new Vector3();
     _ren = new WorldRenderer(Main, _world, (float)Main.Width / Main.Height);
     GL.ClearColor(OpenTK.Graphics.Color4.SkyBlue);
     GL.Enable(EnableCap.DepthTest);
     GL.Enable(EnableCap.Fog);
     float[] fogColor = {
         OpenTK.Graphics.Color4.SkyBlue.R,
         OpenTK.Graphics.Color4.SkyBlue.G,
         OpenTK.Graphics.Color4.SkyBlue.B,
         OpenTK.Graphics.Color4.SkyBlue.A
     };
     GL.Fog(FogParameter.FogColor, fogColor);
     GL.Fog(FogParameter.FogEnd, WorldRenderer.MAX_DEPTH);
     GL.Fog(FogParameter.FogStart, 10f);
     //Input setup.
     System.Windows.Forms.Cursor.Hide();
     Main.Mouse.ButtonDown += ButtonDown;
     Main.Mouse.ButtonUp += ButtonUp;
     Main.Mouse.Move += MouseMove;
     //2D draw setup
     _rects = new LinkedList<Rect2D>();
     _healthbar = new Bitmap(100, 50);
     _healthbarRect = new Rect2D(_healthbar, 0, 0, 100, 50);
     _rects.AddFirst(_healthbarRect);
     //INput setup
     _in.MouseCaptureNeeded = true;
     _in.CaptureMouse = true;
 }
Exemplo n.º 3
0
        public void Tick(World W, float Delta)
        {
            _vel.X *= C_OF_FRICTION;
            _vel.Z *= C_OF_FRICTION;
            ApplyForce (World.GRAVITY);
            bool move = true;
            _pos += _vel;
            _vel += _acc;
            foreach (IEntity ent in W.Ents) {
                if (ent != this) {
                    bool colide = this.Collides (ent);
                    if (colide) {
                        this.OnCollide (ent);
                        ent.OnCollide (this);
                    }
                    move &= !colide;
                }
            }
            if (!move) {
                _pos -= _vel;
                _vel -= _acc;
            }
            _acc.X = _acc.Y = _acc.Z = 0;

            float mheight = W.Terrain [_pos.X, _pos.Z];
            if (_pos.Y <= mheight) {
                _onGround = true;
                _pos.Y = mheight;
            } else {
                _onGround = false;
            }
            if (_pos.Y - mheight < 0.01)
                _onGround = true;

            if (-BOUNDS_SIZE > _pos.X || _pos.X > BOUNDS_SIZE)
                _pos.X = Math.Sign (_pos.X) * BOUNDS_SIZE;
            if (-BOUNDS_SIZE > Pos.Z || _pos.Z > BOUNDS_SIZE)
                _pos.Z = Math.Sign (_pos.Z) * BOUNDS_SIZE;
            _delta = Delta;
            if (_hurtCooldown > 0)
                --_hurtCooldown;
        }